🐛 Fix port in Service URL for Docker Module

This commit is contained in:
Noan
2022-08-22 23:01:47 +02:00
parent 684e3cb2e8
commit 5ab2f2a6f4
4 changed files with 9 additions and 22 deletions

View File

@@ -17,4 +17,4 @@
"enabled": true "enabled": true
} }
} }
} }

View File

@@ -11,9 +11,9 @@ import {
} from '@tabler/icons'; } from '@tabler/icons';
import axios from 'axios'; import axios from 'axios';
import Dockerode from 'dockerode'; import Dockerode from 'dockerode';
import { useState } from 'react';
import { tryMatchService } from '../../tools/addToHomarr'; import { tryMatchService } from '../../tools/addToHomarr';
import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem'; import { AddAppShelfItemForm } from '../../components/AppShelf/AddAppShelfItem';
import { useState } from 'react';
function sendDockerCommand( function sendDockerCommand(
action: string, action: string,
@@ -30,7 +30,7 @@ function sendDockerCommand(
disallowClose: true, disallowClose: true,
}); });
axios axios
.get(`localhost:2375/containers/${containerId}/${action}`) .get(`/api/docker/container/${containerId}?action=${action}`)
.then((res) => { .then((res) => {
updateNotification({ updateNotification({
id: containerId, id: containerId,
@@ -88,7 +88,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
variant="light" variant="light"
color="orange" color="orange"
radius="md" radius="md"
disabled={selected.length === 0}
> >
Restart Restart
</Button> </Button>
@@ -104,7 +103,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
variant="light" variant="light"
color="red" color="red"
radius="md" radius="md"
disabled={selected.length === 0}
> >
Stop Stop
</Button> </Button>
@@ -120,11 +118,10 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
variant="light" variant="light"
color="green" color="green"
radius="md" radius="md"
disabled={selected.length === 0}
> >
Start Start
</Button> </Button>
<Button leftIcon={<IconRefresh />} onClick={() => reload()} variant="light" color="violet" radius="md"> <Button leftIcon={<IconRefresh />} onClick={() => reload()} variant="light" radius="md">
Refresh data Refresh data
</Button> </Button>
<Button <Button
@@ -144,7 +141,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
setOpened(true); setOpened(true);
} }
}} }}
disabled={selected.length === 0}
> >
Add to Homarr Add to Homarr
</Button> </Button>
@@ -160,7 +156,6 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
) )
) )
} }
disabled={selected.length === 0}
> >
Remove Remove
</Button> </Button>

View File

@@ -1,4 +1,4 @@
import { ActionIcon, Drawer, Text, Tooltip } from '@mantine/core'; import { ActionIcon, Drawer, Group, LoadingOverlay, Text, Tooltip } from '@mantine/core';
import axios from 'axios'; import axios from 'axios';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import Docker from 'dockerode'; import Docker from 'dockerode';
@@ -14,12 +14,6 @@ export const DockerModule: IModule = {
description: 'Allows you to easily manage your torrents', description: 'Allows you to easily manage your torrents',
icon: IconBrandDocker, icon: IconBrandDocker,
component: DockerMenuButton, component: DockerMenuButton,
options: {
endpoint: {
name: 'Docker Api endpoint entry',
value: '',
},
},
}; };
export default function DockerMenuButton(props: any) { export default function DockerMenuButton(props: any) {
@@ -27,7 +21,6 @@ export default function DockerMenuButton(props: any) {
const [containers, setContainers] = useState<Docker.ContainerInfo[]>([]); const [containers, setContainers] = useState<Docker.ContainerInfo[]>([]);
const [selection, setSelection] = useState<Docker.ContainerInfo[]>([]); const [selection, setSelection] = useState<Docker.ContainerInfo[]>([]);
const { config } = useConfig(); const { config } = useConfig();
const dockerApi = (config?.modules?.[DockerModule.title]?.options?.endpoint?.value as string) ?? ''; // http://192.168.1.56:2376
const moduleEnabled = config.modules?.[DockerModule.title]?.enabled ?? false; const moduleEnabled = config.modules?.[DockerModule.title]?.enabled ?? false;
useEffect(() => { useEffect(() => {
@@ -40,7 +33,7 @@ export default function DockerMenuButton(props: any) {
} }
setTimeout(() => { setTimeout(() => {
axios axios
.get(`${dockerApi}/v1.41/containers/json`) .get('/api/docker/containers')
.then((res) => { .then((res) => {
setContainers(res.data); setContainers(res.data);
setSelection([]); setSelection([]);
@@ -61,7 +54,8 @@ export default function DockerMenuButton(props: any) {
if (!exists) { if (!exists) {
return null; return null;
} }
// Always allow user to see DockerTable component through ActionIcon in order to set Docker's settings // Check if the user has at least one container
if (containers.length < 1) return null;
return ( return (
<> <>
<Drawer <Drawer

View File

@@ -99,7 +99,6 @@ export default function DockerTable({
icon={<IconSearch size={14} />} icon={<IconSearch size={14} />}
value={search} value={search}
onChange={handleSearchChange} onChange={handleSearchChange}
disabled={usedContainers.length === 0}
/> />
<Table captionSide="bottom" highlightOnHover sx={{ minWidth: 800 }} verticalSpacing="sm"> <Table captionSide="bottom" highlightOnHover sx={{ minWidth: 800 }} verticalSpacing="sm">
<thead> <thead>
@@ -107,10 +106,9 @@ export default function DockerTable({
<th style={{ width: 40 }}> <th style={{ width: 40 }}>
<Checkbox <Checkbox
onChange={toggleAll} onChange={toggleAll}
checked={selection.length === usedContainers.length && usedContainers.length > 0} checked={selection.length === usedContainers.length}
indeterminate={selection.length > 0 && selection.length !== usedContainers.length} indeterminate={selection.length > 0 && selection.length !== usedContainers.length}
transitionDuration={0} transitionDuration={0}
disabled={usedContainers.length === 0}
/> />
</th> </th>
<th>Name</th> <th>Name</th>