From 8729f082d2d5dcf6deb8406f7ef1413d5767c6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Tue, 14 Feb 2023 14:02:02 +0000 Subject: [PATCH] refactor: remove variants per environment feature flag (#3102) https://linear.app/unleash/issue/2-428/clean-up-feature-flag-once-were-done-with-the-migration Cleans up the variants per environment feature flag due to GA. --- .../integration/feature/feature.spec.ts | 78 ++++++++-------- .../cypress/integration/import/import.spec.ts | 6 +- .../FeatureOverview/FeatureOverview.tsx | 21 +---- .../FeatureOverviewMetaData.tsx | 11 --- ...reOverviewSidePanelEnvironmentSwitches.tsx | 2 +- .../EnvironmentVariantsModal.tsx | 2 + .../VariantForm/VariantForm.tsx | 4 + .../FeatureEnvironmentVariants.tsx | 2 + .../FeatureVariants/FeatureVariants.tsx | 10 +-- .../api/getters/useFeature/useFeature.ts | 21 ++--- frontend/src/interfaces/uiConfig.ts | 1 - .../__snapshots__/create-config.test.ts.snap | 2 - src/lib/services/environment-service.ts | 7 -- src/lib/services/state-service.test.ts | 89 +------------------ src/lib/services/state-service.ts | 56 +----------- src/lib/types/experimental.ts | 4 - src/server-dev.ts | 1 - src/test/config/test-config.ts | 1 - src/test/e2e/api/admin/state.e2e.test.ts | 66 -------------- 19 files changed, 63 insertions(+), 321 deletions(-) diff --git a/frontend/cypress/integration/feature/feature.spec.ts b/frontend/cypress/integration/feature/feature.spec.ts index 3781a61ea7..2160b679e8 100644 --- a/frontend/cypress/integration/feature/feature.spec.ts +++ b/frontend/cypress/integration/feature/feature.spec.ts @@ -232,36 +232,29 @@ describe('feature', () => { cy.wait('@addStrategyToFeature'); }); - it('can add two variant to the feature', () => { + it('can add two variants to the development environment', () => { cy.visit(`/projects/default/features/${featureToggleName}/variants`); cy.intercept( 'PATCH', - `/api/admin/projects/default/features/${featureToggleName}/variants`, + `/api/admin/projects/default/features/${featureToggleName}/environments/development/variants`, req => { - if (req.body.length === 1) { - expect(req.body[0].op).to.equal('add'); - expect(req.body[0].path).to.match(/\//); - expect(req.body[0].value.name).to.equal(variant1); - } else if (req.body.length === 2) { - expect(req.body[0].op).to.equal('replace'); - expect(req.body[0].path).to.match(/weight/); - expect(req.body[0].value).to.equal(500); - expect(req.body[1].op).to.equal('add'); - expect(req.body[1].path).to.match(/\//); - expect(req.body[1].value.name).to.equal(variant2); - } + expect(req.body[0].op).to.equal('add'); + expect(req.body[0].path).to.equal('/0'); + expect(req.body[0].value.name).to.equal(variant1); + expect(req.body[0].value.weight).to.equal(500); + expect(req.body[1].op).to.equal('add'); + expect(req.body[1].path).to.equal('/1'); + expect(req.body[1].value.name).to.equal(variant2); + expect(req.body[1].value.weight).to.equal(500); } ).as('variantCreation'); - cy.get('[data-testid=ADD_VARIANT_BUTTON]').click(); + cy.get('[data-testid=ADD_VARIANT_BUTTON]').first().click(); cy.wait(1000); cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variant1); - cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click(); - cy.wait('@variantCreation'); - cy.get('[data-testid=ADD_VARIANT_BUTTON]').click(); - cy.wait(1000); - cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variant2); + cy.get('[data-testid=MODAL_ADD_VARIANT_BUTTON]').click(); + cy.get('[data-testid=VARIANT_NAME_INPUT]').last().type(variant2); cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click(); cy.wait('@variantCreation'); }); @@ -269,60 +262,61 @@ describe('feature', () => { it('can set weight to fixed value for one of the variants', () => { cy.visit(`/projects/default/features/${featureToggleName}/variants`); - cy.get(`[data-testid=VARIANT_EDIT_BUTTON_${variant1}]`).click(); + cy.get('[data-testid=EDIT_VARIANTS_BUTTON]').click(); cy.wait(1000); cy.get('[data-testid=VARIANT_NAME_INPUT]') + .last() .children() .find('input') .should('have.attr', 'disabled'); - cy.get('[data-testid=VARIANT_WEIGHT_CHECK]').find('input').check(); - cy.get('[data-testid=VARIANT_WEIGHT_INPUT]').clear().type('15'); + cy.get('[data-testid=VARIANT_WEIGHT_CHECK]') + .last() + .find('input') + .check(); + cy.get('[data-testid=VARIANT_WEIGHT_INPUT]').last().clear().type('15'); cy.intercept( 'PATCH', - `/api/admin/projects/default/features/${featureToggleName}/variants`, + `/api/admin/projects/default/features/${featureToggleName}/environments/development/variants`, req => { expect(req.body[0].op).to.equal('replace'); - expect(req.body[0].path).to.match(/weight/); - expect(req.body[0].value).to.equal(850); + expect(req.body[0].path).to.equal('/1/weightType'); + expect(req.body[0].value).to.equal('fix'); expect(req.body[1].op).to.equal('replace'); - expect(req.body[1].path).to.match(/weightType/); - expect(req.body[1].value).to.equal('fix'); + expect(req.body[1].path).to.equal('/1/weight'); + expect(req.body[1].value).to.equal(150); expect(req.body[2].op).to.equal('replace'); - expect(req.body[2].path).to.match(/weight/); - expect(req.body[2].value).to.equal(150); + expect(req.body[2].path).to.equal('/0/weight'); + expect(req.body[2].value).to.equal(850); } ).as('variantUpdate'); cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click(); cy.wait('@variantUpdate'); - cy.get(`[data-testid=VARIANT_WEIGHT_${variant1}]`).should( + cy.get(`[data-testid=VARIANT_WEIGHT_${variant2}]`).should( 'have.text', '15 %' ); }); it('can delete variant', () => { - const variantName = 'to-be-deleted'; - cy.visit(`/projects/default/features/${featureToggleName}/variants`); - cy.get('[data-testid=ADD_VARIANT_BUTTON]').click(); + cy.get('[data-testid=EDIT_VARIANTS_BUTTON]').click(); cy.wait(1000); - cy.get('[data-testid=VARIANT_NAME_INPUT]').type(variantName); - cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click(); + cy.get(`[data-testid=VARIANT_DELETE_BUTTON_${variant2}]`).click(); cy.intercept( 'PATCH', - `/api/admin/projects/default/features/${featureToggleName}/variants`, + `/api/admin/projects/default/features/${featureToggleName}/environments/development/variants`, req => { - const patch = req.body.find( - (patch: Record) => patch.op === 'remove' - ); - expect(patch.path).to.match(/\//); + expect(req.body[0].op).to.equal('remove'); + expect(req.body[0].path).to.equal('/1'); + expect(req.body[1].op).to.equal('replace'); + expect(req.body[1].path).to.equal('/0/weight'); + expect(req.body[1].value).to.equal(1000); } ).as('delete'); - cy.get(`[data-testid=VARIANT_DELETE_BUTTON_${variantName}]`).click(); cy.get('[data-testid=DIALOGUE_CONFIRM_ID]').click(); cy.wait('@delete'); }); diff --git a/frontend/cypress/integration/import/import.spec.ts b/frontend/cypress/integration/import/import.spec.ts index a74ccd2965..4038d3f931 100644 --- a/frontend/cypress/integration/import/import.spec.ts +++ b/frontend/cypress/integration/import/import.spec.ts @@ -119,7 +119,11 @@ describe('imports', () => { // cy.contains('Import completed'); cy.visit(`/projects/default/features/${randomFeatureName}`); - cy.contains('enabled in development'); + cy.get( + "[data-testid='feature-toggle-status'] input[type='checkbox']:checked" + ) + .closest('div') + .contains('development'); cy.contains('50%'); }); }); diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverview.tsx b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverview.tsx index 2cd3ed4733..98283955d5 100644 --- a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverview.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverview.tsx @@ -1,6 +1,5 @@ import FeatureOverviewMetaData from './FeatureOverviewMetaData/FeatureOverviewMetaData'; import FeatureOverviewEnvironments from './FeatureOverviewEnvironments/FeatureOverviewEnvironments'; -import FeatureOverviewEnvSwitches from './FeatureOverviewEnvSwitches/FeatureOverviewEnvSwitches'; import { Routes, Route, useNavigate } from 'react-router-dom'; import { FeatureStrategyCreate } from 'component/feature/FeatureStrategy/FeatureStrategyCreate/FeatureStrategyCreate'; import { SidebarModal } from 'component/common/SidebarModal/SidebarModal'; @@ -10,8 +9,6 @@ import { } from 'component/feature/FeatureStrategy/FeatureStrategyEdit/FeatureStrategyEdit'; import { useRequiredPathParam } from 'hooks/useRequiredPathParam'; import { usePageTitle } from 'hooks/usePageTitle'; -import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; -import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import { FeatureOverviewSidePanel } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanel'; import { useHiddenEnvironments } from 'hooks/useHiddenEnvironments'; import { styled } from '@mui/material'; @@ -34,7 +31,6 @@ const StyledMainContent = styled('div')(({ theme }) => ({ })); const FeatureOverview = () => { - const { uiConfig } = useUiConfig(); const navigate = useNavigate(); const projectId = useRequiredPathParam('projectId'); const featureId = useRequiredPathParam('featureId'); @@ -48,20 +44,9 @@ const FeatureOverview = () => {
- - } - elseShow={ - - } +
diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewMetaData/FeatureOverviewMetaData.tsx b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewMetaData/FeatureOverviewMetaData.tsx index 713da1e539..0320a74e83 100644 --- a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewMetaData/FeatureOverviewMetaData.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewMetaData/FeatureOverviewMetaData.tsx @@ -145,17 +145,6 @@ const FeatureOverviewMetaData = () => { /> - 0 && - !Boolean(uiConfig.flags.variantsPerEnvironment) - } - show={ - - - - } - />
); }; diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanelEnvironmentSwitches/FeatureOverviewSidePanelEnvironmentSwitches.tsx b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanelEnvironmentSwitches/FeatureOverviewSidePanelEnvironmentSwitches.tsx index d88821d690..8c1d0598f6 100644 --- a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanelEnvironmentSwitches/FeatureOverviewSidePanelEnvironmentSwitches.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanelEnvironmentSwitches/FeatureOverviewSidePanelEnvironmentSwitches.tsx @@ -59,7 +59,7 @@ export const FeatureOverviewSidePanelEnvironmentSwitches = ({ environment => environment.enabled && environment.variants?.length ); return ( - + {header} {feature.environments.map(environment => { const strategiesLabel = diff --git a/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/EnvironmentVariantsModal.tsx b/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/EnvironmentVariantsModal.tsx index 07a6ed9409..71209243a8 100644 --- a/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/EnvironmentVariantsModal.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureVariants/FeatureEnvironmentVariants/EnvironmentVariantsModal/EnvironmentVariantsModal.tsx @@ -284,6 +284,7 @@ export const EnvironmentVariantsModal = ({ setVariantsEdit(variantsEdit => [ ...variantsEdit, @@ -400,6 +401,7 @@ export const EnvironmentVariantsModal = ({