-
Notifications
You must be signed in to change notification settings - Fork 124
feat: Add support for opt-in and opt-out in Workflow History V2 feature flag #1132
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
Merged
adhityamamallan
merged 8 commits into
cadence-workflow:master
from
adhityamamallan:history-v2-new-flag
Jan 14, 2026
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
84d303f
Modify flag for history v2
adhityamamallan 44c3069
changes to config value
adhityamamallan c32111a
Implement using local storage and restructure code
adhityamamallan 2c5894e
Fix tests
adhityamamallan 3338a71
Add docstring for hook
adhityamamallan d0cc5cd
add comment
adhityamamallan 04c83a0
Rename enabled hook to selected
adhityamamallan 698bdf9
fix lint error
adhityamamallan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
src/config/dynamic/resolvers/history-page-v2-enabled-values.config.ts
This file contains hidden or 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,8 @@ | ||
| const HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG = [ | ||
| 'DISABLED', | ||
| 'OPT_IN', | ||
| 'OPT_OUT', | ||
| 'ENABLED', | ||
| ] as const; | ||
|
|
||
| export default HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,25 @@ | ||
| import HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG from './history-page-v2-enabled-values.config'; | ||
| import { type HistoryPageV2EnabledConfigValue } from './history-page-v2-enabled.types'; | ||
|
|
||
| /** | ||
| * WIP: Returns whether the new Workflow History (V2) page is enabled | ||
| * WIP: Returns the configuration value for the new Workflow History (V2) page | ||
| * | ||
| * To configure the new Workflow History (V2) page, set the CADENCE_HISTORY_PAGE_V2_ENABLED env variable to one of the following: | ||
| * - `DISABLED` - disable the feature entirely (default if env var is not set or invalid) | ||
| * - `OPT_IN` - allow users to view the new page using a button on the old page | ||
| * - `OPT_OUT` - default to the new page with an option to fall back to the old page | ||
| * - `ENABLED` - completely enable the new page with no option to fall back | ||
| * | ||
| * To enable the new Workflow History (V2) page, set the CADENCE_HISTORY_PAGE_V2_ENABLED env variable to true. | ||
| * For further customization, override the implementation of this resolver. | ||
| * | ||
| * @returns {Promise<boolean>} Whether Workflow History (V2) page is enabled. | ||
| * @returns {Promise<HistoryPageV2EnabledConfigValue>} The configuration value for Workflow History (V2) page. | ||
| */ | ||
| export default async function historyPageV2Enabled(): Promise<boolean> { | ||
| return process.env.CADENCE_HISTORY_PAGE_V2_ENABLED === 'true'; | ||
| export default async function historyPageV2Enabled(): Promise<HistoryPageV2EnabledConfigValue> { | ||
| const envValue = process.env.CADENCE_HISTORY_PAGE_V2_ENABLED; | ||
|
|
||
| if (HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG.includes(envValue as any)) { | ||
| return envValue as HistoryPageV2EnabledConfigValue; | ||
| } | ||
|
|
||
| return 'DISABLED'; | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/config/dynamic/resolvers/history-page-v2-enabled.types.ts
This file contains hidden or 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,4 @@ | ||
| import type HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG from './history-page-v2-enabled-values.config'; | ||
|
|
||
| export type HistoryPageV2EnabledConfigValue = | ||
| (typeof HISTORY_PAGE_V2_ENABLED_VALUES_CONFIG)[number]; |
This file contains hidden or 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 hidden or 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 hidden or 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
210 changes: 210 additions & 0 deletions
210
src/views/workflow-history-v2/hooks/__tests__/use-is-workflow-history-v2-enabled.test.tsx
This file contains hidden or 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,210 @@ | ||
| import React, { Suspense } from 'react'; | ||
|
|
||
| import { renderHook, waitFor, act } from '@/test-utils/rtl'; | ||
|
|
||
| import { type UseSuspenseConfigValueResult } from '@/hooks/use-config-value/use-config-value.types'; | ||
| import useSuspenseConfigValue from '@/hooks/use-config-value/use-suspense-config-value'; | ||
| import * as localStorageModule from '@/utils/local-storage'; | ||
| import workflowHistoryUserPreferencesConfig from '@/views/workflow-history/config/workflow-history-user-preferences.config'; | ||
|
|
||
| import useIsWorkflowHistoryV2Enabled from '../use-is-workflow-history-v2-enabled'; | ||
|
|
||
| jest.mock('@/hooks/use-config-value/use-suspense-config-value'); | ||
| jest.mock('@/utils/local-storage', () => ({ | ||
| getLocalStorageValue: jest.fn(), | ||
| setLocalStorageValue: jest.fn(), | ||
| clearLocalStorageValue: jest.fn(), | ||
| })); | ||
|
|
||
| const mockUseSuspenseConfigValue = | ||
| useSuspenseConfigValue as jest.MockedFunction<any>; | ||
|
|
||
| describe(useIsWorkflowHistoryV2Enabled.name, () => { | ||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('should return true when config value is ENABLED', async () => { | ||
| const { result } = setup({ configValue: 'ENABLED' }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return true when config value is OPT_OUT', async () => { | ||
| const { result } = setup({ configValue: 'OPT_OUT' }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return false when config value is DISABLED', async () => { | ||
| const { result } = setup({ configValue: 'DISABLED' }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return false when config value is OPT_IN and localStorage has no value', async () => { | ||
| const { result } = setup({ configValue: 'OPT_IN' }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return true when config value is OPT_IN and localStorage has true', async () => { | ||
| const { result } = setup({ | ||
| configValue: 'OPT_IN', | ||
| localStorageValue: true, | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| it('should return false when config value is OPT_IN and localStorage has false', async () => { | ||
| const { result } = setup({ | ||
| configValue: 'OPT_IN', | ||
| localStorageValue: false, | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not allow setting value when config is DISABLED', async () => { | ||
| const { result, mockSetLocalStorageValue } = setup({ | ||
| configValue: 'DISABLED', | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
|
|
||
| act(() => { | ||
| result.current[1](true); | ||
| }); | ||
|
|
||
| expect(result.current[0]).toBe(false); | ||
| expect(mockSetLocalStorageValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not allow setting value when config is ENABLED', async () => { | ||
| const { result, mockSetLocalStorageValue } = setup({ | ||
| configValue: 'ENABLED', | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
|
|
||
| act(() => { | ||
| result.current[1](false); | ||
| }); | ||
|
|
||
| expect(result.current[0]).toBe(true); | ||
| expect(mockSetLocalStorageValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should allow setting value when config is OPT_OUT', async () => { | ||
| const { result, mockSetLocalStorageValue } = setup({ | ||
| configValue: 'OPT_OUT', | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
|
|
||
| act(() => { | ||
| result.current[1](false); | ||
| }); | ||
|
|
||
| expect(result.current[0]).toBe(false); | ||
| expect(mockSetLocalStorageValue).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should allow setting value and update localStorage when config is OPT_IN', async () => { | ||
| const { result, mockSetLocalStorageValue } = setup({ | ||
| configValue: 'OPT_IN', | ||
| localStorageValue: false, | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(false); | ||
| }); | ||
|
|
||
| act(() => { | ||
| result.current[1](true); | ||
| }); | ||
|
|
||
| expect(result.current[0]).toBe(true); | ||
| expect(mockSetLocalStorageValue).toHaveBeenCalledWith( | ||
| workflowHistoryUserPreferencesConfig.historyV2ViewEnabled.key, | ||
| 'true' | ||
| ); | ||
| }); | ||
|
|
||
| it('should update localStorage when setting value to false in OPT_IN mode', async () => { | ||
| const { result, mockSetLocalStorageValue } = setup({ | ||
| configValue: 'OPT_IN', | ||
| localStorageValue: true, | ||
| }); | ||
|
|
||
| await waitFor(() => { | ||
| expect(result.current[0]).toBe(true); | ||
| }); | ||
|
|
||
| act(() => { | ||
| result.current[1](false); | ||
| }); | ||
|
|
||
| expect(result.current[0]).toBe(false); | ||
| expect(mockSetLocalStorageValue).toHaveBeenCalledWith( | ||
| workflowHistoryUserPreferencesConfig.historyV2ViewEnabled.key, | ||
| 'false' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| function setup({ | ||
| configValue, | ||
| localStorageValue, | ||
| }: { | ||
| configValue: 'DISABLED' | 'OPT_IN' | 'OPT_OUT' | 'ENABLED'; | ||
| localStorageValue?: boolean | null; | ||
| }) { | ||
| mockUseSuspenseConfigValue.mockReturnValue({ | ||
| data: configValue, | ||
| } satisfies Pick< | ||
| UseSuspenseConfigValueResult<'HISTORY_PAGE_V2_ENABLED'>, | ||
| 'data' | ||
| >); | ||
|
|
||
| const mockGetLocalStorageValue = jest.fn(() => localStorageValue ?? null); | ||
| const mockSetLocalStorageValue = jest.fn(); | ||
|
|
||
| jest | ||
| .spyOn(localStorageModule, 'getLocalStorageValue') | ||
| .mockImplementation(mockGetLocalStorageValue); | ||
| jest | ||
| .spyOn(localStorageModule, 'setLocalStorageValue') | ||
| .mockImplementation(mockSetLocalStorageValue); | ||
|
|
||
| const { result } = renderHook( | ||
| () => useIsWorkflowHistoryV2Enabled(), | ||
| undefined, | ||
| { | ||
| wrapper: ({ children }: { children: React.ReactNode }) => ( | ||
| <Suspense>{children}</Suspense> | ||
| ), | ||
| } | ||
| ); | ||
|
|
||
| return { result, mockGetLocalStorageValue, mockSetLocalStorageValue }; | ||
| } |
69 changes: 69 additions & 0 deletions
69
src/views/workflow-history-v2/hooks/use-is-workflow-history-v2-enabled.ts
This file contains hidden or 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,69 @@ | ||
| import { useCallback, useState } from 'react'; | ||
|
|
||
| import useSuspenseConfigValue from '@/hooks/use-config-value/use-suspense-config-value'; | ||
| import { | ||
| getLocalStorageValue, | ||
| setLocalStorageValue, | ||
| } from '@/utils/local-storage'; | ||
| import workflowHistoryUserPreferencesConfig from '@/views/workflow-history/config/workflow-history-user-preferences.config'; | ||
|
|
||
| /** | ||
| * Manages Workflow History V2 enabled state based on config and localStorage. | ||
| * | ||
| * @returns A tuple containing: | ||
| * - `isWorkflowHistoryV2Enabled`: boolean indicating whether Workflow History V2 is enabled | ||
| * - `setIsWorkflowHistoryV2Enabled`: function to update the enabled state | ||
| * | ||
| * Behavior by config mode: | ||
| * - `DISABLED`: Always returns `false`. Setter has no effect. | ||
| * - `ENABLED`: Always returns `true`. Setter has no effect. | ||
| * - `OPT_OUT`: Always starts with `true`. Setter updates state but does not persist to localStorage. | ||
| * - `OPT_IN`: Reads initial state from localStorage (defaults to `false`). Setter updates both state and localStorage. | ||
| */ | ||
| export default function useIsWorkflowHistoryV2Enabled(): [ | ||
| boolean, | ||
| (v: boolean) => void, | ||
| ] { | ||
adhityamamallan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const { data: historyPageV2Config } = useSuspenseConfigValue( | ||
| 'HISTORY_PAGE_V2_ENABLED' | ||
| ); | ||
|
|
||
| const [isEnabled, setIsEnabled] = useState(() => { | ||
| switch (historyPageV2Config) { | ||
| case 'DISABLED': | ||
| return false; | ||
| case 'ENABLED': | ||
| case 'OPT_OUT': | ||
| return true; | ||
| case 'OPT_IN': | ||
| const userPreference = getLocalStorageValue( | ||
| workflowHistoryUserPreferencesConfig.historyV2ViewEnabled.key, | ||
| workflowHistoryUserPreferencesConfig.historyV2ViewEnabled.schema | ||
| ); | ||
| return userPreference ?? false; | ||
| } | ||
| }); | ||
|
|
||
| const setIsWorkflowHistoryV2Enabled = useCallback( | ||
| (v: boolean) => { | ||
| if ( | ||
| historyPageV2Config === 'DISABLED' || | ||
| historyPageV2Config === 'ENABLED' | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| setIsEnabled(v); | ||
|
|
||
| if (historyPageV2Config === 'OPT_IN') { | ||
| setLocalStorageValue( | ||
| workflowHistoryUserPreferencesConfig.historyV2ViewEnabled.key, | ||
| String(v) | ||
| ); | ||
| } | ||
| }, | ||
adhityamamallan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| [historyPageV2Config] | ||
| ); | ||
|
|
||
| return [isEnabled, setIsWorkflowHistoryV2Enabled]; | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.