1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-31 13:47:02 +02:00

fix: archive toggle no longer respects change request (#6882)

This commit is contained in:
Simon Hornby 2024-04-18 13:10:22 +02:00 committed by GitHub
parent fd4bcfffa5
commit 6b5cdc2d24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 10 deletions

View File

@ -112,14 +112,14 @@ test('Add multiple archive feature changes to change request', async () => {
expect(onClose).toBeCalledTimes(1); expect(onClose).toBeCalledTimes(1);
}); });
test('Skip change request', async () => { test('Skip change request does not affect archive', async () => {
const onClose = vi.fn(); const onClose = vi.fn();
const onConfirm = vi.fn(); const onConfirm = vi.fn();
setupHappyPathForChangeRequest(); setupHappyPathForChangeRequest();
setupArchiveValidation([]); setupArchiveValidation([]);
render( render(
<FeatureArchiveDialog <FeatureArchiveDialog
featureIds={['featureA', 'featureB']} featureIds={['featureA']}
projectId={'projectId'} projectId={'projectId'}
isOpen={true} isOpen={true}
onClose={onClose} onClose={onClose}
@ -129,16 +129,17 @@ test('Skip change request', async () => {
{ permissions: [{ permission: 'SKIP_CHANGE_REQUEST' }] }, { permissions: [{ permission: 'SKIP_CHANGE_REQUEST' }] },
); );
await screen.findByText('Archive feature toggles'); await screen.findByText('Archive feature toggle');
const button = await screen.findByText('Archive toggles'); const button = await screen.findByText('Add change to draft');
await waitFor(() => expect(button).toBeEnabled()); await waitFor(() => expect(button).toBeEnabled());
button.click(); button.click();
await waitFor(() => { await waitFor(() => {
expect(onClose).toBeCalledTimes(1); expect(onClose).toBeCalledTimes(1);
}); });
expect(onConfirm).toBeCalledTimes(0); // we didn't setup non Change Request flow so failure expect(onConfirm).toBeCalledTimes(1);
}); });
test('Show error message when multiple parents of orphaned children are archived', async () => { test('Show error message when multiple parents of orphaned children are archived', async () => {

View File

@ -181,15 +181,16 @@ const useActionButtonText = (projectId: string, isBulkArchive: boolean) => {
const getHighestEnvironment = const getHighestEnvironment =
useHighestPermissionChangeRequestEnvironment(projectId); useHighestPermissionChangeRequestEnvironment(projectId);
const environment = getHighestEnvironment(); const environment = getHighestEnvironment();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId); const { isChangeRequestConfiguredForReview } =
useChangeRequestsEnabled(projectId);
if ( if (
environment && environment &&
isChangeRequestConfigured(environment) && isChangeRequestConfiguredForReview(environment) &&
isBulkArchive isBulkArchive
) { ) {
return 'Add to change request'; return 'Add to change request';
} }
if (environment && isChangeRequestConfigured(environment)) { if (environment && isChangeRequestConfiguredForReview(environment)) {
return 'Add change to draft'; return 'Add change to draft';
} }
if (isBulkArchive) { if (isBulkArchive) {
@ -212,7 +213,8 @@ const useArchiveAction = ({
const { setToastData, setToastApiError } = useToast(); const { setToastData, setToastApiError } = useToast();
const { archiveFeatureToggle } = useFeatureApi(); const { archiveFeatureToggle } = useFeatureApi();
const { archiveFeatures } = useProjectApi(); const { archiveFeatures } = useProjectApi();
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId); const { isChangeRequestConfiguredForReview } =
useChangeRequestsEnabled(projectId);
const { addChange } = useChangeRequestApi(); const { addChange } = useChangeRequestApi();
const { refetch: refetchChangeRequests } = const { refetch: refetchChangeRequests } =
usePendingChangeRequests(projectId); usePendingChangeRequests(projectId);
@ -266,7 +268,10 @@ const useArchiveAction = ({
return async () => { return async () => {
try { try {
if (environment && isChangeRequestConfigured(environment)) { if (
environment &&
isChangeRequestConfiguredForReview(environment)
) {
await addArchiveToggleToChangeRequest(); await addArchiveToggleToChangeRequest();
} else if (isBulkArchive) { } else if (isBulkArchive) {
await archiveToggles(); await archiveToggles();