Skip to content

Commit

Permalink
Merge pull request #5 from cphelefu/fixing-more-lint-errors
Browse files Browse the repository at this point in the history
Fixing more lint errors
  • Loading branch information
cphelefu authored Sep 17, 2024
2 parents 58154cb + df7444e commit 931cb5f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 9 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="cgpv-main.js" ></script>
<script src="https://canadian-geospatial-platform.github.io/geoview/public/cgpv-main.js"></script>
<title>GeoView Demo Page</title>
</head>
<body>
Expand Down
10 changes: 9 additions & 1 deletion src/components/GeoViewMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import { useNavigate } from 'react-router-dom';
import { CodeSnippet } from './CodeSnippet';
import { EventsLog } from './EventsLog';
import { LegendLayerStatusTable } from './LegendLayerStatusTable';

interface GeoViewMapProps {
showConfigEditor?: boolean;
showEventsLog?: boolean;
showLegendLayerStatus?: boolean;
config: string | object;
configIsFilePath?: boolean;
codeSnippet?: string;
children?: React.ReactNode;
top?: React.ReactNode;
bottom?: React.ReactNode;

}

function GeoViewMap(props: GeoViewMapProps) {
Expand All @@ -35,6 +36,7 @@ function GeoViewMap(props: GeoViewMapProps) {
const {
showConfigEditor = true,
showEventsLog = true,
showLegendLayerStatus = true,
config = DEFAULT_CONFIG,
configIsFilePath,
codeSnippet,
Expand Down Expand Up @@ -86,6 +88,7 @@ function GeoViewMap(props: GeoViewMapProps) {
{showConfigEditor && <Tab label="Config Editor" value="config-editor" />}
{codeSnippet && <Tab label="Code Snippet" value="code-snippet" />}
{showEventsLog && <Tab label="Events Log" value="events-log" />}
{showLegendLayerStatus && <Tab label="Legend Layer Status" value="legend-layer-status" />}
</Tabs>
</Box>
<Box sx={{ display: selectedTab === 'map' ? 'unset' : 'none' }}>
Expand All @@ -104,6 +107,11 @@ function GeoViewMap(props: GeoViewMapProps) {
<EventsLog />
</Box>
}
{showLegendLayerStatus && <Box sx={{ marginTop: '20px', display: selectedTab === 'legend-layer-status' ? 'unset' : 'none' }}>
<LegendLayerStatusTable />
</Box>
}

</Box>
);
};
Expand Down
47 changes: 47 additions & 0 deletions src/components/LegendLayerStatusTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { useContext } from 'react';
import { CGPVContext } from '../providers/cgpvContextProvider/CGPVContextProvider';
import { Box, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';


export function LegendLayerStatusTable() {
const cgpvContext = useContext(CGPVContext);

if (!cgpvContext) {
throw new Error('CGPVContent must be used within a CGPVProvider');
}

const { legendLayerStatusList } = cgpvContext;


return (
<Box sx={{ p: 2 }}>
<h2>Legend Layer Status</h2>

<TableContainer component={Paper}>
<Table sx={{ minWidth: 550 }} aria-label="simple table">
<TableHead sx={{ fontWeight: 'bold' }}>
<TableRow>
<TableCell>Layer Name</TableCell>
<TableCell>Status</TableCell>
</TableRow>
</TableHead>
<TableBody>
{legendLayerStatusList.map((row, index) => (
<TableRow
key={`$layer_index_${index}`}
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
<TableCell component="th" scope="row">
{row.layerName}
</TableCell>
<TableCell>{row?.status}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Box>
);


};
4 changes: 2 additions & 2 deletions src/components/SplitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function SplitButton({ options, label, title, onClick }: SplitBut
}
};

const handleMenuItemClick = (event: React.MouseEvent<HTMLLIElement, MouseEvent>, index: number) => {
const handleMenuItemClick = (index: number) => {
setSelectedIndex(index);
setOpen(false);
};
Expand Down Expand Up @@ -84,7 +84,7 @@ export default function SplitButton({ options, label, title, onClick }: SplitBut
<ClickAwayListener onClickAway={handleClose}>
<MenuList id="split-button-menu" autoFocusItem>
{options.map((option, index) => (
<MenuItem key={option} selected={index === selectedIndex} onClick={(event) => handleMenuItemClick(event, index)}>
<MenuItem key={option} selected={index === selectedIndex} onClick={() => handleMenuItemClick(index)}>
{option}
</MenuItem>
))}
Expand Down
22 changes: 19 additions & 3 deletions src/providers/cgpvContextProvider/cgpvHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DEFAULT_MAP_WIDTH,
} from '../../constants';
import _ from 'lodash';
import { EventListItemType } from '../../types';
import { EventListItemType, LegendLayerStatus } from '@/types';

export interface ICgpvHook {
mapId: string;
Expand All @@ -20,6 +20,7 @@ export interface ICgpvHook {
mapHeight: number;
setMapHeight: React.Dispatch<React.SetStateAction<number>>;
eventsList: EventListItemType[];
legendLayerStatusList: LegendLayerStatus[];

initializeMap: (mapId: string, config: string | object, configIsFilePath?: boolean) => void;
handleRemoveMap: () => string;
Expand All @@ -42,6 +43,7 @@ export function useCgpvHook(): ICgpvHook {
const [isInitialized, setIsInitialized] = useState<boolean>(false);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [eventsList, setEventsList] = useState<EventListItemType[]>([]);
const [legendLayerStatusList, setLegendLayerStatusList] = useState<LegendLayerStatus[]>([]);


const addEventToList = (eventName: string, description: string) => {
Expand All @@ -50,8 +52,19 @@ export function useCgpvHook(): ICgpvHook {
});
};

const registerEventListeners = () => {
const registerEventListeners = (mapId: string) => {
// Events=====================================================================================================================
console.log('registering events');

cgpv.api.maps[mapId].layer.legendsLayerSet.onLayerSetUpdated((sender: any, payload: any) => {
const { resultSet } = payload;
const resultArr: LegendLayerStatus[] = Object.keys(resultSet).map((key) => {
return { layerName: resultSet[key]?.layerName, status: resultSet[key]?.layerStatus };
});
console.log('resultArr', resultArr);
setLegendLayerStatusList(resultArr);
});

// listen to layer added event
cgpv.api.maps[mapId].layer.onLayerAdded((sender: any, payload: any) => {
addEventToList('onLayerAdded', `layer ${payload.layerPath} added`);
Expand Down Expand Up @@ -168,7 +181,7 @@ export function useCgpvHook(): ICgpvHook {
handleCreateMap(mapId, configJson);
cgpv.init(() => {
// write some code ...
registerEventListeners();
registerEventListeners(mapId);
setIsLoading(false);
});
}
Expand Down Expand Up @@ -209,6 +222,8 @@ export function useCgpvHook(): ICgpvHook {
cgpv.api.createMapFromConfig(theMapId, JSON.stringify(data));
cgpv.init(() => {
// write some code ...
console.log('map created----------------------------------------');
registerEventListeners(theMapId);
});
setConfigJson({ ...data });
setMapId(theMapId);
Expand Down Expand Up @@ -304,6 +319,7 @@ export function useCgpvHook(): ICgpvHook {
isLoading,
applyWidthHeight,
eventsList,
legendLayerStatusList,

initializeMap,
handleRemoveMap,
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ export type EventListItemType = {
eventName: string;
description: string;
status?: string;
}


export type LegendLayerStatus = {
layerName: string;
status: string;
}
6 changes: 3 additions & 3 deletions tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2020",
"target": "ES2021",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"lib": ["ES2021", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,

Expand All @@ -17,7 +17,7 @@
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": true,

"paths": {
Expand Down

0 comments on commit 931cb5f

Please sign in to comment.