mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
fix: allow deletion of segments referencing strategies in archived f… (#6406)
Subset of #6392, allowing you to delete segments that are referenced in strategies on archived features.
This commit is contained in:
parent
a08bada1de
commit
bfbd18eb97
@ -3,7 +3,7 @@ import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
||||
import Input from 'component/common/Input/Input';
|
||||
import { ISegment } from 'interfaces/segment';
|
||||
import { SEGMENT_DIALOG_NAME_ID } from 'utils/testIds';
|
||||
import { styled } from '@mui/material';
|
||||
import { Alert, styled } from '@mui/material';
|
||||
|
||||
const StyledInput = styled(Input)(({ theme }) => ({
|
||||
marginTop: theme.spacing(2),
|
||||
@ -46,6 +46,11 @@ export const SegmentDeleteConfirm = ({
|
||||
onClose={handleCancel}
|
||||
formId={formId}
|
||||
>
|
||||
<Alert sx={{ marginBottom: 2 }} severity='warning'>
|
||||
Deleted segments may be referenced in strategies if the feature
|
||||
flag is archived. Removing the segment will also remove the
|
||||
segments from strategies of archived flags.
|
||||
</Alert>
|
||||
<p>
|
||||
In order to delete this segment, please enter the name of the
|
||||
segment in the field below: <strong>{segment?.name}</strong>
|
||||
|
@ -814,7 +814,14 @@ class FeatureStrategiesStore implements IFeatureStrategiesStore {
|
||||
`${T.featureStrategySegment}.feature_strategy_id`,
|
||||
`${T.featureStrategies}.id`,
|
||||
)
|
||||
.where(`${T.featureStrategySegment}.segment_id`, '=', segmentId);
|
||||
.join(
|
||||
T.features,
|
||||
`${T.features}.name`,
|
||||
`${T.featureStrategies}.feature_name`,
|
||||
)
|
||||
.where(`${T.featureStrategySegment}.segment_id`, '=', segmentId)
|
||||
.andWhere(`${T.features}.archived_at`, 'IS', null);
|
||||
|
||||
stopTimer();
|
||||
return rows.map(mapRow);
|
||||
}
|
||||
|
@ -290,6 +290,36 @@ test('should not delete segments used by strategies', async () => {
|
||||
expect((await fetchSegments()).length).toEqual(1);
|
||||
});
|
||||
|
||||
test('should delete segments used by strategies in archived feature toggles', async () => {
|
||||
await app.createSegment({
|
||||
name: 'a',
|
||||
constraints: [],
|
||||
});
|
||||
const toggle = mockFeatureToggle();
|
||||
await createFeatureToggle(app, toggle);
|
||||
const [segment] = await fetchSegments();
|
||||
|
||||
await addStrategyToFeatureEnv(
|
||||
app,
|
||||
{ ...toggle.strategies[0] },
|
||||
'default',
|
||||
toggle.name,
|
||||
);
|
||||
const [feature] = await fetchFeatures();
|
||||
//@ts-ignore
|
||||
await addSegmentsToStrategy([segment.id], feature.strategies[0].id);
|
||||
const segments = await fetchSegments();
|
||||
expect(segments.length).toEqual(1);
|
||||
|
||||
await app.archiveFeature(feature.name);
|
||||
|
||||
await app.request
|
||||
.delete(`${SEGMENTS_BASE_PATH}/${segments[0].id}`)
|
||||
.expect(204);
|
||||
|
||||
expect((await fetchSegments()).length).toEqual(0);
|
||||
});
|
||||
|
||||
test('should list strategies by segment', async () => {
|
||||
await app.createSegment({
|
||||
name: 'S1',
|
||||
|
Loading…
Reference in New Issue
Block a user