From e281dc782415c8165afeddabaecf76f6071e9c53 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Tue, 4 Mar 2025 13:01:39 +0100 Subject: [PATCH 01/10] feat: display synonyms inputs --- .../nlp/components/NlpValueForm.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index e9e154be0..72eb2fd29 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -25,7 +25,7 @@ import { INlpValue, INlpValueAttributes } from "@/types/nlp-value.types"; export const NlpValueForm: FC< ComponentFormProps<{ data: INlpValue; canHaveSynonyms: boolean }> > = ({ data: props, Wrapper = Fragment, WrapperProps, ...rest }) => { - const { data, canHaveSynonyms } = props || {}; + const { data } = props || {}; const { t } = useTranslate(); const { toast } = useToast(); const { query } = useRouter(); @@ -112,17 +112,15 @@ export const NlpValueForm: FC< /> - {canHaveSynonyms ? ( - - ( - - )} - /> - - ) : null} + + ( + + )} + /> + From 7a2c8532d0efff2b178fc6e1937405dbbc3b68a9 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Tue, 4 Mar 2025 14:12:39 +0100 Subject: [PATCH 02/10] fix: make synonyms upper case & use translation --- frontend/src/components/nlp/components/NlpValueForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 72eb2fd29..03cc3d2a9 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -117,7 +117,7 @@ export const NlpValueForm: FC< name="expressions" control={control} render={({ field }) => ( - + )} /> From 8126b6f37b2fbfe9e6309181d99cdb89a2ef6ab7 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Wed, 5 Mar 2025 11:14:49 +0100 Subject: [PATCH 03/10] fix: support synonyms when we add NLU Values --- .../components/nlp/components/NlpValue.tsx | 7 +++- .../nlp/components/NlpValueForm.tsx | 35 ++++++++++++------- .../nlp/components/NlpValueFormDialog.tsx | 8 ++--- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/nlp/components/NlpValue.tsx b/frontend/src/components/nlp/components/NlpValue.tsx index 12c462e8e..46393d228 100644 --- a/frontend/src/components/nlp/components/NlpValue.tsx +++ b/frontend/src/components/nlp/components/NlpValue.tsx @@ -220,7 +220,12 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { startIcon={} variant="contained" sx={{ float: "right" }} - onClick={() => dialogs.open(NlpValueFormDialog, null)} + onClick={() => + dialogs.open(NlpValueFormDialog, { + data: null, + canHaveSynonyms, + }) + } > {t("button.add")} diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 03cc3d2a9..31490c6bd 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -22,10 +22,17 @@ import { EntityType, Format } from "@/services/types"; import { ComponentFormProps } from "@/types/common/dialogs.types"; import { INlpValue, INlpValueAttributes } from "@/types/nlp-value.types"; -export const NlpValueForm: FC< - ComponentFormProps<{ data: INlpValue; canHaveSynonyms: boolean }> -> = ({ data: props, Wrapper = Fragment, WrapperProps, ...rest }) => { - const { data } = props || {}; +export type NlpValueFormProps = { + data?: INlpValue | null; + canHaveSynonyms?: boolean; +}; +export const NlpValueForm: FC> = ({ + data: props, + Wrapper = Fragment, + WrapperProps, + ...rest +}) => { + const { data, canHaveSynonyms } = props || {}; const { t } = useTranslate(); const { toast } = useToast(); const { query } = useRouter(); @@ -112,15 +119,17 @@ export const NlpValueForm: FC< /> - - ( - - )} - /> - + {canHaveSynonyms ? ( + + ( + + )} + /> + + ) : null} diff --git a/frontend/src/components/nlp/components/NlpValueFormDialog.tsx b/frontend/src/components/nlp/components/NlpValueFormDialog.tsx index a8ef383a9..dbc8c75ed 100644 --- a/frontend/src/components/nlp/components/NlpValueFormDialog.tsx +++ b/frontend/src/components/nlp/components/NlpValueFormDialog.tsx @@ -8,15 +8,11 @@ import { GenericFormDialog } from "@/app-components/dialogs"; import { ComponentFormDialogProps } from "@/types/common/dialogs.types"; -import { INlpValue } from "@/types/nlp-value.types"; -import { NlpValueForm } from "./NlpValueForm"; +import { NlpValueForm, NlpValueFormProps } from "./NlpValueForm"; export const NlpValueFormDialog = < - T extends { data: INlpValue; canHaveSynonyms: boolean } = { - data: INlpValue; - canHaveSynonyms: boolean; - }, + T extends NlpValueFormProps = NlpValueFormProps, >( props: ComponentFormDialogProps, ) => ( From 107e9cc8d356f5bd9b74490317718a097e4b6493 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Wed, 5 Mar 2025 12:52:15 +0100 Subject: [PATCH 04/10] fix: update NlpValueFormProps type --- frontend/src/components/nlp/components/NlpValueForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 31490c6bd..97c9831c6 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -23,7 +23,7 @@ import { ComponentFormProps } from "@/types/common/dialogs.types"; import { INlpValue, INlpValueAttributes } from "@/types/nlp-value.types"; export type NlpValueFormProps = { - data?: INlpValue | null; + data: INlpValue | null; canHaveSynonyms?: boolean; }; export const NlpValueForm: FC> = ({ From 0af186a0c5d5a5ca2113c503b77d58186ad3b401 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Tue, 25 Mar 2025 13:30:16 +0100 Subject: [PATCH 05/10] fix: display an empty synonym input --- frontend/src/components/nlp/components/NlpValueForm.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 97c9831c6..20bea27de 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -125,7 +125,11 @@ export const NlpValueForm: FC> = ({ name="expressions" control={control} render={({ field }) => ( - + )} /> From b1a9f56b7cbf2fc592dc698871a1255d8c16ba23 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 4 Apr 2025 09:22:47 +0100 Subject: [PATCH 06/10] fix: apply feedback (wip) --- .../components/nlp/components/NlpValue.tsx | 10 +++---- .../nlp/components/NlpValueForm.tsx | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/nlp/components/NlpValue.tsx b/frontend/src/components/nlp/components/NlpValue.tsx index 46393d228..bed19eff0 100644 --- a/frontend/src/components/nlp/components/NlpValue.tsx +++ b/frontend/src/components/nlp/components/NlpValue.tsx @@ -34,7 +34,6 @@ import { useToast } from "@/hooks/useToast"; import { useTranslate } from "@/hooks/useTranslate"; import { PageHeader } from "@/layout/content/PageHeader"; import { EntityType, Format } from "@/services/types"; -import { NlpLookups } from "@/types/nlp-entity.types"; import { INlpValue } from "@/types/nlp-value.types"; import { PermissionAction } from "@/types/permission.types"; import { getDateTimeFormatter } from "@/utils/date"; @@ -52,7 +51,6 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { entity: EntityType.NLP_ENTITY, format: Format.FULL, }); - const canHaveSynonyms = nlpEntity?.lookups?.[0] === NlpLookups.keywords; const { onSearch, searchPayload } = useSearch({ $eq: [{ entity: entityId }], $or: ["doc", "value"] @@ -88,7 +86,10 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { { label: ActionColumnLabel.Edit, action: (row) => - dialogs.open(NlpValueFormDialog, { data: row, canHaveSynonyms }), + dialogs.open(NlpValueFormDialog, { + defaultValues: row, + presetValues: nlpEntity, + }), }, { label: ActionColumnLabel.Delete, @@ -222,8 +223,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { sx={{ float: "right" }} onClick={() => dialogs.open(NlpValueFormDialog, { - data: null, - canHaveSynonyms, + presetValues: nlpEntity, }) } > diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index 20bea27de..b5a87a75a 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -20,11 +20,12 @@ import { useToast } from "@/hooks/useToast"; import { useTranslate } from "@/hooks/useTranslate"; import { EntityType, Format } from "@/services/types"; import { ComponentFormProps } from "@/types/common/dialogs.types"; +import { INlpEntity, NlpLookups } from "@/types/nlp-entity.types"; import { INlpValue, INlpValueAttributes } from "@/types/nlp-value.types"; export type NlpValueFormProps = { - data: INlpValue | null; - canHaveSynonyms?: boolean; + defaultValues?: INlpValue; + presetValues: INlpEntity; }; export const NlpValueForm: FC> = ({ data: props, @@ -32,14 +33,18 @@ export const NlpValueForm: FC> = ({ WrapperProps, ...rest }) => { - const { data, canHaveSynonyms } = props || {}; + const { defaultValues: nlpValue, presetValues: nlpEntity } = props || { + defaultValues: null, + presetValues: null, + }; const { t } = useTranslate(); const { toast } = useToast(); const { query } = useRouter(); - const { refetch: refetchEntity } = useGet(data?.entity || String(query.id), { + const { refetch: refetchEntity } = useGet(nlpEntity?.id!, { entity: EntityType.NLP_ENTITY, format: Format.FULL, }); + const canHaveSynonyms = nlpEntity?.lookups?.[0] === NlpLookups.keywords; const { mutate: createNlpValue } = useCreate(EntityType.NLP_VALUE, { onError: () => { rest.onError?.(); @@ -67,9 +72,9 @@ export const NlpValueForm: FC> = ({ } >({ defaultValues: { - value: data?.value || "", + value: nlpValue?.value || "", doc: data?.doc || "", - expressions: data?.expressions || [], + expressions: nlpValue?.expressions || [], }, }); const validationRules = { @@ -80,24 +85,24 @@ export const NlpValueForm: FC> = ({ description: {}, }; const onSubmitForm = async (params: INlpValueAttributes) => { - if (data) { - updateNlpValue({ id: data.id, params }); + if (nlpValue) { + updateNlpValue({ id: nlpValue.id, params }); } else { createNlpValue({ ...params, entity: String(query.id) }); } }; useEffect(() => { - if (data) { + if (nlpValue) { reset({ - value: data.value, - expressions: data.expressions, + value: nlpValue.value, + expressions: nlpValue.expressions, doc: data.doc, }); } else { reset(); } - }, [data, reset]); + }, [nlpValue, reset]); return ( From ec81062b9dc7240ed95d3c721592435633032def Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 4 Apr 2025 11:28:50 +0100 Subject: [PATCH 07/10] fix: conflict --- frontend/src/components/nlp/components/NlpValueForm.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index b5a87a75a..db6b862da 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -73,7 +73,7 @@ export const NlpValueForm: FC> = ({ >({ defaultValues: { value: nlpValue?.value || "", - doc: data?.doc || "", + doc: nlpValue?.doc || "", expressions: nlpValue?.expressions || [], }, }); @@ -97,7 +97,7 @@ export const NlpValueForm: FC> = ({ reset({ value: nlpValue.value, expressions: nlpValue.expressions, - doc: data.doc, + doc: nlpValue.doc, }); } else { reset(); From 7f61a3f5fc4ca2f170f76759e48acc6f6e9ddb10 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 4 Apr 2025 11:34:59 +0100 Subject: [PATCH 08/10] fix: apply feedback --- frontend/src/components/nlp/components/NlpValueForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index db6b862da..b23e18491 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -44,7 +44,7 @@ export const NlpValueForm: FC> = ({ entity: EntityType.NLP_ENTITY, format: Format.FULL, }); - const canHaveSynonyms = nlpEntity?.lookups?.[0] === NlpLookups.keywords; + const canHaveSynonyms = nlpEntity?.lookups.includes(NlpLookups.keywords); const { mutate: createNlpValue } = useCreate(EntityType.NLP_VALUE, { onError: () => { rest.onError?.(); From a404cfa10e6d787c5ed472a19234a70eb88bd863 Mon Sep 17 00:00:00 2001 From: abdou6666 Date: Fri, 4 Apr 2025 11:42:42 +0100 Subject: [PATCH 09/10] fix: typecheck --- frontend/src/components/nlp/components/NlpValue.tsx | 4 ++-- frontend/src/components/nlp/components/NlpValueForm.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/nlp/components/NlpValue.tsx b/frontend/src/components/nlp/components/NlpValue.tsx index bed19eff0..22d8daa29 100644 --- a/frontend/src/components/nlp/components/NlpValue.tsx +++ b/frontend/src/components/nlp/components/NlpValue.tsx @@ -53,7 +53,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { }); const { onSearch, searchPayload } = useSearch({ $eq: [{ entity: entityId }], - $or: ["doc", "value"] + $or: ["doc", "value"], }); const { dataGridProps } = useFind( { entity: EntityType.NLP_VALUE }, @@ -104,7 +104,7 @@ export const NlpValues = ({ entityId }: { entityId: string }) => { ], t("label.operations"), ); - const synonymsColumn = { + const synonymsColumn = { flex: 3, field: "synonyms", headerName: t("label.synonyms"), diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index b23e18491..a20942946 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -25,7 +25,7 @@ import { INlpValue, INlpValueAttributes } from "@/types/nlp-value.types"; export type NlpValueFormProps = { defaultValues?: INlpValue; - presetValues: INlpEntity; + presetValues: INlpEntity | undefined; }; export const NlpValueForm: FC> = ({ data: props, From ccd929062375ec0079606a8d610a4ff0b759d156 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Sat, 12 Apr 2025 05:17:03 +0100 Subject: [PATCH 10/10] fix: apply feedback updates --- .../src/components/nlp/components/NlpValueForm.tsx | 10 +++++++++- .../components/nlp/components/NlpValueFormDialog.tsx | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/nlp/components/NlpValueForm.tsx b/frontend/src/components/nlp/components/NlpValueForm.tsx index a20942946..a20af55f9 100644 --- a/frontend/src/components/nlp/components/NlpValueForm.tsx +++ b/frontend/src/components/nlp/components/NlpValueForm.tsx @@ -66,7 +66,13 @@ export const NlpValueForm: FC> = ({ toast.success(t("message.success_save")); }, }); - const { reset, register, handleSubmit, control } = useForm< + const { + reset, + register, + handleSubmit, + control, + formState: { errors }, + } = useForm< INlpValueAttributes & { expressions: string[]; } @@ -111,8 +117,10 @@ export const NlpValueForm: FC> = ({ diff --git a/frontend/src/components/nlp/components/NlpValueFormDialog.tsx b/frontend/src/components/nlp/components/NlpValueFormDialog.tsx index dbc8c75ed..491db2e27 100644 --- a/frontend/src/components/nlp/components/NlpValueFormDialog.tsx +++ b/frontend/src/components/nlp/components/NlpValueFormDialog.tsx @@ -18,6 +18,7 @@ export const NlpValueFormDialog = < ) => ( Form={NlpValueForm} + rowKey="defaultValues" addText="title.new_nlp_entity_value" editText="title.edit_nlp_value" {...props}