Skip to content

Commit

Permalink
🗑️ Remove deprecated code (ajnart#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rw authored Jul 28, 2023
1 parent a45a1bd commit c99c06c
Show file tree
Hide file tree
Showing 44 changed files with 83 additions and 4,126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const EditAppModal = ({
behaviour: {
externalUrl: (url: string) => {
if (url === undefined || url.length < 1) {
return null;
return 'External URI is required';
}

if (!url.match(appUrlWithAnyProtocolRegex)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const AvailableElementTypes = ({
},
behaviour: {
isOpeningNewTab: true,
externalUrl: '',
externalUrl: 'https://homarr.dev',
},

area: {
Expand Down
85 changes: 29 additions & 56 deletions src/modules/Docker/ContainerActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Button, Group } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import {
Expand All @@ -18,7 +17,6 @@ import { RouterInputs, api } from '~/utils/api';

import { useConfigContext } from '../../config/provider';
import { openContextModalGeneric } from '../../tools/mantineModalManagerExtensions';
import { MatchingImages, ServiceType, tryMatchPort } from '../../tools/types';
import { AppType } from '../../types/app';

export interface ContainerActionBarProps {
Expand All @@ -28,10 +26,15 @@ export interface ContainerActionBarProps {

export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) {
const { t } = useTranslation('modules/docker');
const [isLoading, setisLoading] = useState(false);
const [isLoading, setLoading] = useState(false);
const { config } = useConfigContext();
const getLowestWrapper = () => config?.wrappers.sort((a, b) => a.position - b.position)[0];

const sendDockerCommand = useDockerActionMutation();
if (!config) {
return null;
}
const getLowestWrapper = () =>
config.wrappers.sort((wrapper1, wrapper2) => wrapper1.position - wrapper2.position)[0];

if (process.env.DISABLE_EDIT_MODE === 'true') {
return null;
Expand All @@ -42,10 +45,10 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
<Button
leftIcon={<IconRefresh />}
onClick={() => {
setisLoading(true);
setLoading(true);
setTimeout(() => {
reload();
setisLoading(false);
setLoading(false);
}, 750);
}}
variant="light"
Expand All @@ -57,8 +60,8 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
</Button>
<Button
leftIcon={<IconRotateClockwise />}
onClick={() =>
Promise.all(selected.map((container) => sendDockerCommand(container, 'restart')))
onClick={async () =>
await Promise.all(selected.map((container) => sendDockerCommand(container, 'restart')))
}
variant="light"
color="orange"
Expand All @@ -69,8 +72,8 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
</Button>
<Button
leftIcon={<IconPlayerStop />}
onClick={() =>
Promise.all(selected.map((container) => sendDockerCommand(container, 'stop')))
onClick={async () =>
await Promise.all(selected.map((container) => sendDockerCommand(container, 'stop')))
}
variant="light"
color="red"
Expand All @@ -81,8 +84,8 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
</Button>
<Button
leftIcon={<IconPlayerPlay />}
onClick={() =>
Promise.all(selected.map((container) => sendDockerCommand(container, 'start')))
onClick={async () =>
await Promise.all(selected.map((container) => sendDockerCommand(container, 'start')))
}
variant="light"
color="green"
Expand All @@ -96,8 +99,8 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
color="red"
variant="light"
radius="md"
onClick={() =>
Promise.all(selected.map((container) => sendDockerCommand(container, 'remove')))
onClick={async () =>
await Promise.all(selected.map((container) => sendDockerCommand(container, 'remove')))
}
disabled={selected.length === 0}
>
Expand All @@ -108,29 +111,32 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
color="indigo"
variant="light"
radius="md"
disabled={selected.length === 0 || selected.length > 1}
disabled={selected.length !== 1}
onClick={() => {
const app = tryMatchService(selected.at(0)!);
const containerUrl = `http://localhost:${selected[0].Ports[0]?.PublicPort ?? 0}`;
const containerInfo = selected[0];

const port = containerInfo.Ports.at(0)?.PublicPort;
const address = port ? `http://localhost:${port}` : `http://localhost`;
const name = containerInfo.Names.at(0) ?? 'App';

openContextModalGeneric<{ app: AppType; allowAppNamePropagation: boolean }>({
modal: 'editApp',
zIndex: 202,
innerProps: {
app: {
id: uuidv4(),
name: app.name ? app.name : selected[0].Names[0].substring(1),
url: containerUrl,
name: name,
url: address,
appearance: {
iconUrl: app.icon ? app.icon : '/imgs/logo/logo.png',
iconUrl: '/imgs/logo/logo.png',
},
network: {
enabledStatusChecker: true,
statusCodes: ['200'],
okStatus: [200],
statusCodes: ['200', '301', '302']
},
behaviour: {
isOpeningNewTab: true,
externalUrl: '',
externalUrl: address
},
area: {
type: 'wrapper',
Expand Down Expand Up @@ -204,36 +210,3 @@ const useDockerActionMutation = () => {
);
};
};

/**
* @deprecated legacy code
*/
function tryMatchType(imageName: string): ServiceType {
const match = MatchingImages.find(({ image }) => imageName.includes(image));
if (match) {
return match.type;
}
// TODO: Remove this legacy code
return 'Other';
}

/**
* @deprecated
* @param container the container to match
* @returns a new service
*/
const tryMatchService = (container: Dockerode.ContainerInfo | undefined) => {
if (container === undefined) return {};
const name = container.Names[0].substring(1);
const type = tryMatchType(container.Image);
const port = tryMatchPort(type.toLowerCase())?.value ?? container.Ports[0]?.PublicPort;
return {
name,
id: container.Id,
type: tryMatchType(container.Image),
url: `localhost${port ? `:${port}` : ''}`,
icon: `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${name
.replace(/\s+/g, '-')
.toLowerCase()}.png`,
};
};
9 changes: 0 additions & 9 deletions src/modules/readme.md

This file was deleted.

21 changes: 0 additions & 21 deletions src/pages/api/docker/DockerSingleton.ts

This file was deleted.

59 changes: 0 additions & 59 deletions src/pages/api/docker/container/[id].tsx

This file was deleted.

24 changes: 0 additions & 24 deletions src/pages/api/docker/containers.tsx

This file was deleted.

44 changes: 0 additions & 44 deletions src/pages/api/icons/index.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/pages/api/migrate.ts

This file was deleted.

Loading

0 comments on commit c99c06c

Please sign in to comment.