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

feat(upgrade): adds featureflag-deprecate-flags-prop codemod and deprecates flags prop #17266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6811036
fix: add new props to feature flag props
riddhybansal Aug 22, 2024
2955276
feat(upgrade): featureflag-deprecate-flags-prop codemod
2nikhiltom Aug 25, 2024
e9d9539
feat(upgrade): codemod, test cases and fixtures updated
2nikhiltom Aug 26, 2024
4d596f9
refactor: test fixtures
2nikhiltom Aug 26, 2024
4579831
refactor: sets default flag values to false at destructuring
2nikhiltom Aug 26, 2024
0062b5b
fix: skips transformation of files without FeatureFlags component
2nikhiltom Aug 26, 2024
669d823
refactor: makes conditions readable
2nikhiltom Aug 27, 2024
1b0987c
feat(upgrade): removes old flags trasnformation, added tests
2nikhiltom Aug 28, 2024
c52e9ab
feat(upgrade): adds codemod to @carbon/upgrade migrate
2nikhiltom Aug 28, 2024
5bee8d4
chore: message updated
2nikhiltom Aug 29, 2024
ab7bc72
feat(upgrade): tests updates, old flag removed
2nikhiltom Sep 5, 2024
6467dea
fix: removes oldflag
2nikhiltom Sep 5, 2024
591d8af
fix: added pattern matching for .ts & .tsx
2nikhiltom Sep 5, 2024
8c5c1bb
refactor: yarn dedupe changes
2nikhiltom Sep 5, 2024
f7ca073
refactor: yarn dedupe change, snapshotss
2nikhiltom Sep 5, 2024
315a6fc
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 6, 2024
b85b4eb
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 10, 2024
01aba41
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 10, 2024
99cf188
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 11, 2024
20f219e
fix: removes old flags, updates test outputs
2nikhiltom Sep 11, 2024
bdb26c8
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 11, 2024
c1f69b2
Merge branch 'main' into 17243_CodeModes_FeatureFlags
kennylam Sep 13, 2024
1cd4432
Merge branch 'main' into 17243_CodeModes_FeatureFlags
2nikhiltom Sep 20, 2024
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
5 changes: 0 additions & 5 deletions packages/feature-flags/feature-flags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ feature-flags:
- name: enable-css-custom-properties
description: Describe what the flag does
enabled: false
- name: enable-use-controlled-state-with-value
description: >
Enable components to be created in either a controlled or uncontrolled
mode
enabled: false
- name: enable-css-grid
description: >
Enable CSS Grid Layout in the Grid and Column React components
Expand Down
22 changes: 15 additions & 7 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9801,14 +9801,22 @@ Map {
"children": Object {
"type": "node",
},
"flags": Object {
"args": Array [
Object {
"type": "bool",
},
],
"type": "objectOf",
"enableExperimentalFocusWrapWithoutSentinels": Object {
"type": "bool",
},
"enableTreeviewControllable": Object {
"type": "bool",
},
"enableV12Overflowmenu": Object {
"type": "bool",
},
"enableV12TileDefaultIcons": Object {
"type": "bool",
},
"enableV12TileRadioIcons": Object {
"type": "bool",
},
"flags": [Function],
},
},
"unstable_Layout" => Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('FeatureFlags', () => {
expect(checkFlags).toHaveBeenLastCalledWith(true);
expect(checkFlag).toHaveBeenLastCalledWith(true);
});

