Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion libs/pages/home/src/lib/home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from 'react';
import { YadomsConnectionContext, YadomsConnection } from '@yadoms/shared';
import YButton from './widgets/YButton';
import { YButton } from './widgets/ybutton';
import KeywordLog from './widgets/keywordLog';

/* eslint-disable-next-line */
Expand Down
2 changes: 1 addition & 1 deletion libs/pages/home/src/lib/widgets/ybutton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ButtonStateAcquisitionListener implements AcquisitionListener {
private onNewAcquisition: (newAcquisition: Acquisition) => void;
}

class YButton extends Component<ButtonProps, ButtonState> {
export class YButton extends Component<ButtonProps, ButtonState> {
static contextType = YadomsConnectionContext;
context!: React.ContextType<typeof YadomsConnectionContext>;

Expand Down
62 changes: 62 additions & 0 deletions libs/pages/summary/src/lib/ui/CardComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { ReactNode } from 'react';
import { Badge, Center, Container, Text } from '@mantine/core';
import classes from './summary.module.css';
import { IsVersion } from '@yadoms/shared';

interface CardProps {
icon: ReactNode;
label: string;
content: string | number | undefined;
color: string;
isLoading: boolean;
children: ReactNode;
}

export function Card({
icon,
label,
content,
color,
isLoading,
children,
}: CardProps) {
return (
<Container
p={'xl'}
className={classes.item}
styles={(theme) => ({
root: {
boxShadow: `0px 0px 20px ${color}`,
border: `1px solid ${color}`,
},
})}
>
<Center>{icon}</Center>
<Text weight={500} size={{ base: 'xs', sm: 'lg' }}>
{label}
</Text>
{isLoading ? (
children
) : (
<ContentComponent content={content as string}> </ContentComponent>
)}
</Container>
);
}

function ContentComponent({ content }: { content: string }) {
return IsVersion(content) ? (
<VersionComponentWithBadge content={content} />
) : (
<Text size={{ base: 'xs', sm: 'lg' }}>
{Number.isInteger(content) ? `${content} Octets` : content}
</Text>
);
}
function VersionComponentWithBadge({ content }: { content: string }) {
return (
<Badge color="pink" variant="light" mt={10}>
<Text size={{ base: 'xs', sm: 'lg' }}>{content}</Text>
</Badge>
);
}
38 changes: 38 additions & 0 deletions libs/pages/summary/src/lib/ui/FeatureGridComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { Container, Grid } from '@mantine/core';
import { Card } from './CardComponent';
import { SystemInformation } from './summary';

interface FeaturesGridProps {
systemInformations: SystemInformation[];
children: ReactNode;
isLoading: boolean;
}

export function FeaturesGrid({
systemInformations,
children,
isLoading,
}: FeaturesGridProps) {
const { t } = useTranslation();
return (
<Container size={1100}>
<Grid gutter="xl">
{systemInformations.map((element) => (
<Grid.Col span={{ base: 12, sm: 4, md: 4, lg: 4 }}>
<Card
icon={element.icon}
label={t(`summary.informations.${element.i18nKey}`)}
content={element.dataKey}
color={element.color}
isLoading={isLoading}
>
{children}
</Card>
</Grid.Col>
))}
</Grid>
</Container>
);
}
133 changes: 133 additions & 0 deletions libs/pages/summary/src/lib/ui/icons.tsx

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions libs/pages/summary/src/lib/ui/summary.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.item {
height: 100%;
width: 100%;

transition: box-shadow 150ms ease, transform 100ms ease;
overflow: clip;
@mixin hover {
box-shadow: var(--mantine-shadow-md);
transform: scale(1.05);
}
}

@media (max-width: 48em) {
.item {
display: flex;
flex-direction: column;
}
}
219 changes: 188 additions & 31 deletions libs/pages/summary/src/lib/ui/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,216 @@
import { Box, Flex, LoadingOverlay, Paper, Table, Title } from '@mantine/core';
import React from 'react';
import { Box, Flex, Title, Skeleton } from '@mantine/core';
import { useTranslation } from 'react-i18next';
import { BreadCrumbs } from '@yadoms/shared';
import { loadSystemInformations } from '../summary-api';
import { useQuery } from '@tanstack/react-query';
import React, { ReactNode } from 'react';
import {
DatabaseIcon,
DatabaseVersionIcon,
LinuxLogo,
MacOSLogo,
PostgreSQLLogo,
PowerIcon,
SQLIcon,
SQLiteLogo,
SystemIcon,
VersionIcon,
WindowsLogo,
SizeIcon,
} from './icons';
import { FormatDate } from '@yadoms/shared';
import { FeaturesGrid } from './FeatureGridComponent';

const CUSTOMIZATIONS = {
Window: { color: '#4057dc', size: 40 },
Linux: { color: '#6f706e', size: 40 },
MacOs: { color: '#000000', size: 40 },
DefaultOs: { color: '#6e6e70', size: 40 },
SqLite: { color: '#66b2fc', size: 40 },
Postgres: { color: '#3177ff', size: 40 },
Database: { color: '#f14809', size: 40 },
DatabaseVersion: { color: '#cec483', size: 40 },
Power: { color: '#00ff28', size: 40 },
Version: { color: '#873be1', size: 40 },
Size: { color: '#e52121', size: 40 },
SQL: { color: '#0048fd', size: 40 },
} as const;


type CUSTOMIZATIONS = (typeof CUSTOMIZATIONS)[keyof typeof CUSTOMIZATIONS];

export type SystemInformation = {
i18nKey: string;
dataKey: string | number | undefined;
icon: ReactNode;
color: string;
};

export function Summary() {
const { t } = useTranslation();

const { isLoading, data } = useQuery({
queryKey: ['system-informations'],
queryFn: loadSystemInformations,
});

const breadcrumbsItem = [
{ title: 'home', href: '#' },
{ title: 'summary', href: '#' },
{ title: 'home', href: '/' },
{ title: 'summary', href: '/summary' },
];
const getPlatformIcon = (platform: string | undefined) => {
if (!platform) { // prevent undefined | null case
return (
<SystemIcon
size={CUSTOMIZATIONS.DefaultOs.size}
color={CUSTOMIZATIONS.DefaultOs.color}
/>
);
} else if (platform.startsWith("Linux")) {
return (
<LinuxLogo
size={CUSTOMIZATIONS.Linux.size}
color={CUSTOMIZATIONS.Linux.color}
/>
);
} else if (platform.startsWith("Windows")) {
return (
<WindowsLogo
size={CUSTOMIZATIONS.Window.size}
color={CUSTOMIZATIONS.Window.color}
/>
);
} else if (platform.startsWith("MacOs")) {
return (
<MacOSLogo
size={CUSTOMIZATIONS.MacOs.size}
color={CUSTOMIZATIONS.MacOs.color}
/>
);
} else {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the latest else

return ( // platform not implemented
<SystemIcon
size={CUSTOMIZATIONS.DefaultOs.size}
color={CUSTOMIZATIONS.DefaultOs.color}
/>
);
}
};

const getDatabaseEngineIcon = (engine: string | undefined) => {
if (!engine)
return (
<SQLIcon
size={CUSTOMIZATIONS.SQL.size}
color={CUSTOMIZATIONS.SQL.color}
/>
);
switch (engine) {
case 'SQLite':
return (
<SQLiteLogo
size={CUSTOMIZATIONS.SqLite.size}
color={CUSTOMIZATIONS.SqLite.color}
/>
);
case 'Postgres':
return (
<PostgreSQLLogo
size={CUSTOMIZATIONS.Postgres.size}
color={CUSTOMIZATIONS.Postgres.color}
/>
);
default:
return (
<SQLIcon
size={CUSTOMIZATIONS.SQL.size}
color={CUSTOMIZATIONS.SQL.color}
/>
);
}
};

const systemInformations = [
{ i18nKey: 'platform', dataKey: data?.platform },
{ i18nKey: 'software-version', dataKey: data?.yadomsVersion },
{ i18nKey: 'database-version', dataKey: data?.database.version },
{ i18nKey: 'started-from', dataKey: data?.startupTime },
{ i18nKey: 'database-engine', dataKey: data?.databaseEngine.type },
const systemInformations: SystemInformation[] = [
{
i18nKey: 'platform',
dataKey: data?.platform,
icon: getPlatformIcon(data?.platform),
color: CUSTOMIZATIONS.DefaultOs.color,
},
{
i18nKey: 'software-version',
dataKey: data?.yadomsVersion,
icon: <VersionIcon size={40} color={CUSTOMIZATIONS.Version.color} />,
color: CUSTOMIZATIONS.Version.color,
},
{
i18nKey: 'database-version',
dataKey: data?.database.version,
icon: (
<DatabaseVersionIcon
size={CUSTOMIZATIONS.DatabaseVersion.size}
color={CUSTOMIZATIONS.DatabaseVersion.color}
/>
),
color: CUSTOMIZATIONS.DatabaseVersion.color,
},
{
i18nKey: 'started-from',
dataKey: FormatDate(data?.startupTime),
icon: (
<PowerIcon
size={CUSTOMIZATIONS.Power.size}
color={CUSTOMIZATIONS.Power.color}
/>
),
color: CUSTOMIZATIONS.Power.color,
},
{
i18nKey: 'database-engine',
dataKey: data?.databaseEngine.type,
icon: getDatabaseEngineIcon(data?.databaseEngine.type),
color: CUSTOMIZATIONS.SQL.color,
},
{
i18nKey: 'version-database-engine',
dataKey: data?.databaseEngine.version,
icon: (
<DatabaseIcon
size={CUSTOMIZATIONS.Database.size}
color={CUSTOMIZATIONS.Database.color}
/>
),
color: CUSTOMIZATIONS.Database.color,
},
{
i18nKey: 'database-size',
dataKey: data?.database.size,
icon: (
<SizeIcon
size={CUSTOMIZATIONS.Size.size}
color={CUSTOMIZATIONS.Size.color}
/>
),
color: CUSTOMIZATIONS.Size.color,
},
{ i18nKey: 'database-size', dataKey: data?.database.size },
];

const rows = systemInformations.map((element) => (
<tr>
<th>{t(`summary.informations.${element.i18nKey}`)}</th>
<th>{element.dataKey}</th>
</tr>
));

return (
<Flex direction="column">
<Flex direction={'column'}>
<BreadCrumbs breadcrumbsItems={breadcrumbsItem} />
<Title order={3} size="h3" mt="md">
{t('summary.home.description')}
</Title>
<Box maw={'100%'} pos="relative" pt={'20px'}>
<LoadingOverlay
visible={isLoading}
overlayProps={{ radius: 'sm', blur: 2 }}
/>
<Paper shadow="xs" p="md">
<Table highlightOnHover>
<tbody>{rows}</tbody>
</Table>
</Paper>
<FeaturesGrid
systemInformations={systemInformations}
isLoading={isLoading}
>
<Skeleton
visible={isLoading}
height={20}
mt="md"
width="80%"
radius="sm"
/>
</FeaturesGrid>
</Box>
</Flex>
);
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './lib/components/breadcrumbs/breadcrumbs';
export * from './lib/services/ModalManager';
export * from './lib/services/YadomsWebSocketConnection';
export { axiosInstance } from './lib/http/axios-instance';
export * from './lib/services/IsVersion';
export * from './lib/services/FormatDate';
Loading