feat(onboarding): hide 0-widget integrations and add selectable app grid
- Filter out integrations with no widgets from onboarding selection - Replace single checkbox app toggle with a compact selectable grid - Each Docker-discovered app is individually toggleable (all on by default) - Track selected apps by container ID instead of a boolean flag
This commit is contained in:
4 files changed
+92
-49
No files matched your search
@@ -4,17 +4,18 @@ import { useEffect, useRef, useState } from "react";
|
|||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Badge,
|
Badge,
|
||||||
Checkbox,
|
Card,
|
||||||
Collapse,
|
Collapse,
|
||||||
Divider,
|
|
||||||
Group,
|
Group,
|
||||||
Paper,
|
Paper,
|
||||||
|
ScrollArea,
|
||||||
|
SimpleGrid,
|
||||||
Stack,
|
Stack,
|
||||||
Text,
|
Text,
|
||||||
ThemeIcon,
|
ThemeIcon,
|
||||||
UnstyledButton,
|
UnstyledButton,
|
||||||
} from "@mantine/core";
|
} from "@mantine/core";
|
||||||
import { IconBrandDocker, IconChevronDown } from "@tabler/icons-react";
|
import { IconBrandDocker, IconCheck, IconChevronDown } from "@tabler/icons-react";
|
||||||
|
|
||||||
import type { IntegrationKind } from "@homarr/definitions";
|
import type { IntegrationKind } from "@homarr/definitions";
|
||||||
import { getIntegrationName } from "@homarr/definitions";
|
import { getIntegrationName } from "@homarr/definitions";
|
||||||
@@ -40,31 +41,36 @@ export interface DiscoveredApp {
|
|||||||
interface DockerDiscoveryIndicatorProps {
|
interface DockerDiscoveryIndicatorProps {
|
||||||
integrations: DiscoveredIntegration[];
|
integrations: DiscoveredIntegration[];
|
||||||
apps: DiscoveredApp[];
|
apps: DiscoveredApp[];
|
||||||
appsEnabled: boolean;
|
selectedAppIds: Set<string>;
|
||||||
onToggleAllApps: (checked: boolean) => void;
|
onToggleApp: (containerId: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const APP_CARD_HEIGHT = 80;
|
||||||
|
|
||||||
export const DockerDiscoveryIndicator = ({
|
export const DockerDiscoveryIndicator = ({
|
||||||
integrations,
|
integrations,
|
||||||
apps,
|
apps,
|
||||||
appsEnabled,
|
selectedAppIds,
|
||||||
onToggleAllApps,
|
onToggleApp,
|
||||||
}: DockerDiscoveryIndicatorProps) => {
|
}: DockerDiscoveryIndicatorProps) => {
|
||||||
const hasApps = apps.length > 0;
|
const hasApps = apps.length > 0;
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
|
||||||
const expandedOnce = useRef(false);
|
const expandedOnce = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hasApps && !expandedOnce.current) {
|
if ((hasApps || integrations.length > 0) && !expandedOnce.current) {
|
||||||
expandedOnce.current = true;
|
expandedOnce.current = true;
|
||||||
setExpanded(true);
|
setExpanded(true);
|
||||||
}
|
}
|
||||||
}, [hasApps]);
|
}, [hasApps, integrations.length]);
|
||||||
|
|
||||||
const t = useScopedI18n("init.step.integrations.docker");
|
const t = useScopedI18n("init.step.integrations.docker");
|
||||||
const totalCount = integrations.length + apps.length;
|
const totalCount = integrations.length + apps.length;
|
||||||
|
|
||||||
if (totalCount === 0) return null;
|
if (totalCount === 0) return null;
|
||||||
|
|
||||||
|
const selectedAppCount = apps.filter((app) => selectedAppIds.has(app.containerId)).length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
withBorder
|
withBorder
|
||||||
@@ -75,7 +81,7 @@ export const DockerDiscoveryIndicator = ({
|
|||||||
background: "var(--mantine-color-blue-light)",
|
background: "var(--mantine-color-blue-light)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<UnstyledButton onClick={() => setExpanded((v) => !v)} w="100%">
|
<UnstyledButton onClick={() => setExpanded((prev) => !prev)} w="100%">
|
||||||
<Group justify="space-between" wrap="nowrap">
|
<Group justify="space-between" wrap="nowrap">
|
||||||
<Group gap="sm" wrap="nowrap">
|
<Group gap="sm" wrap="nowrap">
|
||||||
<ThemeIcon variant="light" color="blue" size="lg" radius="md">
|
<ThemeIcon variant="light" color="blue" size="lg" radius="md">
|
||||||
@@ -105,41 +111,63 @@ export const DockerDiscoveryIndicator = ({
|
|||||||
</UnstyledButton>
|
</UnstyledButton>
|
||||||
|
|
||||||
<Collapse in={expanded}>
|
<Collapse in={expanded}>
|
||||||
<Stack gap={4} mt="sm">
|
<Stack gap="xs" mt="sm">
|
||||||
{integrations.map((integration) => (
|
{integrations.length > 0 && (
|
||||||
<Group key={integration.containerId} gap="xs" wrap="nowrap" py={2}>
|
<Stack gap={4}>
|
||||||
<IntegrationAvatar kind={integration.kind} size="xs" />
|
{integrations.map((integration) => (
|
||||||
<Text size="xs" fw={500} lineClamp={1} style={{ flex: 1, minWidth: 0 }}>
|
<Group key={integration.containerId} gap="xs" wrap="nowrap" py={2}>
|
||||||
{integration.containerName}
|
<IntegrationAvatar kind={integration.kind} size="xs" />
|
||||||
</Text>
|
<Text size="xs" fw={500} lineClamp={1} style={{ flex: 1, minWidth: 0 }}>
|
||||||
<Badge size="xs" variant="light" color="blue">
|
{integration.containerName}
|
||||||
{getIntegrationName(integration.kind)}
|
</Text>
|
||||||
</Badge>
|
<Badge size="xs" variant="light" color="blue">
|
||||||
</Group>
|
{getIntegrationName(integration.kind)}
|
||||||
))}
|
</Badge>
|
||||||
|
</Group>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
{hasApps && (
|
{hasApps && (
|
||||||
<>
|
<Stack gap="xs">
|
||||||
{integrations.length > 0 && <Divider my={4} />}
|
<Text size="xs" fw={500}>
|
||||||
<Checkbox
|
{t("appSectionLabel", { count: String(selectedAppCount) })}
|
||||||
size="xs"
|
</Text>
|
||||||
label={t("appSectionLabel", { count: String(apps.length) })}
|
<ScrollArea.Autosize mah="30vh">
|
||||||
checked={appsEnabled}
|
<SimpleGrid cols={{ base: 3, xs: 4, sm: 5 }} spacing="xs">
|
||||||
onChange={() => onToggleAllApps(!appsEnabled)}
|
{apps.map((app) => {
|
||||||
styles={{ label: { fontSize: "var(--mantine-font-size-xs)" } }}
|
const isSelected = selectedAppIds.has(app.containerId);
|
||||||
/>
|
return (
|
||||||
{appsEnabled &&
|
<Card
|
||||||
apps.map((app) => (
|
key={app.containerId}
|
||||||
<Group key={app.containerId} gap="xs" wrap="nowrap" py={2}>
|
h={APP_CARD_HEIGHT}
|
||||||
<Avatar size="xs" radius="sm" src={app.iconUrl} styles={{ image: { objectFit: "contain" } }}>
|
p="xs"
|
||||||
{app.containerName.at(0)?.toUpperCase()}
|
withBorder
|
||||||
</Avatar>
|
style={{
|
||||||
<Text size="xs" c="dimmed" lineClamp={1} style={{ flex: 1, minWidth: 0 }}>
|
cursor: "pointer",
|
||||||
{app.containerName}
|
borderColor: isSelected ? "var(--mantine-color-blue-6)" : undefined,
|
||||||
</Text>
|
borderWidth: isSelected ? 2 : undefined,
|
||||||
</Group>
|
opacity: isSelected ? 1 : 0.6,
|
||||||
))}
|
}}
|
||||||
</>
|
onClick={() => onToggleApp(app.containerId)}
|
||||||
|
>
|
||||||
|
<Stack justify="space-between" h="100%" gap={4} align="center">
|
||||||
|
<Group justify="space-between" w="100%" wrap="nowrap">
|
||||||
|
<Text size="xs" fw={500} lineClamp={1} style={{ flex: 1, minWidth: 0 }}>
|
||||||
|
{app.containerName}
|
||||||
|
</Text>
|
||||||
|
{isSelected && <IconCheck size={14} color="var(--mantine-color-blue-6)" />}
|
||||||
|
</Group>
|
||||||
|
<Avatar size="sm" radius="sm" src={app.iconUrl} styles={{ image: { objectFit: "contain" } }}>
|
||||||
|
{app.containerName.at(0)?.toUpperCase()}
|
||||||
|
</Avatar>
|
||||||
|
</Stack>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</SimpleGrid>
|
||||||
|
</ScrollArea.Autosize>
|
||||||
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export const InitIntegrations = () => {
|
|||||||
const dockerIntegrations = dockerData?.status === "success" ? dockerData.integrations : [];
|
const dockerIntegrations = dockerData?.status === "success" ? dockerData.integrations : [];
|
||||||
const dockerApps = dockerData?.status === "success" ? dockerData.apps : [];
|
const dockerApps = dockerData?.status === "success" ? dockerData.apps : [];
|
||||||
|
|
||||||
const [addDockerApps, setAddDockerApps] = useState(true);
|
const [selectedAppIds, setSelectedAppIds] = useState<Set<string>>(new Set());
|
||||||
|
|
||||||
const dockerApplied = useRef(false);
|
const dockerApplied = useRef(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -89,12 +89,25 @@ export const InitIntegrations = () => {
|
|||||||
|
|
||||||
setDrafts(newDrafts);
|
setDrafts(newDrafts);
|
||||||
setSelectedKinds(Array.from(newKinds));
|
setSelectedKinds(Array.from(newKinds));
|
||||||
|
setSelectedAppIds(new Set(dockerData.apps.map((app) => app.containerId)));
|
||||||
}, [dockerData]);
|
}, [dockerData]);
|
||||||
|
|
||||||
const handleSelectionChange = useCallback((kinds: IntegrationKind[]) => {
|
const handleSelectionChange = useCallback((kinds: IntegrationKind[]) => {
|
||||||
setSelectedKinds(kinds);
|
setSelectedKinds(kinds);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleToggleApp = useCallback((containerId: string) => {
|
||||||
|
setSelectedAppIds((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (next.has(containerId)) {
|
||||||
|
next.delete(containerId);
|
||||||
|
} else {
|
||||||
|
next.add(containerId);
|
||||||
|
}
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleContinueToConfig = () => {
|
const handleContinueToConfig = () => {
|
||||||
const newDrafts = new Map(drafts);
|
const newDrafts = new Map(drafts);
|
||||||
for (const kind of selectedKinds) {
|
for (const kind of selectedKinds) {
|
||||||
@@ -119,9 +132,10 @@ export const InitIntegrations = () => {
|
|||||||
const finishSetupAsync = async () => {
|
const finishSetupAsync = async () => {
|
||||||
setPhase("done");
|
setPhase("done");
|
||||||
try {
|
try {
|
||||||
if (addDockerApps && dockerApps.length > 0) {
|
const appsToCreate = dockerApps.filter((app) => selectedAppIds.has(app.containerId));
|
||||||
|
if (appsToCreate.length > 0) {
|
||||||
await createApps(
|
await createApps(
|
||||||
dockerApps.map((app) => ({
|
appsToCreate.map((app) => ({
|
||||||
name: app.containerName,
|
name: app.containerName,
|
||||||
href: app.suggestedUrl || null,
|
href: app.suggestedUrl || null,
|
||||||
iconUrl: app.iconUrl,
|
iconUrl: app.iconUrl,
|
||||||
@@ -190,8 +204,8 @@ export const InitIntegrations = () => {
|
|||||||
<DockerDiscoveryIndicator
|
<DockerDiscoveryIndicator
|
||||||
integrations={dockerIntegrations}
|
integrations={dockerIntegrations}
|
||||||
apps={dockerApps}
|
apps={dockerApps}
|
||||||
appsEnabled={addDockerApps}
|
selectedAppIds={selectedAppIds}
|
||||||
onToggleAllApps={setAddDockerApps}
|
onToggleApp={handleToggleApp}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack gap="xs">
|
<Stack gap="xs">
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ export const buildSortedIntegrations = (
|
|||||||
integrationKinds
|
integrationKinds
|
||||||
.filter((kind) => {
|
.filter((kind) => {
|
||||||
if (options.onboarding && hiddenFromOnboarding.has(kind)) return false;
|
if (options.onboarding && hiddenFromOnboarding.has(kind)) return false;
|
||||||
|
if (options.onboarding && widgetsByIntegration[kind].length === 0) return false;
|
||||||
if (!options.enableMockIntegration && kind === "mock") return false;
|
if (!options.enableMockIntegration && kind === "mock") return false;
|
||||||
return true;
|
return true;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -125,7 +125,7 @@
|
|||||||
"detected": "Docker detected {count} services",
|
"detected": "Docker detected {count} services",
|
||||||
"detectedBreakdown": "{integrations} integrations · {apps} apps",
|
"detectedBreakdown": "{integrations} integrations · {apps} apps",
|
||||||
"appBadge": "App",
|
"appBadge": "App",
|
||||||
"appSectionLabel": "Also add {count} apps to dashboard"
|
"appSectionLabel": "Apps to add to dashboard ({count} selected)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"finish": {
|
"finish": {
|
||||||
|
|||||||
Reference in new issue
Block a user