-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support feature flag overrides via query string
- Loading branch information
1 parent
0c07a65
commit 51a1330
Showing
58 changed files
with
636 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Banner, Button, Checkbox, Grid, GridItem, Modal } from '@patternfly/react-core'; | ||
import * as React from 'react'; | ||
import { allFeatureFlags } from '~/concepts/areas/const'; | ||
import { isFeatureFlag } from '~/concepts/areas/utils'; | ||
import { DashboardCommonConfig } from '~/k8sTypes'; | ||
import { DevFeatureFlags } from '~/types'; | ||
|
||
type Props = { dashboardConfig: Partial<DashboardCommonConfig> } & DevFeatureFlags; | ||
|
||
const DevdevFeatureFlagsBanner: React.FC<Props> = ({ | ||
dashboardConfig, | ||
devFeatureFlags, | ||
setDevFeatureFlag, | ||
resetDevFeatureFlags, | ||
}) => { | ||
const [isModalOpen, setModalOpen] = React.useState(false); | ||
if (!devFeatureFlags) { | ||
return null; | ||
} | ||
const renderdevFeatureFlags = () => ( | ||
<Grid hasGutter span={6} md={3}> | ||
{allFeatureFlags | ||
.filter(isFeatureFlag) | ||
.toSorted() | ||
.map((key) => { | ||
const value = devFeatureFlags[key] ?? dashboardConfig[key]; | ||
return ( | ||
<React.Fragment key={key}> | ||
<GridItem> | ||
<Checkbox | ||
id={key} | ||
data-testid={`${key}-checkbox`} | ||
label={key} | ||
isChecked={value ?? null} | ||
onChange={(_, checked) => | ||
setDevFeatureFlag(key as keyof DashboardCommonConfig, checked) | ||
} | ||
/> | ||
</GridItem> | ||
<GridItem data-testid={`${key}-value`}>{`${value ?? ''}${ | ||
key in devFeatureFlags ? ' (overridden)' : '' | ||
}`}</GridItem> | ||
</React.Fragment> | ||
); | ||
})} | ||
</Grid> | ||
); | ||
return ( | ||
<> | ||
<Banner variant="blue"> | ||
Feature flags are{' '} | ||
<Button | ||
data-testid="override-feature-flags-button" | ||
variant="link" | ||
isInline | ||
onClick={() => setModalOpen(true)} | ||
> | ||
overridden | ||
</Button>{' '} | ||
in the current session.{' '} | ||
<Button | ||
data-testid="reset-feature-flags-button" | ||
variant="link" | ||
isInline | ||
onClick={resetDevFeatureFlags} | ||
> | ||
Click here | ||
</Button>{' '} | ||
to reset back to default. | ||
</Banner> | ||
<Modal | ||
data-testid="dev-feature-flags-modal" | ||
variant="large" | ||
title="Feature flags" | ||
isOpen={isModalOpen} | ||
onClose={() => setModalOpen(false)} | ||
actions={[ | ||
<Button | ||
data-testid="reset-feature-flags-modal-button" | ||
key="confirm" | ||
variant="link" | ||
onClick={() => resetDevFeatureFlags()} | ||
> | ||
Reset to defaults | ||
</Button>, | ||
]} | ||
> | ||
{renderdevFeatureFlags()} | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default DevdevFeatureFlagsBanner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import * as React from 'react'; | ||
import { act, render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import DevFeatureFlagsBanner from '~/app/DevFeatureFlagsBanner'; | ||
|
||
describe('DevFeatureFlagsBanner', () => { | ||
it('should render not render if no feature flags are overridden', () => { | ||
const result = render( | ||
<DevFeatureFlagsBanner | ||
dashboardConfig={{}} | ||
setDevFeatureFlag={() => undefined} | ||
resetDevFeatureFlags={() => undefined} | ||
devFeatureFlags={null} | ||
/>, | ||
); | ||
expect(result.container).toBeEmptyDOMElement(); | ||
}); | ||
|
||
it('should render banner and open modal', () => { | ||
const resetFn = jest.fn(); | ||
const result = render( | ||
<DevFeatureFlagsBanner | ||
dashboardConfig={{}} | ||
setDevFeatureFlag={() => undefined} | ||
resetDevFeatureFlags={resetFn} | ||
devFeatureFlags={{}} | ||
/>, | ||
); | ||
expect(result.container).not.toBeEmptyDOMElement(); | ||
act(() => result.getByTestId('override-feature-flags-button').click()); | ||
result.getByTestId('dev-feature-flags-modal'); | ||
|
||
act(() => result.getByTestId('reset-feature-flags-button').click()); | ||
expect(resetFn).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render and set feature flags', () => { | ||
const setFeatureFlagFn = jest.fn(); | ||
const resetFn = jest.fn(); | ||
const result = render( | ||
<DevFeatureFlagsBanner | ||
dashboardConfig={{ | ||
disableAcceleratorProfiles: false, | ||
}} | ||
setDevFeatureFlag={setFeatureFlagFn} | ||
resetDevFeatureFlags={resetFn} | ||
devFeatureFlags={{ | ||
disableHome: true, | ||
}} | ||
/>, | ||
); | ||
expect(result.container).not.toBeEmptyDOMElement(); | ||
act(() => result.getByTestId('override-feature-flags-button').click()); | ||
screen.getByTestId('dev-feature-flags-modal'); | ||
|
||
act(() => result.getByTestId('reset-feature-flags-button').click()); | ||
expect(resetFn).toHaveBeenCalled(); | ||
|
||
expect(result.getByTestId('disableHome-checkbox')).toBeChecked(); | ||
expect(result.getByTestId('disableAcceleratorProfiles-checkbox')).not.toBeChecked(); | ||
expect(result.getByTestId('enablement-checkbox')).toBePartiallyChecked(); | ||
|
||
expect(result.getByTestId('disableHome-value').textContent).toBe('true (overridden)'); | ||
expect(result.getByTestId('disableAcceleratorProfiles-value').textContent).toBe('false'); | ||
expect(result.getByTestId('enablement-value').textContent).toBe(''); | ||
|
||
act(() => { | ||
result.getByTestId('disableHome-checkbox').click(); | ||
result.getByTestId('disableAcceleratorProfiles-checkbox').click(); | ||
result.getByTestId('enablement-checkbox').click(); | ||
}); | ||
|
||
expect(setFeatureFlagFn).toHaveBeenCalledTimes(3); | ||
expect(setFeatureFlagFn.mock.calls).toEqual([ | ||
['disableHome', false], | ||
['disableAcceleratorProfiles', true], | ||
['enablement', true], | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.