Skip to content

feat: program details pane #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions containers/ecr-viewer/e2e/dual/admin-program.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,21 @@ test.describe("program management page", () => {
await page.waitForURL("/ecr-viewer/admin/program");
await expect(page.getByText("Program management")).toBeVisible();
await expect(page.getByText(conditionName)).toBeVisible();

// open up side panel
await page.getByText(conditionName).click();
await expect(page.getByText("Program area information")).toBeVisible();

const accessibilityScanResultsSidePanel = await new AxeBuilder({
page,
}).analyze();

// axe struggles with the modal background, but all manual testing
// points to contrast being fine
const nonColorViolations =
accessibilityScanResultsSidePanel.violations.filter(
(v) => v.id !== "color-contrast",
);
expect(nonColorViolations).toEqual([]);
});
});
101 changes: 79 additions & 22 deletions containers/ecr-viewer/src/app/admin/program/ProgramTable.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
"use client";
import { useState } from "react";

import {
DetailsSidePanel,
DetailsTrigger,
useDetailsRef,
} from "@/app/components/DetailsSidePanel";
import {
PaginatedSortableTable,
TableColumn,
} from "@/app/components/table/PaginatedSortableTable";
import { ConditionReference } from "@/app/data/metadataDb/types/core";
import { formatDateTime } from "@/app/services/formatDateService";
import { ListedProgramArea } from "@/app/services/programAreaService";

const tableHeaders: TableColumn<ListedProgramArea>[] = [
{
id: "name",
value: "Program Area",
dataSortable: true,
sortDirection: "ASC",
},
{
id: "conditions",
value: "Number of Conditions",
dataSortable: false,
sortDirection: "",
formatter: (conditions: ConditionReference[]) =>
`${conditions.length} condition${conditions.length === 1 ? "" : "s"}`,
},
];

/**
*
* @param props React props
Expand All @@ -34,11 +25,77 @@ export const ProgramTable = ({
}: {
programAreas: ListedProgramArea[];
}) => {
const detailsRef = useDetailsRef();
const [selectedProgramArea, setSelectedProgramArea] =
useState<ListedProgramArea | null>(null);

const tableHeaders: TableColumn<ListedProgramArea>[] = [
{
id: "name",
value: "Program Area",
dataSortable: true,
sortDirection: "ASC",
formatter: (v: string, programArea: ListedProgramArea) => (
<DetailsTrigger
detailsRef={detailsRef}
onClick={() => {
setSelectedProgramArea(programArea);
}}
>
{v}
</DetailsTrigger>
),
},
{
id: "conditions",
value: "Number of Conditions",
dataSortable: false,
sortDirection: "",
formatter: (conditions: ConditionReference[]) =>
`${conditions.length} condition${conditions.length === 1 ? "" : "s"}`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are other places where we need a pluralizer. Should this be in a utils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do have one for age, but it isn't exported. It's just such a weeeeeee util that I've flip flopped several times on whether its worth it - thoughts?

},
];
return (
<PaginatedSortableTable
initHeaders={tableHeaders}
items={programAreas}
itemType="Program areas"
/>
<div>
<DetailsSidePanel
detailsRef={detailsRef}
title={selectedProgramArea?.name!}
subtitle={`Created on ${formatDateTime(
selectedProgramArea?.date_created.toISOString(),
)}`}
description="Program area information"
details={[
{
title: "Name",
value: selectedProgramArea?.name,
},
{
title: "Conditions",
value:
selectedProgramArea?.conditions.length === 0 ? (
"No conditions assigned"
) : (
<ul className="add-list-reset">
{selectedProgramArea?.conditions
.sort()
.map(({ condition_name, code }) => (
<li
key={code}
className="border-bottom border-base-lightest padding-y-1"
>
{condition_name}
</li>
))}
</ul>
),
},
]}
/>
<PaginatedSortableTable
initHeaders={tableHeaders}
items={programAreas}
itemType="Program areas"
/>
</div>
);
};
12 changes: 10 additions & 2 deletions containers/ecr-viewer/src/app/tests/ProgramAdminPage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { act, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { axe } from "jest-axe";
import { notFound } from "next/navigation";

Expand Down Expand Up @@ -76,14 +77,14 @@ describe("Program Admin Page", () => {
{
code: "456",
concept_name: "condition 1 (disease)",
condition_name: "condition",
condition_name: "condition 1",
condition_category: "category",
program_area_uuid: "789",
},
{
code: "789",
concept_name: "condition 2 (disease)",
condition_name: "condition",
condition_name: "condition 2",
condition_category: "category",
program_area_uuid: "789",
},
Expand All @@ -97,6 +98,13 @@ describe("Program Admin Page", () => {
screen.queryByText("No program areas added"),
).not.toBeInTheDocument();
expect(container).toMatchSnapshot();

const user = userEvent.setup();
await user.click(
screen.getByRole("button", { name: "Program Area Three" }),
);
expect(screen.getByText("Program area information")).toBeInTheDocument();
expect(screen.getByText("condition 1")).toBeInTheDocument();
});

describe("Creating programs", () => {
Expand Down
Loading