Skip to content

Commit

Permalink
fix(frontend): refactor NLP value logic to use synchronous methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yassinedorbozgithub committed Feb 6, 2025
1 parent d5863d2 commit cd31b87
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
25 changes: 12 additions & 13 deletions frontend/src/components/nlp/components/NlpValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/


import { faGraduationCap } from "@fortawesome/free-solid-svg-icons";
import AddIcon from "@mui/icons-material/Add";
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
Expand Down Expand Up @@ -64,22 +63,23 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
params: searchPayload,
},
);
const options = {
const { mutate: deleteNlpValue } = useDelete(EntityType.NLP_VALUE, {
onError: (error: Error) => {
toast.error(error.message || t("message.internal_server_error"));
},
onSuccess() {
refetchEntity();
toast.success(t("message.item_delete_success"));
},
};
const { mutateAsync: deleteNlpValue } = useDelete(
EntityType.NLP_VALUE,
options,
);
const { mutate: deleteNlpValues } = useDeleteMany(
EntityType.NLP_VALUE,
options,
);
});
const { mutate: deleteNlpValues } = useDeleteMany(EntityType.NLP_VALUE, {
onError: (error: Error) => {
toast.error(error.message || t("message.internal_server_error"));
},
onSuccess() {
toast.success(t("message.item_delete_success"));
},
});
const [selectedNlpValues, setSelectedNlpValues] = useState<string[]>([]);
const actionColumns = useActionColumns<INlpValue>(
EntityType.NLP_VALUE,
Expand All @@ -95,8 +95,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
const isConfirmed = await dialogs.confirm(ConfirmDialogBody);

if (isConfirmed) {
await deleteNlpValue(id);
refetchEntity();
deleteNlpValue(id);
}
},
},
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/components/nlp/components/NlpValueForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,27 @@ export const NlpValueForm: FC<
entity: EntityType.NLP_ENTITY,
format: Format.FULL,
});
const options = {
const { mutate: createNlpValue } = useCreate(EntityType.NLP_VALUE, {
onError: () => {
rest.onError?.();
toast.error(t("message.internal_server_error"));
},
onSuccess() {
rest.onSuccess?.();
refetchEntity();
toast.success(t("message.success_save"));
},
};
const { mutateAsync: createNlpValue } = useCreate(
EntityType.NLP_VALUE,
options,
);
const { mutate: updateNlpValue } = useUpdate(EntityType.NLP_VALUE, options);
});
const { mutate: updateNlpValue } = useUpdate(EntityType.NLP_VALUE, {
onError: () => {
rest.onError?.();
toast.error(t("message.internal_server_error"));
},
onSuccess() {
rest.onSuccess?.();
toast.success(t("message.success_save"));
},
});
const { reset, register, handleSubmit, control } = useForm<
INlpValueAttributes & {
expressions: string[];
Expand All @@ -69,8 +75,7 @@ export const NlpValueForm: FC<
if (data) {
updateNlpValue({ id: data.id, params });
} else {
await createNlpValue({ ...params, entity: String(query.id) });
refetchEntity();
createNlpValue({ ...params, entity: String(query.id) });
}
};

Expand Down

0 comments on commit cd31b87

Please sign in to comment.