Implemented Delete function
This commit is contained in:
parent
41cbd918b7
commit
ea211060b3
5 changed files with 464 additions and 440 deletions
779
src/frontend/package-lock.json
generated
779
src/frontend/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -2,11 +2,15 @@ import { cloneDeep } from "lodash";
|
||||||
import React, { ReactNode, useEffect, useRef, useState } from "react";
|
import React, { ReactNode, useEffect, useRef, useState } from "react";
|
||||||
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
||||||
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
||||||
|
import AddNewVariableButton from "../../../../components/addNewVariableButtonComponent/addNewVariableButton";
|
||||||
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
import CodeAreaComponent from "../../../../components/codeAreaComponent";
|
||||||
import DictComponent from "../../../../components/dictComponent";
|
import DictComponent from "../../../../components/dictComponent";
|
||||||
import Dropdown from "../../../../components/dropdownComponent";
|
import Dropdown from "../../../../components/dropdownComponent";
|
||||||
import FloatComponent from "../../../../components/floatComponent";
|
import FloatComponent from "../../../../components/floatComponent";
|
||||||
import IconComponent from "../../../../components/genericIconComponent";
|
import {
|
||||||
|
default as ForwardedIconComponent,
|
||||||
|
default as IconComponent,
|
||||||
|
} from "../../../../components/genericIconComponent";
|
||||||
import InputComponent from "../../../../components/inputComponent";
|
import InputComponent from "../../../../components/inputComponent";
|
||||||
import InputFileComponent from "../../../../components/inputFileComponent";
|
import InputFileComponent from "../../../../components/inputFileComponent";
|
||||||
import InputListComponent from "../../../../components/inputListComponent";
|
import InputListComponent from "../../../../components/inputListComponent";
|
||||||
|
|
@ -24,7 +28,8 @@ import {
|
||||||
OUTPUT_HANDLER_HOVER,
|
OUTPUT_HANDLER_HOVER,
|
||||||
TOOLTIP_EMPTY,
|
TOOLTIP_EMPTY,
|
||||||
} from "../../../../constants/constants";
|
} from "../../../../constants/constants";
|
||||||
import AddNewVariableButton from "../../../../components/addNewVariableButtonComponent/addNewVariableButton";
|
import { deleteGlobalVariable } from "../../../../controllers/API";
|
||||||
|
import DeleteConfirmationModal from "../../../../modals/DeleteConfirmationModal";
|
||||||
import useAlertStore from "../../../../stores/alertStore";
|
import useAlertStore from "../../../../stores/alertStore";
|
||||||
import useFlowStore from "../../../../stores/flowStore";
|
import useFlowStore from "../../../../stores/flowStore";
|
||||||
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
import useFlowsManagerStore from "../../../../stores/flowsManagerStore";
|
||||||
|
|
@ -77,7 +82,36 @@ export default function ParameterComponent({
|
||||||
const globalVariablesEntries = useGlobalVariablesStore(
|
const globalVariablesEntries = useGlobalVariablesStore(
|
||||||
(state) => state.globalVariablesEntries
|
(state) => state.globalVariablesEntries
|
||||||
);
|
);
|
||||||
const setNoticeData = useAlertStore((state) => state.setNoticeData);
|
|
||||||
|
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
|
||||||
|
const removeGlobalVariable = useGlobalVariablesStore(
|
||||||
|
(state) => state.removeGlobalVariable
|
||||||
|
);
|
||||||
|
function handleDelete(key: string) {
|
||||||
|
const id = getVariableId(key);
|
||||||
|
if (id !== undefined) {
|
||||||
|
deleteGlobalVariable(id).then((_) => {
|
||||||
|
removeGlobalVariable(key);
|
||||||
|
if (
|
||||||
|
data?.node?.template[name].value === key &&
|
||||||
|
data?.node?.template[name].load_from_db
|
||||||
|
) {
|
||||||
|
handleOnNewValue("");
|
||||||
|
setNode(data.id, (oldNode) => {
|
||||||
|
let newNode = cloneDeep(oldNode);
|
||||||
|
newNode.data = {
|
||||||
|
...newNode.data,
|
||||||
|
};
|
||||||
|
newNode.data.node.template[name].load_from_db = false;
|
||||||
|
return newNode;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.error("id is undefined");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const flow = currentFlow?.data?.nodes ?? null;
|
const flow = currentFlow?.data?.nodes ?? null;
|
||||||
|
|
||||||
|
|
@ -552,7 +586,7 @@ export default function ParameterComponent({
|
||||||
optionsIcon="Globe"
|
optionsIcon="Globe"
|
||||||
optionsButton={
|
optionsButton={
|
||||||
<AddNewVariableButton>
|
<AddNewVariableButton>
|
||||||
<CommandItem value={"new"}>
|
<CommandItem>
|
||||||
<IconComponent
|
<IconComponent
|
||||||
name="Plus"
|
name="Plus"
|
||||||
className={cn("mr-2 h-4 w-4 text-primary")}
|
className={cn("mr-2 h-4 w-4 text-primary")}
|
||||||
|
|
@ -562,6 +596,32 @@ export default function ParameterComponent({
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
</AddNewVariableButton>
|
</AddNewVariableButton>
|
||||||
}
|
}
|
||||||
|
optionButton={(option) => (
|
||||||
|
<DeleteConfirmationModal
|
||||||
|
onConfirm={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
handleDelete(option);
|
||||||
|
}}
|
||||||
|
description={'variable "' + option + '"'}
|
||||||
|
asChild
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
}}
|
||||||
|
className="pr-1"
|
||||||
|
>
|
||||||
|
<ForwardedIconComponent
|
||||||
|
name="Trash2"
|
||||||
|
className={cn(
|
||||||
|
"h-4 w-4 text-primary opacity-0 hover:text-status-red group-hover:opacity-100"
|
||||||
|
)}
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
</DeleteConfirmationModal>
|
||||||
|
)}
|
||||||
selectedOption={
|
selectedOption={
|
||||||
data?.node?.template[name].load_from_db ?? false
|
data?.node?.template[name].load_from_db ?? false
|
||||||
? data?.node?.template[name].value
|
? data?.node?.template[name].value
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ export default function InputComponent({
|
||||||
options = [],
|
options = [],
|
||||||
optionsPlaceholder = "Search options...",
|
optionsPlaceholder = "Search options...",
|
||||||
optionsButton,
|
optionsButton,
|
||||||
|
optionButton,
|
||||||
}: InputComponentType): JSX.Element {
|
}: InputComponentType): JSX.Element {
|
||||||
const [pwdVisible, setPwdVisible] = useState(false);
|
const [pwdVisible, setPwdVisible] = useState(false);
|
||||||
const refInput = useRef<HTMLInputElement>(null);
|
const refInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
@ -89,7 +90,7 @@ export default function InputComponent({
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Popover open={showOptions} onOpenChange={setShowOptions}>
|
<Popover modal open={showOptions} onOpenChange={setShowOptions}>
|
||||||
<PopoverAnchor>
|
<PopoverAnchor>
|
||||||
<Input
|
<Input
|
||||||
id={id}
|
id={id}
|
||||||
|
|
@ -142,7 +143,8 @@ export default function InputComponent({
|
||||||
<CommandGroup defaultChecked={false}>
|
<CommandGroup defaultChecked={false}>
|
||||||
{options.map((option, id) => (
|
{options.map((option, id) => (
|
||||||
<CommandItem
|
<CommandItem
|
||||||
key={id}
|
className="group"
|
||||||
|
key={option + id}
|
||||||
value={option}
|
value={option}
|
||||||
onSelect={(currentValue) => {
|
onSelect={(currentValue) => {
|
||||||
setSelectedOption &&
|
setSelectedOption &&
|
||||||
|
|
@ -154,17 +156,22 @@ export default function InputComponent({
|
||||||
setShowOptions(false);
|
setShowOptions(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ForwardedIconComponent
|
<div className="flex w-full items-center justify-between">
|
||||||
name="Check"
|
<div className="flex items-center">
|
||||||
className={cn(
|
<ForwardedIconComponent
|
||||||
"mr-2 h-4 w-4 text-primary",
|
name="Check"
|
||||||
selectedOption === option
|
className={cn(
|
||||||
? "opacity-100"
|
"mr-2 h-4 w-4 text-primary",
|
||||||
: "opacity-0"
|
selectedOption === option
|
||||||
)}
|
? "opacity-100"
|
||||||
aria-hidden="true"
|
: "opacity-0"
|
||||||
/>
|
)}
|
||||||
{option}
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
{option}
|
||||||
|
</div>
|
||||||
|
{optionButton && optionButton(option)}
|
||||||
|
</div>
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
))}
|
))}
|
||||||
{optionsButton && optionsButton}
|
{optionsButton && optionsButton}
|
||||||
|
|
|
||||||
|
|
@ -14,14 +14,18 @@ export default function DeleteConfirmationModal({
|
||||||
children,
|
children,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
description,
|
description,
|
||||||
|
asChild,
|
||||||
}: {
|
}: {
|
||||||
children: JSX.Element;
|
children: JSX.Element;
|
||||||
onConfirm: () => void;
|
onConfirm: (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void;
|
||||||
description?: string;
|
description?: string;
|
||||||
|
asChild?: boolean;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Dialog>
|
<Dialog>
|
||||||
<DialogTrigger tabIndex={-1}>{children}</DialogTrigger>
|
<DialogTrigger asChild={asChild} tabIndex={-1}>
|
||||||
|
{children}
|
||||||
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>
|
||||||
|
|
@ -39,16 +43,21 @@ export default function DeleteConfirmationModal({
|
||||||
Note: This action is irreversible.
|
Note: This action is irreversible.
|
||||||
</span>
|
</span>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<DialogClose>
|
<DialogClose asChild>
|
||||||
<Button className="mr-3" variant="outline">
|
<Button
|
||||||
|
onClick={(e) => e.stopPropagation()}
|
||||||
|
className="mr-3"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
</DialogClose>
|
||||||
|
<DialogClose asChild>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="destructive"
|
variant="destructive"
|
||||||
onClick={() => {
|
onClick={(e) => {
|
||||||
onConfirm();
|
onConfirm(e);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete
|
Delete
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ export type InputComponentType = {
|
||||||
optionsPlaceholder?: string;
|
optionsPlaceholder?: string;
|
||||||
options?: string[];
|
options?: string[];
|
||||||
optionsButton?: ReactElement;
|
optionsButton?: ReactElement;
|
||||||
|
optionButton?: (option: string) => ReactElement;
|
||||||
selectedOption?: string;
|
selectedOption?: string;
|
||||||
setSelectedOption?: (value: string) => void;
|
setSelectedOption?: (value: string) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue