diff --git a/lib/components/Base/ChangelogListBase.tsx b/lib/components/Base/ChangelogListBase.tsx new file mode 100644 index 0000000..c19b5c9 --- /dev/null +++ b/lib/components/Base/ChangelogListBase.tsx @@ -0,0 +1,111 @@ +import { Box, Card, CardContent, Chip, Divider, Typography } from '@mui/joy'; +import * as React from 'react'; +import { ChangeType } from '../../changelog.types.ts'; +import { + ChangelogWithComponents, + ChangeTypeMap, + getTypeColor, +} from '../changelog.util.ts'; + +interface Props { + changelogs?: ChangelogWithComponents[]; + changeTypeMapper?: Record; + typeColorResolver?: (type: ChangeType) => string; + hideEntryType?: boolean; +} + +export const ChangelogListBase: React.FC = ({ + changelogs = [], + changeTypeMapper = ChangeTypeMap, + typeColorResolver = getTypeColor, + hideEntryType = false, +}) => ( + + {changelogs.map((changelog, index) => ( + + ({ mb: 1 })}> + Version {changelog.version} + + {new Intl.DateTimeFormat('de-DE', { + year: 'numeric', + month: '2-digit', + day: '2-digit', + }).format(new Date(changelog.releaseDate))} + + + {changelog.description && ( + {changelog.description} + )} + + + {changelog.entries.map((entry) => ( + + {entry.component && ( + <> + {entry.component} + + + )} + + {entry.changelogs.map((entry, entryIndex) => ( + + + {entry.description} + + {!hideEntryType && ( + + {changeTypeMapper[entry.changeType]} + + )} + + ))} + + + ))} + + + ))} + +); diff --git a/lib/components/Base/index.ts b/lib/components/Base/index.ts new file mode 100644 index 0000000..35600c9 --- /dev/null +++ b/lib/components/Base/index.ts @@ -0,0 +1 @@ +export * from './ChangelogListBase.tsx'; diff --git a/lib/components/ChangelogList/ChangelogList.tsx b/lib/components/ChangelogList/ChangelogList.tsx index 132c42c..e2b385a 100644 --- a/lib/components/ChangelogList/ChangelogList.tsx +++ b/lib/components/ChangelogList/ChangelogList.tsx @@ -3,12 +3,10 @@ import { useUpdateHiveContext } from '../ChangelogContext'; import { ChangeType } from '../../changelog.types.ts'; import { ChangelogWithComponents, - ChangeTypeMap, - getTypeColor, groupChangelogsByComponents, ungroupedChangelogs, } from '../changelog.util.ts'; -import ComponentList from './_internal/ComponentList.tsx'; +import { ChangelogListBase } from '../Base'; import { GroupBy } from './ChangelogList.types.ts'; import { useMemo } from 'react'; @@ -16,6 +14,7 @@ interface Props { groupBy?: GroupBy; changeTypeMapper?: Record; typeColorResolver?: (type: ChangeType) => string; + hideEntryType?: boolean; } /** @@ -24,12 +23,14 @@ interface Props { * @param changeTypeMapper Overridable mapping of change types to displayable representations. * @param typeColorResolver Overridable function to resolve the color of a change type. * @param groupBy Group changelogs by component or show a simple list. + * @param hideEntryType Hide the type of the changelog entry. * @constructor */ export const ChangelogList: React.FC = ({ - changeTypeMapper = ChangeTypeMap, - typeColorResolver = getTypeColor, + changeTypeMapper, + typeColorResolver, groupBy = GroupBy.COMPONENT, + hideEntryType = false, }) => { const { data } = useUpdateHiveContext(); @@ -47,14 +48,11 @@ export const ChangelogList: React.FC = ({ }, [data, groupBy]); return ( - <> - {componentChangelogs && ( - - )} - + ); }; diff --git a/lib/components/ChangelogList/MinimalChangelogList.tsx b/lib/components/ChangelogList/MinimalChangelogList.tsx index 57d1886..d0c2736 100644 --- a/lib/components/ChangelogList/MinimalChangelogList.tsx +++ b/lib/components/ChangelogList/MinimalChangelogList.tsx @@ -2,28 +2,25 @@ import * as React from 'react'; import { useUpdateHiveContext } from '../ChangelogContext'; import { ChangelogWithComponents, - ChangeTypeMap, - getTypeColor, ungroupedChangelogs, } from '../changelog.util.ts'; import { ChangeType } from '../../changelog.types.ts'; import { useMemo } from 'react'; -import ComponentList from './_internal/ComponentList.tsx'; +import { ChangelogListBase } from '../Base'; interface Props { changeTypeMapper?: Record; } /** + * @deprecated Use `ChangelogList` with groupBy=GroupBy.NONE instead and hideEntryType=true. * Component which renders a minimal changelog list. * * The list is only ordered by creation. * * @param changeTypeMapper Overridable mapping of change types to displayable representations. */ -export const MinimalChangelogList: React.FC = ({ - changeTypeMapper = ChangeTypeMap, -}) => { +export const MinimalChangelogList: React.FC = ({ changeTypeMapper }) => { const { data } = useUpdateHiveContext(); const componentChangelogs: ChangelogWithComponents[] | undefined = @@ -36,15 +33,10 @@ export const MinimalChangelogList: React.FC = ({ }, [data]); return ( - <> - {componentChangelogs && ( - - )} - + ); }; diff --git a/lib/components/ChangelogList/_internal/ComponentList.tsx b/lib/components/ChangelogList/_internal/ComponentList.tsx deleted file mode 100644 index 27b775a..0000000 --- a/lib/components/ChangelogList/_internal/ComponentList.tsx +++ /dev/null @@ -1,111 +0,0 @@ -import { Box, Card, CardContent, Chip, Divider, Typography } from '@mui/joy'; -import * as React from 'react'; -import { ChangeType } from '../../../changelog.types.ts'; -import { ChangelogWithComponents } from '../../changelog.util.ts'; - -interface Props { - changelogs: ChangelogWithComponents[]; - changeTypeMapper: Record; - typeColorResolver: (type: ChangeType) => string; - hideEntryType?: boolean; -} - -const ComponentList: React.FC = ({ - changelogs, - changeTypeMapper, - typeColorResolver, - hideEntryType = false, -}) => { - return ( - - {changelogs.map((changelog, index) => ( - - ({ mb: 1 })}> - Version {changelog.version} - - {new Intl.DateTimeFormat('de-DE', { - year: 'numeric', - month: '2-digit', - day: '2-digit', - }).format(new Date(changelog.releaseDate))} - - - {changelog.description && ( - {changelog.description} - )} - - - {changelog.entries.map((entry) => ( - - {entry.component && ( - <> - {entry.component} - - - )} - - {entry.changelogs.map((entry, entryIndex) => ( - - - {entry.description} - - {!hideEntryType && ( - - {changeTypeMapper[entry.changeType]} - - )} - - ))} - - - ))} - - - ))} - - ); -}; - -export default ComponentList; diff --git a/lib/components/changelog.util.ts b/lib/components/changelog.util.ts index d805cb2..880f2ad 100644 --- a/lib/components/changelog.util.ts +++ b/lib/components/changelog.util.ts @@ -65,7 +65,7 @@ export const groupChangelogsByComponents = ( }; export interface ComponentEntries { - component?: string; + component: string; changelogs: ChangelogEntryInterface[]; } @@ -89,5 +89,15 @@ export const groupChangelogByComponents = ( componentsArray.push({ component, changelogs }); }); + componentsArray.sort((a, b) => { + if (a.component === 'Weitere Neuerungen') { + return 1; + } + if (b.component === 'Weitere Neuerungen') { + return -1; + } + return a.component.localeCompare(b.component); + }); + return componentsArray; }; diff --git a/lib/updatehive-react.ts b/lib/updatehive-react.ts index fd69700..e0f9b55 100644 --- a/lib/updatehive-react.ts +++ b/lib/updatehive-react.ts @@ -8,6 +8,8 @@ export type { export { useChangelogs } from './changelog.hook'; +export * from './components/changelog.util'; +export * from './components/Base'; export { ChangelogContainer } from './components/ChangelogContainer'; export { useUpdateHiveContext } from './components/ChangelogContext'; export { diff --git a/src/App.tsx b/src/App.tsx index 52a41fa..49db0cc 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,12 @@ import * as React from 'react'; +import { Box, Tab, TabList, TabPanel, Tabs } from '@mui/joy'; import { ChangelogContainer, ChangelogList, useChangelogs, + ChangelogListBase, + groupChangelogsByComponents, + GroupBy, } from '../dist/updatehive-react'; export const App: React.FC = () => { @@ -25,35 +29,61 @@ export const App: React.FC = () => { } return ( -
+

UpdateHive - React Client Component

-

Example using UpdateHive react hook

-
- {loading || error || data === undefined ? ( -
Loading changelogs ...
- ) : ( +

Examples using UpdateHive react components

+ + + Hook + Minimal + ChangelogList + Base + + +

Example using UpdateHive react hook

-
-
Version
-
Description
-
- {data.map((changelog, index) => ( -
-
{changelog.version}
-
{changelog.description}
+ {loading || error || data === undefined ? ( +
Loading changelogs ...
+ ) : ( +
+
+
Version
+
Description
+
+ {data.map((changelog, index) => ( +
+
{changelog.version}
+
{changelog.description}
+
+ ))}
- ))} + )}
- )} -
-

Example using UpdateHive react components

- - - -
+ + + + + + + + + + + + + + + +
); };