Skip to content

Commit 24d4ae5

Browse files
committed
fix flag archive and reset sampling
1 parent ce84abc commit 24d4ae5

File tree

5 files changed

+68
-38
lines changed

5 files changed

+68
-38
lines changed

ui/web-v2/src/components/FeatureConfirmDialog/index.tsx

+13-12
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,15 @@ export const FeatureConfirmDialog: FC<FeatureConfirmDialogProps> = ({
268268
// });
269269
// };
270270

271-
const checkSubmitBtnDisabled = () => {
272-
// if (
273-
// // selectedSwitchEnabledType === SwitchEnabledType.SCHEDULE &&
274-
// saveFeatureType === SaveFeatureType.SCHEDULE &&
275-
// !scheduleErrorMessage
276-
// ) {
277-
// return false;
278-
// }
279-
};
271+
// const checkSubmitBtnDisabled = () => {
272+
// if (
273+
// // selectedSwitchEnabledType === SwitchEnabledType.SCHEDULE &&
274+
// saveFeatureType === SaveFeatureType.SCHEDULE &&
275+
// !scheduleErrorMessage
276+
// ) {
277+
// return false;
278+
// }
279+
// };
280280

281281
return (
282282
<Modal
@@ -293,7 +293,7 @@ export const FeatureConfirmDialog: FC<FeatureConfirmDialogProps> = ({
293293
<div className="mt-2">
294294
<p className="text-sm text-gray-500">{description}</p>
295295
</div>
296-
{flagList.length > 0 && (
296+
{flagList.length > 0 && !feature?.archived && (
297297
<div className="rounded-md bg-red-50 p-4 mt-4">
298298
<div className="flex">
299299
<div className="flex-shrink-0">
@@ -366,7 +366,7 @@ export const FeatureConfirmDialog: FC<FeatureConfirmDialogProps> = ({
366366
id="comment"
367367
rows={3}
368368
className="input-text w-full"
369-
disabled={flagList.length > 0}
369+
disabled={flagList.length > 0 && !feature?.archived}
370370
/>
371371
<p className="input-error">
372372
{errors.comment && (
@@ -536,7 +536,8 @@ export const FeatureConfirmDialog: FC<FeatureConfirmDialogProps> = ({
536536
</div>
537537
)
538538
}
539-
{!isArchive && (
539+
{/* {!isArchive && ( */}
540+
{flagList.length > 0 && !feature?.archived ? null : (
540541
<div className="mt-4 space-y-2">
541542
<div className="flex items-center space-x-2">
542543
<input

ui/web-v2/src/components/FeatureTargetingForm/index.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,12 @@ export const FeatureTargetingForm: FC<FeatureTargetingFormProps> = memo(
211211
</div>
212212
<div className="flex items-center text-primary border-r border-gray-300 px-4 space-x-2">
213213
<PencilIcon className="w-4 h-4" />
214-
<button className="text-sm font-normal">Edit Schedule</button>
214+
<button
215+
className="text-sm font-normal"
216+
onClick={onOpenConfirmDialog}
217+
>
218+
Edit Schedule
219+
</button>
215220
</div>
216221
<div className="flex items-center text-primary border-r border-gray-300 px-4 space-x-2">
217222
<EyeIcon className="w-5 h-5" />

ui/web-v2/src/modules/features.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
UnarchiveFeatureCommand,
2727
Command
2828
} from '../proto/feature/command_pb';
29-
import { Feature, StringListValue } from '../proto/feature/feature_pb';
29+
import { Feature } from '../proto/feature/feature_pb';
3030
import {
3131
ArchiveFeatureRequest,
3232
CreateFeatureRequest,
@@ -58,6 +58,7 @@ import {
5858
RolloutStrategy,
5959
Strategy
6060
} from '../proto/feature/strategy_pb';
61+
import { StringListValue } from '../proto/common/string_pb';
6162

6263
const MODULE_NAME = 'features';
6364

@@ -331,6 +332,8 @@ export interface UpdateFeatureParams {
331332
name?: string;
332333
description?: string;
333334
tags?: string[];
335+
archived?: boolean;
336+
resetSampling?: boolean;
334337
}
335338

336339
export const updateFeature = createAsyncThunk<
@@ -395,6 +398,18 @@ export const updateFeature = createAsyncThunk<
395398
request.setTags(mapTags(params.tags));
396399
}
397400

401+
if (params.archived !== undefined) {
402+
console.log('archived set');
403+
request.setArchived(new BoolValue().setValue(params.archived));
404+
}
405+
406+
if (params.resetSampling) {
407+
console.log('resetSampling set');
408+
request.setResetSamplingSeed(
409+
new BoolValue().setValue(params.resetSampling)
410+
);
411+
}
412+
398413
await featureGrpc.updateFeature(request);
399414
});
400415

ui/web-v2/src/pages/feature/index.tsx

+28-14
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,28 @@ export const FeatureIndexPage: FC = memo(() => {
470470
);
471471

472472
const handleArchive = useCallback(
473-
async (data) => {
474-
dispatch(
475-
data.feature.archived
473+
async (data, saveFeatureType) => {
474+
const handleDispatch = async (action) => {
475+
await dispatch(action);
476+
archiveReset();
477+
setIsArchiveConfirmDialogOpen(false);
478+
history.replace(
479+
`${PAGE_PATH_ROOT}${currentEnvironment.urlCode}${PAGE_PATH_FEATURES}`
480+
);
481+
updateFeatureList(null, 1);
482+
};
483+
484+
if (saveFeatureType === SaveFeatureType.SCHEDULE) {
485+
handleDispatch(
486+
updateFeature({
487+
environmentId: currentEnvironment.id,
488+
id: data.feature.id,
489+
comment: data.comment,
490+
archived: !data.feature.archived
491+
})
492+
);
493+
} else {
494+
const action = data.feature.archived
476495
? unarchiveFeature({
477496
environmentId: currentEnvironment.id,
478497
id: data.feature.id,
@@ -482,15 +501,10 @@ export const FeatureIndexPage: FC = memo(() => {
482501
environmentId: currentEnvironment.id,
483502
id: data.feature.id,
484503
comment: data.comment
485-
})
486-
).then(() => {
487-
archiveReset();
488-
setIsArchiveConfirmDialogOpen(false);
489-
history.replace(
490-
`${PAGE_PATH_ROOT}${currentEnvironment.urlCode}${PAGE_PATH_FEATURES}`
491-
);
492-
updateFeatureList(null, 1);
493-
});
504+
});
505+
506+
handleDispatch(action);
507+
}
494508
},
495509
[dispatch, archiveReset, setIsArchiveConfirmDialogOpen]
496510
);
@@ -620,8 +634,8 @@ export const FeatureIndexPage: FC = memo(() => {
620634
featureId={archiveMethod.getValues().feature?.id}
621635
feature={archiveMethod.getValues().feature}
622636
open={isArchiveConfirmDialogOpen}
623-
handleSubmit={() => {
624-
archiveHandleSubmit(handleArchive)();
637+
handleSubmit={(arg) => {
638+
archiveHandleSubmit((data) => handleArchive(data, arg))();
625639
}}
626640
onClose={() => setIsArchiveConfirmDialogOpen(false)}
627641
title={

ui/web-v2/src/pages/feature/targeting.tsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -181,26 +181,21 @@ export const FeatureTargetingPage: FC<FeatureTargetingPageProps> = memo(
181181
field && JSON.stringify(field).includes('true');
182182

183183
if (saveFeatureType === SaveFeatureType.SCHEDULE) {
184-
const hasDirtyPrerequisites = dirtyFields.prerequisites?.some(
185-
(item) => Object.values(item).includes(true)
186-
);
187-
const hasDirtyTargets = dirtyFields.targets?.some((item) =>
188-
Object.values(item).includes(true)
189-
);
190-
191184
const updatePayload = {
192185
environmentId: currentEnvironment.id,
193186
id: featureId,
194187
comment: data.comment,
195188
enabled: dirtyFields.enabled ? data.enabled : undefined,
196-
prerequisitesList: hasDirtyPrerequisites && data.prerequisites,
197-
targets: hasDirtyTargets && data.targets,
189+
prerequisitesList:
190+
hasDirtyField(dirtyFields.prerequisites) && data.prerequisites,
191+
targets: hasDirtyField(dirtyFields.targets) && data.targets,
198192
rules: hasDirtyField(dirtyFields.rules) && data.rules,
199193
defaultStrategy:
200194
hasDirtyField(dirtyFields.defaultStrategy) &&
201195
data.defaultStrategy,
202196
offVariation:
203-
hasDirtyField(dirtyFields.offVariation) && data.offVariation
197+
hasDirtyField(dirtyFields.offVariation) && data.offVariation,
198+
resetSampling: data.resetSampling
204199
};
205200

206201
await prepareUpdate(updateFeature, updatePayload);

0 commit comments

Comments
 (0)