Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup modals #8432

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions src/frontend/src/components/modals/AboutInvenTreeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { apiUrl, useServerApiState } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
import { useUserState } from '../../states/UserState';
import { CopyButton } from '../buttons/CopyButton';
import { StylishText } from '../items/StylishText';

type AboutLookupRef = {
ref: string;
Expand Down Expand Up @@ -56,9 +57,9 @@ export function AboutInvenTreeModal({
alwaysLink: boolean = false
) {
return lookup.map((map: AboutLookupRef, idx) => (
<tr key={idx}>
<td>{map.title}</td>
<td>
<Table.Tr key={idx}>
<Table.Td>{map.title}</Table.Td>
<Table.Td>
<Group justify="space-between" gap="xs">
{alwaysLink ? (
<Anchor href={data[map.ref]} target="_blank">
Expand All @@ -73,8 +74,8 @@ export function AboutInvenTreeModal({
)}
{map.copy && <CopyButton value={data[map.ref]} />}
</Group>
</td>
</tr>
</Table.Td>
</Table.Tr>
));
}
/* renderer */
Expand All @@ -95,13 +96,10 @@ export function AboutInvenTreeModal({
return (
<Stack>
<Divider />
<Title order={5}>
<Trans>Version Information</Trans>
</Title>
<Group>
<Text>
<Trans>Your InvenTree version status is</Trans>
</Text>
<Group justify="space-between" wrap="nowrap">
<StylishText size="lg">
<Trans>Version Information</Trans>
</StylishText>
{data.dev ? (
<Badge color="blue">
<Trans>Development Version</Trans>
Expand All @@ -116,8 +114,8 @@ export function AboutInvenTreeModal({
</Badge>
)}
</Group>
<Table>
<tbody>
<Table striped>
<Table.Tbody>
{fillTable(
[
{
Expand All @@ -144,9 +142,14 @@ export function AboutInvenTreeModal({
{
ref: 'api',
title: <Trans>API Version</Trans>,
link: `${host}api-doc/`
link: `${host}api-doc/`,
copy: true
},
{
ref: 'python',
title: <Trans>Python Version</Trans>,
copy: true
},
{ ref: 'python', title: <Trans>Python Version</Trans> },
{
ref: 'django',
title: <Trans>Django Version</Trans>,
Expand All @@ -156,37 +159,37 @@ export function AboutInvenTreeModal({
],
data.version
)}
</tbody>
</Table.Tbody>
</Table>
<Title order={5}>
<Divider />
<StylishText size="lg">
<Trans>Links</Trans>
</Title>
<Table>
<tbody>
</StylishText>
<Table striped>
<Table.Tbody>
{fillTable(
[
{ ref: 'doc', title: <Trans>InvenTree Documentation</Trans> },
{ ref: 'code', title: <Trans>View Code on GitHub</Trans> },
{ ref: 'doc', title: <Trans>Documentation</Trans> },
{ ref: 'code', title: <Trans>Source Code</Trans> },
{ ref: 'credit', title: <Trans>Credits</Trans> },
{ ref: 'app', title: <Trans>Mobile App</Trans> },
{ ref: 'bug', title: <Trans>Submit Bug Report</Trans> }
],
data.links,
true
)}
</tbody>
</Table.Tbody>
</Table>
<Divider />
<Group justify="space-between">
<CopyButton value={copyval} label={t`Copy version information`} />
<Space />
<Button
color="red"
onClick={() => {
context.closeModal(id);
}}
>
<Trans>Dismiss</Trans>
<Trans>Close</Trans>
</Button>
</Group>
</Stack>
Expand Down
24 changes: 20 additions & 4 deletions src/frontend/src/components/modals/LicenseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Text
} from '@mantine/core';
import { useQuery } from '@tanstack/react-query';
import { useEffect, useMemo, useState } from 'react';

import { api } from '../../App';
import { ApiEndpoints } from '../../enums/ApiEndpoints';
Expand Down Expand Up @@ -53,14 +54,25 @@ export function LicenceView(entries: any[]) {
export function LicenseModal() {
const { data, isFetching, isError } = useQuery({
queryKey: ['license'],
refetchOnMount: true,
queryFn: () =>
api
.get(apiUrl(ApiEndpoints.license))
.then((res) => res.data ?? {})
.catch(() => {})
});

const rspdata = !data ? [] : Object.keys(data ?? {});
const packageKeys = useMemo(() => {
return !!data ? Object.keys(data ?? {}) : [];
}, [data]);

const [selectedKey, setSelectedKey] = useState<string | null>('');

useEffect(() => {
if (packageKeys.length > 0) {
setSelectedKey(packageKeys[0]);
}
}, [packageKeys]);

return (
<Stack gap="xs">
Expand All @@ -78,16 +90,20 @@ export function LicenseModal() {
</Text>
</Alert>
) : (
<Tabs defaultValue={rspdata[0] ?? ''}>
<Tabs
defaultValue={packageKeys[0] ?? ''}
value={selectedKey}
onChange={setSelectedKey}
>
<Tabs.List>
{rspdata.map((key) => (
{packageKeys.map((key) => (
<Tabs.Tab key={key} value={key}>
<Trans>{key} Packages</Trans>
</Tabs.Tab>
))}
</Tabs.List>

{rspdata.map((key) => (
{packageKeys.map((key) => (
<Tabs.Panel key={key} value={key}>
{LicenceView(data[key] ?? [])}
</Tabs.Panel>
Expand Down
41 changes: 17 additions & 24 deletions src/frontend/src/components/modals/ServerInfoModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ContextModalProps } from '@mantine/modals';

import { useServerApiState } from '../../states/ApiState';
import { OnlyStaff } from '../items/OnlyStaff';
import { StylishText } from '../items/StylishText';

export function ServerInfoModal({
context,
Expand All @@ -22,17 +23,29 @@ export function ServerInfoModal({
return (
<Stack>
<Divider />
<Title order={5}>
<StylishText size="lg">
<Trans>Server</Trans>
</Title>
<Table>
</StylishText>
<Table striped>
<Table.Tbody>
<Table.Tr>
<Table.Td>
<Trans>Instance Name</Trans>
</Table.Td>
<Table.Td>{server.instance}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Td>
<Trans>Server Version</Trans>
</Table.Td>
<Table.Td>{server.version}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Td>
<Trans>API Version</Trans>
</Table.Td>
<Table.Td>{server.apiVersion}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Td>
<Trans>Database</Trans>
Expand Down Expand Up @@ -117,34 +130,14 @@ export function ServerInfoModal({
)}
</Table.Tbody>
</Table>
<Title order={5}>
<Trans>Version</Trans>
</Title>
<Table>
<Table.Tbody>
<Table.Tr>
<Table.Td>
<Trans>Server Version</Trans>
</Table.Td>
<Table.Td>{server.version}</Table.Td>
</Table.Tr>
<Table.Tr>
<Table.Td>
<Trans>API Version</Trans>
</Table.Td>
<Table.Td>{server.apiVersion}</Table.Td>
</Table.Tr>
</Table.Tbody>
</Table>
<Divider />
<Group justify="right">
<Button
color="red"
onClick={() => {
context.closeModal(id);
}}
>
<Trans>Dismiss</Trans>
<Trans>Close</Trans>
</Button>
</Group>
</Stack>
Expand Down
Loading