mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-27 11:02:16 +01:00
* refactor: fix child selector warnings * refactor: update react-router-dom * refactor: use BrowserRouter as in react-router docs * refactor: replace Redirect with Navigate * refactor: replace Switch with Routes * refactor: replace useHistory with useNavigate * refactor: replace useParams types with useRequiredPathParam * refactor: replace NavLink activeStyle with callback * refactor: fix matchPath arg order * refactor: Remove unused link state * refactor: delete broken snapshot test * refactor: render 404 page without redirect * refactor: normalize path parameter names * refactor: fix Route component usage
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
|
|
import { DialogContentText } from '@mui/material';
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
|
import { useFeature } from 'hooks/api/getters/useFeature/useFeature';
|
|
import React from 'react';
|
|
import useToast from 'hooks/useToast';
|
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
|
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
|
|
|
|
interface IStaleDialogProps {
|
|
open: boolean;
|
|
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
|
stale: boolean;
|
|
}
|
|
|
|
const StaleDialog = ({ open, setOpen, stale }: IStaleDialogProps) => {
|
|
const { setToastData, setToastApiError } = useToast();
|
|
const projectId = useRequiredPathParam('projectId');
|
|
const featureId = useRequiredPathParam('featureId');
|
|
const { patchFeatureToggle } = useFeatureApi();
|
|
const { refetchFeature } = useFeature(projectId, featureId);
|
|
|
|
const toggleToStaleContent = (
|
|
<DialogContentText>
|
|
Setting a toggle to stale marks it for cleanup
|
|
</DialogContentText>
|
|
);
|
|
const toggleToActiveContent = (
|
|
<DialogContentText>
|
|
Setting a toggle to active marks it as in active use
|
|
</DialogContentText>
|
|
);
|
|
|
|
const toggleActionText = stale ? 'active' : 'stale';
|
|
|
|
const onSubmit = async (event: React.SyntheticEvent) => {
|
|
event.stopPropagation();
|
|
|
|
try {
|
|
const patch = [{ op: 'replace', path: '/stale', value: !stale }];
|
|
await patchFeatureToggle(projectId, featureId, patch);
|
|
refetchFeature();
|
|
setOpen(false);
|
|
} catch (err: unknown) {
|
|
setToastApiError(formatUnknownError(err));
|
|
}
|
|
|
|
if (stale) {
|
|
setToastData({
|
|
type: 'success',
|
|
title: "And we're back!",
|
|
text: 'The toggle is no longer marked as stale.',
|
|
});
|
|
} else {
|
|
setToastData({
|
|
type: 'success',
|
|
title: 'A job well done.',
|
|
text: 'The toggle has been marked as stale.',
|
|
});
|
|
}
|
|
};
|
|
|
|
const onCancel = () => {
|
|
setOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<Dialogue
|
|
open={open}
|
|
secondaryButtonText={'Cancel'}
|
|
primaryButtonText={`Flip to ${toggleActionText}`}
|
|
title={`Set feature status to ${toggleActionText}`}
|
|
onClick={onSubmit}
|
|
onClose={onCancel}
|
|
>
|
|
<>
|
|
<ConditionallyRender
|
|
condition={stale}
|
|
show={toggleToActiveContent}
|
|
elseShow={toggleToStaleContent}
|
|
/>
|
|
</>
|
|
</Dialogue>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default StaleDialog;
|