1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-23 00:22:19 +01:00

refactor: make uiFlags typesafe (#4996)

This should add some typesafety to our usage of uiFlags.
This commit is contained in:
Nuno Góis 2023-10-11 12:44:54 +01:00 committed by GitHub
parent 4e8c0478bf
commit c3575c7727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 18 deletions

View File

@ -39,6 +39,7 @@ import { IMPORT_BUTTON } from 'utils/testIds';
import { EnterpriseBadge } from 'component/common/EnterpriseBadge/EnterpriseBadge'; import { EnterpriseBadge } from 'component/common/EnterpriseBadge/EnterpriseBadge';
import { Badge } from 'component/common/Badge/Badge'; import { Badge } from 'component/common/Badge/Badge';
import { ProjectDoraMetrics } from './ProjectDoraMetrics/ProjectDoraMetrics'; import { ProjectDoraMetrics } from './ProjectDoraMetrics/ProjectDoraMetrics';
import { UiFlags } from 'interfaces/uiConfig';
const StyledBadge = styled(Badge)(({ theme }) => ({ const StyledBadge = styled(Badge)(({ theme }) => ({
position: 'absolute', position: 'absolute',
@ -49,6 +50,15 @@ const StyledBadge = styled(Badge)(({ theme }) => ({
}, },
})); }));
interface ITab {
title: string;
path: string;
name: string;
flag?: keyof UiFlags;
new?: boolean;
isEnterprise?: boolean;
}
export const Project = () => { export const Project = () => {
const projectId = useRequiredPathParam('projectId'); const projectId = useRequiredPathParam('projectId');
const params = useQueryParams(); const params = useQueryParams();
@ -65,35 +75,27 @@ export const Project = () => {
const [showDelDialog, setShowDelDialog] = useState(false); const [showDelDialog, setShowDelDialog] = useState(false);
const tabs = [ const tabs: ITab[] = [
{ {
title: 'Overview', title: 'Overview',
path: basePath, path: basePath,
name: 'overview', name: 'overview',
flag: undefined,
new: false,
}, },
{ {
title: 'Health', title: 'Health',
path: `${basePath}/health`, path: `${basePath}/health`,
name: 'health', name: 'health',
flag: undefined,
new: false,
}, },
{ {
title: 'Archive', title: 'Archive',
path: `${basePath}/archive`, path: `${basePath}/archive`,
name: 'archive', name: 'archive',
flag: undefined,
new: false,
}, },
{ {
title: 'Change requests', title: 'Change requests',
path: `${basePath}/change-requests`, path: `${basePath}/change-requests`,
name: 'change-request', name: 'change-request',
isEnterprise: true, isEnterprise: true,
flag: undefined,
new: false,
}, },
{ {
title: 'Metrics', title: 'Metrics',
@ -106,17 +108,15 @@ export const Project = () => {
title: 'Event log', title: 'Event log',
path: `${basePath}/logs`, path: `${basePath}/logs`,
name: 'logs', name: 'logs',
flag: undefined,
new: false,
}, },
{ {
title: 'Project settings', title: 'Project settings',
path: `${basePath}/settings${isOss() ? '/environments' : ''}`, path: `${basePath}/settings${isOss() ? '/environments' : ''}`,
name: 'settings', name: 'settings',
flag: undefined,
new: false,
}, },
] ];
const filteredTabs = tabs
.filter((tab) => { .filter((tab) => {
if (tab.flag) { if (tab.flag) {
return uiConfig.flags[tab.flag]; return uiConfig.flags[tab.flag];
@ -125,7 +125,7 @@ export const Project = () => {
}) })
.filter((tab) => !(isOss() && tab.isEnterprise)); .filter((tab) => !(isOss() && tab.isEnterprise));
const activeTab = [...tabs] const activeTab = [...filteredTabs]
.reverse() .reverse()
.find((tab) => pathname.startsWith(tab.path)); .find((tab) => pathname.startsWith(tab.path));
@ -221,7 +221,7 @@ export const Project = () => {
variant='scrollable' variant='scrollable'
allowScrollButtonsMobile allowScrollButtonsMobile
> >
{tabs.map((tab) => { {filteredTabs.map((tab) => {
return ( return (
<StyledTab <StyledTab
key={tab.title} key={tab.title}
@ -235,7 +235,7 @@ export const Project = () => {
icon={ icon={
<> <>
<ConditionallyRender <ConditionallyRender
condition={tab.new} condition={Boolean(tab.new)}
show={ show={
<StyledBadge color='success'> <StyledBadge color='success'>
New New

View File

@ -40,6 +40,7 @@ export type UiFlags = {
P: boolean; P: boolean;
RE: boolean; RE: boolean;
EEA?: boolean; EEA?: boolean;
SE?: boolean;
T?: boolean; T?: boolean;
UNLEASH_CLOUD?: boolean; UNLEASH_CLOUD?: boolean;
UG?: boolean; UG?: boolean;
@ -65,9 +66,9 @@ export type UiFlags = {
variantTypeNumber?: boolean; variantTypeNumber?: boolean;
privateProjects?: boolean; privateProjects?: boolean;
accessOverview?: boolean; accessOverview?: boolean;
datadogJsonTemplate?: boolean;
dependentFeatures?: boolean; dependentFeatures?: boolean;
internalMessageBanners?: boolean; internalMessageBanners?: boolean;
[key: string]: boolean | Variant | undefined;
}; };
export interface IVersionInfo { export interface IVersionInfo {