2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

feat(frontend): Hide empty args in about dialog (#9033)

* clean up version info text

* feat(frontend): Hide empty args in about dialog

* simplify

* simplify more
This commit is contained in:
Matthias Mair 2025-02-04 23:45:48 +01:00 committed by GitHub
parent 72c077c861
commit 8bea3caec4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,13 +31,15 @@ type AboutLookupRef = {
export function AboutInvenTreeModal({ export function AboutInvenTreeModal({
context, context,
id id
}: ContextModalProps<{ }: Readonly<
modalBody: string; ContextModalProps<{
}>) { modalBody: string;
}>
>) {
const [user] = useUserState((state) => [state.user]); const [user] = useUserState((state) => [state.user]);
const [server] = useServerApiState((state) => [state.server]); const [server] = useServerApiState((state) => [state.server]);
if (user?.is_staff != true) if (!user?.is_staff)
return ( return (
<Text> <Text>
<Trans>This information is only available for staff users</Trans> <Trans>This information is only available for staff users</Trans>
@ -75,18 +77,68 @@ export function AboutInvenTreeModal({
/* renderer */ /* renderer */
if (isLoading) return <Trans>Loading</Trans>; if (isLoading) return <Trans>Loading</Trans>;
const commit_set: boolean =
data.version.commit_hash && data.version.commit_date;
const copyval = `InvenTree-Version: ${data.version.server}\nDjango Version: ${ const copyval = `InvenTree-Version: ${data.version.server}\nDjango Version: ${
data.version.django data.version.django
}\n${ }\n${
data.version.commit_hash && commit_set
`Commit Hash: ${data.version.commit_hash}\nCommit Date: ${data.version.commit_date}\nCommit Branch: ${data.version.commit_branch}\n` ? `Commit Hash: ${data.version.commit_hash}\nCommit Date: ${data.version.commit_date}\nCommit Branch: ${data.version.commit_branch}\n`
: ''
}Database: ${server.database}\nDebug-Mode: ${ }Database: ${server.database}\nDebug-Mode: ${
server.debug_mode ? 'True' : 'False' server.debug_mode ? 'True' : 'False'
}\nDeployed using Docker: ${ }\nDeployed using Docker: ${
server.docker_mode ? 'True' : 'False' server.docker_mode ? 'True' : 'False'
}\nPlatform: ${server.platform}\nInstaller: ${server.installer}\n${ }\nPlatform: ${server.platform}\nInstaller: ${server.installer ? server.installer : ''}\n${
server.target && `Target: ${server.target}\n` server.target ? `Target: ${server.target}\n` : ''
}Active plugins: ${JSON.stringify(server.active_plugins)}`; }Active plugins: ${JSON.stringify(server.active_plugins)}`;
const tableData = [
{
ref: 'server',
title: <Trans>InvenTree Version</Trans>,
link: 'https://github.com/inventree/InvenTree/releases',
copy: true
},
{
ref: 'api',
title: <Trans>API Version</Trans>,
link: generateUrl('/api-doc/'),
copy: true
},
{
ref: 'python',
title: <Trans>Python Version</Trans>,
copy: true
},
{
ref: 'django',
title: <Trans>Django Version</Trans>,
link: 'https://www.djangoproject.com/',
copy: true
}
];
if (commit_set) {
tableData.push(
{
ref: 'commit_hash',
title: <Trans>Commit Hash</Trans>,
copy: true
},
{
ref: 'commit_date',
title: <Trans>Commit Date</Trans>,
copy: true
},
{
ref: 'commit_branch',
title: <Trans>Commit Branch</Trans>,
copy: true
}
);
}
return ( return (
<Stack> <Stack>
<Divider /> <Divider />
@ -94,66 +146,10 @@ export function AboutInvenTreeModal({
<StylishText size='lg'> <StylishText size='lg'>
<Trans>Version Information</Trans> <Trans>Version Information</Trans>
</StylishText> </StylishText>
{data.dev ? ( {renderVersionBadge(data)}
<Badge color='blue'>
<Trans>Development Version</Trans>
</Badge>
) : data.up_to_date ? (
<Badge color='green'>
<Trans>Up to Date</Trans>
</Badge>
) : (
<Badge color='teal'>
<Trans>Update Available</Trans>
</Badge>
)}
</Group> </Group>
<Table striped> <Table striped>
<Table.Tbody> <Table.Tbody>{fillTable(tableData, data.version)}</Table.Tbody>
{fillTable(
[
{
ref: 'server',
title: <Trans>InvenTree Version</Trans>,
link: 'https://github.com/inventree/InvenTree/releases',
copy: true
},
{
ref: 'commit_hash',
title: <Trans>Commit Hash</Trans>,
copy: true
},
{
ref: 'commit_date',
title: <Trans>Commit Date</Trans>,
copy: true
},
{
ref: 'commit_branch',
title: <Trans>Commit Branch</Trans>,
copy: true
},
{
ref: 'api',
title: <Trans>API Version</Trans>,
link: generateUrl('/api-doc/'),
copy: true
},
{
ref: 'python',
title: <Trans>Python Version</Trans>,
copy: true
},
{
ref: 'django',
title: <Trans>Django Version</Trans>,
link: 'https://www.djangoproject.com/',
copy: true
}
],
data.version
)}
</Table.Tbody>
</Table> </Table>
<Divider /> <Divider />
<StylishText size='lg'> <StylishText size='lg'>
@ -189,3 +185,17 @@ export function AboutInvenTreeModal({
</Stack> </Stack>
); );
} }
function renderVersionBadge(data: any) {
const badgeType = () => {
if (data.dev) {
return { color: 'blue', label: <Trans>Development Version</Trans> };
} else if (data.up_to_date) {
return { color: 'green', label: <Trans>Up to Date</Trans> };
} else {
return { color: 'teal', label: <Trans>Update Available</Trans> };
}
};
const { color, label } = badgeType();
return <Badge color={color}>{label}</Badge>;
}