Skip to content

Commit

Permalink
🐛 Implement assessment settings columns
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Sep 22, 2023
1 parent 1573d37 commit d567a24
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
10 changes: 6 additions & 4 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ export interface Questionnaire {
revision: number;
questions: number;
rating: string;
dateImported: string;
createTime: string;
required: boolean;
system: boolean;
sections: Section[];
Expand Down Expand Up @@ -687,10 +687,12 @@ export interface Answer {
selected?: boolean;
}
export interface Thresholds {
red: number;
unknown: number;
yellow: number;
red?: number;
unknown?: number;
yellow?: number;
green?: number;
}

export type AssessmentStatus = "empty" | "started" | "complete";
export type Risk = "green" | "yellow" | "red" | "unknown";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EmptyState,
EmptyStateBody,
EmptyStateIcon,
List,
ListItem,
MenuToggle,
MenuToggleElement,
Modal,
Expand Down Expand Up @@ -46,12 +48,16 @@ import { ConditionalTooltip } from "@app/components/ConditionalTooltip";
import { useLocalTableControls } from "@app/hooks/table-controls";
import { NotificationsContext } from "@app/components/NotificationsContext";
import { formatPath, getAxiosErrorMessage } from "@app/utils/utils";
import { Questionnaire } from "@app/api/models";
import { Questionnaire, Thresholds } from "@app/api/models";
import { useHistory } from "react-router-dom";
import { Paths } from "@app/Paths";
import { ImportQuestionnaireForm } from "@app/pages/assessment-management/import-questionnaire-form/import-questionnaire-form";
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog/ConfirmDeleteDialog";
import { ExportQuestionnaireDropdownItem } from "./ExportQuestionnaireDropdownItem";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";

dayjs.extend(utc);

const AssessmentSettings: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -108,7 +114,7 @@ const AssessmentSettings: React.FC = () => {
name: "Name",
questions: "Questions",
rating: "Rating",
dateImported: "Date imported",
createTime: "Date imported",
},
isSelectable: false,
expandableVariant: null,
Expand All @@ -127,10 +133,10 @@ const AssessmentSettings: React.FC = () => {
},
},
],
sortableColumns: ["name", "dateImported"],
sortableColumns: ["name", "createTime"],
getSortValues: (questionnaire) => ({
name: questionnaire.name || "",
dateImported: questionnaire.dateImported || "",
createTime: questionnaire.createTime || "",
}),
initialSort: { columnKey: "name", direction: "asc" },
hasPagination: true,
Expand All @@ -153,6 +159,29 @@ const AssessmentSettings: React.FC = () => {
// TODO: Check RBAC access
const rbacWriteAccess = true; // checkAccess(userScopes, questionnaireWriteScopes);

const calculateTotalQuestions = (obj: Questionnaire) => {
const totalQuestions = (obj.sections || []).reduce((total, section) => {
return total + (section.questions ? section.questions.length : 0);
}, 0);

return totalQuestions.toString();
};

const thresholdsToListItems = (thresholds: Thresholds) => {
const thresholdKeys: (keyof Thresholds)[] = Object.keys(
thresholds
) as (keyof Thresholds)[];

return thresholdKeys.map((color) => {
const percentage: number = thresholds[color] || 0;
return (
<ListItem key={color}>
{color} {percentage}%
</ListItem>
);
});
};

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down Expand Up @@ -225,7 +254,7 @@ const AssessmentSettings: React.FC = () => {
<Th {...getThProps({ columnKey: "name" })} />
<Th {...getThProps({ columnKey: "questions" })} />
<Th {...getThProps({ columnKey: "rating" })} />
<Th {...getThProps({ columnKey: "dateImported" })} />
<Th {...getThProps({ columnKey: "createTime" })} />
</TableHeaderContentWithControls>
</Tr>
</Thead>
Expand All @@ -247,6 +276,12 @@ const AssessmentSettings: React.FC = () => {
numRenderedColumns={numRenderedColumns}
>
{currentPageItems?.map((questionnaire, rowIndex) => {
console.log(questionnaire);

const formattedDate = dayjs(questionnaire.createTime)
.utc()
.format("YYYY-MM-DD HH:mm:ss");

return (
<Tbody key={questionnaire.id}>
<Tr>
Expand Down Expand Up @@ -283,19 +318,21 @@ const AssessmentSettings: React.FC = () => {
width={10}
{...getTdProps({ columnKey: "questions" })}
>
{questionnaire.questions}
{calculateTotalQuestions(questionnaire)}
</Td>
<Td
width={15}
{...getTdProps({ columnKey: "rating" })}
>
{questionnaire.rating}
<List isPlain>
{thresholdsToListItems(questionnaire.thresholds)}
</List>
</Td>
<Td
width={25}
{...getTdProps({ columnKey: "dateImported" })}
{...getTdProps({ columnKey: "createTime" })}
>
{questionnaire.dateImported}
{formattedDate}
</Td>
<Td width={10}>
<Dropdown
Expand Down
6 changes: 3 additions & 3 deletions client/src/mocks/stub-new-work/questionnaireData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const questionnaireData: Record<number, Questionnaire> = {
revision: 1,
questions: 42,
rating: "5% Red, 25% Yellow",
dateImported: "8 Aug. 2023, 10:20 AM EST",
createTime: "8 Aug. 2023, 10:20 AM EST",
required: false,
system: true,
sections: [
Expand Down Expand Up @@ -189,7 +189,7 @@ const questionnaireData: Record<number, Questionnaire> = {
revision: 1,
questions: 24,
rating: "15% Red, 35% Yellow",
dateImported: "9 Aug. 2023, 03:32 PM EST",
createTime: "9 Aug. 2023, 03:32 PM EST",
required: true,
system: false,
sections: [
Expand Down Expand Up @@ -369,7 +369,7 @@ const questionnaireData: Record<number, Questionnaire> = {
revision: 1,
questions: 34,
rating: "7% Red, 25% Yellow",
dateImported: "10 Aug. 2023, 11:23 PM EST",
createTime: "10 Aug. 2023, 11:23 PM EST",
required: true,
system: false,
sections: [
Expand Down

0 comments on commit d567a24

Please sign in to comment.