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

WIP 2 #3

Open
wants to merge 164 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
1878774
active layers tab, draworder component
dennisbergstrom Dec 14, 2022
84d70fe
removed info icon from baselayers (active tab)
dennisbergstrom Dec 14, 2022
8bce472
layout changes and system layers fixes
dennisbergstrom Feb 8, 2023
80f8752
Merge branch 'develop' into feature/1237-update-active-tab
linusfj Feb 8, 2023
c9f125a
layerpackage view from quick access section in ls
dennisbergstrom Mar 15, 2023
34eda85
rewrite layers to use same component (LayerItem)
dennisbergstrom Apr 12, 2023
808a58d
support for quickaccess layers section
dennisbergstrom Apr 26, 2023
61eccd2
snackbar when loading package
dennisbergstrom Apr 26, 2023
4d653d9
Merge branch 'feature/1284-add-theme-management' into fix/1300-zoom-l…
linusfj May 8, 2023
2ff4d17
view for personal layerpackage handling
dennisbergstrom May 10, 2023
11d35a6
Fix sublayer visibility
linusfj May 10, 2023
5565441
Merge branch 'feature/1284-add-theme-management' into fix/1300-zoom-l…
linusfj May 10, 2023
86912e2
quickaccess gui changes, border and menu
dennisbergstrom May 23, 2023
b40d776
only visible sublayers in draworder list
dennisbergstrom May 23, 2023
c44df49
layerpackage text and border changes
dennisbergstrom May 24, 2023
be74a34
check that layerpackage layers exist before load
dennisbergstrom May 24, 2023
f92359b
config for lockedBackgroundInDraworder
dennisbergstrom May 24, 2023
f613734
added layeritemdetails view
dennisbergstrom Jun 1, 2023
f43bb02
Add custom SnackbarProvider and useSnackbar hook
linusfj Jun 8, 2023
84bdc0b
typo in Layerpackage window handling
dennisbergstrom Jun 8, 2023
3009b74
Merge branch 'feature/1284-add-theme-management' into feature/1296-se…
linusfj Jun 8, 2023
bbca267
Filterfunction in layerswitcher testversion
dennisbergstrom Jun 15, 2023
94da8b4
Add queue system to handle state updates
linusfj Jun 16, 2023
0827a5d
Implement useSnackbar hook and fix logic
linusfj Jun 16, 2023
9e9ee97
Improve layer interactivity and Snackbar handling
linusfj Jun 16, 2023
5e22c01
Integrate Snackbar clearing in MapCleaner
linusfj Jun 16, 2023
2eef590
Merge branch 'fix/1300-zoom-level-snackbar-display' into feature/1284…
linusfj Jun 16, 2023
716db7d
Add features for Quick Layers management in admin
linusfj Jul 21, 2023
32d258f
Add classes for Quick Layers structure
linusfj Jul 21, 2023
c85a412
Add option for Active Layers view
linusfj Aug 8, 2023
46070a5
Add settings for Quick Layers in admin
linusfj Aug 9, 2023
d2423e6
search in quickaccesslayers
dennisbergstrom Aug 29, 2023
4c172fd
quicklayer handling text chenges
dennisbergstrom Aug 31, 2023
7d5da82
Merge remote-tracking branch 'origin/feature/1237-update-active-tab' …
linusfj Sep 1, 2023
a819b1d
Merge branch 'feature/1284-add-theme-management' into feature/1380-qu…
linusfj Sep 1, 2023
f94527c
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Sep 1, 2023
c38e6a4
Merge remote-tracking branch 'origin/feature/1365-quick-layers-admin'…
linusfj Sep 1, 2023
6fb5394
added backgroundlayer to layerpackage & quickacces
dennisbergstrom Sep 1, 2023
ae19bee
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Sep 1, 2023
c940da0
legendImage as component
dennisbergstrom Sep 15, 2023
3f01435
legendimage pl
dennisbergstrom Sep 15, 2023
527fb6f
Add condition to show/hide system layer switch
linusfj Sep 20, 2023
a91776a
Remove unused option in admin
linusfj Sep 20, 2023
9409995
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Sep 20, 2023
5bdac0e
bold text for visible layers and groups
dennisbergstrom Sep 20, 2023
2ce31b6
fix for grouplayers in layerpackages
dennisbergstrom Sep 22, 2023
7c6a076
maintan scrollposition between views and tabs
dennisbergstrom Sep 22, 2023
e3a9615
layerpackage empty keyword fix
dennisbergstrom Sep 27, 2023
9e498a3
optimization of layerswitcher search
dennisbergstrom Oct 3, 2023
30bc582
changed quickaccesslayer infotext
dennisbergstrom Oct 10, 2023
dbd7b0a
lazyload legendimages
dennisbergstrom Oct 10, 2023
703584e
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Oct 11, 2023
c878153
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Oct 11, 2023
3a9ecac
GUI changes to quickaccess section
dennisbergstrom Oct 18, 2023
3333329
Merge remote-tracking branch 'origin/feature/1380-quick-layers-in-lay…
linusfj Oct 23, 2023
986411f
theme text and changes
dennisbergstrom Oct 23, 2023
9560016
snackbar for layeritemdetails
dennisbergstrom Oct 23, 2023
a718d81
Optimize layer toggling and code maintainability
linusfj Oct 24, 2023
08a7dfb
Position snackbar at bottom
linusfj Oct 25, 2023
2cd3e34
Remove unused variables
linusfj Oct 25, 2023
518b9ee
new gui for favorite functionality
dennisbergstrom Oct 31, 2023
5e86755
favoriteview cookie handling
dennisbergstrom Nov 1, 2023
e7dba5a
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Nov 2, 2023
16813a3
Merge remote-tracking branch 'origin/fix/1300-zoom-level-snackbar-dis…
linusfj Nov 3, 2023
0b1200c
Add condition for when to display snackbar
linusfj Nov 3, 2023
1cad7b5
Add admin setting for snackbar display conditions
linusfj Nov 3, 2023
f364cc0
Add new operation in snackbar logic
linusfj Nov 3, 2023
5ddf9d6
Merge remote-tracking branch 'origin/fix/1300-zoom-level-snackbar-dis…
linusfj Nov 3, 2023
717fd18
layerswitcher item alignments
dennisbergstrom Nov 8, 2023
675bf2a
lockedBaseLayer in draworder properly locked
dennisbergstrom Nov 8, 2023
3dfa446
snackbar position
dennisbergstrom Nov 9, 2023
d7ffc12
sort favorites and snackbar on remove
dennisbergstrom Nov 9, 2023
1afe223
fix for empty keywords array
dennisbergstrom Nov 10, 2023
8e44296
no quickaccesslayers dialog
dennisbergstrom Nov 10, 2023
189b88a
expand quickaccess on add
dennisbergstrom Nov 10, 2023
1e1276e
adapt to settings from admin
dennisbergstrom Nov 10, 2023
73c65f0
Add admin settings and update parameter names
linusfj Nov 13, 2023
f6da71f
Merge branch 'feature/1365-quick-layers-admin' into feature/1380-quic…
linusfj Nov 13, 2023
5faf2d7
Merge remote-tracking branch 'origin/feature/1296-search-in-layerswit…
linusfj Nov 13, 2023
8fe2a0e
Improve Quick Layer management and UI in admin
linusfj Nov 15, 2023
b05f919
Merge branch 'feature/1365-quick-layers-admin' into feature/1380-quic…
linusfj Nov 15, 2023
7146abf
cql-filter fix
dennisbergstrom Nov 15, 2023
202223b
Merge branch 'feature/1296-search-in-layerswitcher' of https://github…
dennisbergstrom Nov 15, 2023
e851d28
download link fix
dennisbergstrom Nov 15, 2023
9df44a1
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Nov 16, 2023
072ea82
VectorFilter as functional component
dennisbergstrom Nov 16, 2023
c247c40
Restore setting in admin
linusfj Nov 16, 2023
0a64439
Merge branch 'feature/1365-quick-layers-admin' into feature/1380-quic…
linusfj Nov 16, 2023
617dcf3
showattributetable fix
dennisbergstrom Nov 17, 2023
2cb7993
Add default values for informational text
linusfj Nov 17, 2023
21e5784
Update tooltip text
linusfj Nov 17, 2023
d06d087
Add CQL filter option in admin
linusfj Nov 21, 2023
0504dea
expand quickaccess on load
dennisbergstrom Nov 21, 2023
bdeba7e
save favorite text changes
dennisbergstrom Nov 21, 2023
42de31c
debounce filter and dark mode adjustments
dennisbergstrom Nov 22, 2023
b4864a3
Add missing setting to parseSettings
linusfj Nov 22, 2023
4f99815
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Nov 22, 2023
1e45814
Remove parameter from layers config
linusfj Nov 23, 2023
b68d812
Merge branch 'feature/1365-quick-layers-admin' into feature/1380-quic…
linusfj Nov 23, 2023
a16370e
Merge branch 'feature/1284-add-theme-management' into feature/1380-qu…
linusfj Nov 24, 2023
c322162
Merge branch 'develop' into feature/1380-quick-layers-in-layerswitcher
linusfj Nov 24, 2023
1154c2b
search placeholder and input reset
dennisbergstrom Nov 29, 2023
b029254
performance enhancement for group toggle
dennisbergstrom Nov 30, 2023
00d9dcb
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Nov 30, 2023
b478432
truncate sublayeritem label
dennisbergstrom Nov 30, 2023
92d47b4
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Nov 30, 2023
98b51dd
changed icon for vectorfilter chip
dennisbergstrom Nov 30, 2023
b7dd726
quickaccess layer togglebutton update
dennisbergstrom Dec 5, 2023
49abd4b
filter quickaccess layers fix
dennisbergstrom Dec 5, 2023
36db247
Merge branch 'feature/1296-search-in-layerswitcher' into feature/1380…
linusfj Dec 6, 2023
9cae569
Update package.json dependencies
linusfj Dec 15, 2023
06dc0ec
Add showFilter parameter to admin settings
linusfj Jan 10, 2024
b2de348
Change LayerGroup from PureComponent to Component
linusfj Jan 10, 2024
ecd64cc
Resolve ESLint errors and implement useCallback
linusfj Jan 16, 2024
6326a5f
Add default values to simpleMapConfig.json
linusfj Jan 16, 2024
dc2d20b
Remove configuration files containing custom data
linusfj Jan 19, 2024
a550f07
Update default settings in map_1.json
linusfj Jan 19, 2024
71f12bf
Add group expansion and layer filter
linusfj Jan 23, 2024
cad705f
Enable detail view for system layers
linusfj Jan 23, 2024
64fda7e
Merge remote-tracking branch 'origin/develop' into feature/1380-quick…
linusfj Jan 25, 2024
a06c26f
Change to PureComponent and fix clearing filter
linusfj Feb 1, 2024
0fb1686
Add 'information' as supported tool
linusfj Feb 6, 2024
25ff4ac
Revert "Add 'information' as supported tool"
linusfj Feb 6, 2024
4dab50a
Fix visibility of last item in background layers
linusfj Feb 6, 2024
c346e7e
Keep system layers after reset in LayerPackage
linusfj Feb 7, 2024
6729b09
Add option to expand filtered results
linusfj Feb 9, 2024
2455ebd
Refactor useEffect hooks for performance
linusfj Feb 20, 2024
42f4189
Enhance layer filtering in LayerSwitcherView
linusfj Feb 20, 2024
1bb2feb
Resolve ESLint errors
linusfj Feb 20, 2024
87029fa
Remove margin to align layer items in Quick Access
linusfj Feb 22, 2024
42aa21b
Remove default 'Title' text from component
linusfj Feb 28, 2024
89a30e3
Keep system layers after reset in Favorites
linusfj Feb 29, 2024
8ffb3a9
Merge branch 'develop' into temp/test-merge-1380-develop
karljakoblarsson Nov 11, 2024
dcf784b
fix: remaining merge issues
karljakoblarsson Nov 11, 2024
6b121e0
chore: remove unsed packages added in merge
karljakoblarsson Nov 11, 2024
6302fca
fix: remove backendfiles wrongly added in merge
karljakoblarsson Nov 11, 2024
a215799
fix: remove admin changes from layerswitcher
karljakoblarsson Nov 13, 2024
a82e8d9
chore: remove un-related changes from layerswitcher
karljakoblarsson Nov 13, 2024
31d283c
fix: remove erronous changes to wmsLayer
karljakoblarsson Nov 13, 2024
216c2ec
refactor: break out BreadCrumbsContainer component
karljakoblarsson Nov 13, 2024
b842c7b
fix: add warning & fallback for maplayer not found
karljakoblarsson Nov 13, 2024
f172ccb
fix: unmount collapsible list when closed
karljakoblarsson Nov 13, 2024
71a0fd7
fix: make Layer details take up vertical space
karljakoblarsson Nov 18, 2024
3786c78
fix: correct title for QuickAccess
karljakoblarsson Nov 18, 2024
35f0b8b
chore: remove unecessary margins
karljakoblarsson Nov 18, 2024
ab2ba03
fix: show/hide sublayers which are collapsed
karljakoblarsson Nov 20, 2024
ba7eb86
fix: scrolling when LayerSwitcher `height=dynamic`
karljakoblarsson Nov 20, 2024
edcf639
refactor: move LayerListFilter to own component
karljakoblarsson Nov 20, 2024
76baa38
fix: remove filter input ref in LayerSwitcherView
karljakoblarsson Nov 20, 2024
b90f7dc
fix: remove extra box in LayerListFilter
karljakoblarsson Nov 20, 2024
36890b4
refactor: move QuickAccess to own component
karljakoblarsson Nov 20, 2024
6250d3a
refactor: move confirm.dialog to QuickAccessView
karljakoblarsson Nov 20, 2024
8355917
chore: remove unnecessary icon
karljakoblarsson Nov 20, 2024
ceb09b2
refactor: move quickAccess open state to component
karljakoblarsson Nov 20, 2024
5c9f985
refactor: clean up JSX in LayerSwitcherView
karljakoblarsson Nov 20, 2024
d2240cf
refactor: remove GroupLayerAccord from QuickAccess
karljakoblarsson Nov 20, 2024
55a39c1
refactor: remove `LayerSwitcherModel`
karljakoblarsson Nov 20, 2024
fdd30c4
fix: remove unused activeLayersCount
karljakoblarsson Nov 21, 2024
adbfa9f
feat: better text when no LayerPackages exist
karljakoblarsson Nov 21, 2024
fba0fc6
fix: MUI anchorEL warning for LayerPackage tooltip
karljakoblarsson Nov 21, 2024
ea713d6
fix: same font-size as layerswitcher in develop
karljakoblarsson Nov 21, 2024
f35d170
fix: pass the correct localObserver
karljakoblarsson Nov 21, 2024
7d6ddb0
refactor: rename observer to localObserver
karljakoblarsson Nov 21, 2024
10e01ea
fix: byg where quick access layers were not toggle
karljakoblarsson Nov 21, 2024
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
29 changes: 25 additions & 4 deletions apps/client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@
"react-number-format": "^5.3.3",
"react-rnd": "^10.4.1",
"react-scroll": "^1.9.0",
"react-smooth-dnd": "^0.11.1",
"rehype-raw": "^7.0.0",
"remark-gfm": "^4.0.0",
"uuid": "^9.0.1",
"x2js": "^3.4.4",
"xlsx": "^0.18.5"
}
}
}
4 changes: 4 additions & 0 deletions apps/client/public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ body {
min-width: 280px !important;
}

