mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
💄 Change UI for docker module
This commit is contained in:
@@ -11,8 +11,7 @@
|
|||||||
"name": "Name",
|
"name": "Name",
|
||||||
"image": "Image",
|
"image": "Image",
|
||||||
"ports": "Ports",
|
"ports": "Ports",
|
||||||
"state": "State",
|
"state": "State"
|
||||||
"addToHomarr": "Add to homarr"
|
|
||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"portCollapse": "{{ports}} more"
|
"portCollapse": "{{ports}} more"
|
||||||
@@ -43,6 +42,9 @@
|
|||||||
},
|
},
|
||||||
"remove": {
|
"remove": {
|
||||||
"title": "Remove"
|
"title": "Remove"
|
||||||
|
},
|
||||||
|
"addToHomarr": {
|
||||||
|
"title": "Add to Homarr"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
|
|||||||
@@ -24,10 +24,11 @@ import { v4 as uuidv4 } from 'uuid';
|
|||||||
import { useDebouncedValue } from '@mantine/hooks';
|
import { useDebouncedValue } from '@mantine/hooks';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useConfig } from '../../tools/state';
|
import { useConfig } from '../../tools/state';
|
||||||
import { tryMatchPort, ServiceTypeList, StatusCodes } from '../../tools/types';
|
import { tryMatchPort, ServiceTypeList, StatusCodes, Config } from '../../tools/types';
|
||||||
import Tip from '../layout/Tip';
|
import Tip from '../layout/Tip';
|
||||||
|
|
||||||
export function AddItemShelfButton(props: any) {
|
export function AddItemShelfButton(props: any) {
|
||||||
|
const { config, setConfig } = useConfig();
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
const { t } = useTranslation('layout/add-service-app-shelf');
|
const { t } = useTranslation('layout/add-service-app-shelf');
|
||||||
return (
|
return (
|
||||||
@@ -39,7 +40,7 @@ export function AddItemShelfButton(props: any) {
|
|||||||
opened={props.opened || opened}
|
opened={props.opened || opened}
|
||||||
onClose={() => setOpened(false)}
|
onClose={() => setOpened(false)}
|
||||||
>
|
>
|
||||||
<AddAppShelfItemForm close={setOpened} />
|
<AddAppShelfItemForm config={config} setConfig={setConfig} setOpened={setOpened} />
|
||||||
</Modal>
|
</Modal>
|
||||||
<Tooltip withinPortal label={t('actionIcon.tooltip')}>
|
<Tooltip withinPortal label={t('actionIcon.tooltip')}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
@@ -82,9 +83,17 @@ function MatchService(name: string, form: any) {
|
|||||||
|
|
||||||
const DEFAULT_ICON = '/favicon.png';
|
const DEFAULT_ICON = '/favicon.png';
|
||||||
|
|
||||||
export function AddAppShelfItemForm(props: { close: () => void } & any) {
|
interface AddAppShelfItemFormProps {
|
||||||
const { close } = props;
|
setOpened: (b: boolean) => void;
|
||||||
const { config, setConfig } = useConfig();
|
config: Config;
|
||||||
|
setConfig: (config: Config) => void;
|
||||||
|
// Any other props you want to pass to the form
|
||||||
|
[key: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AddAppShelfItemForm(props: AddAppShelfItemFormProps) {
|
||||||
|
const { setOpened, config, setConfig } = props;
|
||||||
|
// Only get config and setConfig from useCOnfig if they are not present in props
|
||||||
const [isLoading, setLoading] = useState(false);
|
const [isLoading, setLoading] = useState(false);
|
||||||
const { t } = useTranslation('layout/add-service-app-shelf');
|
const { t } = useTranslation('layout/add-service-app-shelf');
|
||||||
|
|
||||||
@@ -195,12 +204,13 @@ export function AddAppShelfItemForm(props: { close: () => void } & any) {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
console.log(newForm);
|
||||||
setConfig({
|
setConfig({
|
||||||
...config,
|
...config,
|
||||||
services: [...config.services, newForm],
|
services: [...config.services, newForm],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
close(false);
|
setOpened(false);
|
||||||
form.reset();
|
form.reset();
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import { Button, Group } from '@mantine/core';
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||||
|
import { Button, Group, TextInput, Title } from '@mantine/core';
|
||||||
|
import { closeAllModals, closeModal, openModal } from '@mantine/modals';
|
||||||
import { showNotification, updateNotification } from '@mantine/notifications';
|
import { showNotification, updateNotification } from '@mantine/notifications';
|
||||||
import {
|
import {
|
||||||
IconCheck,
|
IconCheck,
|
||||||
IconPlayerPlay,
|
IconPlayerPlay,
|
||||||
IconPlayerStop,
|
IconPlayerStop,
|
||||||
|
IconPlus,
|
||||||
IconRefresh,
|
IconRefresh,
|
||||||
IconRotateClockwise,
|
IconRotateClockwise,
|
||||||
IconTrash,
|
IconTrash,
|
||||||
@@ -13,6 +16,9 @@ import Dockerode from 'dockerode';
|
|||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { TFunction } from 'react-i18next';
|
import { TFunction } from 'react-i18next';
|
||||||
|
import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem';
|
||||||
|
import { tryMatchService } from '../../tools/addToHomarr';
|
||||||
|
import { useConfig } from '../../tools/state';
|
||||||
|
|
||||||
let t: TFunction<'modules/docker', undefined>;
|
let t: TFunction<'modules/docker', undefined>;
|
||||||
|
|
||||||
@@ -63,6 +69,8 @@ export interface ContainerActionBarProps {
|
|||||||
export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) {
|
export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) {
|
||||||
t = useTranslation('modules/docker').t;
|
t = useTranslation('modules/docker').t;
|
||||||
const [isLoading, setisLoading] = useState(false);
|
const [isLoading, setisLoading] = useState(false);
|
||||||
|
const { config, setConfig } = useConfig();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group>
|
||||||
<Button
|
<Button
|
||||||
@@ -145,6 +153,33 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
|
|||||||
>
|
>
|
||||||
{t('actionBar.remove.title')}
|
{t('actionBar.remove.title')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
leftIcon={<IconPlus />}
|
||||||
|
color="indigo"
|
||||||
|
variant="light"
|
||||||
|
radius="md"
|
||||||
|
disabled={selected.length === 0 || selected.length > 1}
|
||||||
|
onClick={() => {
|
||||||
|
openModal({
|
||||||
|
size: 'xl',
|
||||||
|
modalId: selected.at(0)!.Id,
|
||||||
|
radius: 'md',
|
||||||
|
title: t('actionBar.addService.title'),
|
||||||
|
zIndex: 500,
|
||||||
|
children: (
|
||||||
|
<AddAppShelfItemForm
|
||||||
|
setConfig={setConfig}
|
||||||
|
config={config}
|
||||||
|
setOpened={() => closeModal(selected.at(0)!.Id)}
|
||||||
|
message={t('actionBar.addService.message')}
|
||||||
|
{...tryMatchService(selected.at(0)!)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t('actionBar.addToHomarr.title')}
|
||||||
|
</Button>
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export default function DockerMenuButton(props: any) {
|
|||||||
icon: <IconX />,
|
icon: <IconX />,
|
||||||
message: t('errors.integrationFailed.message'),
|
message: t('errors.integrationFailed.message'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
const exists = config.modules?.[DockerModule.id]?.enabled ?? false;
|
const exists = config.modules?.[DockerModule.id]?.enabled ?? false;
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import {
|
|||||||
ScrollArea,
|
ScrollArea,
|
||||||
TextInput,
|
TextInput,
|
||||||
Modal,
|
Modal,
|
||||||
ActionIcon,
|
|
||||||
} from '@mantine/core';
|
} from '@mantine/core';
|
||||||
import { IconPlus, IconSearch } from '@tabler/icons';
|
import { IconSearch } from '@tabler/icons';
|
||||||
import Dockerode from 'dockerode';
|
import Dockerode from 'dockerode';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
@@ -36,10 +35,8 @@ export default function DockerTable({
|
|||||||
selection: Dockerode.ContainerInfo[];
|
selection: Dockerode.ContainerInfo[];
|
||||||
}) {
|
}) {
|
||||||
const [usedContainers, setContainers] = useState<Dockerode.ContainerInfo[]>(containers);
|
const [usedContainers, setContainers] = useState<Dockerode.ContainerInfo[]>(containers);
|
||||||
const [rowSelected, setRowSelected] = useState<Dockerode.ContainerInfo>();
|
|
||||||
const { classes, cx } = useStyles();
|
const { classes, cx } = useStyles();
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [opened, setOpened] = useState<boolean>(false);
|
|
||||||
|
|
||||||
const { t } = useTranslation('modules/docker');
|
const { t } = useTranslation('modules/docker');
|
||||||
|
|
||||||
@@ -106,38 +103,12 @@ export default function DockerTable({
|
|||||||
<td>
|
<td>
|
||||||
<ContainerState state={element.State} />
|
<ContainerState state={element.State} />
|
||||||
</td>
|
</td>
|
||||||
<td>
|
|
||||||
<ActionIcon
|
|
||||||
color="indigo"
|
|
||||||
variant="light"
|
|
||||||
radius="md"
|
|
||||||
onClick={() => {
|
|
||||||
setRowSelected(element);
|
|
||||||
setOpened(true);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<IconPlus />
|
|
||||||
</ActionIcon>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ScrollArea style={{ height: '80vh' }}>
|
<ScrollArea style={{ height: '80vh' }}>
|
||||||
<Modal
|
|
||||||
size="xl"
|
|
||||||
radius="md"
|
|
||||||
opened={opened}
|
|
||||||
onClose={() => setOpened(false)}
|
|
||||||
title={t('actionBar.addService.title')}
|
|
||||||
>
|
|
||||||
<AddAppShelfItemForm
|
|
||||||
setOpened={setOpened}
|
|
||||||
{...tryMatchService(rowSelected)}
|
|
||||||
message={t('actionBar.addService.message')}
|
|
||||||
/>
|
|
||||||
</Modal>
|
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={t('search.placeholder')}
|
placeholder={t('search.placeholder')}
|
||||||
mt="md"
|
mt="md"
|
||||||
@@ -162,7 +133,6 @@ export default function DockerTable({
|
|||||||
<th>{t('table.header.image')}</th>
|
<th>{t('table.header.image')}</th>
|
||||||
<th>{t('table.header.ports')}</th>
|
<th>{t('table.header.ports')}</th>
|
||||||
<th>{t('table.header.state')}</th>
|
<th>{t('table.header.state')}</th>
|
||||||
<th>{t('table.header.addToHomarr')}</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>{rows}</tbody>
|
<tbody>{rows}</tbody>
|
||||||
|
|||||||
Reference in New Issue
Block a user