mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-15 17:50:48 +02:00
feat: bulk enable disable change requests (#3801)
This commit is contained in:
parent
db61a8a40c
commit
980332a074
@ -8,6 +8,9 @@ import type { FeatureSchema } from 'openapi';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
|
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
|
||||||
import useProject from 'hooks/api/getters/useProject/useProject';
|
import useProject from 'hooks/api/getters/useProject/useProject';
|
||||||
|
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
||||||
|
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
||||||
|
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
|
||||||
|
|
||||||
interface IExportDialogProps {
|
interface IExportDialogProps {
|
||||||
showExportDialog: boolean;
|
showExportDialog: boolean;
|
||||||
@ -33,8 +36,12 @@ export const BulkDisableDialog = ({
|
|||||||
}: IExportDialogProps) => {
|
}: IExportDialogProps) => {
|
||||||
const [selected, setSelected] = useState(environments[0]);
|
const [selected, setSelected] = useState(environments[0]);
|
||||||
const { bulkToggleFeaturesEnvironmentOff } = useFeatureApi();
|
const { bulkToggleFeaturesEnvironmentOff } = useFeatureApi();
|
||||||
const { refetch } = useProject(projectId);
|
const { addChange } = useChangeRequestApi();
|
||||||
const { setToastApiError } = useToast();
|
const { refetch: refetchProject } = useProject(projectId);
|
||||||
|
const { setToastApiError, setToastData } = useToast();
|
||||||
|
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
|
||||||
|
const { refetch: refetchChangeRequests } =
|
||||||
|
usePendingChangeRequests(projectId);
|
||||||
|
|
||||||
const getOptions = () =>
|
const getOptions = () =>
|
||||||
environments.map(env => ({
|
environments.map(env => ({
|
||||||
@ -44,12 +51,35 @@ export const BulkDisableDialog = ({
|
|||||||
|
|
||||||
const onClick = async () => {
|
const onClick = async () => {
|
||||||
try {
|
try {
|
||||||
await bulkToggleFeaturesEnvironmentOff(
|
if (isChangeRequestConfigured(selected)) {
|
||||||
projectId,
|
await addChange(
|
||||||
data.map(feature => feature.name),
|
projectId,
|
||||||
selected
|
selected,
|
||||||
);
|
data.map(feature => ({
|
||||||
refetch();
|
action: 'updateEnabled',
|
||||||
|
feature: feature.name,
|
||||||
|
payload: { enabled: false },
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
refetchChangeRequests();
|
||||||
|
setToastData({
|
||||||
|
text: 'Your disabled feature toggles changes have been added to change request',
|
||||||
|
type: 'success',
|
||||||
|
title: 'Changes added to a draft',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await bulkToggleFeaturesEnvironmentOff(
|
||||||
|
projectId,
|
||||||
|
data.map(feature => feature.name),
|
||||||
|
selected
|
||||||
|
);
|
||||||
|
refetchProject();
|
||||||
|
setToastData({
|
||||||
|
text: 'Your feature toggles have been disabled',
|
||||||
|
type: 'success',
|
||||||
|
title: 'Features disabled',
|
||||||
|
});
|
||||||
|
}
|
||||||
onClose();
|
onClose();
|
||||||
onConfirm?.();
|
onConfirm?.();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
@ -57,13 +87,17 @@ export const BulkDisableDialog = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buttonText = isChangeRequestConfigured(selected)
|
||||||
|
? 'Add to change request'
|
||||||
|
: 'Disable toggles';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialogue
|
<Dialogue
|
||||||
open={showExportDialog}
|
open={showExportDialog}
|
||||||
title="Disable feature toggles"
|
title="Disable feature toggles"
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
primaryButtonText="Disable toggles"
|
primaryButtonText={buttonText}
|
||||||
secondaryButtonText="Cancel"
|
secondaryButtonText="Cancel"
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
|
@ -8,6 +8,9 @@ import type { FeatureSchema } from 'openapi';
|
|||||||
import { formatUnknownError } from 'utils/formatUnknownError';
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
|
import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
|
||||||
import useProject from 'hooks/api/getters/useProject/useProject';
|
import useProject from 'hooks/api/getters/useProject/useProject';
|
||||||
|
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
|
||||||
|
import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useChangeRequestApi';
|
||||||
|
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
|
||||||
|
|
||||||
interface IExportDialogProps {
|
interface IExportDialogProps {
|
||||||
showExportDialog: boolean;
|
showExportDialog: boolean;
|
||||||
@ -33,8 +36,12 @@ export const BulkEnableDialog = ({
|
|||||||
}: IExportDialogProps) => {
|
}: IExportDialogProps) => {
|
||||||
const [selected, setSelected] = useState(environments[0]);
|
const [selected, setSelected] = useState(environments[0]);
|
||||||
const { bulkToggleFeaturesEnvironmentOn } = useFeatureApi();
|
const { bulkToggleFeaturesEnvironmentOn } = useFeatureApi();
|
||||||
const { refetch } = useProject(projectId);
|
const { addChange } = useChangeRequestApi();
|
||||||
const { setToastApiError } = useToast();
|
const { refetch: refetchProject } = useProject(projectId);
|
||||||
|
const { setToastApiError, setToastData } = useToast();
|
||||||
|
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);
|
||||||
|
const { refetch: refetchChangeRequests } =
|
||||||
|
usePendingChangeRequests(projectId);
|
||||||
|
|
||||||
const getOptions = () =>
|
const getOptions = () =>
|
||||||
environments.map(env => ({
|
environments.map(env => ({
|
||||||
@ -44,12 +51,36 @@ export const BulkEnableDialog = ({
|
|||||||
|
|
||||||
const onClick = async () => {
|
const onClick = async () => {
|
||||||
try {
|
try {
|
||||||
await bulkToggleFeaturesEnvironmentOn(
|
if (isChangeRequestConfigured(selected)) {
|
||||||
projectId,
|
await addChange(
|
||||||
data.map(feature => feature.name),
|
projectId,
|
||||||
selected
|
selected,
|
||||||
);
|
data.map(feature => ({
|
||||||
refetch();
|
action: 'updateEnabled',
|
||||||
|
feature: feature.name,
|
||||||
|
payload: { enabled: true },
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
refetchChangeRequests();
|
||||||
|
setToastData({
|
||||||
|
text: 'Your enable feature toggles changes have been added to change request',
|
||||||
|
type: 'success',
|
||||||
|
title: 'Changes added to a draft',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
await bulkToggleFeaturesEnvironmentOn(
|
||||||
|
projectId,
|
||||||
|
data.map(feature => feature.name),
|
||||||
|
selected
|
||||||
|
);
|
||||||
|
refetchProject();
|
||||||
|
setToastData({
|
||||||
|
text: 'Your feature toggles have been enabled',
|
||||||
|
type: 'success',
|
||||||
|
title: 'Features enabled',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
onConfirm?.();
|
onConfirm?.();
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
@ -57,13 +88,17 @@ export const BulkEnableDialog = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buttonText = isChangeRequestConfigured(selected)
|
||||||
|
? 'Add to change request'
|
||||||
|
: 'Enabled toggles';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialogue
|
<Dialogue
|
||||||
open={showExportDialog}
|
open={showExportDialog}
|
||||||
title="Enable feature toggles"
|
title="Enable feature toggles"
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
primaryButtonText="Enable toggles"
|
primaryButtonText={buttonText}
|
||||||
secondaryButtonText="Cancel"
|
secondaryButtonText="Cancel"
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
|
@ -28,7 +28,7 @@ export const useChangeRequestApi = () => {
|
|||||||
const addChange = async (
|
const addChange = async (
|
||||||
project: string,
|
project: string,
|
||||||
environment: string,
|
environment: string,
|
||||||
payload: IChangeSchema
|
payload: IChangeSchema | IChangeSchema[]
|
||||||
) => {
|
) => {
|
||||||
trackEvent('change_request', {
|
trackEvent('change_request', {
|
||||||
props: {
|
props: {
|
||||||
|
Loading…
Reference in New Issue
Block a user