Merge pull request 'feat(ui): display add machine in sidebar when machine list is empty' (#5027) from ui/refine-add-machine into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/5027
This commit is contained in:
@@ -3,12 +3,13 @@ import { A } from "@solidjs/router";
|
|||||||
import { Accordion } from "@kobalte/core/accordion";
|
import { Accordion } from "@kobalte/core/accordion";
|
||||||
import Icon from "../Icon/Icon";
|
import Icon from "../Icon/Icon";
|
||||||
import { Typography } from "@/src/components/Typography/Typography";
|
import { Typography } from "@/src/components/Typography/Typography";
|
||||||
import { For, useContext } from "solid-js";
|
import { For, Show, useContext } from "solid-js";
|
||||||
import { MachineStatus } from "@/src/components/MachineStatus/MachineStatus";
|
import { MachineStatus } from "@/src/components/MachineStatus/MachineStatus";
|
||||||
import { buildMachinePath, useClanURI } from "@/src/hooks/clan";
|
import { buildMachinePath, useClanURI } from "@/src/hooks/clan";
|
||||||
import { useMachineStateQuery } from "@/src/hooks/queries";
|
import { useMachineStateQuery } from "@/src/hooks/queries";
|
||||||
import { SidebarProps } from "./Sidebar";
|
import { SidebarProps } from "./Sidebar";
|
||||||
import { ClanContext } from "@/src/routes/Clan/Clan";
|
import { ClanContext } from "@/src/routes/Clan/Clan";
|
||||||
|
import { Button } from "../Button/Button";
|
||||||
|
|
||||||
interface MachineProps {
|
interface MachineProps {
|
||||||
clanURI: string;
|
clanURI: string;
|
||||||
@@ -71,6 +72,15 @@ export const SidebarBody = (props: SidebarProps) => {
|
|||||||
// we want them all to be open by default
|
// we want them all to be open by default
|
||||||
const defaultAccordionValues = ["your-machines", ...sectionLabels];
|
const defaultAccordionValues = ["your-machines", ...sectionLabels];
|
||||||
|
|
||||||
|
const machines = () => {
|
||||||
|
if (!ctx.machinesQuery.isSuccess) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = ctx.machinesQuery.data;
|
||||||
|
return Object.keys(result).length > 0 ? result : undefined;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="sidebar-body">
|
<div class="sidebar-body">
|
||||||
<Accordion
|
<Accordion
|
||||||
@@ -100,18 +110,42 @@ export const SidebarBody = (props: SidebarProps) => {
|
|||||||
</Accordion.Trigger>
|
</Accordion.Trigger>
|
||||||
</Accordion.Header>
|
</Accordion.Header>
|
||||||
<Accordion.Content class="content">
|
<Accordion.Content class="content">
|
||||||
<nav>
|
<Show
|
||||||
<For each={Object.entries(ctx.machinesQuery.data || {})}>
|
when={machines()}
|
||||||
{([id, machine]) => (
|
fallback={
|
||||||
<MachineRoute
|
<div class="flex w-full flex-col items-center justify-center gap-2.5">
|
||||||
clanURI={clanURI}
|
<Typography
|
||||||
machineID={id}
|
hierarchy="body"
|
||||||
name={machine.name || id}
|
size="s"
|
||||||
serviceCount={0}
|
weight="medium"
|
||||||
/>
|
inverted
|
||||||
)}
|
>
|
||||||
</For>
|
No machines yet
|
||||||
</nav>
|
</Typography>
|
||||||
|
<Button
|
||||||
|
hierarchy="primary"
|
||||||
|
size="s"
|
||||||
|
startIcon="Machine"
|
||||||
|
onClick={() => ctx.setShowAddMachine(true)}
|
||||||
|
>
|
||||||
|
Add machine
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<nav>
|
||||||
|
<For each={Object.entries(machines()!)}>
|
||||||
|
{([id, machine]) => (
|
||||||
|
<MachineRoute
|
||||||
|
clanURI={clanURI}
|
||||||
|
machineID={id}
|
||||||
|
name={machine.name || id}
|
||||||
|
serviceCount={0}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
</nav>
|
||||||
|
</Show>
|
||||||
</Accordion.Content>
|
</Accordion.Content>
|
||||||
</Accordion.Item>
|
</Accordion.Item>
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
on,
|
on,
|
||||||
onMount,
|
onMount,
|
||||||
Show,
|
Show,
|
||||||
|
Signal,
|
||||||
useContext,
|
useContext,
|
||||||
} from "solid-js";
|
} from "solid-js";
|
||||||
import {
|
import {
|
||||||
@@ -49,6 +50,9 @@ interface ClanContextProps {
|
|||||||
|
|
||||||
isLoading(): boolean;
|
isLoading(): boolean;
|
||||||
isError(): boolean;
|
isError(): boolean;
|
||||||
|
|
||||||
|
showAddMachine(): boolean;
|
||||||
|
setShowAddMachine(value: boolean): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class DefaultClanContext implements ClanContextProps {
|
class DefaultClanContext implements ClanContextProps {
|
||||||
@@ -62,6 +66,8 @@ class DefaultClanContext implements ClanContextProps {
|
|||||||
|
|
||||||
allQueries: UseQueryResult[];
|
allQueries: UseQueryResult[];
|
||||||
|
|
||||||
|
showAddMachineSignal: Signal<boolean>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
clanURI: string,
|
clanURI: string,
|
||||||
machinesQuery: MachinesQueryResult,
|
machinesQuery: MachinesQueryResult,
|
||||||
@@ -76,6 +82,8 @@ class DefaultClanContext implements ClanContextProps {
|
|||||||
this.allClansQueries = [activeClanQuery, ...otherClanQueries];
|
this.allClansQueries = [activeClanQuery, ...otherClanQueries];
|
||||||
|
|
||||||
this.allQueries = [machinesQuery, activeClanQuery, ...otherClanQueries];
|
this.allQueries = [machinesQuery, activeClanQuery, ...otherClanQueries];
|
||||||
|
|
||||||
|
this.showAddMachineSignal = createSignal(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoading(): boolean {
|
isLoading(): boolean {
|
||||||
@@ -85,6 +93,16 @@ class DefaultClanContext implements ClanContextProps {
|
|||||||
isError(): boolean {
|
isError(): boolean {
|
||||||
return this.activeClanQuery.isError;
|
return this.activeClanQuery.isError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setShowAddMachine(value: boolean) {
|
||||||
|
const [_, setShow] = this.showAddMachineSignal;
|
||||||
|
setShow(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
showAddMachine(): boolean {
|
||||||
|
const [show, _] = this.showAddMachineSignal;
|
||||||
|
return show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ClanContext = createContext<ClanContextProps>();
|
export const ClanContext = createContext<ClanContextProps>();
|
||||||
@@ -140,7 +158,6 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
|
|
||||||
const [showService, setShowService] = createSignal(false);
|
const [showService, setShowService] = createSignal(false);
|
||||||
|
|
||||||
const [showCreate, setShowCreate] = createSignal(false);
|
|
||||||
const [currentPromise, setCurrentPromise] = createSignal<{
|
const [currentPromise, setCurrentPromise] = createSignal<{
|
||||||
resolve: ({ id }: { id: string }) => void;
|
resolve: ({ id }: { id: string }) => void;
|
||||||
reject: (err: unknown) => void;
|
reject: (err: unknown) => void;
|
||||||
@@ -148,7 +165,7 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
|
|
||||||
const onCreate = async (): Promise<{ id: string }> => {
|
const onCreate = async (): Promise<{ id: string }> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setShowCreate(true);
|
ctx.setShowAddMachine(true);
|
||||||
setCurrentPromise({ resolve, reject });
|
setCurrentPromise({ resolve, reject });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -244,7 +261,7 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
<Show when={loadingError()}>
|
<Show when={loadingError()}>
|
||||||
<ListClansModal error={loadingError()} />
|
<ListClansModal error={loadingError()} />
|
||||||
</Show>
|
</Show>
|
||||||
<Show when={showCreate()}>
|
<Show when={ctx.showAddMachine()}>
|
||||||
<AddMachine
|
<AddMachine
|
||||||
onCreated={async (id) => {
|
onCreated={async (id) => {
|
||||||
const promise = currentPromise();
|
const promise = currentPromise();
|
||||||
@@ -255,7 +272,7 @@ const ClanSceneController = (props: RouteSectionProps) => {
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setShowCreate(false);
|
ctx.setShowAddMachine(false);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Show>
|
</Show>
|
||||||
|
|||||||
Reference in New Issue
Block a user