Skip to content

Commit

Permalink
chore: initial sort data by release date
Browse files Browse the repository at this point in the history
  • Loading branch information
saschb2b committed Sep 10, 2024
1 parent 72c2b73 commit de2f92c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
13 changes: 12 additions & 1 deletion lib/changelog.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,18 @@ 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) => {
return (
new Date(b.releaseDate).getTime() -
new Date(a.releaseDate).getTime()
);
}),
);
}
} 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
4 changes: 0 additions & 4 deletions lib/components/changelog.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ export const getTypeColor = (type: ChangeType): string => {
}
};

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

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

0 comments on commit de2f92c

Please sign in to comment.