/* Z-index override for draggable listitem in layerswitcher */
.smooth-dnd-ghost.vertical.smooth-dnd-draggable-wrapper {
z-index: 99999 !important;
}
.material-icons {
font-family: "Material Icons";
font-weight: normal;
Expand Down
14 changes: 13 additions & 1 deletion apps/client/src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PLUGINS_TO_IGNORE_IN_HASH_APP_STATE } from "constants";

import PropTypes from "prop-types";
import { styled } from "@mui/material/styles";
import { SnackbarProvider } from "notistack";
import Observer from "react-event-observer";
import { isMobile } from "../utils/IsMobile";
import { getMergedSearchAndHashParams } from "../utils/getMergedSearchAndHashParams";
Expand All @@ -24,6 +23,7 @@ import Alert from "./Alert";
import PluginWindows from "./PluginWindows";
import SimpleDialog from "./SimpleDialog";
import MapClickViewer from "./MapClickViewer/MapClickViewer";
import SnackbarProvider from "./SnackbarProvider";

import Search from "./Search/Search.js";

Expand Down Expand Up @@ -806,6 +806,18 @@ class App extends React.PureComponent {
// to anyone wanting to act on layer visibility change.
this.globalObserver.publish("core.layerVisibilityChanged", e);
});
// Listener for "quickAccess" changes
layer.on("change:quickAccess", (e) => {
// Send an event on the global observer
// to anyone wanting to act on layer quickAccess change.
this.globalObserver.publish("core.layerQuickAccessChanged", e);
});
// Listener for "subLayers" changes
layer.on("change:subLayers", (e) => {
// Send an event on the global observer
// to anyone wanting to act on layer subLayers change.
this.globalObserver.publish("core.layerSubLayersChanged", e);
});
});
}

