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: useUiFlag shorthand hook #4566

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions frontend/src/component/menu/Header/DrawerMenu/DrawerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ReactComponent as UnleashLogo } from 'assets/img/logoDarkWithText.svg';
import { ReactComponent as UnleashLogoWhite } from 'assets/img/logoWithWhiteText.svg';
import NavigationLink from '../NavigationLink/NavigationLink';
import { basePath } from 'utils/formatPath';
import { IFlags } from 'interfaces/uiConfig';
import { INavigationMenuItem } from 'interfaces/route';
import styles from './DrawerMenu.module.scss'; // FIXME: useStyle - theme
import theme from 'themes/theme';
Expand Down Expand Up @@ -36,7 +35,6 @@ interface IDrawerMenuProps {
href: string;
title: string;
}>;
flags?: IFlags;
routes: {
mainNavRoutes: INavigationMenuItem[];
mobileRoutes: INavigationMenuItem[];
Expand All @@ -46,7 +44,6 @@ interface IDrawerMenuProps {

export const DrawerMenu: VFC<IDrawerMenuProps> = ({
links = [],
flags = {},
open = false,
toggleDrawer,
routes,
Expand Down
1 change: 0 additions & 1 deletion frontend/src/component/menu/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const Header: VFC = () => {
</IconButton>
</Tooltip>
<DrawerMenu
flags={uiConfig.flags}
links={uiConfig.links}
open={openDrawer}
toggleDrawer={toggleDrawer}
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/hooks/useUiFlag.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';

type flags = ReturnType<typeof useUiConfig>['uiConfig']['flags'];

export const useUiFlag = <K extends keyof flags>(flag: K) => {
const { uiConfig } = useUiConfig();

return uiConfig?.flags?.[flag] || false;
};
6 changes: 3 additions & 3 deletions frontend/src/interfaces/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { VoidFunctionComponent } from 'react';
import { IFlags, IUiConfig } from 'interfaces/uiConfig';
import { UiFlags, IUiConfig } from 'interfaces/uiConfig';

export interface IRoute {
path: string;
title: string;
type: 'protected' | 'unprotected';
layout?: string;
parent?: string;
flag?: keyof IFlags;
flag?: keyof UiFlags;
configFlag?: keyof IUiConfig;
hidden?: boolean;
enterprise?: boolean;
Expand All @@ -20,7 +20,7 @@ export interface INavigationMenuItem {
path: string;
title: string;
menu: IRouteMenu;
flag?: keyof IFlags;
flag?: keyof UiFlags;
configFlag?: keyof IUiConfig;
group?: string;
}
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ import { Variant } from 'utils/variants';
export interface IUiConfig {
authenticationType?: string;
baseUriPath?: string;
flags: IFlags;
/**
* @deprecated `useUiFlags` can be used instead
* @example
* ```ts
* const yourFlag = useUiFlags("yourFlag")
* ```
*/
flags: UiFlags;
name: string;
slogan: string;
environment?: string;
Expand All @@ -29,7 +36,7 @@ export interface IProclamationToast {
link: string;
}

export interface IFlags {
export type UiFlags = {
P: boolean;
RE: boolean;
EEA?: boolean;
Expand Down Expand Up @@ -59,7 +66,7 @@ export interface IFlags {
featureNamingPattern?: boolean;
doraMetrics?: boolean;
[key: string]: boolean | Variant | undefined;
}
};

export interface IVersionInfo {
instanceId: string;
Expand Down
Loading