Skip to content

Commit c5401de

Browse files
committed
tweak user level tab view
1 parent 7a3d9e0 commit c5401de

File tree

6 files changed

+174
-215
lines changed

6 files changed

+174
-215
lines changed

frontend/src/components/resources/deployment/tabs.tsx

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { useDeployment } from ".";
33
import { useLocalStorage, usePermissions } from "@lib/hooks";
44
import { useServer } from "../server";
55
import { useMemo } from "react";
6-
import {
7-
MobileFriendlyTabsSelector,
8-
TabNoContent,
9-
} from "@ui/mobile-friendly-tabs";
6+
import { MobileFriendlyTabsSelector } from "@ui/mobile-friendly-tabs";
107
import { DeploymentConfig } from "./config";
118
import { DeploymentLogs } from "./log";
129
import { DeploymentInspect } from "./inspect";
@@ -58,44 +55,32 @@ const DeploymentTabsInner = ({
5855
? "Config"
5956
: _view;
6057

61-
const tabsNoContent = useMemo<TabNoContent<DeploymentTabsView>[]>(
62-
() => [
63-
{
64-
value: "Config",
65-
},
66-
{
67-
value: "Log",
68-
hidden: !specificLogs,
69-
disabled: logsDisabled,
70-
},
71-
{
72-
value: "Inspect",
73-
hidden: !specificInspect,
74-
disabled: inspectDisabled,
75-
},
76-
{
77-
value: "Terminals",
78-
hidden: !specificTerminal,
79-
disabled: terminalDisabled,
80-
},
81-
],
82-
[
83-
specificLogs,
84-
logsDisabled,
85-
specificInspect,
86-
inspectDisabled,
87-
specificTerminal,
88-
terminalDisabled,
89-
]
90-
);
91-
92-
const Selector = (
93-
<MobileFriendlyTabsSelector
94-
tabs={tabsNoContent}
95-
value={view}
96-
onValueChange={setView as any}
97-
tabsTriggerClassname="w-[110px]"
98-
/>
58+
const Selector = useMemo(
59+
() => (
60+
<MobileFriendlyTabsSelector
61+
tabs={[
62+
{
63+
value: "Config",
64+
},
65+
{
66+
value: "Log",
67+
disabled: logsDisabled,
68+
},
69+
{
70+
value: "Inspect",
71+
disabled: inspectDisabled,
72+
},
73+
{
74+
value: "Terminals",
75+
disabled: terminalDisabled,
76+
},
77+
]}
78+
value={view}
79+
onValueChange={setView as any}
80+
tabsTriggerClassname="w-[110px]"
81+
/>
82+
),
83+
[logsDisabled, inspectDisabled, terminalDisabled]
9984
);
10085

10186
const target: Types.TerminalTarget = useMemo(

frontend/src/components/resources/server/tabs.tsx

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { useLocalStorage, usePermissions, useRead, useUser } from "@lib/hooks";
22
import { useServer } from ".";
33
import { ReactNode, useMemo } from "react";
4-
import {
5-
MobileFriendlyTabsSelector,
6-
TabNoContent,
7-
} from "@ui/mobile-friendly-tabs";
4+
import { MobileFriendlyTabsSelector } from "@ui/mobile-friendly-tabs";
85
import { ServerStats } from "./stats";
96
import { ServerInfo } from "./info";
107
import { ServerConfig } from "./config";
@@ -27,9 +24,8 @@ export const ServerTabs = ({ id }: { id: string }) => {
2724

2825
const { specificTerminal } = usePermissions({ type: "Server", id });
2926
const server_info = useServer(id)?.info;
30-
const terminals_disabled = server_info?.terminals_disabled ?? true;
31-
const container_terminals_disabled =
32-
server_info?.container_terminals_disabled ?? true;
27+
const terminalDisabled =
28+
!specificTerminal || (server_info?.terminals_disabled ?? true);
3329

3430
const deployments =
3531
useRead("ListDeployments", {}).data?.filter(
@@ -49,43 +45,34 @@ export const ServerTabs = ({ id }: { id: string }) => {
4945

5046
const noResources = noDeployments && noRepos && noStacks;
5147

52-
const tabsNoContent = useMemo<TabNoContent<ServerTabView>[]>(
53-
() => [
54-
{
55-
value: "Config",
56-
},
57-
{
58-
value: "Stats",
59-
},
60-
{
61-
value: "Docker",
62-
},
63-
{
64-
value: "Resources",
65-
disabled: noResources,
66-
},
67-
{
68-
value: "Terminals",
69-
disabled:
70-
!specificTerminal ||
71-
(terminals_disabled && container_terminals_disabled),
72-
},
73-
],
74-
[
75-
noResources,
76-
specificTerminal,
77-
terminals_disabled,
78-
container_terminals_disabled,
79-
]
80-
);
81-
82-
const Selector = (
83-
<MobileFriendlyTabsSelector
84-
tabs={tabsNoContent}
85-
value={view}
86-
onValueChange={setView as any}
87-
tabsTriggerClassname="w-[110px]"
88-
/>
48+
const Selector = useMemo(
49+
() => (
50+
<MobileFriendlyTabsSelector
51+
tabs={[
52+
{
53+
value: "Config",
54+
},
55+
{
56+
value: "Stats",
57+
},
58+
{
59+
value: "Docker",
60+
},
61+
{
62+
value: "Resources",
63+
disabled: noResources,
64+
},
65+
{
66+
value: "Terminals",
67+
disabled: terminalDisabled,
68+
},
69+
]}
70+
value={view}
71+
onValueChange={setView as any}
72+
tabsTriggerClassname="w-[110px]"
73+
/>
74+
),
75+
[noResources, terminalDisabled]
8976
);
9077

9178
switch (view) {

frontend/src/components/resources/stack/tabs.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ export const StackTabs = ({ id }: { id: string }) => {
1919
"Config"
2020
);
2121
const info = useStack(id)?.info;
22-
const { specific, specificLogs } = usePermissions({ type: "Stack", id });
22+
const { specificLogs } = usePermissions({ type: "Stack", id });
2323

2424
const state = info?.state;
2525
const hideInfo = !info?.files_on_host && !info?.repo && !info?.linked_repo;
2626
const hideServices =
2727
state === undefined ||
2828
state === Types.StackState.Unknown ||
2929
state === Types.StackState.Down;
30-
const hideLogs =
31-
hideServices || !specific.includes(Types.SpecificPermission.Logs);
30+
const hideLogs = hideServices || !specificLogs;
3231

3332
const view =
3433
(_view === "Info" && hideInfo) ||
@@ -52,7 +51,6 @@ export const StackTabs = ({ id }: { id: string }) => {
5251
},
5352
{
5453
value: "Log",
55-
hidden: !specificLogs,
5654
disabled: hideLogs,
5755
},
5856
],

frontend/src/components/topbar/index.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ export const Topbar = () => {
2323
<div className="fixed top-0 w-full bg-accent z-50 border-b shadow-sm">
2424
<div className="container px-[1.2rem] h-16 flex items-center justify-between md:grid md:grid-cols-[auto_1fr] lg:grid-cols-3">
2525
{/* Logo */}
26-
<Link
27-
to="/"
28-
className="flex gap-3 items-center text-2xl tracking-widest md:mx-2"
29-
>
30-
<img src="/komodo-512x512.png" className="w-[32px]" />
31-
<div className="hidden lg:block">KOMODO</div>
32-
</Link>
26+
<div className="flex items-center gap-1">
27+
<Link
28+
to="/"
29+
className="flex gap-3 items-center text-2xl tracking-widest md:mx-2"
30+
>
31+
<img src="/komodo-512x512.png" className="w-[32px]" />
32+
<div className="hidden lg:block">KOMODO</div>
33+
</Link>
34+
<MobileDropdown />
35+
</div>
3336

3437
{/* Searchbar */}
3538
<div className="hidden lg:flex justify-center">
@@ -38,7 +41,6 @@ export const Topbar = () => {
3841

3942
{/* Shortcuts */}
4043
<div className="flex justify-end items-center gap-1">
41-
<MobileDropdown />
4244
<OmniSearch setOpen={setOmniOpen} className="lg:hidden" />
4345
<div className="flex gap-0">
4446
<Docs />

frontend/src/pages/stack-service/index.tsx

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
} from "@lib/color";
2020
import {
2121
usePermissions,
22-
useLocalStorage,
2322
useRead,
2423
useSetTitle,
2524
useContainerPortsMap,
@@ -28,20 +27,12 @@ import { cn } from "@lib/utils";
2827
import { Types } from "komodo_client";
2928
import { ChevronLeft, Clapperboard, Layers2 } from "lucide-react";
3029
import { Link, useParams } from "react-router-dom";
31-
import { StackServiceLogs } from "./log";
3230
import { Button } from "@ui/button";
3331
import { ExportButton } from "@components/export";
3432
import { ContainerPortLink, DockerResourceLink } from "@components/util";
3533
import { ResourceNotifications } from "@pages/resource-notifications";
3634
import { Fragment } from "react/jsx-runtime";
37-
import { ContainerTerminals } from "@components/terminal/container";
38-
import { useServer } from "@components/resources/server";
39-
import { StackServiceInspect } from "./inspect";
40-
import { useMemo } from "react";
41-
import {
42-
MobileFriendlyTabsSelector,
43-
TabNoContent,
44-
} from "@ui/mobile-friendly-tabs";
35+
import { StackServiceTabs } from "./tabs";
4536

4637
type IdServiceComponent = React.FC<{ id: string; service?: string }>;
4738

@@ -224,110 +215,3 @@ const StackServicePageInner = ({
224215
</div>
225216
);
226217
};
227-
228-
type StackServiceTabsView = "Log" | "Inspect" | "Terminals";
229-
230-
const StackServiceTabs = ({
231-
stack,
232-
service,
233-
container_state,
234-
}: {
235-
stack: Types.StackListItem;
236-
service: string;
237-
container_state: Types.ContainerStateStatusEnum;
238-
}) => {
239-
const [_view, setView] = useLocalStorage<StackServiceTabsView>(
240-
`stack-${stack.id}-${service}-tabs-v2`,
241-
"Log"
242-
);
243-
const { specificLogs, specificInspect, specificTerminal } = usePermissions({
244-
type: "Stack",
245-
id: stack.id,
246-
});
247-
const container_terminals_disabled =
248-
useServer(stack.info.server_id)?.info.container_terminals_disabled ?? true;
249-
const logDisabled =
250-
!specificLogs || container_state === Types.ContainerStateStatusEnum.Empty;
251-
const inspectDisabled =
252-
!specificInspect ||
253-
container_state === Types.ContainerStateStatusEnum.Empty;
254-
const terminalDisabled =
255-
!specificTerminal ||
256-
container_terminals_disabled ||
257-
container_state !== Types.ContainerStateStatusEnum.Running;
258-
const view =
259-
(inspectDisabled && _view === "Inspect") ||
260-
(terminalDisabled && _view === "Terminals")
261-
? "Log"
262-
: _view;
263-
264-
const tabsNoContent = useMemo<TabNoContent<StackServiceTabsView>[]>(
265-
() => [
266-
{
267-
value: "Log",
268-
hidden: !specificLogs,
269-
disabled: logDisabled,
270-
},
271-
{
272-
value: "Inspect",
273-
hidden: !specificInspect,
274-
disabled: inspectDisabled,
275-
},
276-
{
277-
value: "Terminals",
278-
hidden: !specificTerminal,
279-
disabled: terminalDisabled,
280-
},
281-
],
282-
[
283-
specificLogs,
284-
logDisabled,
285-
specificInspect,
286-
inspectDisabled,
287-
specificTerminal,
288-
terminalDisabled,
289-
]
290-
);
291-
292-
const Selector = (
293-
<MobileFriendlyTabsSelector
294-
tabs={tabsNoContent}
295-
value={view}
296-
onValueChange={setView as any}
297-
tabsTriggerClassname="w-[110px]"
298-
/>
299-
);
300-
301-
const target: Types.TerminalTarget = useMemo(
302-
() => ({
303-
type: "Stack",
304-
params: {
305-
stack: stack.id,
306-
service,
307-
},
308-
}),
309-
[stack.id, service]
310-
);
311-
312-
switch (view) {
313-
case "Log":
314-
return (
315-
<StackServiceLogs
316-
id={stack.id}
317-
service={service}
318-
titleOther={Selector}
319-
disabled={logDisabled}
320-
/>
321-
);
322-
case "Inspect":
323-
return (
324-
<StackServiceInspect
325-
id={stack.id}
326-
service={service}
327-
titleOther={Selector}
328-
/>
329-
);
330-
case "Terminals":
331-
return <ContainerTerminals target={target} titleOther={Selector} />;
332-
}
333-
};

0 commit comments

Comments
 (0)