-
Notifications
You must be signed in to change notification settings - Fork 43
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
✨ Dynamic assess button and view assessments page #1325
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
223 changes: 223 additions & 0 deletions
223
client/src/app/components/questionnaire-summary/questionnaire-summary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
import React, { useState, useMemo } from "react"; | ||
import { | ||
Tabs, | ||
Tab, | ||
SearchInput, | ||
Toolbar, | ||
ToolbarItem, | ||
ToolbarContent, | ||
TextContent, | ||
PageSection, | ||
PageSectionVariants, | ||
Breadcrumb, | ||
BreadcrumbItem, | ||
Button, | ||
Text, | ||
} from "@patternfly/react-core"; | ||
import AngleLeftIcon from "@patternfly/react-icons/dist/esm/icons/angle-left-icon"; | ||
import { Link } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Paths } from "@app/Paths"; | ||
import { ConditionalRender } from "@app/components/ConditionalRender"; | ||
import { AppPlaceholder } from "@app/components/AppPlaceholder"; | ||
import QuestionsTable from "@app/components/questions-table/questions-table"; | ||
import { Assessment, Questionnaire } from "@app/api/models"; | ||
import QuestionnaireSectionTabTitle from "./components/questionnaire-section-tab-title"; | ||
import { AxiosError } from "axios"; | ||
import { formatPath } from "@app/utils/utils"; | ||
|
||
export enum SummaryType { | ||
Assessment = "Assessment", | ||
Questionnaire = "Questionnaire", | ||
} | ||
|
||
interface QuestionnaireSummaryProps { | ||
isFetching: boolean; | ||
fetchError: AxiosError | null; | ||
summaryData: Assessment | Questionnaire | undefined; | ||
summaryType: SummaryType; | ||
} | ||
|
||
const QuestionnaireSummary: React.FC<QuestionnaireSummaryProps> = ({ | ||
summaryData, | ||
summaryType, | ||
isFetching, | ||
fetchError, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const [activeSectionIndex, setActiveSectionIndex] = useState<"all" | number>( | ||
"all" | ||
); | ||
|
||
const handleTabClick = ( | ||
_event: React.MouseEvent<any> | React.KeyboardEvent | MouseEvent, | ||
tabKey: string | number | ||
) => { | ||
setActiveSectionIndex(tabKey as "all" | number); | ||
}; | ||
|
||
const [searchValue, setSearchValue] = useState(""); | ||
|
||
const filteredSummaryData = useMemo<Assessment | Questionnaire | null>(() => { | ||
if (!summaryData) return null; | ||
|
||
return { | ||
...summaryData, | ||
sections: summaryData?.sections.map((section) => ({ | ||
...section, | ||
questions: section.questions.filter(({ text, explanation }) => | ||
[text, explanation].some( | ||
(text) => text?.toLowerCase().includes(searchValue.toLowerCase()) | ||
) | ||
), | ||
})), | ||
}; | ||
}, [summaryData, searchValue]); | ||
|
||
const allQuestions = | ||
summaryData?.sections.flatMap((section) => section.questions) || []; | ||
const allMatchingQuestions = | ||
filteredSummaryData?.sections.flatMap((section) => section.questions) || []; | ||
|
||
if (!summaryData) { | ||
return <div>No data available.</div>; | ||
} | ||
const BreadcrumbPath = | ||
summaryType === SummaryType.Assessment ? ( | ||
<Breadcrumb> | ||
<BreadcrumbItem> | ||
<Link | ||
to={formatPath(Paths.assessmentActions, { | ||
applicationId: (summaryData as Assessment)?.application?.id, | ||
})} | ||
> | ||
Assessment | ||
</Link> | ||
</BreadcrumbItem> | ||
<BreadcrumbItem to="#" isActive> | ||
{summaryData?.name} | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
) : ( | ||
<Breadcrumb> | ||
<BreadcrumbItem> | ||
<Link to={Paths.assessment}>Assessment</Link> | ||
</BreadcrumbItem> | ||
<BreadcrumbItem to="#" isActive> | ||
{summaryData?.name} | ||
</BreadcrumbItem> | ||
</Breadcrumb> | ||
); | ||
return ( | ||
<> | ||
<PageSection variant={PageSectionVariants.light}> | ||
<TextContent> | ||
<Text component="h1">{summaryType}</Text> | ||
</TextContent> | ||
{BreadcrumbPath} | ||
</PageSection> | ||
<PageSection> | ||
<ConditionalRender when={isFetching} then={<AppPlaceholder />}> | ||
<div | ||
style={{ | ||
backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", | ||
}} | ||
> | ||
<Toolbar> | ||
<ToolbarContent> | ||
<ToolbarItem widths={{ default: "300px" }}> | ||
<SearchInput | ||
placeholder="Search questions" | ||
value={searchValue} | ||
onChange={(_event, value) => setSearchValue(value)} | ||
onClear={() => setSearchValue("")} | ||
resultsCount={ | ||
(searchValue && allMatchingQuestions.length) || undefined | ||
} | ||
/> | ||
</ToolbarItem> | ||
</ToolbarContent> | ||
</Toolbar> | ||
|
||
<Link | ||
to={ | ||
summaryType === SummaryType.Assessment | ||
? formatPath(Paths.assessmentActions, { | ||
applicationId: (summaryData as Assessment)?.application | ||
?.id, | ||
}) | ||
: Paths.assessment | ||
} | ||
> | ||
<Button variant="link" icon={<AngleLeftIcon />}> | ||
Back to {summaryType.toLowerCase()} | ||
</Button> | ||
</Link> | ||
<div className="tabs-vertical-container"> | ||
<Tabs | ||
activeKey={activeSectionIndex} | ||
onSelect={handleTabClick} | ||
isVertical | ||
aria-label="Tabs for summaryData sections" | ||
role="region" | ||
> | ||
{[ | ||
<Tab | ||
key="all" | ||
eventKey="all" | ||
title={ | ||
<QuestionnaireSectionTabTitle | ||
isSearching={!!searchValue} | ||
sectionName="All questions" | ||
unfilteredQuestions={allQuestions} | ||
filteredQuestions={allMatchingQuestions} | ||
/> | ||
} | ||
> | ||
<QuestionsTable | ||
fetchError={fetchError} | ||
questions={allMatchingQuestions} | ||
isSearching={!!searchValue} | ||
data={summaryData} | ||
isAllQuestionsTab | ||
hideAnswerKey={summaryType === SummaryType.Assessment} | ||
/> | ||
</Tab>, | ||
...(summaryData?.sections.map((section, index) => { | ||
const filteredQuestions = | ||
filteredSummaryData?.sections[index]?.questions || []; | ||
return ( | ||
<Tab | ||
key={index} | ||
eventKey={index} | ||
title={ | ||
<QuestionnaireSectionTabTitle | ||
isSearching={!!searchValue} | ||
sectionName={section.name} | ||
unfilteredQuestions={section.questions} | ||
filteredQuestions={filteredQuestions} | ||
/> | ||
} | ||
> | ||
<QuestionsTable | ||
fetchError={fetchError} | ||
questions={filteredQuestions} | ||
isSearching={!!searchValue} | ||
data={summaryData} | ||
hideAnswerKey={summaryType === SummaryType.Assessment} | ||
/> | ||
</Tab> | ||
); | ||
}) || []), | ||
]} | ||
</Tabs> | ||
</div> | ||
</div> | ||
</ConditionalRender> | ||
</PageSection> | ||
</> | ||
); | ||
}; | ||
|
||
export default QuestionnaireSummary; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we might want to see if we can get rid of this inline style somehow