2025-08-15 13:24:55 +00:00
|
|
|
import React, { useContext, useState } from "react";
|
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
import Button from "components/buttons/Button";
|
2025-09-02 19:55:47 +00:00
|
|
|
import TooltipTruncatedText from "components/TooltipTruncatedText";
|
2025-08-15 13:24:55 +00:00
|
|
|
import { ISecret } from "interfaces/secrets";
|
|
|
|
|
import { NotificationContext } from "context/notification";
|
|
|
|
|
|
2025-08-22 14:22:37 +00:00
|
|
|
import formatErrorResponse from "utilities/format_error_response";
|
2025-08-15 13:24:55 +00:00
|
|
|
import secretsAPI from "services/entities/secrets";
|
|
|
|
|
|
2026-04-21 15:13:17 +00:00
|
|
|
interface DeleteCustomVariableModalProps {
|
2025-08-15 13:24:55 +00:00
|
|
|
secret: ISecret | undefined;
|
2025-09-02 19:55:47 +00:00
|
|
|
onExit: () => void;
|
Refactor paginated list to use UseQuery (#33669)
# Details
As mentioned in a previous front-end sync, I realized after having to
add a `reload()` method to the `PaginatedList` imperative handle that I
had strayed too far from the path. The original concept for this
component was for it to be fully self-contained, so the parent didn't
have to concern itself with pagination at all other than being told what
page to load. But the addition of an `onChangePage` property isn't a
tragedy and is totally worth the reduction in code, consistency with use
of `useQuery` elsewhere and React best practice of passing data from
parent to child.
This refactor still retains the use of the imperative handle for
querying the "dirty state" of the list, so parents don't have to manage
that state themselves.
## Testing
- [X] Added/updated automated tests
Updated PaginatedList tests as needed. Also confirmed that tests for the
upstream components (PoliciesPaginatedList, Secrets, RunBatchScriptModal
and ScriptBatchProgress) all passed without any modification.
- [X] QA'd all new/changed functionality manually
Added enough data to paginate each of the components that uses
PaginatedList, confirmed pagination still works and dirty state
functionality (in PoliciesPaginatedList) still works. Also confirmed
add/delete functionality works as expected in Secrets.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Consistent, responsive pagination across Scripts, Secrets, Hosts, and
Policies pages with clearer loading and empty states.
- Bug Fixes
- Delete Secret modal now reliably displays errors and refreshes the
list after deletion.
- Refactor
- Unified data-driven pagination flow for improved performance and
smoother navigation.
- Simplified list interactions by removing manual reloads.
- Tests
- Updated tests to align with the new pagination behavior and data flow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-10-28 16:27:05 +00:00
|
|
|
onDeleteSecret: () => void;
|
2025-08-15 13:24:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-04-21 15:13:17 +00:00
|
|
|
const baseClass = "delete-custom-variable-modal";
|
2025-08-15 13:24:55 +00:00
|
|
|
|
2026-04-21 15:13:17 +00:00
|
|
|
const DeleteCustomVariableModal = ({
|
2025-08-15 13:24:55 +00:00
|
|
|
secret,
|
2025-09-02 19:55:47 +00:00
|
|
|
onExit,
|
Refactor paginated list to use UseQuery (#33669)
# Details
As mentioned in a previous front-end sync, I realized after having to
add a `reload()` method to the `PaginatedList` imperative handle that I
had strayed too far from the path. The original concept for this
component was for it to be fully self-contained, so the parent didn't
have to concern itself with pagination at all other than being told what
page to load. But the addition of an `onChangePage` property isn't a
tragedy and is totally worth the reduction in code, consistency with use
of `useQuery` elsewhere and React best practice of passing data from
parent to child.
This refactor still retains the use of the imperative handle for
querying the "dirty state" of the list, so parents don't have to manage
that state themselves.
## Testing
- [X] Added/updated automated tests
Updated PaginatedList tests as needed. Also confirmed that tests for the
upstream components (PoliciesPaginatedList, Secrets, RunBatchScriptModal
and ScriptBatchProgress) all passed without any modification.
- [X] QA'd all new/changed functionality manually
Added enough data to paginate each of the components that uses
PaginatedList, confirmed pagination still works and dirty state
functionality (in PoliciesPaginatedList) still works. Also confirmed
add/delete functionality works as expected in Secrets.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Consistent, responsive pagination across Scripts, Secrets, Hosts, and
Policies pages with clearer loading and empty states.
- Bug Fixes
- Delete Secret modal now reliably displays errors and refreshes the
list after deletion.
- Refactor
- Unified data-driven pagination flow for improved performance and
smoother navigation.
- Simplified list interactions by removing manual reloads.
- Tests
- Updated tests to align with the new pagination behavior and data flow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-10-28 16:27:05 +00:00
|
|
|
onDeleteSecret,
|
2026-04-21 15:13:17 +00:00
|
|
|
}: DeleteCustomVariableModalProps) => {
|
2025-08-15 13:24:55 +00:00
|
|
|
const [isDeleting, setIsDeleting] = useState(false);
|
|
|
|
|
|
|
|
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
|
|
|
|
|
|
|
|
const onClickDelete = async () => {
|
|
|
|
|
if (!secret) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setIsDeleting(true);
|
|
|
|
|
try {
|
|
|
|
|
await secretsAPI.deleteSecret(secret.id);
|
2025-08-26 20:45:02 +00:00
|
|
|
renderFlash("success", "Variable successfully deleted.");
|
Refactor paginated list to use UseQuery (#33669)
# Details
As mentioned in a previous front-end sync, I realized after having to
add a `reload()` method to the `PaginatedList` imperative handle that I
had strayed too far from the path. The original concept for this
component was for it to be fully self-contained, so the parent didn't
have to concern itself with pagination at all other than being told what
page to load. But the addition of an `onChangePage` property isn't a
tragedy and is totally worth the reduction in code, consistency with use
of `useQuery` elsewhere and React best practice of passing data from
parent to child.
This refactor still retains the use of the imperative handle for
querying the "dirty state" of the list, so parents don't have to manage
that state themselves.
## Testing
- [X] Added/updated automated tests
Updated PaginatedList tests as needed. Also confirmed that tests for the
upstream components (PoliciesPaginatedList, Secrets, RunBatchScriptModal
and ScriptBatchProgress) all passed without any modification.
- [X] QA'd all new/changed functionality manually
Added enough data to paginate each of the components that uses
PaginatedList, confirmed pagination still works and dirty state
functionality (in PoliciesPaginatedList) still works. Also confirmed
add/delete functionality works as expected in Secrets.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Consistent, responsive pagination across Scripts, Secrets, Hosts, and
Policies pages with clearer loading and empty states.
- Bug Fixes
- Delete Secret modal now reliably displays errors and refreshes the
list after deletion.
- Refactor
- Unified data-driven pagination flow for improved performance and
smoother navigation.
- Simplified list interactions by removing manual reloads.
- Tests
- Updated tests to align with the new pagination behavior and data flow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-10-28 16:27:05 +00:00
|
|
|
onDeleteSecret();
|
2025-08-15 13:24:55 +00:00
|
|
|
} catch (error) {
|
2025-08-22 14:22:37 +00:00
|
|
|
const errorObject = formatErrorResponse(error);
|
|
|
|
|
const isInUseError =
|
|
|
|
|
errorObject.http_status === 409 &&
|
|
|
|
|
/used by/.test(errorObject?.base ?? "");
|
|
|
|
|
const message =
|
|
|
|
|
isInUseError && typeof errorObject?.base === "string"
|
|
|
|
|
? errorObject.base
|
|
|
|
|
: "An error occurred while deleting the custom variable. Please try again.";
|
|
|
|
|
renderFlash("error", message);
|
Refactor paginated list to use UseQuery (#33669)
# Details
As mentioned in a previous front-end sync, I realized after having to
add a `reload()` method to the `PaginatedList` imperative handle that I
had strayed too far from the path. The original concept for this
component was for it to be fully self-contained, so the parent didn't
have to concern itself with pagination at all other than being told what
page to load. But the addition of an `onChangePage` property isn't a
tragedy and is totally worth the reduction in code, consistency with use
of `useQuery` elsewhere and React best practice of passing data from
parent to child.
This refactor still retains the use of the imperative handle for
querying the "dirty state" of the list, so parents don't have to manage
that state themselves.
## Testing
- [X] Added/updated automated tests
Updated PaginatedList tests as needed. Also confirmed that tests for the
upstream components (PoliciesPaginatedList, Secrets, RunBatchScriptModal
and ScriptBatchProgress) all passed without any modification.
- [X] QA'd all new/changed functionality manually
Added enough data to paginate each of the components that uses
PaginatedList, confirmed pagination still works and dirty state
functionality (in PoliciesPaginatedList) still works. Also confirmed
add/delete functionality works as expected in Secrets.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- New Features
- Consistent, responsive pagination across Scripts, Secrets, Hosts, and
Policies pages with clearer loading and empty states.
- Bug Fixes
- Delete Secret modal now reliably displays errors and refreshes the
list after deletion.
- Refactor
- Unified data-driven pagination flow for improved performance and
smoother navigation.
- Simplified list interactions by removing manual reloads.
- Tests
- Updated tests to align with the new pagination behavior and data flow.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-10-28 16:27:05 +00:00
|
|
|
onExit();
|
2025-08-15 13:24:55 +00:00
|
|
|
} finally {
|
|
|
|
|
setIsDeleting(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
title="Delete custom variable?"
|
2025-09-02 19:55:47 +00:00
|
|
|
onExit={onExit}
|
2025-08-15 13:24:55 +00:00
|
|
|
className={baseClass}
|
|
|
|
|
>
|
2026-03-10 22:30:55 +00:00
|
|
|
<div className={`${baseClass}__message`}>
|
|
|
|
|
<span>
|
|
|
|
|
This will delete the
|
|
|
|
|
<b>
|
|
|
|
|
<TooltipTruncatedText value={secret?.name} />
|
|
|
|
|
</b>
|
|
|
|
|
custom variable.
|
|
|
|
|
</span>
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
If this custom variable is used in any configuration profiles or
|
|
|
|
|
scripts, they will fail. To resolve, edit the configuration profile or
|
|
|
|
|
script.
|
|
|
|
|
</div>
|
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
<Button
|
|
|
|
|
variant="alert"
|
|
|
|
|
onClick={onClickDelete}
|
|
|
|
|
isLoading={isDeleting}
|
|
|
|
|
disabled={isDeleting}
|
|
|
|
|
>
|
|
|
|
|
Delete
|
|
|
|
|
</Button>
|
|
|
|
|
<Button variant="inverse-alert" onClick={onExit}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-08-15 13:24:55 +00:00
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2026-04-21 15:13:17 +00:00
|
|
|
export default DeleteCustomVariableModal;
|