-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding feature flag infrastructure (#4428)
* initial front end feature flag implementation * Initial server implementation * Converting state to object over array * Cleaning up dev test changes * created HOC to abstract feature flag checking for UI features. Changed feature flag toggle per new designs. * Added feature flag value population for hidden feature flags via env variables * Making PR changes: variable and file name changes, general clean up, simplifying types * adding format message for feature flag strings * moving ComposerFeature HOC to client workspace so it is implicitly aware of recoil state * changed default feature flags to function for format message, created hook for filtered templates, replaced env variable featue flag with new feature flag * adding selector for feature flag filtered template state, created feature flag hook for reuse, type and name fixes * removing unneeded div * Adding util functions and reusing hook in HOC * Updating UI for electron and web view of feature flag toggle per design spec * Added feature flag documentation * removing unused imports and variables * Updated unit tests, added build locale autogenerated file updates Co-authored-by: Patrick Volum <pavolum@microsoft.com> Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
- Loading branch information
1 parent
ff51727
commit b534797
Showing
39 changed files
with
555 additions
and
49 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
16 changes: 16 additions & 0 deletions
16
Composer/packages/client/src/components/ComposerFeature.tsx
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,16 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
import { FeatureFlagKey } from '@bfc/shared'; | ||
import React, { Fragment } from 'react'; | ||
|
||
import { useFeatureFlag } from '../utils/hooks'; | ||
|
||
type ComposerFeatureProps = { | ||
featureFlagKey: FeatureFlagKey; | ||
}; | ||
|
||
export const ComposerFeature: React.FC<ComposerFeatureProps> = (props) => { | ||
const { featureFlagKey } = props; | ||
const featureIsEnabled = useFeatureFlag(featureFlagKey); | ||
return <Fragment>{featureIsEnabled ? props.children : null}</Fragment>; | ||
}; |
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
40 changes: 40 additions & 0 deletions
40
Composer/packages/client/src/pages/setting/app-settings/FeatureFlagCheckBox.tsx
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,40 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import { jsx } from '@emotion/core'; | ||
import React from 'react'; | ||
import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox'; | ||
import { FeatureFlagKey } from '@bfc/shared'; | ||
|
||
import * as styles from './styles'; | ||
|
||
type FeatureFlagCheckBoxProps = { | ||
featureFlagKey: FeatureFlagKey; | ||
featureFlagName: string; | ||
description: string; | ||
enabled: boolean; | ||
toggleFeatureFlag: (FeatureFlagKey: FeatureFlagKey, enabled: boolean) => void; | ||
}; | ||
|
||
const renderLabel = (featureName: string, description: string) => () => ( | ||
<span> | ||
<span css={styles.featureFlagTitle}>{`${featureName}.`}</span> | ||
{` ${description}`} | ||
</span> | ||
); | ||
|
||
export const FeatureFlagCheckBox: React.FC<FeatureFlagCheckBoxProps> = (props) => { | ||
return ( | ||
<Checkbox | ||
checked={props.enabled} | ||
css={styles.featureFlagContainer} | ||
onChange={(e: any, checked?: boolean) => { | ||
if (checked !== undefined) { | ||
props.toggleFeatureFlag(props.featureFlagKey, checked); | ||
} | ||
}} | ||
onRenderLabel={renderLabel(props.featureFlagName, props.description)} | ||
/> | ||
); | ||
}; |
60 changes: 60 additions & 0 deletions
60
Composer/packages/client/src/pages/setting/app-settings/PreviewFeatureToggle.tsx
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,60 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
/** @jsx jsx */ | ||
import { jsx } from '@emotion/core'; | ||
import { Fragment, useState } from 'react'; | ||
import formatMessage from 'format-message'; | ||
import { FeatureFlag, FeatureFlagKey } from '@bfc/shared'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { dispatcherState, featureFlagsState } from '../../../recoilModel'; | ||
|
||
import { featureFlagGroupContainer } from './styles'; | ||
import { SettingToggle } from './SettingToggle'; | ||
import * as images from './images'; | ||
import { FeatureFlagCheckBox } from './FeatureFlagCheckBox'; | ||
|
||
export const PreviewFeatureToggle: React.FC = () => { | ||
const featureFlags = useRecoilValue(featureFlagsState); | ||
const { toggleFeatureFlag } = useRecoilValue(dispatcherState); | ||
const [featureFlagVisible, showFeatureFlag] = useState(false); | ||
|
||
const renderFeatureFlagOptions = () => { | ||
const result: React.ReactNode[] = []; | ||
Object.keys(featureFlags).forEach((key: string) => { | ||
const featureFlag: FeatureFlag = featureFlags[key]; | ||
if (!featureFlag.isHidden) { | ||
result.push( | ||
<FeatureFlagCheckBox | ||
key={key} | ||
description={featureFlag.description} | ||
enabled={featureFlag.enabled} | ||
featureFlagKey={key as FeatureFlagKey} | ||
featureFlagName={featureFlag.displayName} | ||
toggleFeatureFlag={toggleFeatureFlag} | ||
/> | ||
); | ||
} | ||
}); | ||
return <div css={featureFlagGroupContainer}>{result}</div>; | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
<SettingToggle | ||
hideToggle | ||
checked={featureFlagVisible} | ||
description={formatMessage( | ||
'Try new features in preview and help us make Composer better. You can turn them on or off at any time.' | ||
)} | ||
image={images.previewFeatures} | ||
title={formatMessage('Preview features')} | ||
onToggle={(checked: boolean) => { | ||
showFeatureFlag(checked); | ||
}} | ||
/> | ||
{renderFeatureFlagOptions()} | ||
</Fragment> | ||
); | ||
}; |
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
12 changes: 12 additions & 0 deletions
12
...oser/packages/client/src/pages/setting/app-settings/images/preview-features.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.