@procore/saved-views 1.0.0 → 1.0.1-alpha.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.
@@ -11433,176 +11433,13 @@ var ExpandedPanel = styled_components_esm_default(Panel)`
11433
11433
  `;
11434
11434
 
11435
11435
  // src/components/panels/PanelContent.tsx
11436
- import { Flex as Flex3, useI18nContext as useI18nContext5 } from "@procore/core-react";
11436
+ import { Flex as Flex3, useI18nContext as useI18nContext4 } from "@procore/core-react";
11437
11437
  import { useToastAlertContext as useToastAlertContext2 } from "@procore/toast-alert";
11438
11438
  import React17 from "react";
11439
11439
 
11440
- // node_modules/@procore/core-http/dist/modern/index.js
11441
- function getCSRFToken() {
11442
- const token = document.cookie.match("(^|;)\\s*csrf_token\\s*=\\s*([^;]+)");
11443
- return token ? decodeURIComponent(token.pop() || "") : "";
11444
- }
11445
- function getCSRFHeader() {
11446
- const csrfToken = getCSRFToken();
11447
- return csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {};
11448
- }
11449
- function removeLeadingSlash(url) {
11450
- return url.startsWith("/") ? url.substring(1, url.length) : url;
11451
- }
11452
- function removeTrailingSlash(url) {
11453
- return url.endsWith("/") ? url.substring(0, url.length - 1) : url;
11454
- }
11455
- function applyBaseUrl(url, baseUrl) {
11456
- return `${removeTrailingSlash(baseUrl)}/${removeLeadingSlash(url)}`;
11457
- }
11458
- function getOptions({ headers, ...options }) {
11459
- const opts = {
11460
- credentials: "same-origin",
11461
- headers: {
11462
- ...getCSRFHeader(),
11463
- ...headers
11464
- },
11465
- mode: "same-origin",
11466
- ...options
11467
- };
11468
- return opts;
11469
- }
11470
- function getUrl(url, baseUrl) {
11471
- return baseUrl ? applyBaseUrl(url, baseUrl) : url;
11472
- }
11473
- function request(url, { baseUrl, ...options } = {}) {
11474
- return fetch(getUrl(url, baseUrl), getOptions(options));
11475
- }
11476
- function requestJSON(url, requestParams = {}) {
11477
- return request(url, requestParams).then(
11478
- (response) => response.json()
11479
- );
11480
- }
11481
-
11482
- // src/utils/api/queries.ts
11483
- import { useQuery } from "@tanstack/react-query";
11484
-
11485
- // src/utils/api/queriesHandler.ts
11486
- import { useMutation, useQueryClient } from "@tanstack/react-query";
11487
- import { useI18nContext as useI18nContext3 } from "@procore/core-react";
11488
- var useApiRequest = (props, method, mutationKey) => {
11489
- const { projectId, companyId, domain, tableName } = props;
11490
- const queryClient2 = useQueryClient();
11491
- const { locale: locale2 } = useI18nContext3();
11492
- return useMutation({
11493
- mutationKey,
11494
- mutationFn: async (savedView) => {
11495
- let url = "";
11496
- if (method === "DELETE" || method === "PUT") {
11497
- url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedView.share_token}?permissions_domain=${domain}`;
11498
- } else {
11499
- url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
11500
- }
11501
- const response = await requestJSON(url, {
11502
- method,
11503
- body: JSON.stringify(savedView),
11504
- headers: {
11505
- "Content-Type": "application/json",
11506
- "Accept-Language": locale2
11507
- }
11508
- });
11509
- if (response.error) {
11510
- throw response.error;
11511
- }
11512
- return response.data;
11513
- },
11514
- onSuccess: (savedView) => {
11515
- if (method === "DELETE" || method === "POST") {
11516
- queryClient2.invalidateQueries({
11517
- queryKey: ["savedViews", domain, tableName]
11518
- });
11519
- return;
11520
- } else {
11521
- const oldData = queryClient2.getQueryData([
11522
- "savedViews",
11523
- domain,
11524
- tableName
11525
- ]);
11526
- const oldView = oldData?.find(
11527
- (item) => item.share_token === savedView.share_token
11528
- );
11529
- if (oldView?.name !== savedView.name) {
11530
- queryClient2.invalidateQueries({
11531
- queryKey: ["savedViews", domain, tableName]
11532
- });
11533
- return;
11534
- }
11535
- }
11536
- queryClient2.setQueryData(
11537
- ["savedViews", domain, tableName],
11538
- (oldData) => {
11539
- if (!oldData)
11540
- return [savedView];
11541
- return oldData.map(
11542
- (item) => item.share_token === savedView.share_token ? savedView : item
11543
- );
11544
- }
11545
- );
11546
- }
11547
- });
11548
- };
11549
-
11550
11440
  // src/utils/constants/viewLevels.ts
11551
11441
  var VIEW_LEVELS = ["company", "project", "personal"];
11552
11442
 
11553
- // src/utils/api/queries.ts
11554
- var PAGE_SIZE = 50 * VIEW_LEVELS.length;
11555
- var useSavedViewsQuery = (props) => {
11556
- const { projectId, companyId, domain, tableName } = props;
11557
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
11558
- return useQuery({
11559
- queryKey: ["savedViews", domain, tableName],
11560
- queryFn: async () => {
11561
- const getUrl2 = `${url}&per_page=${PAGE_SIZE}`;
11562
- const response = await requestJSON(getUrl2);
11563
- return response.data;
11564
- }
11565
- });
11566
- };
11567
- var useSavedViewsPermissions = (props) => {
11568
- const { projectId, companyId, domain } = props;
11569
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/permissions?permissions_domain=${domain}`;
11570
- return useQuery({
11571
- queryKey: ["savedViewsConfig", domain],
11572
- queryFn: async () => {
11573
- const response = await requestJSON(url);
11574
- return response.data;
11575
- }
11576
- });
11577
- };
11578
- var useCreateSavedView = (props) => useApiRequest(props, "POST", [
11579
- "createSavedView",
11580
- props.domain,
11581
- props.tableName
11582
- ]);
11583
- var useUpdateSavedView = (props) => useApiRequest(props, "PUT", [
11584
- "updateSavedView",
11585
- props.domain,
11586
- props.tableName
11587
- ]);
11588
- var useDeleteSavedView = (props) => useApiRequest(props, "DELETE", [
11589
- "deleteSavedView",
11590
- props.domain,
11591
- props.tableName
11592
- ]);
11593
- var useFetchSavedViewById = (savedViewToken, queryInput, enabled = true) => {
11594
- const { projectId, companyId } = queryInput;
11595
- return useQuery({
11596
- enabled: enabled && Boolean(savedViewToken),
11597
- queryKey: ["savedView", savedViewToken],
11598
- queryFn: async () => {
11599
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedViewToken}`;
11600
- const response = await requestJSON(url);
11601
- return response.data;
11602
- }
11603
- });
11604
- };
11605
-
11606
11443
  // src/components/panels/PanelContentUtils.ts
11607
11444
  var import_lodash = __toESM(require_lodash());
11608
11445
 
@@ -11752,12 +11589,13 @@ var normalizeForComparison = (config) => {
11752
11589
  if (!config?.columnState)
11753
11590
  return config;
11754
11591
  return {
11755
- ...config,
11592
+ ...import_lodash.default.omit(config, ["enableRowGrouping", "enableColumnGrouping"]),
11756
11593
  columnState: config.columnState.map((col) => {
11594
+ const res = import_lodash.default.omit(col, ["aggFunc"]);
11757
11595
  if (col.flex) {
11758
- return import_lodash.default.omit(col, ["width", "flex"]);
11596
+ return import_lodash.default.omit(res, ["width", "flex"]);
11759
11597
  }
11760
- return col;
11598
+ return res;
11761
11599
  })
11762
11600
  };
11763
11601
  };
@@ -11770,10 +11608,9 @@ var isEqual = (viewTableConfig, tableConfig, defaultViewConfig, provider) => {
11770
11608
  );
11771
11609
  const normalizedViewConfig = normalizeForComparison(syncedViewTableConfig);
11772
11610
  const normalizedCurrentConfig = normalizeForComparison(tableConfig);
11773
- return import_lodash.default.isEqual(
11774
- cleanObject(normalizedViewConfig, provider),
11775
- cleanObject(normalizedCurrentConfig, provider)
11776
- );
11611
+ const cleanedViewConfig = cleanObject(normalizedViewConfig, provider);
11612
+ const cleanedCurrentConfig = cleanObject(normalizedCurrentConfig, provider);
11613
+ return import_lodash.default.isEqual(cleanedViewConfig, cleanedCurrentConfig);
11777
11614
  };
11778
11615
  var hasPermissionForViewLevel = (viewLevel, permissions) => {
11779
11616
  switch (viewLevel) {
@@ -11806,7 +11643,7 @@ import {
11806
11643
  Flex as Flex2,
11807
11644
  spacing,
11808
11645
  Typography,
11809
- useI18nContext as useI18nContext4
11646
+ useI18nContext as useI18nContext3
11810
11647
  } from "@procore/core-react";
11811
11648
  import React16 from "react";
11812
11649
  var groupIcon = (group) => {
@@ -11826,7 +11663,7 @@ var Header = styled_components_esm_default(Flex2)`
11826
11663
  }
11827
11664
  `;
11828
11665
  var ViewLevelHeader = ({ expanded, toggleGroup, group }) => {
11829
- const I18n = useI18nContext4();
11666
+ const I18n = useI18nContext3();
11830
11667
  return /* @__PURE__ */ React16.createElement(
11831
11668
  Header,
11832
11669
  {
@@ -11883,9 +11720,9 @@ var Panel2 = styled_components_esm_default(DetailPage.Card)`
11883
11720
  var PanelContent = (props) => {
11884
11721
  const { queryInput, selectedSavedView, tableConfig } = props;
11885
11722
  const { showToast } = useToastAlertContext2();
11886
- const I18n = useI18nContext5();
11887
- const { data: savedViewsFromQuery, error: savedViewsError } = useSavedViewsQuery(props.queryInput);
11888
- const updateMutation = useUpdateSavedView(queryInput);
11723
+ const I18n = useI18nContext4();
11724
+ const { data: savedViewsFromQuery, error: savedViewsError } = props.backend.useSavedViewsQuery(props.queryInput);
11725
+ const updateMutation = props.backend.useUpdateSavedView(queryInput);
11889
11726
  const { mutate: updateSavedView } = updateMutation;
11890
11727
  const isUpdateLoading = "isPending" in updateMutation ? updateMutation.isPending : updateMutation.isLoading ?? false;
11891
11728
  const savedViews = props.savedViews ?? savedViewsFromQuery;
@@ -11896,7 +11733,9 @@ var PanelContent = (props) => {
11896
11733
  errorToastRef.current = savedViewsError;
11897
11734
  }
11898
11735
  }, [savedViewsError, showToast, I18n]);
11899
- const { data: permissions } = useSavedViewsPermissions(props.queryInput);
11736
+ const { data: permissions } = props.backend.useSavedViewsPermissions(
11737
+ props.queryInput
11738
+ );
11900
11739
  const selectedRowRef = useScrollToRef(savedViews);
11901
11740
  const { groups, toggleGroup } = useGroups();
11902
11741
  const isTemporarySelected = selectedSavedView?.id === "temporary";
@@ -12012,7 +11851,7 @@ import {
12012
11851
  Tooltip,
12013
11852
  useI18nContext as useI18nContext11
12014
11853
  } from "@procore/core-react";
12015
- import React22, { useState as useState4, useEffect as useEffect3, useCallback as useCallback3 } from "react";
11854
+ import React22, { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
12016
11855
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
12017
11856
  import { useToastAlertContext as useToastAlertContext3, ToastAlertProvider } from "@procore/toast-alert";
12018
11857
 
@@ -12022,7 +11861,7 @@ import {
12022
11861
  ConfirmModal,
12023
11862
  Modal,
12024
11863
  P as P2,
12025
- useI18nContext as useI18nContext6
11864
+ useI18nContext as useI18nContext5
12026
11865
  } from "@procore/core-react";
12027
11866
  import React18 from "react";
12028
11867
  var SavedViewsDeleteConfirmationModalShared = ({
@@ -12030,7 +11869,7 @@ var SavedViewsDeleteConfirmationModalShared = ({
12030
11869
  onDelete,
12031
11870
  open
12032
11871
  }) => {
12033
- const i18n = useI18nContext6();
11872
+ const i18n = useI18nContext5();
12034
11873
  return /* @__PURE__ */ React18.createElement(
12035
11874
  ConfirmModal,
12036
11875
  {
@@ -12061,7 +11900,7 @@ import {
12061
11900
  Modal as Modal2,
12062
11901
  spacing as spacing3,
12063
11902
  Typography as Typography2,
12064
- useI18nContext as useI18nContext7
11903
+ useI18nContext as useI18nContext6
12065
11904
  } from "@procore/core-react";
12066
11905
  import * as React19 from "react";
12067
11906
 
@@ -14391,6 +14230,7 @@ function extractMessage(error, I18n) {
14391
14230
  }
14392
14231
 
14393
14232
  // src/components/modals/form-modal/FormModalBase.tsx
14233
+ var { useEffect: useEffect2, useRef: useRef2 } = React19;
14394
14234
  var ScrollContainer = styled_components_esm_default("div")`
14395
14235
  overflow: auto;
14396
14236
  `;
@@ -14407,22 +14247,38 @@ var FormModalBase = ({
14407
14247
  defaultView,
14408
14248
  selectedSavedView,
14409
14249
  setOpenEditCreateModal,
14410
- onSelect
14250
+ onSelect,
14251
+ backend
14411
14252
  }) => {
14412
- const I18n = useI18nContext7();
14253
+ const I18n = useI18nContext6();
14413
14254
  const NAME_MAX_LENGTH = 150;
14255
+ const originalBodyWidth = useRef2("");
14256
+ useEffect2(() => {
14257
+ if (open) {
14258
+ originalBodyWidth.current = document.body.style.width || "";
14259
+ document.body.style.width = "100%";
14260
+ } else {
14261
+ document.body.style.width = originalBodyWidth.current;
14262
+ }
14263
+ return () => {
14264
+ if (originalBodyWidth.current !== void 0) {
14265
+ document.body.style.width = originalBodyWidth.current;
14266
+ }
14267
+ };
14268
+ }, [open]);
14269
+ const { useCreateSavedView: useCreateSavedView2, useUpdateSavedView: useUpdateSavedView2, useSavedViewsPermissions: useSavedViewsPermissions2 } = backend;
14414
14270
  const {
14415
14271
  mutate: createSavedView,
14416
14272
  isPending: isCreating,
14417
14273
  error: createError,
14418
14274
  reset: resetCreateMutation
14419
- } = useCreateSavedView(queryInput);
14275
+ } = useCreateSavedView2(queryInput);
14420
14276
  const {
14421
14277
  mutate: updateSavedView,
14422
14278
  isPending: isUpdating,
14423
14279
  error: updateError,
14424
14280
  reset: resetUpdateMutation
14425
- } = useUpdateSavedView(queryInput);
14281
+ } = useUpdateSavedView2(queryInput);
14426
14282
  const resetMutations = () => {
14427
14283
  resetCreateMutation();
14428
14284
  resetUpdateMutation();
@@ -14431,7 +14287,7 @@ var FormModalBase = ({
14431
14287
  resetMutations();
14432
14288
  onCancel();
14433
14289
  };
14434
- const { data: permissions } = useSavedViewsPermissions(queryInput);
14290
+ const { data: permissions } = useSavedViewsPermissions2(queryInput);
14435
14291
  const isLoading = isCreating || isUpdating;
14436
14292
  const errors = extractMessage(createError || updateError, I18n);
14437
14293
  const handleOnSubmit = (data) => {
@@ -14542,6 +14398,7 @@ var FormModalBase = ({
14542
14398
  Form.Select,
14543
14399
  {
14544
14400
  name: "view_level",
14401
+ qa: { label: "view-level" },
14545
14402
  options: viewLevelOptions,
14546
14403
  label: I18n.t("savedViews.modal.fields.viewLevel"),
14547
14404
  colWidth: 12,
@@ -14565,7 +14422,7 @@ var FormModalBase = ({
14565
14422
  };
14566
14423
 
14567
14424
  // src/components/modals/form-modal/FormModal.tsx
14568
- import { useI18nContext as useI18nContext8 } from "@procore/core-react";
14425
+ import { useI18nContext as useI18nContext7 } from "@procore/core-react";
14569
14426
  var FormModal = ({
14570
14427
  open,
14571
14428
  mode,
@@ -14576,9 +14433,10 @@ var FormModal = ({
14576
14433
  selectedSavedView,
14577
14434
  setOpenEditCreateModal,
14578
14435
  onSelect,
14579
- defaultView
14436
+ defaultView,
14437
+ backend
14580
14438
  }) => {
14581
- const i18n = useI18nContext8();
14439
+ const i18n = useI18nContext7();
14582
14440
  return /* @__PURE__ */ React20.createElement(
14583
14441
  FormModalBase,
14584
14442
  {
@@ -14594,7 +14452,8 @@ var FormModal = ({
14594
14452
  selectedSavedView,
14595
14453
  setOpenEditCreateModal,
14596
14454
  onSelect,
14597
- defaultView
14455
+ defaultView,
14456
+ backend
14598
14457
  }
14599
14458
  );
14600
14459
  };
@@ -14611,7 +14470,7 @@ import {
14611
14470
  P as P3,
14612
14471
  spacing as spacing4,
14613
14472
  Typography as Typography3,
14614
- useI18nContext as useI18nContext9
14473
+ useI18nContext as useI18nContext8
14615
14474
  } from "@procore/core-react";
14616
14475
  import * as React21 from "react";
14617
14476
  var SharedViewFormModal = ({
@@ -14624,7 +14483,7 @@ var SharedViewFormModal = ({
14624
14483
  isCreating,
14625
14484
  resetCreateError
14626
14485
  }) => {
14627
- const I18n = useI18nContext9();
14486
+ const I18n = useI18nContext8();
14628
14487
  const NAME_MAX_LENGTH = 150;
14629
14488
  const errors = extractMessage(createError, I18n);
14630
14489
  const handleNameChange = () => {
@@ -14754,9 +14613,9 @@ var SharedViewFormModal = ({
14754
14613
  };
14755
14614
 
14756
14615
  // src/utils/hooks/useViewSelection.ts
14757
- import { useState as useState3, useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useMemo } from "react";
14616
+ import { useState as useState3, useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3, useMemo } from "react";
14758
14617
  import { useSearchParams } from "react-router-dom";
14759
- import { useI18nContext as useI18nContext10 } from "@procore/core-react";
14618
+ import { useI18nContext as useI18nContext9 } from "@procore/core-react";
14760
14619
 
14761
14620
  // src/utils/viewStorage.ts
14762
14621
  var ViewStorage = {
@@ -14819,11 +14678,11 @@ var restoreUrlParameter = (currentParam, previousParam, setSearchParams) => {
14819
14678
  }
14820
14679
  };
14821
14680
  var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) => {
14822
- const I18n = useI18nContext10();
14681
+ const I18n = useI18nContext9();
14823
14682
  const storageKey = `savedView_${config.domain}_${config.tableName}_${config.companyId}_${config.projectId}_${config.userId}`;
14824
14683
  const temporaryStorageKey = `${storageKey}-temporary`;
14825
14684
  const [searchParams, setSearchParams] = useSearchParams();
14826
- const previousSavedViewParamRef = useRef2(null);
14685
+ const previousSavedViewParamRef = useRef3(null);
14827
14686
  const [selectedSavedView, setSelectedSavedView] = useState3(() => {
14828
14687
  const stored = ViewStorage.load(storageKey, config.defaultView);
14829
14688
  return stored ?? config.defaultView;
@@ -14894,7 +14753,7 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) =>
14894
14753
  },
14895
14754
  [isViewAlreadySelected, openSharedViewModal, allViews, selectView]
14896
14755
  );
14897
- useEffect2(() => {
14756
+ useEffect3(() => {
14898
14757
  const savedViewId = searchParams.get("saved-view");
14899
14758
  restoreUrlParameter(
14900
14759
  savedViewId,
@@ -14918,6 +14777,177 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) =>
14918
14777
  };
14919
14778
  };
14920
14779
 
14780
+ // node_modules/@procore/core-http/dist/modern/index.js
14781
+ function getCSRFToken() {
14782
+ const token = document.cookie.match("(^|;)\\s*csrf_token\\s*=\\s*([^;]+)");
14783
+ return token ? decodeURIComponent(token.pop() || "") : "";
14784
+ }
14785
+ function getCSRFHeader() {
14786
+ const csrfToken = getCSRFToken();
14787
+ return csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {};
14788
+ }
14789
+ function removeLeadingSlash(url) {
14790
+ return url.startsWith("/") ? url.substring(1, url.length) : url;
14791
+ }
14792
+ function removeTrailingSlash(url) {
14793
+ return url.endsWith("/") ? url.substring(0, url.length - 1) : url;
14794
+ }
14795
+ function applyBaseUrl(url, baseUrl) {
14796
+ return `${removeTrailingSlash(baseUrl)}/${removeLeadingSlash(url)}`;
14797
+ }
14798
+ function getOptions({ headers, ...options }) {
14799
+ const opts = {
14800
+ credentials: "same-origin",
14801
+ headers: {
14802
+ ...getCSRFHeader(),
14803
+ ...headers
14804
+ },
14805
+ mode: "same-origin",
14806
+ ...options
14807
+ };
14808
+ return opts;
14809
+ }
14810
+ function getUrl(url, baseUrl) {
14811
+ return baseUrl ? applyBaseUrl(url, baseUrl) : url;
14812
+ }
14813
+ function request(url, { baseUrl, ...options } = {}) {
14814
+ return fetch(getUrl(url, baseUrl), getOptions(options));
14815
+ }
14816
+ function requestJSON(url, requestParams = {}) {
14817
+ return request(url, requestParams).then(
14818
+ (response) => response.json()
14819
+ );
14820
+ }
14821
+
14822
+ // src/utils/api/queries.ts
14823
+ import { useQuery } from "@tanstack/react-query";
14824
+
14825
+ // src/utils/api/queriesHandler.ts
14826
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
14827
+ import { useI18nContext as useI18nContext10 } from "@procore/core-react";
14828
+ var useApiRequest = (props, method, mutationKey) => {
14829
+ const { projectId, companyId, domain, tableName } = props;
14830
+ const queryClient2 = useQueryClient();
14831
+ const { locale: locale2 } = useI18nContext10();
14832
+ return useMutation({
14833
+ mutationKey,
14834
+ mutationFn: async (savedView) => {
14835
+ let url = "";
14836
+ if (method === "DELETE" || method === "PUT") {
14837
+ url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedView.share_token}?permissions_domain=${domain}`;
14838
+ } else {
14839
+ url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
14840
+ }
14841
+ const response = await requestJSON(url, {
14842
+ method,
14843
+ body: JSON.stringify(savedView),
14844
+ headers: {
14845
+ "Content-Type": "application/json",
14846
+ "Accept-Language": locale2
14847
+ }
14848
+ });
14849
+ if (response.error) {
14850
+ throw response.error;
14851
+ }
14852
+ return response.data;
14853
+ },
14854
+ onSuccess: (savedView) => {
14855
+ if (method === "DELETE" || method === "POST") {
14856
+ queryClient2.invalidateQueries({
14857
+ queryKey: ["savedViews", domain, tableName]
14858
+ });
14859
+ return;
14860
+ } else {
14861
+ const oldData = queryClient2.getQueryData([
14862
+ "savedViews",
14863
+ domain,
14864
+ tableName
14865
+ ]);
14866
+ const oldView = oldData?.find(
14867
+ (item) => item.share_token === savedView.share_token
14868
+ );
14869
+ if (oldView?.name !== savedView.name) {
14870
+ queryClient2.invalidateQueries({
14871
+ queryKey: ["savedViews", domain, tableName]
14872
+ });
14873
+ return;
14874
+ }
14875
+ }
14876
+ queryClient2.setQueryData(
14877
+ ["savedViews", domain, tableName],
14878
+ (oldData) => {
14879
+ if (!oldData)
14880
+ return [savedView];
14881
+ return oldData.map(
14882
+ (item) => item.share_token === savedView.share_token ? savedView : item
14883
+ );
14884
+ }
14885
+ );
14886
+ }
14887
+ });
14888
+ };
14889
+
14890
+ // src/utils/api/queries.ts
14891
+ var PAGE_SIZE = 50 * VIEW_LEVELS.length;
14892
+ var useSavedViewsQuery = (props) => {
14893
+ const { projectId, companyId, domain, tableName } = props;
14894
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
14895
+ return useQuery({
14896
+ queryKey: ["savedViews", domain, tableName],
14897
+ queryFn: async () => {
14898
+ const getUrl2 = `${url}&per_page=${PAGE_SIZE}`;
14899
+ const response = await requestJSON(getUrl2);
14900
+ return response.data;
14901
+ }
14902
+ });
14903
+ };
14904
+ var useSavedViewsPermissions = (props) => {
14905
+ const { projectId, companyId, domain } = props;
14906
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/permissions?permissions_domain=${domain}`;
14907
+ return useQuery({
14908
+ queryKey: ["savedViewsConfig", domain],
14909
+ queryFn: async () => {
14910
+ const response = await requestJSON(url);
14911
+ return response.data;
14912
+ }
14913
+ });
14914
+ };
14915
+ var useCreateSavedView = (props) => useApiRequest(props, "POST", [
14916
+ "createSavedView",
14917
+ props.domain,
14918
+ props.tableName
14919
+ ]);
14920
+ var useUpdateSavedView = (props) => useApiRequest(props, "PUT", [
14921
+ "updateSavedView",
14922
+ props.domain,
14923
+ props.tableName
14924
+ ]);
14925
+ var useDeleteSavedView = (props) => useApiRequest(props, "DELETE", [
14926
+ "deleteSavedView",
14927
+ props.domain,
14928
+ props.tableName
14929
+ ]);
14930
+ var useFetchSavedViewById = (savedViewToken, queryInput, enabled = true) => {
14931
+ const { projectId, companyId } = queryInput;
14932
+ return useQuery({
14933
+ enabled: enabled && Boolean(savedViewToken),
14934
+ queryKey: ["savedView", savedViewToken],
14935
+ queryFn: async () => {
14936
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedViewToken}`;
14937
+ const response = await requestJSON(url);
14938
+ return response.data;
14939
+ }
14940
+ });
14941
+ };
14942
+ var createQueries = (customBackend) => ({
14943
+ useSavedViewsQuery: customBackend?.useSavedViewsQuery ?? useSavedViewsQuery,
14944
+ useSavedViewsPermissions: customBackend?.useSavedViewsPermissions ?? useSavedViewsPermissions,
14945
+ useCreateSavedView: customBackend?.useCreateSavedView ?? useCreateSavedView,
14946
+ useUpdateSavedView: customBackend?.useUpdateSavedView ?? useUpdateSavedView,
14947
+ useDeleteSavedView: customBackend?.useDeleteSavedView ?? useDeleteSavedView,
14948
+ useFetchSavedViewById: customBackend?.useFetchSavedViewById ?? useFetchSavedViewById
14949
+ });
14950
+
14921
14951
  // src/components/saved-views/SavedViews.tsx
14922
14952
  var StyledPanel = styled_components_esm_default.div`
14923
14953
  border: ${({ provider }) => provider === "data-table" ? "1px solid #d6dadc" : "none"};
@@ -14925,14 +14955,15 @@ var StyledPanel = styled_components_esm_default.div`
14925
14955
  var queryClient = new QueryClient();
14926
14956
  var SavedViewsContent = (props) => {
14927
14957
  const { projectId, companyId } = props;
14958
+ const backend = createQueries(props.backend);
14928
14959
  const queryInput = {
14929
14960
  domain: props.domain,
14930
14961
  tableName: props.tableName,
14931
14962
  projectId,
14932
14963
  companyId
14933
14964
  };
14934
- const { data: savedViews } = useSavedViewsQuery(queryInput);
14935
- const { mutate: deleteSavedView } = useDeleteSavedView(queryInput);
14965
+ const { data: savedViews } = backend.useSavedViewsQuery(queryInput);
14966
+ const { mutate: deleteSavedView } = backend.useDeleteSavedView(queryInput);
14936
14967
  const { showToast } = useToastAlertContext3();
14937
14968
  const i18n = useI18nContext11();
14938
14969
  const [activeModal, setActiveModal] = useState4(null);
@@ -14969,7 +15000,7 @@ var SavedViewsContent = (props) => {
14969
15000
  props.presetViews,
14970
15001
  openSharedViewModal
14971
15002
  );
14972
- const { data: fetchedView, isError: fetchError } = useFetchSavedViewById(
15003
+ const { data: fetchedView, isError: fetchError } = backend.useFetchSavedViewById(
14973
15004
  modalData?.viewId ?? null,
14974
15005
  queryInput,
14975
15006
  Boolean(modalData?.viewId)
@@ -14979,8 +15010,8 @@ var SavedViewsContent = (props) => {
14979
15010
  isPending: isCreating,
14980
15011
  error: createError,
14981
15012
  reset: resetCreateError
14982
- } = useCreateSavedView(queryInput);
14983
- useEffect3(() => {
15013
+ } = backend.useCreateSavedView(queryInput);
15014
+ useEffect4(() => {
14984
15015
  if (fetchError) {
14985
15016
  showToast.error(i18n.t("savedViews.errors.notFound"));
14986
15017
  selectView(selectedView ?? props.defaultView);
@@ -15066,7 +15097,8 @@ var SavedViewsContent = (props) => {
15066
15097
  savedViews: allViews,
15067
15098
  provider: props.provider,
15068
15099
  userId: props.userId,
15069
- onClearTemporary: clearTemporaryView
15100
+ onClearTemporary: clearTemporaryView,
15101
+ backend
15070
15102
  }
15071
15103
  ))
15072
15104
  ), (isModalOpen("create" /* CREATE */) || isModalOpen("update" /* UPDATE */)) && /* @__PURE__ */ React22.createElement(
@@ -15081,7 +15113,8 @@ var SavedViewsContent = (props) => {
15081
15113
  selectedSavedView: selectedView,
15082
15114
  onSelect: selectView,
15083
15115
  setOpenEditCreateModal: closeModal,
15084
- defaultView: props.defaultView
15116
+ defaultView: props.defaultView,
15117
+ backend
15085
15118
  }
15086
15119
  ), selectedView && isModalOpen("delete" /* DELETE */) && /* @__PURE__ */ React22.createElement(
15087
15120
  SavedViewsDeleteConfirmationModalShared,
@@ -15172,7 +15205,7 @@ var useNormalizedDefaultViews = (defaultViews, gridApi) => {
15172
15205
  };
15173
15206
 
15174
15207
  // src/components/adapters/smart-grid/useSmartGridConfig.ts
15175
- import { useState as useState5, useEffect as useEffect4 } from "react";
15208
+ import { useState as useState5, useEffect as useEffect5, useRef as useRef4 } from "react";
15176
15209
  var GRID_STATE_EVENTS = [
15177
15210
  "sortChanged",
15178
15211
  "filterOpened",
@@ -15191,10 +15224,14 @@ var useSmartGridConfig = (gridApi) => {
15191
15224
  const [config, setConfig] = useState5(
15192
15225
  () => getSmartGridConfig(gridApi)
15193
15226
  );
15194
- useEffect4(() => {
15227
+ const eventListenersDisabledRef = useRef4(false);
15228
+ useEffect5(() => {
15195
15229
  if (!gridApi)
15196
15230
  return;
15197
15231
  const updateConfig = () => {
15232
+ if (eventListenersDisabledRef.current) {
15233
+ return;
15234
+ }
15198
15235
  setConfig(getSmartGridConfig(gridApi));
15199
15236
  };
15200
15237
  GRID_STATE_EVENTS.forEach((event) => {
@@ -15206,7 +15243,13 @@ var useSmartGridConfig = (gridApi) => {
15206
15243
  });
15207
15244
  };
15208
15245
  }, [gridApi]);
15209
- return { config, setConfig };
15246
+ const disableEventListeners = () => {
15247
+ eventListenersDisabledRef.current = true;
15248
+ };
15249
+ const enableEventListeners = () => {
15250
+ eventListenersDisabledRef.current = false;
15251
+ };
15252
+ return { config, setConfig, disableEventListeners, enableEventListeners };
15210
15253
  };
15211
15254
 
15212
15255
  // src/components/adapters/smart-grid/SmartGridSavedViews.tsx
@@ -15250,7 +15293,8 @@ var SmartGridSavedViews = (props) => {
15250
15293
  defaultView,
15251
15294
  presetViews,
15252
15295
  tableName: props.tableName,
15253
- tableConfig
15296
+ tableConfig,
15297
+ backend: props.backend
15254
15298
  }
15255
15299
  );
15256
15300
  };