🐛 Fix package attributes readout

This commit is contained in:
Manuel
2023-02-04 20:48:55 +01:00
parent 1569a01b27
commit e27aa51b4d
5 changed files with 73 additions and 12 deletions

View File

@@ -9,7 +9,12 @@
"configTip": "Upload your config file by drag and dropping it onto the page!" "configTip": "Upload your config file by drag and dropping it onto the page!"
}, },
"credits": { "credits": {
"madeWithLove": "Made with ❤️ by @" "madeWithLove": "Made with ❤️ by @",
"thirdPartyContent": "See third party content",
"thirdPartyContentTable": {
"dependencyName": "Dependency",
"dependencyVersion": "Version"
}
}, },
"grow": "Grow grid (take all space)", "grow": "Grow grid (take all space)",
"layout": { "layout": {

View File

@@ -90,6 +90,7 @@ export const AboutModal = ({ opened, closeModal, newVersionAvailable }: AboutMod
))} ))}
</tbody> </tbody>
</Table> </Table>
<Divider variant="dashed" mb="md" /> <Divider variant="dashed" mb="md" />
<Title order={6} mb="xs" align="center"> <Title order={6} mb="xs" align="center">
{t('layout/modals/about:contact')} {t('layout/modals/about:contact')}

View File

@@ -1,11 +1,13 @@
import { Group, Anchor, Text } from '@mantine/core'; import { Anchor, Box, Collapse, Flex, Table, Text } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { usePackageAttributesStore } from '../../../tools/client/zustands/usePackageAttributesStore';
export default function Credits() { export default function Credits() {
const { t } = useTranslation('settings/common'); const { t } = useTranslation('settings/common');
return ( return (
<Group position="center" mt="xs"> <Flex justify="center" direction="column" mt="xs">
<Text <Text
style={{ style={{
fontSize: '0.90rem', fontSize: '0.90rem',
@@ -22,6 +24,49 @@ export default function Credits() {
</Anchor>{' '} </Anchor>{' '}
and you! and you!
</Text> </Text>
</Group> <DependencyTable />
</Flex>
); );
} }
const DependencyTable = () => {
const { t } = useTranslation('settings/common');
const [opened, { toggle }] = useDisclosure(false);
const { attributes } = usePackageAttributesStore();
return (
<>
<Text variant="link" mx="auto" size="xs" opacity={0.3} onClick={toggle}>
{t('credits.thirdPartyContent')}
</Text>
<Collapse in={opened}>
<Box
sx={(theme) => ({
backgroundColor:
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[0],
padding: theme.spacing.xl,
borderRadius: theme.radius.md,
})}
mt="md"
>
<Table>
<thead>
<tr>
<th>{t('credits.thirdPartyContentTable.dependencyName')}</th>
<th>{t('credits.thirdPartyContentTable.dependencyVersion')}</th>
</tr>
</thead>
{Object.keys(attributes.dependencies).map((key, index) => (
<tbody key={`dependency-${index}`}>
<tr>
<td>{key}</td>
<td>{attributes.dependencies[key]}</td>
</tr>
</tbody>
))}
</Table>
</Box>
</Collapse>
</>
);
};

View File

@@ -8,7 +8,7 @@ interface PackageAttributesState {
} }
export const usePackageAttributesStore = create<PackageAttributesState>((set) => ({ export const usePackageAttributesStore = create<PackageAttributesState>((set) => ({
attributes: { packageVersion: undefined, environment: 'test' }, attributes: { packageVersion: undefined, environment: 'test', dependencies: {} },
setInitialPackageAttributes(attributes) { setInitialPackageAttributes(attributes) {
set((state) => ({ ...state, attributes })); set((state) => ({ ...state, attributes }));
}, },

View File

@@ -1,14 +1,24 @@
const getServerPackageVersion = (): string | undefined => process.env.npm_package_version; import packageJson from '../../../package.json';
const getServerNodeEnvironment = (): 'development' | 'production' | 'test' => const getServerPackageVersion = (): string | undefined => packageJson.version;
process.env.NODE_ENV;
export const getServiceSidePackageAttributes = (): ServerSidePackageAttributesType => ({ const getServerNodeEnvironment = (): 'development' | 'production' | 'test' => process.env.NODE_ENV;
const getDependencies = (): PackageJsonDependencies => packageJson.dependencies;
export const getServiceSidePackageAttributes = (): ServerSidePackageAttributesType => {
const result = {
packageVersion: getServerPackageVersion(), packageVersion: getServerPackageVersion(),
environment: getServerNodeEnvironment(), environment: getServerNodeEnvironment(),
}); dependencies: getDependencies(),
} as ServerSidePackageAttributesType;
return result;
};
export type ServerSidePackageAttributesType = { export type ServerSidePackageAttributesType = {
packageVersion: string | undefined; packageVersion: string | undefined;
environment: 'development' | 'production' | 'test'; environment: 'development' | 'production' | 'test';
dependencies: PackageJsonDependencies;
}; };
type PackageJsonDependencies = { [key in string]: string };