@procore/saved-views 6.0.0 → 6.0.1
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/legacy/index.d.mts +2 -1
- package/dist/legacy/index.d.ts +2 -1
- package/dist/legacy/index.js +216 -76
- package/dist/legacy/index.mjs +200 -60
- package/dist/modern/index.d.mts +2 -1
- package/dist/modern/index.d.ts +2 -1
- package/dist/modern/index.js +206 -76
- package/dist/modern/index.mjs +190 -60
- package/package.json +2 -1
package/dist/modern/index.mjs
CHANGED
|
@@ -8758,11 +8758,38 @@ var bt = "__sc-".concat(a, "__");
|
|
|
8758
8758
|
"production" !== process.env.NODE_ENV && "test" !== process.env.NODE_ENV && "undefined" != typeof window && (window[bt] || (window[bt] = 0), 1 === window[bt] && console.warn("It looks like there are several instances of 'styled-components' initialized in this application. This may cause dynamic styles to not render properly, errors during the rehydration process, a missing theme prop, and makes your application bigger without good reason.\n\nSee https://styled-components.com/docs/faqs#why-am-i-getting-a-warning-about-several-instances-of-module-on-the-page for more info."), window[bt] += 1);
|
|
8759
8759
|
|
|
8760
8760
|
// src/components/EnvironmentI18nProvider.tsx
|
|
8761
|
-
import React12 from "react";
|
|
8761
|
+
import React12, { useEffect, useMemo } from "react";
|
|
8762
8762
|
import { I18nContext, useI18n, useI18nContext } from "@procore/core-react";
|
|
8763
|
+
|
|
8764
|
+
// src/utils/translations/translationCache.ts
|
|
8765
|
+
var CACHE_KEY_PREFIX = "sg-saved-views-translations";
|
|
8766
|
+
function cacheKey(locale) {
|
|
8767
|
+
return `${CACHE_KEY_PREFIX}-${locale}`;
|
|
8768
|
+
}
|
|
8769
|
+
function readCache(locale) {
|
|
8770
|
+
try {
|
|
8771
|
+
const raw = localStorage.getItem(cacheKey(locale));
|
|
8772
|
+
if (!raw) return null;
|
|
8773
|
+
return JSON.parse(raw);
|
|
8774
|
+
} catch {
|
|
8775
|
+
return null;
|
|
8776
|
+
}
|
|
8777
|
+
}
|
|
8778
|
+
function writeCache(locale, translations) {
|
|
8779
|
+
try {
|
|
8780
|
+
localStorage.setItem(cacheKey(locale), JSON.stringify(translations));
|
|
8781
|
+
} catch {
|
|
8782
|
+
}
|
|
8783
|
+
}
|
|
8784
|
+
|
|
8785
|
+
// src/components/EnvironmentI18nProvider.tsx
|
|
8763
8786
|
import { useRequestTranslations } from "@procore/cdn-translations";
|
|
8764
8787
|
var useCDNTranslations = () => {
|
|
8765
8788
|
const i18n = useI18nContext();
|
|
8789
|
+
const cachedTranslations = useMemo(
|
|
8790
|
+
() => readCache(i18n.locale),
|
|
8791
|
+
[i18n.locale]
|
|
8792
|
+
);
|
|
8766
8793
|
const cdnTranslations = useRequestTranslations(
|
|
8767
8794
|
{
|
|
8768
8795
|
type: "file",
|
|
@@ -8777,8 +8804,17 @@ var useCDNTranslations = () => {
|
|
|
8777
8804
|
enableCDN: i18n.enableCDN
|
|
8778
8805
|
}
|
|
8779
8806
|
);
|
|
8807
|
+
useEffect(() => {
|
|
8808
|
+
if (cdnTranslations.status === "resolved" && cdnTranslations.translations) {
|
|
8809
|
+
writeCache(
|
|
8810
|
+
i18n.locale,
|
|
8811
|
+
cdnTranslations.translations
|
|
8812
|
+
);
|
|
8813
|
+
}
|
|
8814
|
+
}, [cdnTranslations.status, cdnTranslations.translations, i18n.locale]);
|
|
8815
|
+
const translationsToUse = cdnTranslations.status === "resolved" ? cdnTranslations.translations : cachedTranslations ?? getTranslations(i18n.locale);
|
|
8780
8816
|
return useI18n({
|
|
8781
|
-
translations:
|
|
8817
|
+
translations: translationsToUse,
|
|
8782
8818
|
locale: i18n.locale
|
|
8783
8819
|
});
|
|
8784
8820
|
};
|
|
@@ -9172,7 +9208,6 @@ function setSmartGridConfig(api, config) {
|
|
|
9172
9208
|
});
|
|
9173
9209
|
api.setColumnGroupState(config.columnGroupState);
|
|
9174
9210
|
api.setRowGroupColumns(config.rowGroupState);
|
|
9175
|
-
api.setFilterModel(config.filterState);
|
|
9176
9211
|
if (config.rowHeight) {
|
|
9177
9212
|
api.setGridOption("rowHeight", config.rowHeight);
|
|
9178
9213
|
}
|
|
@@ -9225,11 +9260,21 @@ var updateTableConfig = (view, tableApi, provider) => {
|
|
|
9225
9260
|
const dataTableApi = tableApi;
|
|
9226
9261
|
const tableConfig = view.table_config;
|
|
9227
9262
|
if (tableConfig) {
|
|
9228
|
-
const
|
|
9263
|
+
const currentTableConfig = dataTableApi?.getTableConfiguration?.();
|
|
9264
|
+
const rowHeight = tableConfig?.rowHeight ?? currentTableConfig?.rowHeight;
|
|
9265
|
+
const hasServerFilters = Boolean(currentTableConfig?.serverFilters?.length) || Boolean(tableConfig?.serverFilters?.length);
|
|
9266
|
+
const usesServerSideFiltering = hasServerFilters;
|
|
9229
9267
|
if (rowHeight !== void 0) {
|
|
9230
9268
|
dataTableApi?.setRowHeight(rowHeight);
|
|
9231
9269
|
}
|
|
9232
|
-
|
|
9270
|
+
if (usesServerSideFiltering) {
|
|
9271
|
+
dataTableApi?.setTableConfiguration({
|
|
9272
|
+
...tableConfig,
|
|
9273
|
+
filters: void 0
|
|
9274
|
+
});
|
|
9275
|
+
} else {
|
|
9276
|
+
dataTableApi?.setTableConfiguration(tableConfig);
|
|
9277
|
+
}
|
|
9233
9278
|
}
|
|
9234
9279
|
}
|
|
9235
9280
|
};
|
|
@@ -9410,10 +9455,10 @@ var ViewLevelHeader = ({ expanded, toggleGroup, group }) => {
|
|
|
9410
9455
|
var ViewLevelHeader_default = ViewLevelHeader;
|
|
9411
9456
|
|
|
9412
9457
|
// src/utils/hooks/useScrollToRef.ts
|
|
9413
|
-
import { useEffect, useRef } from "react";
|
|
9458
|
+
import { useEffect as useEffect2, useRef } from "react";
|
|
9414
9459
|
var useScrollToRef = (dependency) => {
|
|
9415
9460
|
const ref = useRef(null);
|
|
9416
|
-
|
|
9461
|
+
useEffect2(() => {
|
|
9417
9462
|
if (ref.current) {
|
|
9418
9463
|
ref.current.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
9419
9464
|
}
|
|
@@ -9612,7 +9657,7 @@ import {
|
|
|
9612
9657
|
Tooltip,
|
|
9613
9658
|
useI18nContext as useI18nContext12
|
|
9614
9659
|
} from "@procore/core-react";
|
|
9615
|
-
import React23, { useState as useState4, useEffect as
|
|
9660
|
+
import React23, { useState as useState4, useEffect as useEffect6, useCallback as useCallback4 } from "react";
|
|
9616
9661
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
9617
9662
|
import { useToastAlertContext as useToastAlertContext3, ToastAlertProvider } from "@procore/toast-alert";
|
|
9618
9663
|
|
|
@@ -10083,7 +10128,7 @@ var SharedViewFormModal = ({
|
|
|
10083
10128
|
};
|
|
10084
10129
|
|
|
10085
10130
|
// src/utils/hooks/useViewSelection.ts
|
|
10086
|
-
import { useState as useState3, useCallback as
|
|
10131
|
+
import { useState as useState3, useCallback as useCallback3, useEffect as useEffect4, useRef as useRef3, useMemo as useMemo2 } from "react";
|
|
10087
10132
|
import { useSearchParams } from "react-router-dom";
|
|
10088
10133
|
import { useI18nContext as useI18nContext11 } from "@procore/core-react";
|
|
10089
10134
|
|
|
@@ -10109,6 +10154,16 @@ var ViewStorage = {
|
|
|
10109
10154
|
}
|
|
10110
10155
|
};
|
|
10111
10156
|
|
|
10157
|
+
// src/utils/hooks/useLatest.ts
|
|
10158
|
+
import { useCallback as useCallback2, useLayoutEffect, useRef as useRef2 } from "react";
|
|
10159
|
+
var useLatest = (callback) => {
|
|
10160
|
+
const ref = useRef2(callback);
|
|
10161
|
+
useLayoutEffect(() => {
|
|
10162
|
+
ref.current = callback;
|
|
10163
|
+
});
|
|
10164
|
+
return useCallback2((...args) => ref.current(...args), []);
|
|
10165
|
+
};
|
|
10166
|
+
|
|
10112
10167
|
// src/utils/hooks/useViewSelection.ts
|
|
10113
10168
|
var isSmartGridConfig = (config) => {
|
|
10114
10169
|
return config != null && "rowGroupState" in config;
|
|
@@ -10160,7 +10215,7 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10160
10215
|
const storageKey = `savedView_${config.domain}_${config.tableName}_${config.companyId}_${projectIdSegment}_${config.userId}`;
|
|
10161
10216
|
const temporaryStorageKey = `${storageKey}-temporary`;
|
|
10162
10217
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
10163
|
-
const previousSavedViewParamRef =
|
|
10218
|
+
const previousSavedViewParamRef = useRef3(null);
|
|
10164
10219
|
const [selectedSavedView, setSelectedSavedView] = useState3(() => {
|
|
10165
10220
|
const stored = ViewStorage.load(storageKey, config.defaultView);
|
|
10166
10221
|
return stored ?? config.defaultView;
|
|
@@ -10169,22 +10224,22 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10169
10224
|
const loaded = ViewStorage.load(temporaryStorageKey, config.defaultView);
|
|
10170
10225
|
return loaded && (loaded.id === "temporary" || loaded.view_level === "temporary") ? loaded : null;
|
|
10171
10226
|
});
|
|
10172
|
-
const persistViewToStorageAndUrl =
|
|
10227
|
+
const persistViewToStorageAndUrl = useCallback3(
|
|
10173
10228
|
(view) => {
|
|
10174
10229
|
ViewStorage.save(storageKey, view);
|
|
10175
10230
|
setViewInUrl(view, setSearchParams);
|
|
10176
10231
|
},
|
|
10177
10232
|
[storageKey, setSearchParams]
|
|
10178
10233
|
);
|
|
10179
|
-
const baseViews =
|
|
10234
|
+
const baseViews = useMemo2(
|
|
10180
10235
|
() => [...savedViews ?? [], ...presetViews ?? []],
|
|
10181
10236
|
[savedViews, presetViews]
|
|
10182
10237
|
);
|
|
10183
|
-
const allViews =
|
|
10238
|
+
const allViews = useMemo2(
|
|
10184
10239
|
() => temporaryView ? [...baseViews, temporaryView] : baseViews,
|
|
10185
10240
|
[baseViews, temporaryView]
|
|
10186
10241
|
);
|
|
10187
|
-
const selectView =
|
|
10242
|
+
const selectView = useCallback3(
|
|
10188
10243
|
(view) => {
|
|
10189
10244
|
const viewToSelect = config.onSelect({ item: view });
|
|
10190
10245
|
setSelectedSavedView(viewToSelect);
|
|
@@ -10193,7 +10248,7 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10193
10248
|
},
|
|
10194
10249
|
[config, persistViewToStorageAndUrl]
|
|
10195
10250
|
);
|
|
10196
|
-
const createTemporaryView =
|
|
10251
|
+
const createTemporaryView = useCallback3(
|
|
10197
10252
|
(fetchedView) => {
|
|
10198
10253
|
const tempView = {
|
|
10199
10254
|
...fetchedView,
|
|
@@ -10208,30 +10263,27 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10208
10263
|
},
|
|
10209
10264
|
[temporaryStorageKey, selectView]
|
|
10210
10265
|
);
|
|
10211
|
-
const clearTemporaryView =
|
|
10266
|
+
const clearTemporaryView = useCallback3(() => {
|
|
10212
10267
|
ViewStorage.remove(temporaryStorageKey);
|
|
10213
10268
|
setTemporaryView(null);
|
|
10214
10269
|
selectView(config.defaultView);
|
|
10215
10270
|
}, [temporaryStorageKey, config.defaultView, selectView]);
|
|
10216
|
-
const isViewAlreadySelected =
|
|
10271
|
+
const isViewAlreadySelected = useCallback3(
|
|
10217
10272
|
(viewId) => checkIsViewSelected(selectedSavedView, viewId),
|
|
10218
10273
|
[selectedSavedView]
|
|
10219
10274
|
);
|
|
10220
|
-
const handleSavedViewFromUrl =
|
|
10221
|
-
(viewId)
|
|
10222
|
-
|
|
10223
|
-
|
|
10224
|
-
|
|
10225
|
-
|
|
10226
|
-
|
|
10227
|
-
|
|
10228
|
-
|
|
10229
|
-
|
|
10230
|
-
|
|
10231
|
-
|
|
10232
|
-
[isViewAlreadySelected, openSharedViewModal, allViews, selectView]
|
|
10233
|
-
);
|
|
10234
|
-
useEffect3(() => {
|
|
10275
|
+
const handleSavedViewFromUrl = useLatest((viewId) => {
|
|
10276
|
+
if (isViewAlreadySelected(viewId)) {
|
|
10277
|
+
return;
|
|
10278
|
+
}
|
|
10279
|
+
const viewInList = findViewByToken(allViews, viewId);
|
|
10280
|
+
if (viewInList) {
|
|
10281
|
+
selectView(viewInList);
|
|
10282
|
+
} else {
|
|
10283
|
+
openSharedViewModal(viewId);
|
|
10284
|
+
}
|
|
10285
|
+
});
|
|
10286
|
+
useEffect4(() => {
|
|
10235
10287
|
const savedViewId = searchParams.get("saved-view");
|
|
10236
10288
|
restoreUrlParameter(
|
|
10237
10289
|
savedViewId,
|
|
@@ -10245,14 +10297,14 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10245
10297
|
handleSavedViewFromUrl(savedViewId);
|
|
10246
10298
|
}
|
|
10247
10299
|
}, [searchParams, handleSavedViewFromUrl, allViews.length]);
|
|
10248
|
-
const previousRowGroupStateRef =
|
|
10300
|
+
const previousRowGroupStateRef = useRef3(
|
|
10249
10301
|
isSmartGridConfig(tableConfig) ? tableConfig.rowGroupState : void 0
|
|
10250
10302
|
);
|
|
10251
|
-
const selectedViewRef =
|
|
10303
|
+
const selectedViewRef = useRef3(selectedSavedView);
|
|
10252
10304
|
selectedViewRef.current = selectedSavedView;
|
|
10253
|
-
const defaultViewRef =
|
|
10305
|
+
const defaultViewRef = useRef3(config.defaultView);
|
|
10254
10306
|
defaultViewRef.current = config.defaultView;
|
|
10255
|
-
|
|
10307
|
+
useEffect4(() => {
|
|
10256
10308
|
if (!isSmartGridConfig(tableConfig) || !presetViews?.length) return;
|
|
10257
10309
|
const currentView = selectedViewRef.current;
|
|
10258
10310
|
const isPresetSelected = !currentView || currentView.view_level === "default";
|
|
@@ -10291,7 +10343,54 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal, ta
|
|
|
10291
10343
|
};
|
|
10292
10344
|
};
|
|
10293
10345
|
|
|
10346
|
+
// src/components/saved-views/FocusScopeToggle.tsx
|
|
10347
|
+
import { useFocusManager } from "@react-aria/focus";
|
|
10348
|
+
import { useEffect as useEffect5, useRef as useRef4 } from "react";
|
|
10349
|
+
var useFocusScopeToggle = (isOpen) => {
|
|
10350
|
+
const focusManager = useFocusManager();
|
|
10351
|
+
const triggerRef = useRef4(null);
|
|
10352
|
+
const firstFocusedElementRef = useRef4(null);
|
|
10353
|
+
useEffect5(() => {
|
|
10354
|
+
const handleKeyDown = (event) => {
|
|
10355
|
+
if (!event.shiftKey || event.key !== "Tab") {
|
|
10356
|
+
return;
|
|
10357
|
+
}
|
|
10358
|
+
if (document.activeElement !== firstFocusedElementRef.current) {
|
|
10359
|
+
return;
|
|
10360
|
+
}
|
|
10361
|
+
event.preventDefault();
|
|
10362
|
+
triggerRef.current?.focus();
|
|
10363
|
+
};
|
|
10364
|
+
if (isOpen) {
|
|
10365
|
+
triggerRef.current = document.activeElement;
|
|
10366
|
+
focusManager?.focusFirst({ tabbable: true });
|
|
10367
|
+
firstFocusedElementRef.current = document.activeElement;
|
|
10368
|
+
firstFocusedElementRef.current?.addEventListener(
|
|
10369
|
+
"keydown",
|
|
10370
|
+
handleKeyDown
|
|
10371
|
+
);
|
|
10372
|
+
} else {
|
|
10373
|
+
firstFocusedElementRef.current = null;
|
|
10374
|
+
const activeElement = document.activeElement;
|
|
10375
|
+
if (!activeElement || activeElement === document.body) {
|
|
10376
|
+
triggerRef.current?.focus();
|
|
10377
|
+
}
|
|
10378
|
+
}
|
|
10379
|
+
return () => {
|
|
10380
|
+
firstFocusedElementRef.current?.removeEventListener(
|
|
10381
|
+
"keydown",
|
|
10382
|
+
handleKeyDown
|
|
10383
|
+
);
|
|
10384
|
+
};
|
|
10385
|
+
}, [isOpen, focusManager]);
|
|
10386
|
+
};
|
|
10387
|
+
var FocusScopeToggle = ({ isOpen }) => {
|
|
10388
|
+
useFocusScopeToggle(isOpen);
|
|
10389
|
+
return null;
|
|
10390
|
+
};
|
|
10391
|
+
|
|
10294
10392
|
// src/components/saved-views/SavedViews.tsx
|
|
10393
|
+
import { FocusScope } from "@react-aria/focus";
|
|
10295
10394
|
var StyledPanel = pt.div`
|
|
10296
10395
|
border: ${({ provider }) => provider === "data-table" ? "1px solid #d6dadc" : "none"};
|
|
10297
10396
|
`;
|
|
@@ -10314,7 +10413,7 @@ var SavedViewsContent = (props) => {
|
|
|
10314
10413
|
setActiveModal(type);
|
|
10315
10414
|
setModalData(data ?? null);
|
|
10316
10415
|
};
|
|
10317
|
-
const closeModal =
|
|
10416
|
+
const closeModal = useCallback4(() => {
|
|
10318
10417
|
setActiveModal(null);
|
|
10319
10418
|
setModalData(null);
|
|
10320
10419
|
}, []);
|
|
@@ -10354,7 +10453,7 @@ var SavedViewsContent = (props) => {
|
|
|
10354
10453
|
error: createError,
|
|
10355
10454
|
reset: resetCreateError
|
|
10356
10455
|
} = useCreateSavedView(queryInput);
|
|
10357
|
-
|
|
10456
|
+
useEffect6(() => {
|
|
10358
10457
|
if (fetchError) {
|
|
10359
10458
|
showToast.error(i18n.t("savedViews.errors.notFound"));
|
|
10360
10459
|
selectView(selectedView ?? props.defaultView);
|
|
@@ -10402,7 +10501,7 @@ var SavedViewsContent = (props) => {
|
|
|
10402
10501
|
deleteSelectedView();
|
|
10403
10502
|
closeModal();
|
|
10404
10503
|
};
|
|
10405
|
-
return /* @__PURE__ */ React23.createElement(StyledPanel, { id: "saved-views-panel", provider: props.provider }, /* @__PURE__ */ React23.createElement(
|
|
10504
|
+
return /* @__PURE__ */ React23.createElement(FocusScope, { contain: false }, /* @__PURE__ */ React23.createElement(StyledPanel, { id: "saved-views-panel", provider: props.provider }, /* @__PURE__ */ React23.createElement(FocusScopeToggle, { isOpen: props.isPanelOpen ?? true }), /* @__PURE__ */ React23.createElement(
|
|
10406
10505
|
ExpandedPanel,
|
|
10407
10506
|
{
|
|
10408
10507
|
"data-testid": "saved-view-expanded-panel",
|
|
@@ -10490,17 +10589,17 @@ var SavedViewsContent = (props) => {
|
|
|
10490
10589
|
isCreating,
|
|
10491
10590
|
resetCreateError
|
|
10492
10591
|
}
|
|
10493
|
-
));
|
|
10592
|
+
)));
|
|
10494
10593
|
};
|
|
10495
10594
|
var SavedViews = (props) => {
|
|
10496
10595
|
return /* @__PURE__ */ React23.createElement(EnvironmentI18nProvider, null, /* @__PURE__ */ React23.createElement(QueryClientProvider, { client: queryClient }, /* @__PURE__ */ React23.createElement(ToastAlertProvider, null, /* @__PURE__ */ React23.createElement(SavedViewsContent, { ...props }))));
|
|
10497
10596
|
};
|
|
10498
10597
|
|
|
10499
10598
|
// src/components/adapters/smart-grid/SmartGridSavedViews.tsx
|
|
10500
|
-
import React24, { useCallback as
|
|
10599
|
+
import React24, { useCallback as useCallback5 } from "react";
|
|
10501
10600
|
|
|
10502
10601
|
// src/components/adapters/smart-grid/SmartGridDefaultSavedView.tsx
|
|
10503
|
-
import { useMemo as
|
|
10602
|
+
import { useMemo as useMemo3 } from "react";
|
|
10504
10603
|
var DEFAULT_COLUMN_STATE = {
|
|
10505
10604
|
hide: false,
|
|
10506
10605
|
pinned: null,
|
|
@@ -10547,7 +10646,7 @@ var extractDefaultView = (gridApi, receivedConfig) => {
|
|
|
10547
10646
|
return result;
|
|
10548
10647
|
};
|
|
10549
10648
|
var useNormalizedDefaultViews = (defaultViews, gridApi) => {
|
|
10550
|
-
return
|
|
10649
|
+
return useMemo3(() => {
|
|
10551
10650
|
if (!gridApi)
|
|
10552
10651
|
return defaultViews.map((view) => ({ ...view, share_token: view.id }));
|
|
10553
10652
|
return defaultViews.map((view) => ({
|
|
@@ -10559,7 +10658,7 @@ var useNormalizedDefaultViews = (defaultViews, gridApi) => {
|
|
|
10559
10658
|
};
|
|
10560
10659
|
|
|
10561
10660
|
// src/components/adapters/smart-grid/useSmartGridConfig.ts
|
|
10562
|
-
import { useState as useState5, useEffect as
|
|
10661
|
+
import { useState as useState5, useEffect as useEffect7 } from "react";
|
|
10563
10662
|
var GRID_STATE_EVENTS = [
|
|
10564
10663
|
"sortChanged",
|
|
10565
10664
|
"filterOpened",
|
|
@@ -10578,7 +10677,7 @@ var useSmartGridConfig = (gridApi) => {
|
|
|
10578
10677
|
const [config, setConfig] = useState5(
|
|
10579
10678
|
() => getSmartGridConfig(gridApi)
|
|
10580
10679
|
);
|
|
10581
|
-
|
|
10680
|
+
useEffect7(() => {
|
|
10582
10681
|
if (!gridApi) return;
|
|
10583
10682
|
const updateConfig = () => {
|
|
10584
10683
|
setConfig(getSmartGridConfig(gridApi));
|
|
@@ -10595,19 +10694,43 @@ var useSmartGridConfig = (gridApi) => {
|
|
|
10595
10694
|
return { config, setConfig };
|
|
10596
10695
|
};
|
|
10597
10696
|
|
|
10697
|
+
// src/components/adapters/smart-grid/useSavedViewsPanelOpen.ts
|
|
10698
|
+
import { useEffect as useEffect8, useState as useState6 } from "react";
|
|
10699
|
+
var SAVED_VIEWS_PANEL_ID = "savedViews";
|
|
10700
|
+
var useSavedViewsPanelOpen = (gridApi) => {
|
|
10701
|
+
const [isOpen, setIsOpen] = useState6(
|
|
10702
|
+
gridApi.getOpenedToolPanel?.() === SAVED_VIEWS_PANEL_ID
|
|
10703
|
+
);
|
|
10704
|
+
useEffect8(() => {
|
|
10705
|
+
const syncOpenState = () => {
|
|
10706
|
+
setIsOpen(gridApi.getOpenedToolPanel?.() === SAVED_VIEWS_PANEL_ID);
|
|
10707
|
+
};
|
|
10708
|
+
syncOpenState();
|
|
10709
|
+
gridApi.addEventListener?.("toolPanelVisibleChanged", syncOpenState);
|
|
10710
|
+
return () => {
|
|
10711
|
+
gridApi.removeEventListener?.("toolPanelVisibleChanged", syncOpenState);
|
|
10712
|
+
};
|
|
10713
|
+
}, [gridApi]);
|
|
10714
|
+
return isOpen;
|
|
10715
|
+
};
|
|
10716
|
+
|
|
10598
10717
|
// src/components/adapters/smart-grid/SmartGridSavedViews.tsx
|
|
10599
10718
|
var SmartGridSavedViews = (props) => {
|
|
10600
10719
|
const { gridApi, userId, projectId, companyId } = props;
|
|
10601
10720
|
const { config: tableConfig, setConfig: setTableConfig } = useSmartGridConfig(gridApi);
|
|
10721
|
+
const isPanelOpen = useSavedViewsPanelOpen(gridApi);
|
|
10602
10722
|
const presetViews = useNormalizedDefaultViews(props.defaultViews, gridApi);
|
|
10603
10723
|
const defaultView = presetViews.find((view) => view.id === "default") ?? presetViews[0];
|
|
10604
|
-
const onSelect =
|
|
10724
|
+
const onSelect = useCallback5(
|
|
10605
10725
|
({ item }) => {
|
|
10606
10726
|
if (!gridApi) return item;
|
|
10607
10727
|
const isPresetView = item.view_level === "default";
|
|
10608
10728
|
if (isPresetView) {
|
|
10609
10729
|
updateTableConfig(item, gridApi, "smart-grid");
|
|
10610
|
-
setTableConfig(
|
|
10730
|
+
setTableConfig({
|
|
10731
|
+
...item.table_config,
|
|
10732
|
+
filterState: gridApi.getFilterModel?.() ?? {}
|
|
10733
|
+
});
|
|
10611
10734
|
return item;
|
|
10612
10735
|
}
|
|
10613
10736
|
const updatedView = {
|
|
@@ -10618,7 +10741,9 @@ var SmartGridSavedViews = (props) => {
|
|
|
10618
10741
|
)
|
|
10619
10742
|
};
|
|
10620
10743
|
updateTableConfig(updatedView, gridApi, "smart-grid");
|
|
10621
|
-
|
|
10744
|
+
const updatedConfig = updatedView.table_config;
|
|
10745
|
+
gridApi.setFilterModel(updatedConfig.filterState ?? {});
|
|
10746
|
+
setTableConfig(updatedConfig);
|
|
10622
10747
|
return updatedView;
|
|
10623
10748
|
},
|
|
10624
10749
|
[gridApi, tableConfig, setTableConfig]
|
|
@@ -10635,7 +10760,8 @@ var SmartGridSavedViews = (props) => {
|
|
|
10635
10760
|
defaultView,
|
|
10636
10761
|
presetViews,
|
|
10637
10762
|
tableName: props.tableName,
|
|
10638
|
-
tableConfig
|
|
10763
|
+
tableConfig,
|
|
10764
|
+
isPanelOpen
|
|
10639
10765
|
}
|
|
10640
10766
|
);
|
|
10641
10767
|
};
|
|
@@ -10644,12 +10770,12 @@ var SmartGridSavedViews = (props) => {
|
|
|
10644
10770
|
import React25, {
|
|
10645
10771
|
forwardRef as forwardRef11,
|
|
10646
10772
|
useImperativeHandle,
|
|
10647
|
-
useState as
|
|
10648
|
-
useCallback as
|
|
10773
|
+
useState as useState7,
|
|
10774
|
+
useCallback as useCallback6
|
|
10649
10775
|
} from "react";
|
|
10650
10776
|
|
|
10651
10777
|
// src/components/adapters/data-table/DataTableDefaultSavedView.tsx
|
|
10652
|
-
import { useMemo as
|
|
10778
|
+
import { useMemo as useMemo4 } from "react";
|
|
10653
10779
|
var DEFAULT_COLUMN_STATE2 = {
|
|
10654
10780
|
hidden: false,
|
|
10655
10781
|
pinned: null,
|
|
@@ -10696,7 +10822,7 @@ var extractDefaultView2 = (columnDefinitions, receivedConfigFromTool) => {
|
|
|
10696
10822
|
return result;
|
|
10697
10823
|
};
|
|
10698
10824
|
var useNormalizedDefaultViews2 = (defaultViews, columnDefinitions) => {
|
|
10699
|
-
return
|
|
10825
|
+
return useMemo4(
|
|
10700
10826
|
() => defaultViews.map((view) => ({
|
|
10701
10827
|
...view,
|
|
10702
10828
|
share_token: view.id,
|
|
@@ -10714,7 +10840,7 @@ var DataTableSavedViews = forwardRef11((props, ref) => {
|
|
|
10714
10840
|
props.columnDefinitions
|
|
10715
10841
|
);
|
|
10716
10842
|
const defaultView = presetViews.find((view) => view.id === "default") ?? presetViews[0];
|
|
10717
|
-
const [internalTableConfig, setInternalTableConfig] =
|
|
10843
|
+
const [internalTableConfig, setInternalTableConfig] = useState7(
|
|
10718
10844
|
ViewStorage.load(props.stickyViewsKey, defaultView).table_config
|
|
10719
10845
|
);
|
|
10720
10846
|
useImperativeHandle(ref, () => ({
|
|
@@ -10722,17 +10848,21 @@ var DataTableSavedViews = forwardRef11((props, ref) => {
|
|
|
10722
10848
|
setInternalTableConfig(newConfig);
|
|
10723
10849
|
}
|
|
10724
10850
|
}));
|
|
10725
|
-
const onSelect =
|
|
10851
|
+
const onSelect = useCallback6(
|
|
10726
10852
|
({ item }) => {
|
|
10727
10853
|
const isPresetView = item.view_level === "default";
|
|
10854
|
+
const syncReferenceConfig = tableApi?.getTableConfiguration?.() ?? defaultView.table_config;
|
|
10855
|
+
const syncedConfig = isPresetView ? item.table_config : customAndConfigSync(
|
|
10856
|
+
item.table_config,
|
|
10857
|
+
syncReferenceConfig
|
|
10858
|
+
);
|
|
10728
10859
|
const updatedView = isPresetView ? item : {
|
|
10729
10860
|
...item,
|
|
10730
|
-
table_config:
|
|
10731
|
-
item.table_config,
|
|
10732
|
-
defaultView.table_config
|
|
10733
|
-
)
|
|
10861
|
+
table_config: syncedConfig
|
|
10734
10862
|
};
|
|
10735
|
-
|
|
10863
|
+
if (tableApi) {
|
|
10864
|
+
updateTableConfig(updatedView, tableApi, "data-table");
|
|
10865
|
+
}
|
|
10736
10866
|
setInternalTableConfig(updatedView.table_config);
|
|
10737
10867
|
return updatedView;
|
|
10738
10868
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@procore/saved-views",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Saved Views Component for Data Table",
|
|
5
5
|
"author": "Procore Technologies, Inc",
|
|
6
6
|
"repository": {
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"typescript": "^5.2.2"
|
|
113
113
|
},
|
|
114
114
|
"dependencies": {
|
|
115
|
+
"@react-aria/focus": "3.21.2",
|
|
115
116
|
"@tanstack/react-query": "^5.83.0",
|
|
116
117
|
"yup": "^1.6.1"
|
|
117
118
|
}
|