Skip to content

Commit

Permalink
Merge branch 'main' into mta-1903
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 15, 2023
2 parents d6cdf09 + 86ac8ac commit eee5e2e
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const QuestionsTable: React.FC<{
section: "Section",
},
isExpansionEnabled: true,
isPaginationEnabled: false,
expandableVariant: "single",
forceNumRenderedColumns: isAllQuestionsTab ? 3 : 2, // columns+1 for expand control
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const getLocalTableControlDerivedState = <
items: sortedItems,
});
return {
totalItemCount: items.length,
totalItemCount: filteredItems.length,
currentPageItems: isPaginationEnabled ? currentPageItems : sortedItems,
};
};
2 changes: 1 addition & 1 deletion client/src/app/hooks/table-controls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export type ITableControlDerivedState<TItem> = {
*/
currentPageItems: TItem[];
/**
* The total number of items in the entire un-filtered, un-paginated table (the size of the entire API collection being tabulated).
* The total number of items after filtering but before pagination.
*/
totalItemCount: number;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const ApplicationDetailDrawer: React.FC<
isCompact
columnModifier={{ default: "1Col" }}
horizontalTermWidthModifier={{
default: "14ch",
default: "15ch",
}}
>
<DescriptionListGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ApplicationReviewStatus: React.FC<
> = ({ application }) => {
const { t } = useTranslation();

const { archetypes, isFetching } = useFetchArchetypes();
const { archetypes, isFetching, error } = useFetchArchetypes();
const isAppReviewed = !!application.review;

const applicationArchetypes = application.archetypes?.map((archetypeRef) => {
Expand All @@ -27,6 +27,10 @@ export const ApplicationReviewStatus: React.FC<
applicationArchetypes?.filter((archetype) => !!archetype?.review).length ||
0;

if (error) {
return <EmptyTextMessage message={t("terms.notAvailable")} />;
}

if (isFetching) {
return <Spinner size="md" />;
}
Expand All @@ -43,9 +47,5 @@ export const ApplicationReviewStatus: React.FC<
statusPreset = "NotStarted";
}

if (!applicationArchetypes || applicationArchetypes.length === 0) {
return <EmptyTextMessage message={t("terms.notAvailable")} />;
}

return <IconedStatus preset={statusPreset} tooltipCount={tooltipCount} />;
};
88 changes: 62 additions & 26 deletions client/src/app/pages/archetypes/archetypes-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ import { SimplePagination } from "@app/components/SimplePagination";
import { TablePersistenceKeyPrefix } from "@app/Constants";
import { useDeleteAssessmentMutation } from "@app/queries/assessments";
import { useDeleteReviewMutation } from "@app/queries/reviews";
import {
assessmentWriteScopes,
reviewsWriteScopes,
archetypesWriteScopes,
} from "@app/rbac";
import { checkAccess } from "@app/utils/rbac-utils";
import keycloak from "@app/keycloak";

const Archetypes: React.FC = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -272,6 +279,12 @@ const Archetypes: React.FC = () => {
}
};

const token = keycloak.tokenParsed;
const userScopes: string[] = token?.scope.split(" ") || [],
archetypeWriteAccess = checkAccess(userScopes, archetypesWriteScopes),
assessmentWriteAccess = checkAccess(userScopes, assessmentWriteScopes),
reviewsWriteAccess = checkAccess(userScopes, reviewsWriteScopes);

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down Expand Up @@ -367,26 +380,44 @@ const Archetypes: React.FC = () => {
<Td isActionCell>
<ActionsColumn
items={[
{
title: t("actions.duplicate"),
onClick: () =>
setArchetypeToDuplicate(archetype),
},
{
title: t("actions.assess"),
onClick: () =>
assessSelectedArchetype(archetype),
},
{
title: t("actions.review"),
onClick: () =>
reviewSelectedArchetype(archetype),
},
{
title: t("actions.edit"),
onClick: () => setArchetypeToEdit(archetype),
},
...(archetype?.assessments?.length
...(archetypeWriteAccess
? [
{
title: t("actions.duplicate"),
onClick: () =>
setArchetypeToDuplicate(archetype),
},
]
: []),
...(assessmentWriteAccess
? [
{
title: t("actions.assess"),
onClick: () =>
assessSelectedArchetype(archetype),
},
]
: []),
...(reviewsWriteAccess
? [
{
title: t("actions.review"),
onClick: () =>
reviewSelectedArchetype(archetype),
},
]
: []),
...(archetypeWriteAccess
? [
{
title: t("actions.edit"),
onClick: () =>
setArchetypeToEdit(archetype),
},
]
: []),
...(archetype?.assessments?.length &&
assessmentWriteAccess
? [
{
title: t("actions.discardAssessment"),
Expand All @@ -395,7 +426,7 @@ const Archetypes: React.FC = () => {
},
]
: []),
...(archetype?.review
...(archetype?.review && reviewsWriteAccess
? [
{
title: t("actions.discardReview"),
Expand All @@ -405,11 +436,16 @@ const Archetypes: React.FC = () => {
]
: []),
{ isSeparator: true },
{
title: t("actions.delete"),
onClick: () => setArchetypeToDelete(archetype),
isDanger: true,
},
...(archetypeWriteAccess
? [
{
title: t("actions.delete"),
onClick: () =>
setArchetypeToDelete(archetype),
isDanger: true,
},
]
: []),
]}
/>
</Td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const ArchetypeDetailDrawer: React.FC<IArchetypeDetailDrawerProps> = ({
</Tab>
<Tab
eventKey={TabKey.Reviews}
title={<TabTitleText>{t("terms.review")}</TabTitleText>}
title={<TabTitleText>{t("terms.reviews")}</TabTitleText>}
>
<ReviewFields archetype={archetype} />
</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from "@tanstack/react-query";
import { TrashIcon } from "@patternfly/react-icons";
import useIsArchetype from "@app/hooks/useIsArchetype";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";

enum AssessmentAction {
Take = "Take",
Expand Down Expand Up @@ -189,6 +190,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
assessmentId: assessment.id,
applicationName: application?.name,
applicationId: application?.id,
archetypeName: archetype?.name,
archetypeId: archetype?.id,
}).then(() => {
createAssessment();
Expand Down Expand Up @@ -222,7 +224,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
{action}
</Button>
) : (
<Spinner role="status" size="md">
<Spinner role="status" size="md" className={spacing.mxLg}>
<span className="sr-only">Loading...</span>
</Spinner>
)}
Expand Down Expand Up @@ -262,6 +264,7 @@ const DynamicAssessmentActionsRow: FunctionComponent<
assessmentId: assessment.id,
applicationName: application?.name,
applicationId: application?.id,
archetypeName: archetype?.name,
archetypeId: archetype?.id,
});
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
assessmentId: assessment.id,
applicationName: assessment.application?.name,
applicationId: assessment.application?.id,
archetypeName: assessment.archetype?.name,
archetypeId: assessment.archetype?.id,
});
} else {
Expand All @@ -455,6 +456,7 @@ export const AssessmentWizard: React.FC<AssessmentWizardProps> = ({
assessmentId: assessment.id,
applicationName: assessment.application?.name,
applicationId: assessment.application?.id,
archetypeName: assessment.archetype?.name,
archetypeId: assessment.archetype?.id,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ const ViewArchetypesTable: React.FC<ViewArchetypesTableProps> = ({
const archivedQuestionnaires = questionnaires.filter(
(questionnaire) => !questionnaire.required
);

const nonRequiredQuestionnaireIds = questionnaires
.filter((q) => !q.required)
.map((q) => q.id);

const relevantAssessmentIds = (archetype?.assessments || []).map((a) => a.id);

const filteredArchivedAssessments = assessments.filter(
(assessment) =>
nonRequiredQuestionnaireIds.includes(assessment.questionnaire.id) &&
relevantAssessmentIds.includes(assessment.id)
);
const filteredArchivedQuestionnaires = archivedQuestionnaires.filter(
(questionnaire) =>
filteredArchivedAssessments.some(
(assessment) => assessment.questionnaire.id === questionnaire.id
)
);
return (
<>
<QuestionnairesTable
Expand All @@ -34,15 +52,16 @@ const ViewArchetypesTable: React.FC<ViewArchetypesTableProps> = ({
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Required questionnaires"
/>

<QuestionnairesTable
isReadonly
archetype={archetype}
questionnaires={archivedQuestionnaires}
assessments={assessments}
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Archived questionnaires"
/>
{filteredArchivedAssessments.length === 0 ? null : (
<QuestionnairesTable
archetype={archetype}
isReadonly
questionnaires={filteredArchivedQuestionnaires}
assessments={filteredArchivedAssessments}
isFetching={isFetchingQuestionnaires || isFetchingAssessmentsById}
tableName="Archived questionnaires"
/>
)}
</>
);
};
Expand Down
8 changes: 8 additions & 0 deletions client/src/app/pages/reports/components/donut/donut.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
StackItem,
Text,
TextContent,
TextVariants,
} from "@patternfly/react-core";

export interface IDonutProps {
Expand All @@ -31,6 +32,7 @@ export const Donut: React.FC<IDonutProps> = ({
riskLabel,
isAssessment,
riskTitle,
riskDescription,
}) => {
const { t } = useTranslation();

Expand Down Expand Up @@ -63,6 +65,12 @@ export const Donut: React.FC<IDonutProps> = ({
<StackItem style={{ width: "100%" }}>
<TextContent className="pf-v5-u-text-align-center">
<Text component="h3">{riskLabel}</Text>
<Text
component={TextVariants.small}
className="pf-v5-u-color-200 pf-v5-u-font-weight-light"
>
{riskDescription}
</Text>
</TextContent>
</StackItem>
</Stack>
Expand Down
6 changes: 4 additions & 2 deletions client/src/app/queries/assessments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const useUpdateAssessmentMutation = (
};

export const useDeleteAssessmentMutation = (
onSuccess?: (applicationName: string) => void,
onSuccess?: (name: string) => void,
onError?: (err: AxiosError) => void
) => {
const queryClient = useQueryClient();
Expand All @@ -117,6 +117,7 @@ export const useDeleteAssessmentMutation = (
assessmentId: number;
applicationName?: string;
applicationId?: number;
archetypeName?: string;
archetypeId?: number;
}) => {
const deletedAssessment = deleteAssessment(args.assessmentId);
Expand All @@ -138,7 +139,8 @@ export const useDeleteAssessmentMutation = (
return deletedAssessment;
},
onSuccess: (_, args) => {
onSuccess && onSuccess(args?.applicationName || "Unknown");
onSuccess &&
onSuccess(args?.applicationName || args?.archetypeName || "Unknown");
},
onError: onError,
});
Expand Down
6 changes: 6 additions & 0 deletions client/src/app/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export const applicationsWriteScopes = [
"applications:delete",
];

export const archetypesWriteScopes = [
"archetypes:put",
"archetypes:post",
"archetypes:delete",
];

export const analysisWriteScopes = [
"applications.analysis:put",
"applications.analysis:post",
Expand Down

0 comments on commit eee5e2e

Please sign in to comment.