Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove featureSwitchRefactor flag #5329

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { styled } from '@mui/material';
import StringTruncator from 'component/common/StringTruncator/StringTruncator';
import { FeatureOverviewSidePanelEnvironmentHider } from './FeatureOverviewSidePanelEnvironmentHider';
import { FeatureToggleSwitch } from 'component/project/Project/ProjectFeatureToggles/FeatureToggleSwitch/LegacyFeatureToggleSwitch';
import { FeatureToggleSwitch } from 'component/project/Project/ProjectFeatureToggles/FeatureToggleSwitch/FeatureToggleSwitch';
import { useFeatureToggleSwitch } from 'component/project/Project/ProjectFeatureToggles/FeatureToggleSwitch/useFeatureToggleSwitch';
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';

const StyledContainer = styled('div')(({ theme }) => ({
marginLeft: theme.spacing(-1.5),
Expand All @@ -24,7 +26,6 @@ const StyledLabel = styled('label')(() => ({
interface IFeatureOverviewSidePanelEnvironmentSwitchProps {
environment: IFeatureEnvironment;
callback?: () => void;
showInfoBox: () => void;
children?: React.ReactNode;
hiddenEnvironments: Set<String>;
setHiddenEnvironments: (environment: string) => void;
Expand All @@ -33,30 +34,49 @@ interface IFeatureOverviewSidePanelEnvironmentSwitchProps {
export const FeatureOverviewSidePanelEnvironmentSwitch = ({
environment,
callback,
showInfoBox,
children,
hiddenEnvironments,
setHiddenEnvironments,
}: IFeatureOverviewSidePanelEnvironmentSwitchProps) => {
const { name, enabled } = environment;

const projectId = useRequiredPathParam('projectId');
const featureId = useRequiredPathParam('featureId');
const { feature, refetchFeature } = useFeature(projectId, featureId);
const { isChangeRequestConfigured } = useChangeRequestsEnabled(projectId);

const defaultContent = (
<>
{' '}
<span data-loading>{enabled ? 'enabled' : 'disabled'} in</span>
<span data-loading>
{environment.enabled ? 'enabled' : 'disabled'} in
</span>
&nbsp;
<StringTruncator text={name} maxWidth='120' maxLength={15} />
<StringTruncator
text={environment.name}
maxWidth='120'
maxLength={15}
/>
</>
);
const { onToggle: onFeatureToggle, modals: featureToggleModals } =
useFeatureToggleSwitch(projectId);

const handleToggle = () => {
refetchFeature();
if (callback) callback();
};
const handleToggle = (newState: boolean, onRollback: () => void) =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using new FeatureSwitch here allows us to remove legacy implementation not only from the table.

onFeatureToggle(newState, {
projectId,
featureId,
environmentName: environment.name,
environmentType: environment.type,
hasStrategies: environment.strategies.length > 0,
hasEnabledStrategies: environment.strategies.some(
(strategy) => !strategy.disabled,
),
isChangeRequestEnabled: isChangeRequestConfigured(environment.name),
onRollback,
onSuccess: () => {
if (callback) callback();
refetchFeature();
},
});

return (
<StyledContainer>
Expand All @@ -66,8 +86,7 @@ export const FeatureOverviewSidePanelEnvironmentSwitch = ({
projectId={projectId}
environmentName={environment.name}
onToggle={handleToggle}
onError={showInfoBox}
value={enabled}
value={environment.enabled}
/>
{children ?? defaultContent}
</StyledLabel>
Expand All @@ -76,6 +95,7 @@ export const FeatureOverviewSidePanelEnvironmentSwitch = ({
hiddenEnvironments={hiddenEnvironments}
setHiddenEnvironments={setHiddenEnvironments}
/>
{featureToggleModals}
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import EnvironmentStrategyDialog from 'component/common/EnvironmentStrategiesDialog/EnvironmentStrategyDialog';
import { IFeatureToggle } from 'interfaces/featureToggle';
import { useState } from 'react';
import { type IFeatureToggle } from 'interfaces/featureToggle';
import { FeatureOverviewSidePanelEnvironmentSwitch } from 'component/feature/FeatureView/FeatureOverview/FeatureOverviewSidePanel/FeatureOverviewSidePanelEnvironmentSwitches/FeatureOverviewSidePanelEnvironmentSwitch/FeatureOverviewSidePanelEnvironmentSwitch';
import { Link, styled, Tooltip } from '@mui/material';
import { Link as RouterLink } from 'react-router-dom';
Expand Down Expand Up @@ -53,8 +51,6 @@ export const FeatureOverviewSidePanelEnvironmentSwitches = ({
hiddenEnvironments,
setHiddenEnvironments,
}: IFeatureOverviewSidePanelEnvironmentSwitchesProps) => {
const [showInfoBox, setShowInfoBox] = useState(false);
const [environmentName, setEnvironmentName] = useState('');
const someEnabledEnvironmentHasVariants = feature.environments.some(
(environment) => environment.enabled && environment.variants?.length,
);
Expand Down Expand Up @@ -96,10 +92,6 @@ export const FeatureOverviewSidePanelEnvironmentSwitches = ({
environment={environment}
hiddenEnvironments={hiddenEnvironments}
setHiddenEnvironments={setHiddenEnvironments}
showInfoBox={() => {
setEnvironmentName(environment.name);
setShowInfoBox(true);
}}
>
<StyledSwitchLabel>
<StyledLabel>{environment.name}</StyledLabel>
Expand All @@ -120,13 +112,6 @@ export const FeatureOverviewSidePanelEnvironmentSwitches = ({
</FeatureOverviewSidePanelEnvironmentSwitch>
);
})}
<EnvironmentStrategyDialog
open={showInfoBox}
onClose={() => setShowInfoBox(false)}
projectId={feature.project}
featureId={feature.name}
environmentName={environmentName}
/>
</StyledContainer>
);
};
Loading
Loading