Skip to content

Commit

Permalink
MAT-7791: update delete function
Browse files Browse the repository at this point in the history
  • Loading branch information
chubert-sb committed Dec 6, 2024
1 parent 772ff06 commit fb69bb3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ArgumentsProps {
functionArguments?: FunctionArgument[];
canEdit: boolean;
addArgumentToFunctionsArguments: Function;
deleteArgumentFromFunctionArguments: Function;
}

const availableDataTypes = [
Expand All @@ -35,7 +36,12 @@ const availableDataTypes = [
];

export default function ArgumentSection(props: ArgumentsProps) {
const { addArgumentToFunctionsArguments, functionArguments, canEdit } = props;
const {
addArgumentToFunctionsArguments,
deleteArgumentFromFunctionArguments,
functionArguments,
canEdit,
} = props;
const [functionDataType, setFunctionDataType] = useState("");
const [confirmationDialog, setConfirmationDialog] = useState<boolean>(false);

Expand Down Expand Up @@ -159,7 +165,11 @@ export default function ArgumentSection(props: ArgumentsProps) {
</Button>
</div>
<div style={{ paddingTop: "24px" }}>
<Arguments functionArguments={functionArguments} canEdit={canEdit} />
<Arguments
functionArguments={functionArguments}
canEdit={canEdit}
handleDeleteArgument={deleteArgumentFromFunctionArguments}
/>
</div>
<ConfirmationDialog
open={confirmationDialog}
Expand Down
30 changes: 26 additions & 4 deletions src/CqlBuilderPanel/functionsSection/argumentSection/Arguments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import toastReducer from "../../../common/ToastReducer";

type PropTypes = {
functionArguments: Array<FunctionArgument>;
handleDeleteArgument?: (argument) => void;
handleDeleteArgument?: Function;
canEdit: boolean;
};

Expand All @@ -51,7 +51,7 @@ const Arguments = ({
const [visibleArguments, setVisibleArguments] = useState<FunctionArgument[]>(
[]
);

const [selectedArgument, setSelectedArgument] = useState<FunctionArgument>();
const [deleteDialogOpen, setDeleteDialogOpen] = useState<boolean>(false);

// toast utilities
Expand Down Expand Up @@ -118,6 +118,21 @@ const Arguments = ({
managePagination();
}, [functionArguments, currentPage, currentLimit]);

const deleteFunctionArgument = () => {
handleDeleteArgument(selectedArgument);
setDeleteDialogOpen(false);
dispatch({
type: "SHOW_TOAST",
payload: {
type: "success",
message:
"Argument " +
selectedArgument.argumentName +
" has been successfully removed from the function",
},
});
};

// table data
const data = visibleArguments.map((argument, i) => {
return {
Expand Down Expand Up @@ -179,7 +194,14 @@ const Arguments = ({
"data-testid": `delete-button-${row.id}`,
"aria-label": `delete-button-${row.id}`,
size: "small",
onClick: () => {},
onClick: () => {
// const rowModal = table.getRow(row.id).original;
setSelectedArgument({
argumentName: row.row.original.name,
dataType: row.row.original.datatype,
} as FunctionArgument);
setDeleteDialogOpen(true);
},
}}
>
<DeleteOutlineIcon color="error" />
Expand Down Expand Up @@ -278,7 +300,7 @@ const Arguments = ({
/>
<MadieDeleteDialog
open={deleteDialogOpen}
onContinue={() => handleDeleteArgument(null)}
onContinue={() => deleteFunctionArgument()}
onClose={() => setDeleteDialogOpen(false)}
dialogTitle="Are you sure?"
name={"this Argument"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ export default function FunctionBuilder({
formik.setFieldValue("functionsArguments", newArgs);
};

const deleteArgumentFromFunctionArguments = (fn) => {
const newArgs = formik.values.functionsArguments.filter(
(argument) =>
argument?.argumentName !== fn.argumentName &&
argument?.dataType !== fn.dataType
);
formik.setFieldValue("functionsArguments", newArgs);
};

return (
<div>
<form id="function-form" onSubmit={formik.handleSubmit}>
Expand Down Expand Up @@ -126,6 +135,9 @@ export default function FunctionBuilder({
<ArgumentSection
canEdit={canEdit}
addArgumentToFunctionsArguments={addArgumentToFunctionsArguments}
deleteArgumentFromFunctionArguments={
deleteArgumentFromFunctionArguments
}
functionArguments={formik.values.functionsArguments}
/>
</ExpandingSection>
Expand Down

0 comments on commit fb69bb3

Please sign in to comment.