fix: support synonyms when we add NLU Values

This commit is contained in:
yassinedorbozgithub 2025-03-05 11:14:49 +01:00 committed by abdou6666
parent 7a2c8532d0
commit 8126b6f37b
3 changed files with 30 additions and 20 deletions

View File

@ -220,7 +220,12 @@ export const NlpValues = ({ entityId }: { entityId: string }) => {
startIcon={<AddIcon />}
variant="contained"
sx={{ float: "right" }}
onClick={() => dialogs.open(NlpValueFormDialog, null)}
onClick={() =>
dialogs.open(NlpValueFormDialog, {
data: null,
canHaveSynonyms,
})
}
>
{t("button.add")}
</Button>

View File

@ -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<ComponentFormProps<NlpValueFormProps>> = ({
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<
/>
</ContentItem>
<ContentItem>
<Controller
name="expressions"
control={control}
render={({ field }) => (
<MultipleInput label={t("label.synonyms")} {...field} />
)}
/>
</ContentItem>
{canHaveSynonyms ? (
<ContentItem>
<Controller
name="expressions"
control={control}
render={({ field }) => (
<MultipleInput label={t("label.synonyms")} {...field} />
)}
/>
</ContentItem>
) : null}
</ContentContainer>
</form>
</Wrapper>

View File

@ -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<T>,
) => (