-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from OpenCatalogi/feature/OP-115/ratings-table
UPDATE rating component to table
- Loading branch information
Showing
4 changed files
with
65 additions
and
55 deletions.
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
13 changes: 8 additions & 5 deletions
13
pwa/src/templates/templateParts/ratingOverview/RatingOverview.module.css
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
.popupDescription { | ||
max-height: 500px; | ||
overflow: auto; | ||
.container { | ||
display: block; | ||
max-height: 60vh; | ||
overflow-y: scroll; | ||
} | ||
|
||
ul { | ||
list-style-type: none; | ||
.header { | ||
top: 0; | ||
position: sticky; | ||
background-color: var(--web-app-color-grey) !important; | ||
} |
88 changes: 48 additions & 40 deletions
88
pwa/src/templates/templateParts/ratingOverview/RatingOverview.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 |
---|---|---|
@@ -1,51 +1,59 @@ | ||
import * as React from "react"; | ||
import * as styles from "./RatingOverview.module.css"; | ||
import { QueryObserverSuccessResult } from "react-query"; | ||
import { t } from "i18next"; | ||
import { UnorderedList } from "@utrecht/component-library-react/dist/css-module"; | ||
import { | ||
StatusBadge, | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHeader, | ||
TableHeaderCell, | ||
TableRow, | ||
} from "@utrecht/component-library-react"; | ||
|
||
interface RatingOverviewProps { | ||
getComponent: QueryObserverSuccessResult<any, Error>; | ||
rating: any; | ||
} | ||
|
||
export const RatingOverview: React.FC<RatingOverviewProps> = ({ getComponent }) => { | ||
return ( | ||
<> | ||
{getComponent.data.embedded?.rating?.rating && ( | ||
<span>{`${getComponent.data.embedded?.rating?.rating}/${getComponent.data.embedded?.rating?.maxRating}`}</span> | ||
)} | ||
{!getComponent.data.embedded?.rating?.rating && <span>{t("No rating available")}</span>} | ||
export const RatingOverview: React.FC<RatingOverviewProps> = ({ rating }) => { | ||
const [acceptedRatings, setAcceptedRatings] = React.useState<string[]>([]); | ||
const [rejectedRatings, setRejectedRatings] = React.useState<string[]>([]); | ||
|
||
React.useEffect(() => { | ||
setAcceptedRatings(rating.results.filter((rating: string) => !rating.includes("Cannot rate the"))); | ||
setRejectedRatings(rating.results.filter((rating: string) => rating.includes("Cannot rate the"))); | ||
}, [rating]); | ||
|
||
<div className={styles.popupDescription}> | ||
<UnorderedList> | ||
{getComponent.data.embedded?.rating?.rating >= 1 && ( | ||
<> | ||
<li>Behaalde punten</li> | ||
return ( | ||
<Table className={styles.container}> | ||
<TableHeader className={styles.header}> | ||
<TableRow> | ||
<TableHeaderCell>Status</TableHeaderCell> | ||
<TableHeaderCell>Message</TableHeaderCell> | ||
<TableHeaderCell>Points</TableHeaderCell> | ||
</TableRow> | ||
</TableHeader> | ||
|
||
{getComponent.data.embedded?.rating?.results | ||
.filter((result: string) => !/^Cannot rate the/.test(result)) | ||
.map((result: string) => ( | ||
<ul> | ||
<li>{result}</li> | ||
</ul> | ||
))} | ||
</> | ||
)} | ||
{getComponent.data.embedded?.rating?.rating !== getComponent.data.embedded?.rating?.maxRating && ( | ||
<> | ||
<li>Onbehaalde punten</li> | ||
<TableBody> | ||
{acceptedRatings.map((acceptedRating, idx) => ( | ||
<TableRow key={idx}> | ||
<TableCell> | ||
<StatusBadge status="safe">Passed</StatusBadge> | ||
</TableCell> | ||
<TableCell>{acceptedRating}</TableCell> | ||
<TableCell>1</TableCell> | ||
</TableRow> | ||
))} | ||
|
||
{getComponent.data.embedded?.rating?.results | ||
.filter((result: string) => /^Cannot rate the/.test(result)) | ||
.map((result: string) => ( | ||
<ul> | ||
<li>{result}</li> | ||
</ul> | ||
))} | ||
</> | ||
)} | ||
</UnorderedList> | ||
</div> | ||
</> | ||
{rejectedRatings.map((rejectedRating, idx) => ( | ||
<TableRow key={idx}> | ||
<TableCell> | ||
<StatusBadge status="danger">Failed</StatusBadge> | ||
</TableCell> | ||
<TableCell>{rejectedRating}</TableCell> | ||
<TableCell>0</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); | ||
}; |