Skip to content
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

[TM-1535] loader count polygons #722

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface SitePolygonReviewAsideProps {
setPolygonFromMap?: any;
refresh?: () => void;
mapFunctions: any;
totalPolygons?: number;
}

const SitePolygonReviewAside = (props: SitePolygonReviewAsideProps) => (
Expand All @@ -18,6 +19,7 @@ const SitePolygonReviewAside = (props: SitePolygonReviewAsideProps) => (
setPolygonFromMap={props?.setPolygonFromMap}
refresh={props?.refresh}
mapFunctions={props?.mapFunctions}
totalPolygons={props?.totalPolygons}
/>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Box, LinearProgress } from "@mui/material";
import React, { useEffect, useRef, useState } from "react";
import { When } from "react-if";

import Button from "@/components/elements/Button/Button";
import Drawer from "@/components/elements/Drawer/Drawer";
Expand Down Expand Up @@ -40,6 +42,7 @@ export interface IPolygonProps {
setPolygonFromMap?: any;
refresh?: () => void;
mapFunctions: any;
totalPolygons?: number;
}

export const polygonData = [
Expand All @@ -62,13 +65,13 @@ const Polygons = (props: IPolygonProps) => {
const context = useSitePolygonData();
const contextMapArea = useMapAreaContext();
const reloadSiteData = context?.reloadSiteData;
const sitePolygonData = context?.sitePolygonData;
const { setIsUserDrawingEnabled, setSelectedPolygonsInCheckbox, selectedPolygonsInCheckbox } = contextMapArea;
const [openCollapseAll, setOpenCollapseAll] = useState(false);

useEffect(() => {
setPolygonMenu(props.menu);
}, [props.menu]);

useEffect(() => {
if (polygonFromMap?.isOpen) {
const newSelectedPolygon = polygonMenu.find(polygon => polygon.uuid === polygonFromMap.uuid);
Expand Down Expand Up @@ -200,6 +203,7 @@ const Polygons = (props: IPolygonProps) => {
setSelectedPolygonsInCheckbox(checkedUuids);
};

const polygonSitePolygonCount = sitePolygonData?.length ?? 0;
return (
<div>
<Drawer isOpen={isOpenPolygonDrawer} setIsOpen={setIsOpenPolygonDrawer} setPolygonFromMap={setPolygonFromMap}>
Expand Down Expand Up @@ -232,6 +236,21 @@ const Polygons = (props: IPolygonProps) => {
</Button>
</div>
</div>
<div className="mb-4 flex flex-col gap-1">
<When condition={props.totalPolygons ?? 0 > 0}>
<Text variant="text-14-semibold" className="text-darkCustom">
<span className="font-bold">{polygonSitePolygonCount}</span> of{" "}
<span className="font-bold">{props.totalPolygons}</span> polygons
</Text>
<Box sx={{ width: "100%" }}>
<LinearProgress
variant="determinate"
value={(polygonSitePolygonCount / (props.totalPolygons ?? 1)) * 100}
sx={{ borderRadius: 5 }}
/>
</Box>
</When>
</div>
<div ref={containerRef} className="flex max-h-[150vh] flex-col gap-2 overflow-auto">
{polygonMenu.map(item => (
<div key={item.id}>
Expand Down
13 changes: 11 additions & 2 deletions src/admin/components/ResourceTabs/PolygonReviewTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ const PolygonReviewAside: FC<{
setPolygonFromMap: any;
refresh?: () => void;
mapFunctions: any;
}> = ({ type, data, polygonFromMap, setPolygonFromMap, refresh, mapFunctions }) => {
totalPolygons?: number;
}> = ({ type, data, polygonFromMap, setPolygonFromMap, refresh, mapFunctions, totalPolygons }) => {
switch (type) {
case "sites":
return (
Expand All @@ -106,6 +107,7 @@ const PolygonReviewAside: FC<{
setPolygonFromMap={setPolygonFromMap}
mapFunctions={mapFunctions}
refresh={refresh}
totalPolygons={totalPolygons}
/>
);
default:
Expand Down Expand Up @@ -165,7 +167,13 @@ const PolygonReviewTab: FC<IProps> = props => {
storePolygon(geojson, record, refetch, setPolygonFromMap, refreshEntity);
};
const mapFunctions = useMap(onSave);
const { data: sitePolygonData, refetch, polygonCriteriaMap, loading } = useLoadCriteriaSite(record.uuid, "sites");
const {
data: sitePolygonData,
refetch,
polygonCriteriaMap,
loading,
total
} = useLoadCriteriaSite(record.uuid, "sites");

const { data: modelFilesData } = useGetV2MODELUUIDFiles<GetV2MODELUUIDFilesResponse>({
pathParams: { model: "sites", uuid: record.uuid }
Expand Down Expand Up @@ -759,6 +767,7 @@ const PolygonReviewTab: FC<IProps> = props => {
setPolygonFromMap={setPolygonFromMap}
mapFunctions={mapFunctions}
refresh={refetch}
totalPolygons={total}
/>
</Grid>
</Grid>
Expand Down
Loading