Skip to content

Commit

Permalink
Merge pull request #388 from OpenCatalogi/feature/OP-115/ratings-table
Browse files Browse the repository at this point in the history
UPDATE rating component to table
  • Loading branch information
lencodes authored Nov 7, 2023
2 parents 46a759c + 0d65482 commit e7a886a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,10 @@
.popup {
position: fixed;
max-width: var(--web-app-download-popup-width);
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 700;
outline: 0;
top: 50px;
left: 25%;
}

.organizations {
Expand Down
14 changes: 7 additions & 7 deletions pwa/src/templates/componentDetail/ComponentsDetailTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const ComponentsDetailTemplate: React.FC<ComponentsDetailTemplateProps> =
const _useComponent = useComponent(queryClient);
const _getComponent = _useComponent.getOne(componentId);

const rating = _getComponent.data?.embedded?.rating;

const layer: TCategories = t(_.upperFirst(_getComponent.data?.embedded?.nl?.embedded?.commonground.layerType));
const _categories =
layer &&
Expand Down Expand Up @@ -284,8 +286,8 @@ export const ComponentsDetailTemplate: React.FC<ComponentsDetailTemplateProps> =
<>
<RatingIndicatorTemplate
layoutClassName={styles.ratingIndicatorContainer}
maxRating={_getComponent.data.embedded?.rating?.maxRating}
rating={_getComponent.data.embedded?.rating?.rating}
maxRating={rating.maxRating}
rating={rating.rating}
/>
<span className={styles.link}>
<Link onClick={show}>
Expand All @@ -297,9 +299,7 @@ export const ComponentsDetailTemplate: React.FC<ComponentsDetailTemplateProps> =
</span>
</>
)}
{!_getComponent.data.embedded?.rating && (
<div className={styles.noRatingStyle}>{t("No rating available")}</div>
)}
{!rating && <div className={styles.noRatingStyle}>{t("No rating available")}</div>}
</>
}
layoutClassName={styles.infoCard}
Expand All @@ -308,8 +308,8 @@ export const ComponentsDetailTemplate: React.FC<ComponentsDetailTemplateProps> =
<div className={styles.overlay}>
<NotificationPopUp
{...{ hide, isVisible }}
title="Rating"
description={<RatingOverview getComponent={_getComponent} />}
title={`Rating (${rating?.rating}/${rating?.maxRating})`}
description={<RatingOverview {...{ rating }} />}
primaryButton={{
label: t("Score calculation"),
handleClick: () => {
Expand Down
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 pwa/src/templates/templateParts/ratingOverview/RatingOverview.tsx
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>
);
};

0 comments on commit e7a886a

Please sign in to comment.