it('should provide access to the feature flags for a scope', () => {
it('should provide access to the feature flags for a scope through deprecated flags prop', () => {
consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
const checkFlags = jest.fn();
const checkFlag = jest.fn();

Expand Down Expand Up @@ -69,6 +69,49 @@ describe('FeatureFlags', () => {
a: true,
b: false,
});
consoleSpy.mockRestore();
});

it('should provide access to the feature flags for a scope', () => {
const checkFlags = jest.fn();
const checkFlag = jest.fn();

function TestComponent() {
const featureFlags = useFeatureFlags();
const enableV12Overflowmenu = useFeatureFlag('enable-v12-overflowmenu');
const enableTreeviewControllable = useFeatureFlag(
'enable-treeview-controllable'
);

checkFlags({
enableV12Overflowmenu: featureFlags.enabled('enable-v12-overflowmenu'),
enableTreeviewControllable: featureFlags.enabled(
'enable-treeview-controllable'
),
});

checkFlag({
enableV12Overflowmenu,
enableTreeviewControllable,
});

return null;
}

render(
<FeatureFlags enableV12Overflowmenu>
<TestComponent />
</FeatureFlags>
);

expect(checkFlags).toHaveBeenLastCalledWith({
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});
expect(checkFlag).toHaveBeenLastCalledWith({
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});
});

it('should re-render when flags change', () => {
Expand All @@ -77,104 +120,192 @@ describe('FeatureFlags', () => {

function TestComponent() {
const featureFlags = useFeatureFlags();
const a = useFeatureFlag('a');
const b = useFeatureFlag('b');
const enableV12Overflowmenu = useFeatureFlag('enable-v12-overflowmenu');
const enableTreeviewControllable = useFeatureFlag(
'enable-treeview-controllable'
);

checkFlags({
a: featureFlags.enabled('a'),
b: featureFlags.enabled('b'),
enableV12Overflowmenu: featureFlags.enabled('enable-v12-overflowmenu'),
enableTreeviewControllable: featureFlags.enabled(
'enable-treeview-controllable'
),
});

checkFlag({
a,
b,
enableV12Overflowmenu,
enableTreeviewControllable,
});

return null;
}

const { rerender } = render(
<FeatureFlags flags={{ a: true, b: false }}>
<FeatureFlags enableV12Overflowmenu>
<TestComponent />
</FeatureFlags>
);

expect(checkFlags).toHaveBeenLastCalledWith({
a: true,
b: false,
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});
expect(checkFlag).toHaveBeenLastCalledWith({
a: true,
b: false,
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});

rerender(
<FeatureFlags flags={{ a: false, b: true }}>
<FeatureFlags enableTreeviewControllable>
<TestComponent />
</FeatureFlags>
);

expect(checkFlags).toHaveBeenLastCalledWith({
a: false,
b: true,
enableV12Overflowmenu: false,
enableTreeviewControllable: true,
});
expect(checkFlag).toHaveBeenLastCalledWith({
a: false,
b: true,
enableV12Overflowmenu: false,
enableTreeviewControllable: true,
});
});

it('should merge scopes and overwrite duplicate keys', () => {
GlobalFeatureFlags.add('global', true);

const checkFlag = jest.fn();

function TestComponent() {
const global = useFeatureFlag('global');
const local = useFeatureFlag('local');
const enableV12Overflowmenu = useFeatureFlag('enable-v12-overflowmenu');
const enableTreeviewControllable = useFeatureFlag(
'enable-treeview-controllable'
);

checkFlag({ global, local });
checkFlag({ enableV12Overflowmenu, enableTreeviewControllable });

return null;
}

render(
<FeatureFlags flags={{ local: true }}>
<FeatureFlags enableTreeviewControllable>
<TestComponent />
</FeatureFlags>
);

expect(checkFlag).toHaveBeenLastCalledWith({
global: true,
local: true,
enableV12Overflowmenu: false,
enableTreeviewControllable: true,
});

render(
<FeatureFlags flags={{ local: true }}>
<FeatureFlags flags={{ global: false }}>
<FeatureFlags enableTreeviewControllable>
<FeatureFlags enableV12Overflowmenu>
<TestComponent />
</FeatureFlags>
</FeatureFlags>
);

expect(checkFlag).toHaveBeenLastCalledWith({
global: false,
local: true,
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});

render(
<FeatureFlags flags={{ local: true }}>
<FeatureFlags flags={{ global: false }}>
<FeatureFlags flags={{ local: false }}>
<FeatureFlags enableTreeviewControllable>
<FeatureFlags enableV12Overflowmenu>
<FeatureFlags
enableTreeviewControllable={false}
enableV12Overflowmenu={false}>
<TestComponent />
</FeatureFlags>
</FeatureFlags>
</FeatureFlags>
);

expect(checkFlag).toHaveBeenLastCalledWith({
global: false,
local: false,
enableV12Overflowmenu: false,
enableTreeviewControllable: false,
});
});
it('should handle boolean props and flags object with no overlapping keys', () => {
const checkFlags = jest.fn();
const checkFlag = jest.fn();

function TestComponent() {
const featureFlags = useFeatureFlags();
const enableV12Overflowmenu = useFeatureFlag('enable-v12-overflowmenu');
const enableExperimentalFocusWrapWithoutSentinels = useFeatureFlag(
'enable-experimental-focus-wrap-without-sentinels'
);

checkFlags({
enableV12Overflowmenu: featureFlags.enabled('enable-v12-overflowmenu'),
enableExperimentalFocusWrapWithoutSentinels: featureFlags.enabled(
'enable-experimental-focus-wrap-without-sentinels'
),
});

checkFlag({
enableV12Overflowmenu,
enableExperimentalFocusWrapWithoutSentinels,
});

return null;
}

render(
<FeatureFlags enableExperimentalFocusWrapWithoutSentinels>
<TestComponent />
</FeatureFlags>
);

expect(checkFlags).toHaveBeenLastCalledWith({
enableV12Overflowmenu: false,
enableExperimentalFocusWrapWithoutSentinels: true,
});
expect(checkFlag).toHaveBeenLastCalledWith({
enableV12Overflowmenu: false,
enableExperimentalFocusWrapWithoutSentinels: true,
});
});
it('should handle boolean props correctly when no flags object is provided', () => {
const checkFlags = jest.fn();
const checkFlag = jest.fn();

function TestComponent() {
const featureFlags = useFeatureFlags();
const enableV12Overflowmenu = useFeatureFlag('enable-v12-overflowmenu');
const enableTreeviewControllable = useFeatureFlag(
'enable-treeview-controllable'
);

checkFlags({
enableV12Overflowmenu: featureFlags.enabled('enable-v12-overflowmenu'),
enableTreeviewControllable: featureFlags.enabled(
'enable-treeview-controllable'
),
});

checkFlag({
enableV12Overflowmenu,
enableTreeviewControllable,
});

return null;
}

render(
<FeatureFlags enableV12Overflowmenu enableTreeviewControllable={false}>
<TestComponent />
</FeatureFlags>
);

expect(checkFlags).toHaveBeenLastCalledWith({
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});
expect(checkFlag).toHaveBeenLastCalledWith({
enableV12Overflowmenu: true,
enableTreeviewControllable: false,
});
});
});
Loading
Loading