forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable Bulk Delete variables on variables list page (apache#45761)
* initial setup * disable other buttons * delete dialog text * checkbox colour * decrease limit
- Loading branch information
1 parent
6c4eb3c
commit 2b1b399
Showing
8 changed files
with
226 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
airflow/ui/src/pages/Variables/DeleteVariablesButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*! | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { Flex, useDisclosure, Text, VStack, Heading, Code } from "@chakra-ui/react"; | ||
import { FiTrash, FiTrash2 } from "react-icons/fi"; | ||
|
||
import { ErrorAlert } from "src/components/ErrorAlert"; | ||
import { Button, Dialog } from "src/components/ui"; | ||
import { useBulkDeleteVariables } from "src/queries/useBulkDeleteVariables"; | ||
|
||
type Props = { | ||
readonly clearSelections: VoidFunction; | ||
readonly deleteKeys: Array<string>; | ||
}; | ||
|
||
const DeleteVariablesButton = ({ clearSelections, deleteKeys: variableKeys }: Props) => { | ||
const { onClose, onOpen, open } = useDisclosure(); | ||
const { error, isPending, mutate } = useBulkDeleteVariables({ clearSelections, onSuccessConfirm: onClose }); | ||
|
||
return ( | ||
<> | ||
<Button | ||
onClick={() => { | ||
onOpen(); | ||
}} | ||
size="sm" | ||
variant="outline" | ||
> | ||
<FiTrash2 /> | ||
Delete | ||
</Button> | ||
|
||
<Dialog.Root onOpenChange={onClose} open={open} size="xl"> | ||
<Dialog.Content backdrop> | ||
<Dialog.Header> | ||
<VStack align="start" gap={4}> | ||
<Heading size="xl">Delete Variable{variableKeys.length > 1 ? "s" : ""}</Heading> | ||
</VStack> | ||
</Dialog.Header> | ||
|
||
<Dialog.CloseTrigger /> | ||
|
||
<Dialog.Body width="full"> | ||
<Text color="gray.solid" fontSize="md" fontWeight="semibold" mb={4}> | ||
You are about to delete{" "} | ||
<strong> | ||
{variableKeys.length} variable{variableKeys.length > 1 ? "s" : ""}. | ||
</strong> | ||
<br /> | ||
<Code mb={2} mt={2} p={4}> | ||
{variableKeys.join(", ")} | ||
</Code> | ||
<br /> | ||
This action is permanent and cannot be undone.{" "} | ||
<strong>Are you sure you want to proceed?</strong> | ||
</Text> | ||
<ErrorAlert error={error} /> | ||
<Flex justifyContent="end" mt={3}> | ||
<Button | ||
colorPalette="red" | ||
loading={isPending} | ||
onClick={() => { | ||
mutate({ | ||
requestBody: { | ||
actions: [ | ||
{ | ||
action: "delete" as const, | ||
action_if_not_exists: "fail", | ||
keys: variableKeys, | ||
}, | ||
], | ||
}, | ||
}); | ||
}} | ||
> | ||
<FiTrash /> <Text fontWeight="bold">Yes, Delete</Text> | ||
</Button> | ||
</Flex> | ||
</Dialog.Body> | ||
</Dialog.Content> | ||
</Dialog.Root> | ||
</> | ||
); | ||
}; | ||
|
||
export default DeleteVariablesButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*! | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
|
||
import { useVariableServiceBulkVariables, useVariableServiceGetVariablesKey } from "openapi/queries"; | ||
import { toaster } from "src/components/ui"; | ||
|
||
type Props = { | ||
readonly clearSelections: VoidFunction; | ||
readonly onSuccessConfirm: VoidFunction; | ||
}; | ||
|
||
export const useBulkDeleteVariables = ({ clearSelections, onSuccessConfirm }: Props) => { | ||
const queryClient = useQueryClient(); | ||
const [error, setError] = useState<unknown>(undefined); | ||
|
||
const onSuccess = async (responseData: { delete?: { errors: Array<unknown>; success: Array<string> } }) => { | ||
await queryClient.invalidateQueries({ | ||
queryKey: [useVariableServiceGetVariablesKey], | ||
}); | ||
|
||
if (responseData.delete) { | ||
const { errors, success } = responseData.delete; | ||
|
||
if (Array.isArray(errors) && errors.length > 0) { | ||
const apiError = errors[0] as { error: string }; | ||
|
||
setError({ | ||
body: { detail: apiError.error }, | ||
}); | ||
} else if (Array.isArray(success) && success.length > 0) { | ||
toaster.create({ | ||
description: `${success.length} variables deleted successfully. Keys: ${success.join(", ")}`, | ||
title: "Delete Variables Request Successful", | ||
type: "success", | ||
}); | ||
clearSelections(); | ||
onSuccessConfirm(); | ||
} | ||
} | ||
}; | ||
|
||
const onError = (_error: unknown) => { | ||
setError(_error); | ||
}; | ||
|
||
const { isPending, mutate } = useVariableServiceBulkVariables({ | ||
onError, | ||
onSuccess, | ||
}); | ||
|
||
return { error, isPending, mutate }; | ||
}; |