Skip to content

Commit

Permalink
feat: add release date to changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
saschb2b authored Sep 25, 2024
1 parent fe2e674 commit b1f7db1
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
8 changes: 7 additions & 1 deletion lib/changelog.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ export function useChangelogs(config: UpdateHiveConfig): UpdateHiveHookResult {
throw new Error(error.message);
}

setData(await result.json());
const resultData: Changelog[] | undefined = await result.json();

if (resultData) {
setData(
resultData.sort((a, b) => Date.parse(b.releaseDate) - Date.parse(a.releaseDate)),
);
}
} catch (error) {
if (error instanceof Error) {
setError(error.message);
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export type Changelog = {
product: string;
variant: VariantType;
version: string;
releaseDate: Date;
releaseDate: string;
title?: string;
description?: string;
entries: ChangelogEntryInterface[];
Expand Down
7 changes: 2 additions & 5 deletions lib/components/ChangelogList/ChangelogList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ChangeTypeMap,
getTypeColor,
groupChangelogsByComponents,
reorderChangelogs,
ungroupedChangelogs,
} from '../changelog.util.ts';
import ComponentList from './_internal/ComponentList.tsx';
Expand Down Expand Up @@ -40,13 +39,11 @@ export const ChangelogList: React.FC<Props> = ({
return undefined;
}

const reorderedChangelogs = reorderChangelogs(data);

if (groupBy === GroupBy.NONE) {
return ungroupedChangelogs(reorderedChangelogs);
return ungroupedChangelogs(data);
}

return groupChangelogsByComponents(reorderedChangelogs);
return groupChangelogsByComponents(data);
}, [data, groupBy]);

return (
Expand Down
4 changes: 1 addition & 3 deletions lib/components/ChangelogList/MinimalChangelogList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ChangelogWithComponents,
ChangeTypeMap,
getTypeColor,
reorderChangelogs,
ungroupedChangelogs,
} from '../changelog.util.ts';
import { ChangeType } from '../../changelog.types.ts';
Expand Down Expand Up @@ -33,8 +32,7 @@ export const MinimalChangelogList: React.FC<Props> = ({
return undefined;
}

const reorderedChangelogs = reorderChangelogs(data);
return ungroupedChangelogs(reorderedChangelogs);
return ungroupedChangelogs(data);
}, [data]);

return (
Expand Down
7 changes: 7 additions & 0 deletions lib/components/ChangelogList/_internal/ComponentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ const ComponentList: React.FC<Props> = ({
<Card key={`changelogs-${index}`} variant={'soft'}>
<Box sx={() => ({ mb: 1 })}>
<Typography level="h1">Version {changelog.version}</Typography>
<Typography level="h4" color={'neutral'}>
{new Intl.DateTimeFormat('de-DE', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).format(new Date(changelog.releaseDate))}
</Typography>
<Divider
sx={{
mt: 1,
Expand Down
12 changes: 4 additions & 8 deletions lib/components/changelog.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ export const getTypeColor = (type: ChangeType): string => {
}
};

export const reorderChangelogs = (changelogs: Changelog[]) => {
return changelogs.toReversed();
};

export interface ChangelogWithComponents {
version: string;
description?: string;

export interface ChangelogWithComponents
extends Pick<Changelog, 'version' | 'description' | 'releaseDate'> {
entries: ComponentEntries[];
}

Expand All @@ -48,6 +42,7 @@ export const ungroupedChangelogs = (
return changelogs.map((changelog) => ({
version: changelog.version,
description: changelog.description,
releaseDate: changelog.releaseDate,
entries: [{ component: '', changelogs: changelog.entries }],
}));
};
Expand All @@ -61,6 +56,7 @@ export const groupChangelogsByComponents = (
mapped.push({
version: changelog.version,
description: changelog.description,
releaseDate: changelog.releaseDate,
entries: groupChangelogByComponents(changelog),
});
});
Expand Down

0 comments on commit b1f7db1

Please sign in to comment.