Skip to content

Commit

Permalink
feat: disable bulk toggles flag (#3827)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed May 22, 2023
1 parent 40185e9 commit e34c9bc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
Expand Up @@ -8,6 +8,8 @@ import { ManageTags } from './ManageTags';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
import { BulkDisableDialog } from 'component/feature/FeatureToggleList/BulkDisableDialog';
import { BulkEnableDialog } from 'component/feature/FeatureToggleList/BulkEnableDialog';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';

interface IProjectFeaturesBatchActionsProps {
selectedIds: string[];
Expand All @@ -18,6 +20,7 @@ interface IProjectFeaturesBatchActionsProps {
export const ProjectFeaturesBatchActions: FC<
IProjectFeaturesBatchActionsProps
> = ({ selectedIds, data, projectId }) => {
const { uiConfig } = useUiConfig();
const [showExportDialog, setShowExportDialog] = useState(false);
const [showBulkEnableDialog, setShowBulkEnableDialog] = useState(false);
const [showBulkDisableDialog, setShowBulkDisableDialog] = useState(false);
Expand Down Expand Up @@ -59,20 +62,32 @@ export const ProjectFeaturesBatchActions: FC<

return (
<>
<Button
variant="outlined"
size="small"
onClick={() => setShowBulkEnableDialog(true)}
>
Enable
</Button>
<Button
variant="outlined"
size="small"
onClick={() => setShowBulkDisableDialog(true)}
>
Disable
</Button>
<ConditionallyRender
condition={Boolean(uiConfig?.flags?.disableBulkToggle)}
show={null}
elseShow={
<Button
variant="outlined"
size="small"
onClick={() => setShowBulkEnableDialog(true)}
>
Enable
</Button>
}
/>
<ConditionallyRender
condition={Boolean(uiConfig?.flags?.disableBulkToggle)}
show={null}
elseShow={
<Button
variant="outlined"
size="small"
onClick={() => setShowBulkDisableDialog(true)}
>
Disable
</Button>
}
/>
<ArchiveButton projectId={projectId} features={selectedIds} />
<Button
variant="outlined"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/interfaces/uiConfig.ts
Expand Up @@ -50,6 +50,7 @@ export interface IFlags {
googleAuthEnabled?: boolean;
variantMetrics?: boolean;
strategyImprovements?: boolean;
disableBulkToggle?: boolean;
}

export interface IVersionInfo {
Expand Down
14 changes: 12 additions & 2 deletions src/lib/routes/admin-api/project/project-features.ts
Expand Up @@ -186,7 +186,7 @@ export default class ProjectFeaturesController extends Controller {
permission: UPDATE_FEATURE_ENVIRONMENT,
middleware: [
openApiService.validPath({
tags: ['Unstable'],
tags: ['Features'],
description:
'This endpoint enables multiple feature toggles.',
summary: 'Bulk enable a list of features.',
Expand All @@ -206,7 +206,7 @@ export default class ProjectFeaturesController extends Controller {
permission: UPDATE_FEATURE_ENVIRONMENT,
middleware: [
openApiService.validPath({
tags: ['Unstable'],
tags: ['Features'],
description:
'This endpoint disables multiple feature toggles.',
summary: 'Bulk disabled a list of features.',
Expand Down Expand Up @@ -748,6 +748,11 @@ export default class ProjectFeaturesController extends Controller {
const { shouldActivateDisabledStrategies } = req.query;
const { features } = req.body;

if (this.flagResolver.isEnabled('disableBulkToggle')) {
res.status(409).end();
return;
}

await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).bulkUpdateEnabled(
projectId,
Expand Down Expand Up @@ -775,6 +780,11 @@ export default class ProjectFeaturesController extends Controller {
const { shouldActivateDisabledStrategies } = req.query;
const { features } = req.body;

if (this.flagResolver.isEnabled('disableBulkToggle')) {
res.status(409).end();
return;
}

await this.startTransaction(async (tx) =>
this.transactionalFeatureToggleService(tx).bulkUpdateEnabled(
projectId,
Expand Down
3 changes: 2 additions & 1 deletion src/lib/types/experimental.ts
Expand Up @@ -20,7 +20,8 @@ export type IFlagKey =
| 'demo'
| 'strategyImprovements'
| 'googleAuthEnabled'
| 'variantMetrics';
| 'variantMetrics'
| 'disableBulkToggle';

export type IFlags = Partial<{ [key in IFlagKey]: boolean | Variant }>;

Expand Down
Expand Up @@ -9678,7 +9678,7 @@ If the provided project does not exist, the list of events will be empty.",
},
"summary": "Bulk disabled a list of features.",
"tags": [
"Unstable",
"Features",
],
},
},
Expand Down Expand Up @@ -9722,7 +9722,7 @@ If the provided project does not exist, the list of events will be empty.",
},
"summary": "Bulk enable a list of features.",
"tags": [
"Unstable",
"Features",
],
},
},
Expand Down

0 comments on commit e34c9bc

Please sign in to comment.