Skip to content

Commit 3beb834

Browse files
committed
feat(results-page): add title to instance page and make project list item clickable
1 parent e5cef4c commit 3beb834

File tree

6 files changed

+76
-16
lines changed

6 files changed

+76
-16
lines changed

components/instances/Instance.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@ import { captureException } from "@sentry/nextjs";
66

77
import { getErrorMessage } from "../../utils/next/orvalError";
88
import { CenterLoader } from "../CenterLoader";
9+
import type { ProjectListItemProps } from "../projects/ProjectListItem";
910
import { ResultApplicationCard } from "./ResultApplicationCard";
1011
import { ResultJobCard } from "./ResultJobCard";
1112

1213
export interface InstanceProps {
1314
instanceId: InstanceSummary["id"];
1415
instanceSummary?: InstanceSummary;
16+
projectClickAction: ProjectListItemProps["clickAction"];
1517
collapsedByDefault?: boolean;
1618
}
1719

1820
export const Instance = ({
1921
instanceId,
20-
collapsedByDefault = true,
22+
projectClickAction,
2123
instanceSummary,
24+
collapsedByDefault = true,
2225
}: InstanceProps) => {
2326
// The instance summary is sufficient but not always provided. If only the ID is provided, the
2427
// instance get response is then requested and switched in.
@@ -45,6 +48,7 @@ export const Instance = ({
4548
collapsedByDefault={collapsedByDefault}
4649
instance={instance}
4750
instanceId={instanceId}
51+
projectClickAction={projectClickAction}
4852
/>
4953
</Box>
5054
);
@@ -54,6 +58,7 @@ export const Instance = ({
5458
collapsedByDefault={collapsedByDefault}
5559
instance={instance}
5660
instanceId={instanceId}
61+
projectClickAction={projectClickAction}
5762
/>
5863
);
5964
default:

components/instances/ResultApplicationCard.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export interface ResultApplicationCardProps {
2121
* Instance of the application
2222
*/
2323
instance: InstanceSummary | InstanceGetResponse;
24+
/**
25+
* Action to take when the project is clicked
26+
*/
27+
projectClickAction: "select-project" | "navigate-to-project";
2428
/**
2529
* Whether the card should have its collapsed content visible immediately. Defaults to true.
2630
*/
@@ -30,6 +34,7 @@ export interface ResultApplicationCardProps {
3034
export const ResultApplicationCard = ({
3135
instance,
3236
instanceId,
37+
projectClickAction,
3338
collapsedByDefault = true,
3439
}: ResultApplicationCardProps) => {
3540
const query = useInstanceRouterQuery();
@@ -78,9 +83,11 @@ export const ResultApplicationCard = ({
7883
state={instance.phase}
7984
>
8085
<ListItem>
81-
<ListItemText primary={instance.name} />
86+
<ListItemText primary={instance.name} secondary={instance.application_id} />
8287
</ListItem>
83-
<ProjectListItem projectName={associatedProject?.name || "loading..."} />
88+
{associatedProject && (
89+
<ProjectListItem clickAction={projectClickAction} project={associatedProject} />
90+
)}
8491
<ArchivedStatus archived={instance.archived} />
8592
</ResultCard>
8693
);

components/instances/ResultJobCard.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { LogsButton } from "../../components/results/LogsButton";
66
import { RerunJobButton } from "../../components/results/RerunJobButton";
77
import { ResultCard } from "../../components/results/ResultCard";
88
import { useIsUserAdminOrEditorOfCurrentProject, useProjectFromId } from "../../hooks/projectHooks";
9+
import type { ProjectListItemProps } from "../projects/ProjectListItem";
910
import { ProjectListItem } from "../projects/ProjectListItem";
1011
import { ArchivedStatus } from "./ArchivedStatus";
1112
import { ArchiveInstance } from "./ArchiveInstance";
@@ -25,6 +26,10 @@ export interface ResultJobCardProps {
2526
* Instance of the job
2627
*/
2728
instance: InstanceSummary | InstanceGetResponse;
29+
/**
30+
* Action to take when the project is clicked
31+
*/
32+
projectClickAction: ProjectListItemProps["clickAction"];
2833
collapsedByDefault?: boolean;
2934
}
3035

@@ -34,6 +39,7 @@ export interface ResultJobCardProps {
3439
export const ResultJobCard = ({
3540
instanceId,
3641
instance,
42+
projectClickAction,
3743
collapsedByDefault = true,
3844
}: ResultJobCardProps) => {
3945
const query = useInstanceRouterQuery();
@@ -80,7 +86,9 @@ export const ResultJobCard = ({
8086
<ListItem>
8187
<ListItemText primary={instance.name} secondary={instance.job_name} />
8288
</ListItem>
83-
<ProjectListItem projectName={associatedProject?.name || "loading..."} />
89+
{associatedProject && (
90+
<ProjectListItem clickAction={projectClickAction} project={associatedProject} />
91+
)}
8492
<ArchivedStatus archived={instance.archived} />
8593
</ResultCard>
8694
);
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,46 @@
1+
import type { ProjectDetail } from "@squonk/data-manager-client";
2+
13
import { AccountTreeRounded as AccountTreeRoundedIcon } from "@mui/icons-material";
2-
import { ListItem, ListItemIcon, ListItemText } from "@mui/material";
4+
import { ListItemButton, ListItemIcon, ListItemText, Tooltip } from "@mui/material";
5+
import { useRouter } from "next/router";
6+
7+
import { useCurrentProjectId } from "../../hooks/projectHooks";
8+
9+
type ProjectClickActions = "select-project" | "navigate-to-project";
310

411
export interface ProjectListItemProps {
5-
projectName: string;
12+
project: ProjectDetail;
13+
clickAction: ProjectClickActions;
614
}
715

8-
export const ProjectListItem = ({ projectName }: ProjectListItemProps) => {
16+
export const TOOLTIPS = {
17+
"select-project": "Select project",
18+
"navigate-to-project": "Go to project",
19+
} as const satisfies Record<ProjectClickActions, string>;
20+
21+
export const ProjectListItem = ({ project, clickAction }: ProjectListItemProps) => {
22+
const { projectId, setCurrentProjectId } = useCurrentProjectId();
23+
const { push } = useRouter();
24+
25+
const action =
26+
clickAction === "navigate-to-project" || projectId === project.project_id
27+
? "navigate-to-project"
28+
: "select-project";
29+
30+
const onClick = () => {
31+
setCurrentProjectId(project.project_id);
32+
if (action === "navigate-to-project") {
33+
push("/project");
34+
}
35+
};
936
return (
10-
<ListItem>
11-
<ListItemIcon sx={{ minWidth: "40px" }}>
12-
<AccountTreeRoundedIcon />
13-
</ListItemIcon>
14-
<ListItemText primary={projectName} />
15-
</ListItem>
37+
<Tooltip title={TOOLTIPS[action]}>
38+
<ListItemButton component="li" sx={{ flexGrow: 0 }} onClick={onClick}>
39+
<ListItemIcon sx={{ minWidth: "40px" }}>
40+
<AccountTreeRoundedIcon />
41+
</ListItemIcon>
42+
<ListItemText primary={project.name} />
43+
</ListItemButton>
44+
</Tooltip>
1645
);
1746
};

features/results/ResultCards.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ export const ResultCards = ({ resultTypes, searchValue, instances, tasks }: Resu
7878
const instance = instanceOrTask;
7979
return (
8080
<Grid item key={instance.id} xs={12}>
81-
<Instance instanceId={instance.id} instanceSummary={instance} />
81+
<Instance
82+
instanceId={instance.id}
83+
instanceSummary={instance}
84+
projectClickAction="select-project"
85+
/>
8286
</Grid>
8387
);
8488
});

pages/results/instance/[instanceId].tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getGetInstanceQueryKey } from "@squonk/data-manager-client/instance";
22

33
import { withPageAuthRequired as withPageAuthRequiredCSR } from "@auth0/nextjs-auth0/client";
44
import { RefreshRounded as RefreshRoundedIcon } from "@mui/icons-material";
5-
import { Box, Container, IconButton, Tooltip } from "@mui/material";
5+
import { Box, Container, IconButton, Tooltip, Typography } from "@mui/material";
66
import { useQueryClient } from "@tanstack/react-query";
77
import NextError from "next/error";
88
import { useRouter } from "next/router";
@@ -34,6 +34,9 @@ const Result = () => {
3434
<RoleRequired roles={AS_ROLES}>
3535
<Layout>
3636
<Container maxWidth="md">
37+
<Typography component="h1" variant="h1">
38+
Instance
39+
</Typography>
3740
<Box alignItems="flex-start" display="flex">
3841
<EventDebugSwitch />
3942
<Tooltip title="Refresh Instance">
@@ -49,7 +52,11 @@ const Result = () => {
4952

5053
{instanceId && <InstanceTitle instanceId={instanceId} />}
5154

52-
<Instance collapsedByDefault={false} instanceId={instanceId} />
55+
<Instance
56+
collapsedByDefault={false}
57+
instanceId={instanceId}
58+
projectClickAction="navigate-to-project"
59+
/>
5360
<AllResultsButton instanceId={instanceId} />
5461
</Container>
5562
</Layout>

0 commit comments

Comments
 (0)