mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 04:48:51 +00:00
fix: remove nlp import dialog
This commit is contained in:
parent
54bbe94164
commit
5347b8fa39
@ -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>
|
|
||||||
);
|
|
||||||
};
|
|
@ -62,7 +62,6 @@ import { PermissionAction } from "@/types/permission.types";
|
|||||||
import { getDateTimeFormatter } from "@/utils/date";
|
import { getDateTimeFormatter } from "@/utils/date";
|
||||||
import { buildURL } from "@/utils/URL";
|
import { buildURL } from "@/utils/URL";
|
||||||
|
|
||||||
import { NlpImportDialog } from "../NlpImportDialog";
|
|
||||||
import { NlpSampleDialog } from "../NlpSampleDialog";
|
import { NlpSampleDialog } from "../NlpSampleDialog";
|
||||||
|
|
||||||
const NLP_SAMPLE_TYPE_COLORS = {
|
const NLP_SAMPLE_TYPE_COLORS = {
|
||||||
@ -150,7 +149,6 @@ export default function NlpSample() {
|
|||||||
);
|
);
|
||||||
const deleteDialogCtl = useDialog<string>(false);
|
const deleteDialogCtl = useDialog<string>(false);
|
||||||
const editDialogCtl = useDialog<INlpDatasetSample>(false);
|
const editDialogCtl = useDialog<INlpDatasetSample>(false);
|
||||||
const importDialogCtl = useDialog<never>(false);
|
|
||||||
const actionColumns = getActionsColumn<INlpSample>(
|
const actionColumns = getActionsColumn<INlpSample>(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -315,7 +313,6 @@ export default function NlpSample() {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<NlpImportDialog {...getDisplayDialogs(importDialogCtl)} />
|
|
||||||
<Grid container alignItems="center">
|
<Grid container alignItems="center">
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
|
Loading…
Reference in New Issue
Block a user