Skip to content

Commit b1f7db1

Browse files
authored
feat: add release date to changelog
1 parent fe2e674 commit b1f7db1

File tree

6 files changed

+22
-18
lines changed

6 files changed

+22
-18
lines changed

lib/changelog.hook.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ export function useChangelogs(config: UpdateHiveConfig): UpdateHiveHookResult {
4545
throw new Error(error.message);
4646
}
4747

48-
setData(await result.json());
48+
const resultData: Changelog[] | undefined = await result.json();
49+
50+
if (resultData) {
51+
setData(
52+
resultData.sort((a, b) => Date.parse(b.releaseDate) - Date.parse(a.releaseDate)),
53+
);
54+
}
4955
} catch (error) {
5056
if (error instanceof Error) {
5157
setError(error.message);

lib/changelog.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export type Changelog = {
5353
product: string;
5454
variant: VariantType;
5555
version: string;
56-
releaseDate: Date;
56+
releaseDate: string;
5757
title?: string;
5858
description?: string;
5959
entries: ChangelogEntryInterface[];

lib/components/ChangelogList/ChangelogList.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
ChangeTypeMap,
77
getTypeColor,
88
groupChangelogsByComponents,
9-
reorderChangelogs,
109
ungroupedChangelogs,
1110
} from '../changelog.util.ts';
1211
import ComponentList from './_internal/ComponentList.tsx';
@@ -40,13 +39,11 @@ export const ChangelogList: React.FC<Props> = ({
4039
return undefined;
4140
}
4241

43-
const reorderedChangelogs = reorderChangelogs(data);
44-
4542
if (groupBy === GroupBy.NONE) {
46-
return ungroupedChangelogs(reorderedChangelogs);
43+
return ungroupedChangelogs(data);
4744
}
4845

49-
return groupChangelogsByComponents(reorderedChangelogs);
46+
return groupChangelogsByComponents(data);
5047
}, [data, groupBy]);
5148

5249
return (

lib/components/ChangelogList/MinimalChangelogList.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
ChangelogWithComponents,
55
ChangeTypeMap,
66
getTypeColor,
7-
reorderChangelogs,
87
ungroupedChangelogs,
98
} from '../changelog.util.ts';
109
import { ChangeType } from '../../changelog.types.ts';
@@ -33,8 +32,7 @@ export const MinimalChangelogList: React.FC<Props> = ({
3332
return undefined;
3433
}
3534

36-
const reorderedChangelogs = reorderChangelogs(data);
37-
return ungroupedChangelogs(reorderedChangelogs);
35+
return ungroupedChangelogs(data);
3836
}, [data]);
3937

4038
return (

lib/components/ChangelogList/_internal/ComponentList.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ const ComponentList: React.FC<Props> = ({
2828
<Card key={`changelogs-${index}`} variant={'soft'}>
2929
<Box sx={() => ({ mb: 1 })}>
3030
<Typography level="h1">Version {changelog.version}</Typography>
31+
<Typography level="h4" color={'neutral'}>
32+
{new Intl.DateTimeFormat('de-DE', {
33+
year: 'numeric',
34+
month: '2-digit',
35+
day: '2-digit',
36+
}).format(new Date(changelog.releaseDate))}
37+
</Typography>
3138
<Divider
3239
sx={{
3340
mt: 1,

lib/components/changelog.util.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ export const getTypeColor = (type: ChangeType): string => {
3131
}
3232
};
3333

34-
export const reorderChangelogs = (changelogs: Changelog[]) => {
35-
return changelogs.toReversed();
36-
};
37-
38-
export interface ChangelogWithComponents {
39-
version: string;
40-
description?: string;
41-
34+
export interface ChangelogWithComponents
35+
extends Pick<Changelog, 'version' | 'description' | 'releaseDate'> {
4236
entries: ComponentEntries[];
4337
}
4438

@@ -48,6 +42,7 @@ export const ungroupedChangelogs = (
4842
return changelogs.map((changelog) => ({
4943
version: changelog.version,
5044
description: changelog.description,
45+
releaseDate: changelog.releaseDate,
5146
entries: [{ component: '', changelogs: changelog.entries }],
5247
}));
5348
};
@@ -61,6 +56,7 @@ export const groupChangelogsByComponents = (
6156
mapped.push({
6257
version: changelog.version,
6358
description: changelog.description,
59+
releaseDate: changelog.releaseDate,
6460
entries: groupChangelogByComponents(changelog),
6561
});
6662
});

0 commit comments

Comments
 (0)