Skip to content

Commit 40df1ab

Browse files
committed
types and constants cleanup
1 parent ccbba0f commit 40df1ab

File tree

10 files changed

+70
-44
lines changed

10 files changed

+70
-44
lines changed

apps/site/components/EOL/EOLModal/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import type { FC } from 'react';
44

55
import UnknownSeveritySection from '#site/components/EOL/UnknownSeveritySection';
66
import VulnerabilitiesTable from '#site/components/EOL/VulnerabilitiesTable';
7-
import { SEVERITY_ORDER } from '#site/components/EOL/VulnerabilityChips';
8-
import type { ModalProps } from '#site/providers/modalProvider';
9-
import type { NodeRelease } from '#site/types';
7+
import { SEVERITY_ORDER } from '#site/next.constants.mjs';
8+
import type { ModalProps, NodeRelease } from '#site/types';
109
import type { Vulnerability } from '#site/types/vulnerabilities';
1110

1211
type EOLModalData = {

apps/site/components/EOL/EOLReleaseTable/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import type { FC } from 'react';
33

44
import FormattedTime from '#site/components/Common/FormattedTime';
55
import DetailsButton from '#site/components/Downloads/DownloadReleasesTable/DetailsButton';
6+
import VulnerabilityChips from '#site/components/EOL/VulnerabilityChips';
67
import provideReleaseData from '#site/next-data/providers/releaseData';
78
import provideVulnerabilities from '#site/next-data/providers/vulnerabilities';
8-
9-
import VulnerabilityChips from '../VulnerabilityChips';
9+
import { EOL_VERSION_IDENTIFIER } from '#site/next.constants.mjs';
1010

1111
const EOLReleaseTable: FC = () => {
1212
const releaseData = provideReleaseData();
1313
const vulnerabilities = provideVulnerabilities();
1414
const eolReleases = releaseData.filter(
15-
release => release.status === 'End-of-life'
15+
release => release.status === EOL_VERSION_IDENTIFIER
1616
);
1717

1818
const t = useTranslations();

apps/site/components/EOL/VulnerabilityChips/Chip/index.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
import Badge from '@node-core/ui-components/Common/Badge';
1+
import Badge, { type BadgeKind } from '@node-core/ui-components/Common/Badge';
22
import { useTranslations } from 'next-intl';
33
import type { FC } from 'react';
44

5-
import styles from './index.module.css';
5+
import { SEVERITY_KIND_MAP } from '#site/next.constants.mjs';
66

7-
const SEVERITY_KIND_MAP = {
8-
unknown: 'neutral',
9-
low: 'default',
10-
medium: 'info',
11-
high: 'warning',
12-
critical: 'error',
13-
} as const;
7+
import styles from './index.module.css';
148

159
type VulnerabilityChipProps = {
1610
severity: keyof typeof SEVERITY_KIND_MAP;
@@ -24,7 +18,11 @@ const VulnerabilityChip: FC<VulnerabilityChipProps> = ({
2418
const t = useTranslations();
2519

2620
return (
27-
<Badge size="small" kind={SEVERITY_KIND_MAP[severity]} className="mr-1">
21+
<Badge
22+
size="small"
23+
kind={SEVERITY_KIND_MAP[severity] as BadgeKind}
24+
className="mr-1"
25+
>
2826
{count > 0 ? <span className={styles.chipCount}>{count}</span> : null}
2927
{t(`components.eolChip.severity.${severity}`)}
3028
</Badge>

apps/site/components/EOL/VulnerabilityChips/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import type { FC } from 'react';
22

3+
import VulnerabilityChip from '#site/components/EOL/VulnerabilityChips/Chip';
4+
import { SEVERITY_ORDER } from '#site/next.constants.mjs';
35
import type { Vulnerability } from '#site/types/vulnerabilities';
46

5-
import VulnerabilityChip from './Chip';
6-
7-
export const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low'] as const;
8-
97
type VulnerabilityChipsProps = {
108
vulnerabilities: Array<Vulnerability>;
119
};

apps/site/components/withLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import GlowingBackdropLayout from '#site/layouts/GlowingBackdrop';
99
import LearnLayout from '#site/layouts/Learn';
1010
import PostLayout from '#site/layouts/Post';
1111
import { ModalProvider } from '#site/providers/modalProvider';
12-
import type { Layouts } from '#site/types';
12+
import type { Layouts, ModalType } from '#site/types';
1313

1414
const layouts = {
1515
about: AboutLayout,
@@ -24,7 +24,7 @@ const layouts = {
2424

2525
type WithLayoutProps<L = Layouts> = PropsWithChildren<{
2626
layout: L;
27-
modal?: string;
27+
modal?: ModalType;
2828
}>;
2929

3030
const WithLayout: FC<WithLayoutProps<Layouts>> = ({

apps/site/next.constants.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,24 @@ export const GITHUB_API_KEY = process.env.NEXT_GITHUB_API_KEY || '';
174174
*/
175175
export const TRANSLATION_URL =
176176
'https://github.com/nodejs/nodejs.org/blob/main/TRANSLATION.md#how-to-translate';
177+
178+
/**
179+
* Define the order in which vulnerabilities should be sorted
180+
*/
181+
export const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low'];
182+
183+
/**
184+
* Maps vulnerability severity levels to UI Badge kinds
185+
*/
186+
export const SEVERITY_KIND_MAP = {
187+
unknown: 'neutral',
188+
low: 'default',
189+
medium: 'info',
190+
high: 'warning',
191+
critical: 'error',
192+
};
193+
194+
/**
195+
* Which Node.js versions do we want to display vulnerabilities for?
196+
*/
197+
export const EOL_VERSION_IDENTIFIER = 'End-of-life';

apps/site/providers/modalProvider.tsx

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
'use client';
22

3-
import type { FC, PropsWithChildren, ComponentType } from 'react';
3+
import type { FC, ComponentType } from 'react';
44
import { createContext, useState } from 'react';
55

6-
import ReleaseModal from '../components/Downloads/ReleaseModal';
7-
import EOLModal from '../components/EOL/EOLModal';
8-
9-
export type ModalProps = {
10-
open: boolean;
11-
closeModal: () => void;
12-
data: unknown;
13-
};
14-
15-
type ModalContextType = {
16-
data: unknown;
17-
openModal: (data: unknown) => void;
18-
closeModal: () => void;
19-
};
6+
import ReleaseModal from '#site/components/Downloads/ReleaseModal';
7+
import EOLModal from '#site/components/EOL/EOLModal';
8+
import type {
9+
ModalContextType,
10+
ModalProps,
11+
ModalProviderProps,
12+
ModalType,
13+
} from '#site/types/modal';
2014

2115
export const ModalContext = createContext<ModalContextType>({
2216
data: null,
2317
openModal: () => {},
2418
closeModal: () => {},
2519
});
2620

27-
const MODALS: Record<string, ComponentType<ModalProps>> = {
21+
const MODALS = {
2822
release: ReleaseModal,
2923
eol: EOLModal,
30-
};
31-
32-
type ModalProviderProps = PropsWithChildren<{
33-
type: keyof typeof MODALS;
34-
}>;
24+
} satisfies Record<ModalType, ComponentType<ModalProps>>;
3525

3626
export const ModalProvider: FC<ModalProviderProps> = ({ type, children }) => {
3727
const [data, setData] = useState<unknown>(null);

apps/site/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './features';
44
export * from './frontmatter';
55
export * from './i18n';
66
export * from './layouts';
7+
export * from './modal';
78
export * from './navigation';
89
export * from './releases';
910
export * from './redirects';

apps/site/types/modal.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { PropsWithChildren } from 'react';
2+
3+
export type ModalProps = {
4+
open: boolean;
5+
closeModal: () => void;
6+
data: unknown;
7+
};
8+
9+
export type ModalContextType = {
10+
data: unknown;
11+
openModal: (data: unknown) => void;
12+
closeModal: () => void;
13+
};
14+
15+
export type ModalType = 'release' | 'eol';
16+
17+
export type ModalProviderProps = PropsWithChildren<{
18+
type: ModalType;
19+
}>;

packages/ui-components/src/Common/Badge/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FC, HTMLAttributes, PropsWithChildren } from 'react';
33

44
import styles from './index.module.css';
55

6-
type BadgeKind = 'default' | 'warning' | 'error' | 'info' | 'neutral';
6+
export type BadgeKind = 'default' | 'warning' | 'error' | 'info' | 'neutral';
77
type BadgeSize = 'small' | 'medium';
88

99
type BadgeProps = HTMLAttributes<HTMLSpanElement> & {

0 commit comments

Comments
 (0)