@abcagency/hc-ui-components 1.0.3 → 1.0.4

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/dist/index.js CHANGED
@@ -1190,27 +1190,25 @@ var setStorageObject = function setStorageObject(key, item) {
1190
1190
  };
1191
1191
 
1192
1192
  var updateURLWithFilters = function updateURLWithFilters(filters, location, navigate, query) {
1193
- console.log("attempting to update url");
1194
- console.log(filters);
1195
- console.log(location);
1196
- console.log(navigate);
1197
- console.log(query);
1198
- var searchParams = new URLSearchParams();
1199
-
1200
- // Add the new filters to search params
1193
+ var searchParams = new URLSearchParams(location.search);
1194
+ Object.keys(Object.fromEntries(searchParams)).forEach(function (key) {
1195
+ if (!key.includes('.') && key !== 'query') {
1196
+ searchParams.set(key, searchParams.get(key));
1197
+ }
1198
+ });
1199
+ if (query) {
1200
+ searchParams.set('query', query);
1201
+ }
1201
1202
  Object.keys(filters).forEach(function (category) {
1202
1203
  Object.keys(filters[category]).forEach(function (filter) {
1204
+ var key = "".concat(category, ".").concat(filter);
1203
1205
  if (filters[category][filter]) {
1204
- var key = "".concat(category, ".").concat(filter);
1205
1206
  searchParams.set(key, 'true');
1207
+ } else {
1208
+ searchParams["delete"](key);
1206
1209
  }
1207
1210
  });
1208
1211
  });
1209
-
1210
- // Add the query to search params if it exists
1211
- if (query) {
1212
- searchParams.set('query', query);
1213
- }
1214
1212
  navigate({
1215
1213
  search: searchParams.toString()
1216
1214
  }, {
@@ -1278,7 +1276,6 @@ var hasFiltersInURL = function hasFiltersInURL(location) {
1278
1276
  });
1279
1277
  };
1280
1278
  var hasQueryInUrl = function hasQueryInUrl(location) {
1281
- console.log(location);
1282
1279
  if (!location || !location.search) return;
1283
1280
  var queryParams = parseQueryParams(location.search);
1284
1281
  if (!queryParams) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abcagency/hc-ui-components",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,33 +1,33 @@
1
1
  export const updateURLWithFilters = (filters, location, navigate, query) => {
2
- console.log("attempting to update url");
3
- console.log(filters);
4
- console.log(location);
5
- console.log(navigate);
6
- console.log(query);
7
-
8
- const searchParams = new URLSearchParams();
9
-
10
- // Add the new filters to search params
11
- Object.keys(filters).forEach(category => {
12
- Object.keys(filters[category]).forEach(filter => {
13
- if (filters[category][filter]) {
14
- const key = `${category}.${filter}`;
15
- searchParams.set(key, 'true');
16
- }
17
- });
18
- });
19
-
20
- // Add the query to search params if it exists
21
- if (query) {
22
- searchParams.set('query', query);
23
- }
24
-
25
- navigate({
26
- search: searchParams.toString(),
27
- }, { replace: true });
28
-
29
- notifyParentOfUrlChange();
30
- };
2
+ const searchParams = new URLSearchParams(location.search);
3
+
4
+ Object.keys(Object.fromEntries(searchParams)).forEach(key => {
5
+ if (!key.includes('.') && key !== 'query') {
6
+ searchParams.set(key, searchParams.get(key));
7
+ }
8
+ });
9
+
10
+ if (query) {
11
+ searchParams.set('query', query);
12
+ }
13
+
14
+ Object.keys(filters).forEach(category => {
15
+ Object.keys(filters[category]).forEach(filter => {
16
+ const key = `${category}.${filter}`;
17
+ if (filters[category][filter]) {
18
+ searchParams.set(key, 'true');
19
+ } else {
20
+ searchParams.delete(key);
21
+ }
22
+ });
23
+ });
24
+
25
+ navigate({
26
+ search: searchParams.toString(),
27
+ }, { replace: true });
28
+
29
+ notifyParentOfUrlChange();
30
+ };
31
31
 
32
32
  function notifyParentOfUrlChange() {
33
33
  setTimeout(() => {
@@ -83,7 +83,6 @@ export const hasFiltersInURL = location => {
83
83
  };
84
84
 
85
85
  export const hasQueryInUrl = location => {
86
- console.log(location);
87
86
  if (!location || !location.search) return;
88
87
  const queryParams = parseQueryParams(location.search);
89
88
  if (!queryParams) return;