mirror of
https://github.com/hexastack/hexabot
synced 2025-04-30 11:04:37 +00:00
fix(frontend): refactor NLP value logic to use synchronous methods
This commit is contained in:
parent
d5863d2413
commit
cd31b873fd
@ -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).
|
* 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 { faGraduationCap } from "@fortawesome/free-solid-svg-icons";
|
||||||
import AddIcon from "@mui/icons-material/Add";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
import ArrowBackIcon from "@mui/icons-material/ArrowBack";
|
||||||
@ -64,22 +63,23 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
|
|||||||
params: searchPayload,
|
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 { mutate: deleteNlpValues } = useDeleteMany(EntityType.NLP_VALUE, {
|
||||||
onError: (error: Error) => {
|
onError: (error: Error) => {
|
||||||
toast.error(error.message || t("message.internal_server_error"));
|
toast.error(error.message || t("message.internal_server_error"));
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
toast.success(t("message.item_delete_success"));
|
toast.success(t("message.item_delete_success"));
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
const { mutateAsync: deleteNlpValue } = useDelete(
|
|
||||||
EntityType.NLP_VALUE,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
const { mutate: deleteNlpValues } = useDeleteMany(
|
|
||||||
EntityType.NLP_VALUE,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
const [selectedNlpValues, setSelectedNlpValues] = useState<string[]>([]);
|
const [selectedNlpValues, setSelectedNlpValues] = useState<string[]>([]);
|
||||||
const actionColumns = useActionColumns<INlpValue>(
|
const actionColumns = useActionColumns<INlpValue>(
|
||||||
EntityType.NLP_VALUE,
|
EntityType.NLP_VALUE,
|
||||||
@ -95,8 +95,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
|
|||||||
const isConfirmed = await dialogs.confirm(ConfirmDialogBody);
|
const isConfirmed = await dialogs.confirm(ConfirmDialogBody);
|
||||||
|
|
||||||
if (isConfirmed) {
|
if (isConfirmed) {
|
||||||
await deleteNlpValue(id);
|
deleteNlpValue(id);
|
||||||
refetchEntity();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -33,7 +33,18 @@ export const NlpValueForm: FC<
|
|||||||
entity: EntityType.NLP_ENTITY,
|
entity: EntityType.NLP_ENTITY,
|
||||||
format: Format.FULL,
|
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 { mutate: updateNlpValue } = useUpdate(EntityType.NLP_VALUE, {
|
||||||
onError: () => {
|
onError: () => {
|
||||||
rest.onError?.();
|
rest.onError?.();
|
||||||
toast.error(t("message.internal_server_error"));
|
toast.error(t("message.internal_server_error"));
|
||||||
@ -42,12 +53,7 @@ export const NlpValueForm: FC<
|
|||||||
rest.onSuccess?.();
|
rest.onSuccess?.();
|
||||||
toast.success(t("message.success_save"));
|
toast.success(t("message.success_save"));
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
const { mutateAsync: createNlpValue } = useCreate(
|
|
||||||
EntityType.NLP_VALUE,
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
const { mutate: updateNlpValue } = useUpdate(EntityType.NLP_VALUE, options);
|
|
||||||
const { reset, register, handleSubmit, control } = useForm<
|
const { reset, register, handleSubmit, control } = useForm<
|
||||||
INlpValueAttributes & {
|
INlpValueAttributes & {
|
||||||
expressions: string[];
|
expressions: string[];
|
||||||
@ -69,8 +75,7 @@ export const NlpValueForm: FC<
|
|||||||
if (data) {
|
if (data) {
|
||||||
updateNlpValue({ id: data.id, params });
|
updateNlpValue({ id: data.id, params });
|
||||||
} else {
|
} else {
|
||||||
await createNlpValue({ ...params, entity: String(query.id) });
|
createNlpValue({ ...params, entity: String(query.id) });
|
||||||
refetchEntity();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user