Merge pull request #488 from Hexastack/fix/remove-nlp-import-dialog
Some checks are pending
Build and Push Docker API Image / build-and-push (push) Waiting to run
Build and Push Docker Base Image / build-and-push (push) Waiting to run
Build and Push Docker NLU Image / build-and-push (push) Waiting to run
Build and Push Docker UI Image / build-and-push (push) Waiting to run

fix: remove nlp import dialog
This commit is contained in:
Med Marrouchi 2024-12-29 14:40:30 +01:00 committed by GitHub
commit 4ea98abfbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 108 deletions

View File

@ -1,105 +0,0 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 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 CloseIcon from "@mui/icons-material/Close";
import { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
import { FC, useState } from "react";
import { useMutation, useQueryClient } from "react-query";
import AttachmentInput from "@/app-components/attachment/AttachmentInput";
import { DialogTitle } from "@/app-components/dialogs/DialogTitle";
import { ContentContainer } from "@/app-components/dialogs/layouts/ContentContainer";
import { ContentItem } from "@/app-components/dialogs/layouts/ContentItem";
import { isSameEntity } from "@/hooks/crud/helpers";
import { useApiClient } from "@/hooks/useApiClient";
import { DialogControlProps } from "@/hooks/useDialog";
import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate";
import { EntityType, QueryType } from "@/services/types";
export type NlpImportDialogProps = DialogControlProps<never>;
export const NlpImportDialog: FC<NlpImportDialogProps> = ({
open,
closeDialog,
...rest
}) => {
const [attachmentId, setAttachmentId] = useState<string | null>(null);
const { t } = useTranslate();
const queryClient = useQueryClient();
const { toast } = useToast();
const { apiClient } = useApiClient();
const { mutateAsync: importNlpSamples, isLoading: isImporting } = useMutation(
{
mutationFn: async (attachmentId: string | null) => {
attachmentId && (await apiClient.importNlpSamples(attachmentId));
},
onSuccess: () => {
queryClient.removeQueries({
predicate: ({ queryKey }) => {
const [qType, qEntity] = queryKey;
return (
((qType === QueryType.count || qType === QueryType.collection) &&
isSameEntity(qEntity, EntityType.NLP_SAMPLE)) ||
isSameEntity(qEntity, EntityType.NLP_SAMPLE_ENTITY) ||
isSameEntity(qEntity, EntityType.NLP_ENTITY) ||
isSameEntity(qEntity, EntityType.NLP_VALUE)
);
},
});
handleCloseDialog();
toast.success(t("message.success_save"));
},
onError() {
toast.error(t("message.internal_server_error"));
},
},
);
const handleCloseDialog = () => {
closeDialog();
setAttachmentId(null);
};
return (
<Dialog open={open} fullWidth onClose={handleCloseDialog} {...rest}>
<DialogTitle onClose={handleCloseDialog}>{t("title.import")}</DialogTitle>
<DialogContent>
<ContentContainer>
<ContentItem>
<AttachmentInput
format="basic"
accept="text/csv"
onChange={(id, _) => {
setAttachmentId(id);
}}
label=""
value={attachmentId}
/>
</ContentItem>
</ContentContainer>
</DialogContent>
<DialogActions>
<Button
disabled={!attachmentId || isImporting}
onClick={() => importNlpSamples(attachmentId)}
>
{t("button.import")}
</Button>
<Button
startIcon={<CloseIcon />}
variant="outlined"
onClick={handleCloseDialog}
disabled={isImporting}
>
{t("button.cancel")}
</Button>
</DialogActions>
</Dialog>
);
};

View File

@ -62,7 +62,6 @@ import { PermissionAction } from "@/types/permission.types";
import { getDateTimeFormatter } from "@/utils/date";
import { buildURL } from "@/utils/URL";
import { NlpImportDialog } from "../NlpImportDialog";
import { NlpSampleDialog } from "../NlpSampleDialog";
const NLP_SAMPLE_TYPE_COLORS = {
@ -150,7 +149,6 @@ export default function NlpSample() {
);
const deleteDialogCtl = useDialog<string>(false);
const editDialogCtl = useDialog<INlpDatasetSample>(false);
const importDialogCtl = useDialog<never>(false);
const actionColumns = getActionsColumn<INlpSample>(
[
{
@ -315,7 +313,6 @@ export default function NlpSample() {
}
}}
/>
<NlpImportDialog {...getDisplayDialogs(importDialogCtl)} />
<Grid container alignItems="center">
<Grid
container