Skip to content

Commit 6eca48c

Browse files
gregaubertsonartech
authored andcommitted
SC-37401 Rename and move useNewUI to rely on the useFlags instead (#3945)
GitOrigin-RevId: ecb36eaf195e93d61b4b3300104b8eca19ad8de4
1 parent 6e0296e commit 6eca48c

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

apps/sq-server/src/main/js/app/components/ComponentContainer.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import { createPortal } from 'react-dom';
2525
import { Helmet } from 'react-helmet-async';
2626
import { useIntl } from 'react-intl';
2727
import { Navigate, Outlet } from 'react-router-dom';
28+
import { useFlags } from '~adapters/helpers/feature-flags';
2829
import { useCurrentBranchQuery } from '~adapters/queries/branch';
2930
import { CenteredLayout } from '~design-system';
3031
import { useLocation, useRouter } from '~shared/components/hoc/withRouter';
3132
import { isFile, isPortfolioLike } from '~shared/helpers/component';
3233
import { isDefined } from '~shared/helpers/types';
3334
import { getProjectOverviewUrl } from '~shared/helpers/urls';
34-
import { useNewUI } from '~shared/helpers/useNewUI';
3535
import { ComponentQualifier } from '~shared/types/component';
3636
import { HttpStatus } from '~shared/types/request';
3737
import { validateProjectAlmBinding } from '~sq-server-commons/api/alm-settings';
@@ -71,7 +71,7 @@ function ComponentContainer({ hasFeature }: Readonly<WithAvailableFeaturesProps>
7171
} = useLocation();
7272
const router = useRouter();
7373
const intl = useIntl();
74-
const [newUI] = useNewUI();
74+
const { frontEndEngineeringEnableSidebarNavigation } = useFlags();
7575

7676
const [component, setComponent] = React.useState<Component>();
7777
const [projectComponent, setProjectComponent] = React.useState<Component>();
@@ -401,16 +401,20 @@ function ComponentContainer({ hasFeature }: Readonly<WithAvailableFeaturesProps>
401401
{ project: component?.name ?? '' },
402402
)}
403403
/>
404-
{newUI && component && !isFile(component.qualifier) && <ComponentNav component={component} />}
404+
{frontEndEngineeringEnableSidebarNavigation && component && !isFile(component.qualifier) && (
405+
<ComponentNav component={component} />
406+
)}
405407
<Layout.ContentGrid>
406-
{!newUI && component && !isFile(component.qualifier) && (
407-
<LegacyComponentNavCompatibleWithNewLayout
408-
component={component}
409-
isInProgress={isInProgress}
410-
isPending={isPending}
411-
projectBindingErrors={projectBindingErrors}
412-
/>
413-
)}
408+
{!frontEndEngineeringEnableSidebarNavigation &&
409+
component &&
410+
!isFile(component.qualifier) && (
411+
<LegacyComponentNavCompatibleWithNewLayout
412+
component={component}
413+
isInProgress={isInProgress}
414+
isPending={isPending}
415+
projectBindingErrors={projectBindingErrors}
416+
/>
417+
)}
414418
<Layout.PageGrid>
415419
<Layout.PageContent>
416420
{loading ? (

libs/shared/src/helpers/useNewUI.ts renamed to libs/sq-server-commons/src/helpers/useEnableSidebarNavigation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
2020

21-
import useLocalStorage from './useLocalStorage';
21+
import useLocalStorage from '~shared/helpers/useLocalStorage';
2222

23-
const NEW_UI_PREFERENCE = 'user.preferences.new_ui';
23+
const NEW_UI_PREFERENCE = 'user.preferences.enable-sidebar-navigation';
2424

2525
/**
2626
* Thin wrapper around useLocalStorage to ensure we have a value and not have ot repeat the key
2727
*/
28-
export function useNewUI() {
28+
export function useEnableSidebarNavigation() {
2929
const [value = false, setter] = useLocalStorage<boolean>(NEW_UI_PREFERENCE, false);
3030

3131
return [value, setter] as [boolean, (v: boolean) => void];

libs/sq-server-commons/src/sq-server-adapters/helpers/feature-flags.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@
1919
*/
2020

2121
import { FlagSet } from '~shared/types/feature-flags';
22+
import { useEnableSidebarNavigation } from '../../helpers/useEnableSidebarNavigation';
23+
24+
interface SQSFlagSet extends FlagSet {
25+
frontEndEngineeringEnableSidebarNavigation?: boolean;
26+
}
2227

2328
// SQS doesn't use LaunchDarkly for feature flags, so we just pass a default hardcoded flag set for
2429
// compatibility with SQC in shared code.
2530
// Add features flags here as needed in shared code, especially useful if you want a default value other than falsy for SQS.
26-
const defaultFlags: FlagSet = {};
31+
const defaultFlags: SQSFlagSet = {};
2732

2833
export function useFlags(): FlagSet {
29-
return defaultFlags;
34+
const [frontEndEngineeringEnableSidebarNavigation] = useEnableSidebarNavigation();
35+
36+
return { ...defaultFlags, frontEndEngineeringEnableSidebarNavigation };
3037
}

0 commit comments

Comments
 (0)