💄 improve ui of DockerTable component

This commit is contained in:
Noan
2022-08-23 19:57:03 +02:00
parent 8edda19e05
commit 9003ee6350
3 changed files with 53 additions and 45 deletions

View File

@@ -1,7 +1,9 @@
import { Table, Checkbox, Group, Badge, createStyles, ScrollArea, TextInput } from '@mantine/core';
import { IconSearch } from '@tabler/icons';
import { Table, Checkbox, Group, Badge, createStyles, ScrollArea, TextInput, Button, Modal, ActionIcon, Tooltip } from '@mantine/core';
import { IconPlus, IconSearch } from '@tabler/icons';
import Dockerode from 'dockerode';
import { useEffect, useState } from 'react';
import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem';
import { tryMatchService } from '../../tools/addToHomarr';
import ContainerState from './ContainerState';
const useStyles = createStyles((theme) => ({
@@ -23,8 +25,10 @@ export default function DockerTable({
selection: Dockerode.ContainerInfo[];
}) {
const [usedContainers, setContainers] = useState<Dockerode.ContainerInfo[]>(containers);
const [rowSelected, setRowSelected] = useState<Dockerode.ContainerInfo>();
const { classes, cx } = useStyles();
const [search, setSearch] = useState('');
const [opened, setOpened] = useState<boolean>(false);
useEffect(() => {
setContainers(containers);
@@ -64,7 +68,9 @@ export default function DockerTable({
/>
</td>
<td>{element.Names[0].replace('/', '')}</td>
<td>{element.Image}</td>
<td>
{element.Image}
</td>
<td>
<Group>
{element.Ports.sort((a, b) => a.PrivatePort - b.PrivatePort)
@@ -87,18 +93,49 @@ export default function DockerTable({
<td>
<ContainerState state={element.State} />
</td>
<td>
<Group>
<Tooltip label="Add to Homarr">
<ActionIcon
color="indigo"
variant="light"
radius="md"
onClick={() => {
setRowSelected(element);
setOpened(true);
}}
>
<IconPlus />
</ActionIcon>
</Tooltip>
</Group>
</td>
</tr>
);
});
return (
<ScrollArea style={{ height: '80vh' }}>
<Modal
size="xl"
radius="md"
opened={opened}
onClose={() => setOpened(false)}
title="Add service"
>
<AddAppShelfItemForm
setOpened={setOpened}
{...tryMatchService(rowSelected)}
message="Add service to homarr"
/>
</Modal>
<TextInput
placeholder="Search by container or image name"
mt="md"
icon={<IconSearch size={14} />}
value={search}
onChange={handleSearchChange}
disabled={usedContainers.length === 0}
/>
<Table captionSide="bottom" highlightOnHover sx={{ minWidth: 800 }} verticalSpacing="sm">
<thead>
@@ -106,15 +143,17 @@ export default function DockerTable({
<th style={{ width: 40 }}>
<Checkbox
onChange={toggleAll}
checked={selection.length === usedContainers.length}
checked={selection.length === usedContainers.length && selection.length > 0}
indeterminate={selection.length > 0 && selection.length !== usedContainers.length}
transitionDuration={0}
disabled={usedContainers.length === 0}
/>
</th>
<th>Name</th>
<th>Image</th>
<th>Ports</th>
<th>State</th>
<th>Action</th>
</tr>
</thead>
<tbody>{rows}</tbody>