Expand Down
19 changes: 17 additions & 2 deletions apps/client/src/components/ConfirmationDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@ const ConfirmationDialog = ({
<Typography>{contentDescription}</Typography>
</DialogContent>
<DialogActions>
<Button onClick={handleConfirm}>{confirm}</Button>
<Button onClick={handleAbort} variant="contained">
<Button
onClick={(e) => {
e.stopPropagation();
handleAbort();
}}
>
{cancel}
</Button>
{confirm && (
<Button
onClick={(e) => {
e.stopPropagation();
handleConfirm();
}}
variant="contained"
>
{confirm}
</Button>
)}
</DialogActions>
</Dialog>,
document.getElementById("map")
Expand Down
49 changes: 49 additions & 0 deletions apps/client/src/components/SnackbarProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React, { createContext, useState } from "react";
import {
SnackbarProvider as NotistackSnackbarProvider,
useSnackbar,
} from "notistack";

// Create a context for sharing state across components.
// This context will hold message items and functions to control the snackbar.
export const SnackbarContext = createContext();

// SnackbarProvider is a custom component that sets up the SnackbarContext provider.
// It uses the useSnackbar hook to provide snackbar controls to its child components.
const SnackbarProvider = ({
// Destructure and set defaults for maxSnack and anchorOrigin props.
// maxSnack is the maximum number of snackbar notifications that can be displayed at once.
// anchorOrigin defines the position of the snackbar on the screen.
children,
maxSnack = 3,
anchorOrigin = { vertical: "bottom", horizontal: "left" },
...props
}) => {
// Initialize the shared state (messageItems) and its updater (setMessageItems)
// messageItems holds a list of messages to be displayed in the snackbar.
const [messageItems, setMessageItems] = useState([]);

// Get the snackbar object containing functions control the snackbar's visibility and its messages.
const snackbar = useSnackbar();

// Render the NotistackSnackbarProvider and provide the shared state and functions through the SnackbarContext.
// This allows any child component to access the snackbar controls and the shared state.
return (
<NotistackSnackbarProvider
maxSnack={maxSnack}
anchorOrigin={anchorOrigin}
preventDuplicate
{...props}
>
{/* Pass shared state and functions to the SnackbarContext.Provider value. */}
{/* This allows child components to access the snackbar controls and the shared state. */}
<SnackbarContext.Provider
value={{ ...snackbar, messageItems, setMessageItems }}
>
{children}
</SnackbarContext.Provider>
</NotistackSnackbarProvider>
);
};

export default SnackbarProvider;
11 changes: 11 additions & 0 deletions apps/client/src/controls/MapCleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import { styled } from "@mui/material/styles";
import HajkToolTip from "components/HajkToolTip";

import useSnackbar from "../hooks/useSnackbar";

const StyledPaper = styled(Paper)(({ theme }) => ({
marginBottom: theme.spacing(1),
}));
Expand All @@ -20,6 +22,10 @@ const StyledIconButton = styled(IconButton)(({ theme }) => ({
* @returns {object} React
*/
const MapCleaner = React.memo((props) => {
// Import the clearAllMessages function from the useSnackbar hook.
// This allows us to clear the Snackbar's state when the button is clicked.
const { clearSnackbar } = useSnackbar();

return (
props.appModel.config.mapConfig.map.mapcleaner && (
<HajkToolTip title="Dölj alla aktiva lager">
Expand All @@ -28,6 +34,11 @@ const MapCleaner = React.memo((props) => {
aria-label="Rensa kartan"
onClick={(e) => {
props.appModel.clear();

// Call the clearAllMessages function from the useCustomSnackbar hook.
// This clears the state of messageItems in the Snackbar,
// ensuring it stays in sync with the actual visibility of the layers.
clearSnackbar();
}}
>
<VisibilityOffIcon />
Expand Down
139 changes: 139 additions & 0 deletions apps/client/src/hooks/useSnackbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { useContext, useEffect, useState, useRef, useCallback } from "react";
import { useSnackbar as useNotistackSnackbar } from "notistack";
import { IconButton } from "@mui/material";
import { Close as CloseIcon } from "@mui/icons-material";
import { SnackbarContext } from "../components/SnackbarProvider";

// Constants for operation types.
const ADD = "ADD";
const SHOW = "SHOW";
const REMOVE = "REMOVE";
const ADD_ONLY = "ADD_ONLY";

// Function to generate a composite key for identifying message items.
const generateCompositeKey = (id, caption) => `${id}-${caption}`;

// Custom hook to manage snackbars.
const useSnackbar = () => {
const { enqueueSnackbar, closeSnackbar } = useNotistackSnackbar();
const { messageItems, setMessageItems } = useContext(SnackbarContext);
const [operationType, setOperationType] = useState(null);

// Reference to keep track of the current message items.
const messageItemsRef = useRef({});

// Effect to update messageItemsRef whenever messageItems changes.
useEffect(() => {
if (messageItems !== messageItemsRef.current) {
messageItemsRef.current = messageItems;
}
}, [messageItems]);

// Function to format the message text for the snackbar.
const formatMessage = (items) => {
const keys = Object.keys(items);
if (keys.length === 0) return "";

const mostRecentKey = keys[keys.length - 1];
const mostRecentLayer = items[mostRecentKey];
const otherLayersCount = keys.length - 1;

return otherLayersCount > 0
? `Lagret '${mostRecentLayer}' och ${otherLayersCount} andra lager är inte synliga vid aktuell zoomnivå.`
: `Lagret '${mostRecentLayer}' är inte synligt vid aktuell zoomnivå.`;
};

// Function to display the snackbar.
const displaySnackbar = useCallback(() => {
const message = formatMessage(messageItemsRef.current);
if (!message) return;

// Action to display a close button on the snackbar.
const action = (key) => (
<IconButton
size="small"
color="inherit"
onClick={() => closeSnackbar(key)}
>
<CloseIcon fontSize="small" />
</IconButton>
);

enqueueSnackbar(message, {
variant: "warning",
autoHideDuration: 5000,
action,
anchorOrigin: {
vertical: "bottom",
horizontal: "center",
},
});
}, [enqueueSnackbar, closeSnackbar]);

// Effect to handle the display of the snackbar based on operationType.
useEffect(() => {
if (!operationType || Object.keys(messageItems).length === 0) return;

// Exclude REMOVE operation type from triggering snackbar.
if ([ADD, SHOW].includes(operationType)) {
displaySnackbar();
}

setOperationType(null);
}, [operationType, messageItems, displaySnackbar]);

// Function to update the snackbar messages and type.
const updateSnackbar = useCallback(
(type, id, caption) => {
if (!id || !caption) return;
const key = generateCompositeKey(id, caption);

setMessageItems((prevItems) => {
if ([ADD, ADD_ONLY].includes(type)) {
return { ...prevItems, [key]: caption };
}
const { [key]: _, ...rest } = prevItems;
return rest;
});

if (type !== ADD_ONLY) {
setOperationType(type);
}
},
[setMessageItems]
);

// Function to add a new message to the snackbar.
const addToSnackbar = (id, caption, addOnly = false) => {
updateSnackbar(addOnly ? ADD_ONLY : ADD, id, caption);
};

// Function to remove a message from the snackbar.
const removeFromSnackbar = (id, caption) =>
updateSnackbar(REMOVE, id, caption);

// Function to hide the snackbar.
const hideSnackbar = useCallback(
(key) => {
if (key) closeSnackbar(key);
},
[closeSnackbar]
);

// Function to clear all messages from the snackbar.
const clearSnackbar = () => setMessageItems({});

// Function to display the snackbar.
const showSnackbar = () => setOperationType(SHOW);

// Return the snackbar methods.
return {
addToSnackbar,
removeFromSnackbar,
hideSnackbar,
clearSnackbar,
showSnackbar,
};
};

export default useSnackbar;
6 changes: 6 additions & 0 deletions apps/client/src/models/layers/WMSLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ class WMSLayer {
this.layer.layersInfo = config.layersInfo;
this.layer.subLayers = this.subLayers;
this.layer.visibleAtStartSubLayers = config.visibleAtStartSubLayers;
this.layer.set(
"subLayers",
config.visibleAtStartSubLayers?.length > 0
? config.visibleAtStartSubLayers
: this.subLayers
);
this.layer.getSource().set("url", config.url);
this.type = "wms";
this.bindHandlers();
Expand Down
Loading