From 8bea3caec42805a1c96ba9a64f7782f605df1609 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 4 Feb 2025 23:45:48 +0100 Subject: [PATCH] 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 --- .../components/modals/AboutInvenTreeModal.tsx | 142 ++++++++++-------- 1 file changed, 76 insertions(+), 66 deletions(-) diff --git a/src/frontend/src/components/modals/AboutInvenTreeModal.tsx b/src/frontend/src/components/modals/AboutInvenTreeModal.tsx index 1862d60848..35130f0116 100644 --- a/src/frontend/src/components/modals/AboutInvenTreeModal.tsx +++ b/src/frontend/src/components/modals/AboutInvenTreeModal.tsx @@ -31,13 +31,15 @@ type AboutLookupRef = { export function AboutInvenTreeModal({ context, id -}: ContextModalProps<{ - modalBody: string; -}>) { +}: Readonly< + ContextModalProps<{ + modalBody: string; + }> +>) { const [user] = useUserState((state) => [state.user]); const [server] = useServerApiState((state) => [state.server]); - if (user?.is_staff != true) + if (!user?.is_staff) return ( This information is only available for staff users @@ -75,18 +77,68 @@ export function AboutInvenTreeModal({ /* renderer */ if (isLoading) return Loading; + const commit_set: boolean = + data.version.commit_hash && data.version.commit_date; + const copyval = `InvenTree-Version: ${data.version.server}\nDjango Version: ${ data.version.django }\n${ - data.version.commit_hash && - `Commit Hash: ${data.version.commit_hash}\nCommit Date: ${data.version.commit_date}\nCommit Branch: ${data.version.commit_branch}\n` + commit_set + ? `Commit Hash: ${data.version.commit_hash}\nCommit Date: ${data.version.commit_date}\nCommit Branch: ${data.version.commit_branch}\n` + : '' }Database: ${server.database}\nDebug-Mode: ${ server.debug_mode ? 'True' : 'False' }\nDeployed using Docker: ${ server.docker_mode ? 'True' : 'False' - }\nPlatform: ${server.platform}\nInstaller: ${server.installer}\n${ - server.target && `Target: ${server.target}\n` + }\nPlatform: ${server.platform}\nInstaller: ${server.installer ? server.installer : ''}\n${ + server.target ? `Target: ${server.target}\n` : '' }Active plugins: ${JSON.stringify(server.active_plugins)}`; + + const tableData = [ + { + ref: 'server', + title: InvenTree Version, + link: 'https://github.com/inventree/InvenTree/releases', + copy: true + }, + { + ref: 'api', + title: API Version, + link: generateUrl('/api-doc/'), + copy: true + }, + { + ref: 'python', + title: Python Version, + copy: true + }, + { + ref: 'django', + title: Django Version, + link: 'https://www.djangoproject.com/', + copy: true + } + ]; + if (commit_set) { + tableData.push( + { + ref: 'commit_hash', + title: Commit Hash, + copy: true + }, + { + ref: 'commit_date', + title: Commit Date, + copy: true + }, + { + ref: 'commit_branch', + title: Commit Branch, + copy: true + } + ); + } + return ( @@ -94,66 +146,10 @@ export function AboutInvenTreeModal({ Version Information - {data.dev ? ( - - Development Version - - ) : data.up_to_date ? ( - - Up to Date - - ) : ( - - Update Available - - )} + {renderVersionBadge(data)} - - {fillTable( - [ - { - ref: 'server', - title: InvenTree Version, - link: 'https://github.com/inventree/InvenTree/releases', - copy: true - }, - { - ref: 'commit_hash', - title: Commit Hash, - copy: true - }, - { - ref: 'commit_date', - title: Commit Date, - copy: true - }, - { - ref: 'commit_branch', - title: Commit Branch, - copy: true - }, - { - ref: 'api', - title: API Version, - link: generateUrl('/api-doc/'), - copy: true - }, - { - ref: 'python', - title: Python Version, - copy: true - }, - { - ref: 'django', - title: Django Version, - link: 'https://www.djangoproject.com/', - copy: true - } - ], - data.version - )} - + {fillTable(tableData, data.version)}
@@ -189,3 +185,17 @@ export function AboutInvenTreeModal({
); } + +function renderVersionBadge(data: any) { + const badgeType = () => { + if (data.dev) { + return { color: 'blue', label: Development Version }; + } else if (data.up_to_date) { + return { color: 'green', label: Up to Date }; + } else { + return { color: 'teal', label: Update Available }; + } + }; + const { color, label } = badgeType(); + return {label}; +}