Skip to content

Commit

Permalink
Merge branch 'main' into rename_processGroup_to_processDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
RonFed authored Dec 19, 2024
2 parents a78ee54 + b5795e7 commit e3ff1cc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ export const ActionDrawer: React.FC<Props> = () => {
ACTION_OPTIONS.find(({ id }) => id === 'attributes')?.items?.find(({ type }) => type === item.type) ||
ACTION_OPTIONS.find(({ id }) => id === 'sampler')?.items?.find(({ type }) => type === item.type);

if (!found) return undefined;

loadFormWithDrawerItem(selectedItem);

return found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const buildMonitorsList = (exportedSignals: ExportedSignals): string =>
.filter((key) => exportedSignals[key])
.join(', ');

const buildCard = (destination: ActualDestination, destinationTypeDetails: DestinationDetailsResponse['destinationTypeDetails']) => {
const buildCard = (destination: ActualDestination, destinationTypeDetails?: DestinationDetailsResponse['destinationTypeDetails']) => {
const { exportedSignals, destinationType, fields } = destination;

const arr: DataCardRow[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,22 @@ export const DestinationDrawer: React.FC<Props> = () => {
const [isFormDirty, setIsFormDirty] = useState(false);

const cardData = useMemo(() => {
if (!selectedItem || !destinationTypeDetails) return [];
if (!selectedItem) return [];

const { item } = selectedItem as { item: ActualDestination };
const arr = buildCard(item, destinationTypeDetails);

return arr;
}, [selectedItem, destinationTypeDetails]);

const thisDestination = useMemo(() => {
const thisDestinationType = useMemo(() => {
if (!destinationTypes.length || !selectedItem || !isEditing) {
resetFormData();
return undefined;
}

const { item } = selectedItem as { item: ActualDestination };
const found = destinationTypes.map(({ items }) => items.filter(({ type }) => type === item.destinationType.type)).filter((arr) => !!arr.length)[0][0];

if (!found) return undefined;
const found = destinationTypes.map(({ items }) => items.filter(({ type }) => type === item.destinationType.type)).filter((arr) => !!arr.length)?.[0]?.[0];

loadFormWithDrawerItem(selectedItem);

Expand Down Expand Up @@ -119,7 +117,7 @@ export const DestinationDrawer: React.FC<Props> = () => {
<FormContainer>
<DestinationFormBody
isUpdate
destination={thisDestination}
destination={thisDestinationType}
formData={formData}
formErrors={formErrors}
validateForm={validateForm}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export const RuleDrawer: React.FC<Props> = () => {
const { item } = selectedItem as { item: InstrumentationRuleSpecMapped };
const found = RULE_OPTIONS.find(({ type }) => type === item.type);

if (!found) return undefined;

loadFormWithDrawerItem(selectedItem);

return found;
Expand Down
15 changes: 14 additions & 1 deletion frontend/webapp/hooks/sources/useSourceCRUD.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from 'react';
import { useMutation } from '@apollo/client';
import { useNotificationStore } from '@/store';
import { ACTION, getSseTargetFromId } from '@/utils';
Expand All @@ -16,6 +17,18 @@ export const useSourceCRUD = (params?: Params) => {
const { data, refetch } = useComputePlatform();
const { addNotification } = useNotificationStore();

const startPolling = useCallback(async () => {
let retries = 0;
const maxRetries = 5;
const retryInterval = 1 * 1000; // time in milliseconds

while (retries < maxRetries) {
await new Promise((resolve) => setTimeout(resolve, retryInterval));
refetch();
retries++;
}
}, [refetch]);

const notifyUser = (type: NOTIFICATION_TYPE, title: string, message: string, id?: WorkloadId) => {
addNotification({
type,
Expand All @@ -33,7 +46,7 @@ export const useSourceCRUD = (params?: Params) => {

const handleComplete = (title: string, message: string, id?: WorkloadId) => {
notifyUser(NOTIFICATION_TYPE.SUCCESS, title, message, id);
refetch();
startPolling();
params?.onSuccess?.(title);
};

Expand Down

0 comments on commit e3ff1cc

Please sign in to comment.