@snapdragonsnursery/react-components 1.23.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ChildSearchModal.jsx +36 -0
package/package.json
CHANGED
package/src/ChildSearchModal.jsx
CHANGED
|
@@ -101,6 +101,42 @@ const ChildSearchModal = ({
|
|
|
101
101
|
return () => clearTimeout(timer);
|
|
102
102
|
}, [searchTerm]);
|
|
103
103
|
|
|
104
|
+
// Value-stable key for siteIds so the sync effect only runs when the set of site IDs actually
|
|
105
|
+
// changes, not on every parent re-render (avoids resetting user's site/room selection and pagination).
|
|
106
|
+
const siteIdsKey = useMemo(
|
|
107
|
+
() =>
|
|
108
|
+
Array.isArray(siteIds) && siteIds.length > 0
|
|
109
|
+
? [...siteIds].sort((a, b) => a - b).join(",")
|
|
110
|
+
: "",
|
|
111
|
+
[siteIds]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Keep the internal site filter in sync with externally controlled site changes
|
|
115
|
+
// (for example when the app site is switched from a sidebar while the page stays mounted).
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
const nextSelectedSiteId =
|
|
118
|
+
siteIdsKey !== "" ? "" : siteId || "";
|
|
119
|
+
|
|
120
|
+
setAdvancedFilters((prev) => {
|
|
121
|
+
if (
|
|
122
|
+
prev.selectedSiteId === nextSelectedSiteId &&
|
|
123
|
+
prev.selectedRoomId === ""
|
|
124
|
+
) {
|
|
125
|
+
return prev;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
...prev,
|
|
130
|
+
selectedSiteId: nextSelectedSiteId,
|
|
131
|
+
selectedRoomId: "",
|
|
132
|
+
};
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
setPagination((prev) =>
|
|
136
|
+
prev.page === 1 ? prev : { ...prev, page: 1 }
|
|
137
|
+
);
|
|
138
|
+
}, [siteId, siteIdsKey]);
|
|
139
|
+
|
|
104
140
|
// Close modal when clicking outside
|
|
105
141
|
useEffect(() => {
|
|
106
142
|
const handleClickOutside = (event) => {
|