@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.
@@ -11436,176 +11436,13 @@ var ExpandedPanel = styled_components_esm_default(Panel)`
11436
11436
  `;
11437
11437
 
11438
11438
  // src/components/panels/PanelContent.tsx
11439
- import { Flex as Flex3, useI18nContext as useI18nContext5 } from "@procore/core-react";
11439
+ import { Flex as Flex3, useI18nContext as useI18nContext4 } from "@procore/core-react";
11440
11440
  import { useToastAlertContext as useToastAlertContext2 } from "@procore/toast-alert";
11441
11441
  import React17 from "react";
11442
11442
 
11443
- // node_modules/@procore/core-http/dist/modern/index.js
11444
- function getCSRFToken() {
11445
- const token = document.cookie.match("(^|;)\\s*csrf_token\\s*=\\s*([^;]+)");
11446
- return token ? decodeURIComponent(token.pop() || "") : "";
11447
- }
11448
- function getCSRFHeader() {
11449
- const csrfToken = getCSRFToken();
11450
- return csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {};
11451
- }
11452
- function removeLeadingSlash(url) {
11453
- return url.startsWith("/") ? url.substring(1, url.length) : url;
11454
- }
11455
- function removeTrailingSlash(url) {
11456
- return url.endsWith("/") ? url.substring(0, url.length - 1) : url;
11457
- }
11458
- function applyBaseUrl(url, baseUrl) {
11459
- return `${removeTrailingSlash(baseUrl)}/${removeLeadingSlash(url)}`;
11460
- }
11461
- function getOptions({ headers, ...options }) {
11462
- const opts = {
11463
- credentials: "same-origin",
11464
- headers: {
11465
- ...getCSRFHeader(),
11466
- ...headers
11467
- },
11468
- mode: "same-origin",
11469
- ...options
11470
- };
11471
- return opts;
11472
- }
11473
- function getUrl(url, baseUrl) {
11474
- return baseUrl ? applyBaseUrl(url, baseUrl) : url;
11475
- }
11476
- function request(url, { baseUrl, ...options } = {}) {
11477
- return fetch(getUrl(url, baseUrl), getOptions(options));
11478
- }
11479
- function requestJSON(url, requestParams = {}) {
11480
- return request(url, requestParams).then(
11481
- (response) => response.json()
11482
- );
11483
- }
11484
-
11485
- // src/utils/api/queries.ts
11486
- import { useQuery } from "@tanstack/react-query";
11487
-
11488
- // src/utils/api/queriesHandler.ts
11489
- import { useMutation, useQueryClient } from "@tanstack/react-query";
11490
- import { useI18nContext as useI18nContext3 } from "@procore/core-react";
11491
- var useApiRequest = (props, method, mutationKey) => {
11492
- const { projectId, companyId, domain, tableName } = props;
11493
- const queryClient2 = useQueryClient();
11494
- const { locale: locale2 } = useI18nContext3();
11495
- return useMutation({
11496
- mutationKey,
11497
- mutationFn: async (savedView) => {
11498
- let url = "";
11499
- if (method === "DELETE" || method === "PUT") {
11500
- url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedView.share_token}?permissions_domain=${domain}`;
11501
- } else {
11502
- url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
11503
- }
11504
- const response = await requestJSON(url, {
11505
- method,
11506
- body: JSON.stringify(savedView),
11507
- headers: {
11508
- "Content-Type": "application/json",
11509
- "Accept-Language": locale2
11510
- }
11511
- });
11512
- if (response.error) {
11513
- throw response.error;
11514
- }
11515
- return response.data;
11516
- },
11517
- onSuccess: (savedView) => {
11518
- if (method === "DELETE" || method === "POST") {
11519
- queryClient2.invalidateQueries({
11520
- queryKey: ["savedViews", domain, tableName]
11521
- });
11522
- return;
11523
- } else {
11524
- const oldData = queryClient2.getQueryData([
11525
- "savedViews",
11526
- domain,
11527
- tableName
11528
- ]);
11529
- const oldView = oldData == null ? void 0 : oldData.find(
11530
- (item) => item.share_token === savedView.share_token
11531
- );
11532
- if ((oldView == null ? void 0 : oldView.name) !== savedView.name) {
11533
- queryClient2.invalidateQueries({
11534
- queryKey: ["savedViews", domain, tableName]
11535
- });
11536
- return;
11537
- }
11538
- }
11539
- queryClient2.setQueryData(
11540
- ["savedViews", domain, tableName],
11541
- (oldData) => {
11542
- if (!oldData)
11543
- return [savedView];
11544
- return oldData.map(
11545
- (item) => item.share_token === savedView.share_token ? savedView : item
11546
- );
11547
- }
11548
- );
11549
- }
11550
- });
11551
- };
11552
-
11553
11443
  // src/utils/constants/viewLevels.ts
11554
11444
  var VIEW_LEVELS = ["company", "project", "personal"];
11555
11445
 
11556
- // src/utils/api/queries.ts
11557
- var PAGE_SIZE = 50 * VIEW_LEVELS.length;
11558
- var useSavedViewsQuery = (props) => {
11559
- const { projectId, companyId, domain, tableName } = props;
11560
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
11561
- return useQuery({
11562
- queryKey: ["savedViews", domain, tableName],
11563
- queryFn: async () => {
11564
- const getUrl2 = `${url}&per_page=${PAGE_SIZE}`;
11565
- const response = await requestJSON(getUrl2);
11566
- return response.data;
11567
- }
11568
- });
11569
- };
11570
- var useSavedViewsPermissions = (props) => {
11571
- const { projectId, companyId, domain } = props;
11572
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/permissions?permissions_domain=${domain}`;
11573
- return useQuery({
11574
- queryKey: ["savedViewsConfig", domain],
11575
- queryFn: async () => {
11576
- const response = await requestJSON(url);
11577
- return response.data;
11578
- }
11579
- });
11580
- };
11581
- var useCreateSavedView = (props) => useApiRequest(props, "POST", [
11582
- "createSavedView",
11583
- props.domain,
11584
- props.tableName
11585
- ]);
11586
- var useUpdateSavedView = (props) => useApiRequest(props, "PUT", [
11587
- "updateSavedView",
11588
- props.domain,
11589
- props.tableName
11590
- ]);
11591
- var useDeleteSavedView = (props) => useApiRequest(props, "DELETE", [
11592
- "deleteSavedView",
11593
- props.domain,
11594
- props.tableName
11595
- ]);
11596
- var useFetchSavedViewById = (savedViewToken, queryInput, enabled = true) => {
11597
- const { projectId, companyId } = queryInput;
11598
- return useQuery({
11599
- enabled: enabled && Boolean(savedViewToken),
11600
- queryKey: ["savedView", savedViewToken],
11601
- queryFn: async () => {
11602
- const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedViewToken}`;
11603
- const response = await requestJSON(url);
11604
- return response.data;
11605
- }
11606
- });
11607
- };
11608
-
11609
11446
  // src/components/panels/PanelContentUtils.ts
11610
11447
  var import_lodash = __toESM(require_lodash());
11611
11448
 
@@ -11755,12 +11592,13 @@ var normalizeForComparison = (config) => {
11755
11592
  if (!(config == null ? void 0 : config.columnState))
11756
11593
  return config;
11757
11594
  return {
11758
- ...config,
11595
+ ...import_lodash.default.omit(config, ["enableRowGrouping", "enableColumnGrouping"]),
11759
11596
  columnState: config.columnState.map((col) => {
11597
+ const res = import_lodash.default.omit(col, ["aggFunc"]);
11760
11598
  if (col.flex) {
11761
- return import_lodash.default.omit(col, ["width", "flex"]);
11599
+ return import_lodash.default.omit(res, ["width", "flex"]);
11762
11600
  }
11763
- return col;
11601
+ return res;
11764
11602
  })
11765
11603
  };
11766
11604
  };
@@ -11773,10 +11611,9 @@ var isEqual = (viewTableConfig, tableConfig, defaultViewConfig, provider) => {
11773
11611
  );
11774
11612
  const normalizedViewConfig = normalizeForComparison(syncedViewTableConfig);
11775
11613
  const normalizedCurrentConfig = normalizeForComparison(tableConfig);
11776
- return import_lodash.default.isEqual(
11777
- cleanObject(normalizedViewConfig, provider),
11778
- cleanObject(normalizedCurrentConfig, provider)
11779
- );
11614
+ const cleanedViewConfig = cleanObject(normalizedViewConfig, provider);
11615
+ const cleanedCurrentConfig = cleanObject(normalizedCurrentConfig, provider);
11616
+ return import_lodash.default.isEqual(cleanedViewConfig, cleanedCurrentConfig);
11780
11617
  };
11781
11618
  var hasPermissionForViewLevel = (viewLevel, permissions) => {
11782
11619
  switch (viewLevel) {
@@ -11809,7 +11646,7 @@ import {
11809
11646
  Flex as Flex2,
11810
11647
  spacing,
11811
11648
  Typography,
11812
- useI18nContext as useI18nContext4
11649
+ useI18nContext as useI18nContext3
11813
11650
  } from "@procore/core-react";
11814
11651
  import React16 from "react";
11815
11652
  var groupIcon = (group) => {
@@ -11829,7 +11666,7 @@ var Header = styled_components_esm_default(Flex2)`
11829
11666
  }
11830
11667
  `;
11831
11668
  var ViewLevelHeader = ({ expanded, toggleGroup, group }) => {
11832
- const I18n = useI18nContext4();
11669
+ const I18n = useI18nContext3();
11833
11670
  return /* @__PURE__ */ React16.createElement(
11834
11671
  Header,
11835
11672
  {
@@ -11886,9 +11723,9 @@ var Panel2 = styled_components_esm_default(DetailPage.Card)`
11886
11723
  var PanelContent = (props) => {
11887
11724
  const { queryInput, selectedSavedView, tableConfig } = props;
11888
11725
  const { showToast } = useToastAlertContext2();
11889
- const I18n = useI18nContext5();
11890
- const { data: savedViewsFromQuery, error: savedViewsError } = useSavedViewsQuery(props.queryInput);
11891
- const updateMutation = useUpdateSavedView(queryInput);
11726
+ const I18n = useI18nContext4();
11727
+ const { data: savedViewsFromQuery, error: savedViewsError } = props.backend.useSavedViewsQuery(props.queryInput);
11728
+ const updateMutation = props.backend.useUpdateSavedView(queryInput);
11892
11729
  const { mutate: updateSavedView } = updateMutation;
11893
11730
  const isUpdateLoading = "isPending" in updateMutation ? updateMutation.isPending : updateMutation.isLoading ?? false;
11894
11731
  const savedViews = props.savedViews ?? savedViewsFromQuery;
@@ -11899,7 +11736,9 @@ var PanelContent = (props) => {
11899
11736
  errorToastRef.current = savedViewsError;
11900
11737
  }
11901
11738
  }, [savedViewsError, showToast, I18n]);
11902
- const { data: permissions } = useSavedViewsPermissions(props.queryInput);
11739
+ const { data: permissions } = props.backend.useSavedViewsPermissions(
11740
+ props.queryInput
11741
+ );
11903
11742
  const selectedRowRef = useScrollToRef(savedViews);
11904
11743
  const { groups, toggleGroup } = useGroups();
11905
11744
  const isTemporarySelected = (selectedSavedView == null ? void 0 : selectedSavedView.id) === "temporary";
@@ -12015,7 +11854,7 @@ import {
12015
11854
  Tooltip,
12016
11855
  useI18nContext as useI18nContext11
12017
11856
  } from "@procore/core-react";
12018
- import React22, { useState as useState4, useEffect as useEffect3, useCallback as useCallback3 } from "react";
11857
+ import React22, { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
12019
11858
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
12020
11859
  import { useToastAlertContext as useToastAlertContext3, ToastAlertProvider } from "@procore/toast-alert";
12021
11860
 
@@ -12025,7 +11864,7 @@ import {
12025
11864
  ConfirmModal,
12026
11865
  Modal,
12027
11866
  P as P2,
12028
- useI18nContext as useI18nContext6
11867
+ useI18nContext as useI18nContext5
12029
11868
  } from "@procore/core-react";
12030
11869
  import React18 from "react";
12031
11870
  var SavedViewsDeleteConfirmationModalShared = ({
@@ -12033,7 +11872,7 @@ var SavedViewsDeleteConfirmationModalShared = ({
12033
11872
  onDelete,
12034
11873
  open
12035
11874
  }) => {
12036
- const i18n = useI18nContext6();
11875
+ const i18n = useI18nContext5();
12037
11876
  return /* @__PURE__ */ React18.createElement(
12038
11877
  ConfirmModal,
12039
11878
  {
@@ -12064,7 +11903,7 @@ import {
12064
11903
  Modal as Modal2,
12065
11904
  spacing as spacing3,
12066
11905
  Typography as Typography2,
12067
- useI18nContext as useI18nContext7
11906
+ useI18nContext as useI18nContext6
12068
11907
  } from "@procore/core-react";
12069
11908
  import * as React19 from "react";
12070
11909
 
@@ -14394,6 +14233,7 @@ function extractMessage(error, I18n) {
14394
14233
  }
14395
14234
 
14396
14235
  // src/components/modals/form-modal/FormModalBase.tsx
14236
+ var { useEffect: useEffect2, useRef: useRef2 } = React19;
14397
14237
  var ScrollContainer = styled_components_esm_default("div")`
14398
14238
  overflow: auto;
14399
14239
  `;
@@ -14410,22 +14250,38 @@ var FormModalBase = ({
14410
14250
  defaultView,
14411
14251
  selectedSavedView,
14412
14252
  setOpenEditCreateModal,
14413
- onSelect
14253
+ onSelect,
14254
+ backend
14414
14255
  }) => {
14415
- const I18n = useI18nContext7();
14256
+ const I18n = useI18nContext6();
14416
14257
  const NAME_MAX_LENGTH = 150;
14258
+ const originalBodyWidth = useRef2("");
14259
+ useEffect2(() => {
14260
+ if (open) {
14261
+ originalBodyWidth.current = document.body.style.width || "";
14262
+ document.body.style.width = "100%";
14263
+ } else {
14264
+ document.body.style.width = originalBodyWidth.current;
14265
+ }
14266
+ return () => {
14267
+ if (originalBodyWidth.current !== void 0) {
14268
+ document.body.style.width = originalBodyWidth.current;
14269
+ }
14270
+ };
14271
+ }, [open]);
14272
+ const { useCreateSavedView: useCreateSavedView2, useUpdateSavedView: useUpdateSavedView2, useSavedViewsPermissions: useSavedViewsPermissions2 } = backend;
14417
14273
  const {
14418
14274
  mutate: createSavedView,
14419
14275
  isPending: isCreating,
14420
14276
  error: createError,
14421
14277
  reset: resetCreateMutation
14422
- } = useCreateSavedView(queryInput);
14278
+ } = useCreateSavedView2(queryInput);
14423
14279
  const {
14424
14280
  mutate: updateSavedView,
14425
14281
  isPending: isUpdating,
14426
14282
  error: updateError,
14427
14283
  reset: resetUpdateMutation
14428
- } = useUpdateSavedView(queryInput);
14284
+ } = useUpdateSavedView2(queryInput);
14429
14285
  const resetMutations = () => {
14430
14286
  resetCreateMutation();
14431
14287
  resetUpdateMutation();
@@ -14434,7 +14290,7 @@ var FormModalBase = ({
14434
14290
  resetMutations();
14435
14291
  onCancel();
14436
14292
  };
14437
- const { data: permissions } = useSavedViewsPermissions(queryInput);
14293
+ const { data: permissions } = useSavedViewsPermissions2(queryInput);
14438
14294
  const isLoading = isCreating || isUpdating;
14439
14295
  const errors = extractMessage(createError || updateError, I18n);
14440
14296
  const handleOnSubmit = (data) => {
@@ -14545,6 +14401,7 @@ var FormModalBase = ({
14545
14401
  Form.Select,
14546
14402
  {
14547
14403
  name: "view_level",
14404
+ qa: { label: "view-level" },
14548
14405
  options: viewLevelOptions,
14549
14406
  label: I18n.t("savedViews.modal.fields.viewLevel"),
14550
14407
  colWidth: 12,
@@ -14568,7 +14425,7 @@ var FormModalBase = ({
14568
14425
  };
14569
14426
 
14570
14427
  // src/components/modals/form-modal/FormModal.tsx
14571
- import { useI18nContext as useI18nContext8 } from "@procore/core-react";
14428
+ import { useI18nContext as useI18nContext7 } from "@procore/core-react";
14572
14429
  var FormModal = ({
14573
14430
  open,
14574
14431
  mode,
@@ -14579,9 +14436,10 @@ var FormModal = ({
14579
14436
  selectedSavedView,
14580
14437
  setOpenEditCreateModal,
14581
14438
  onSelect,
14582
- defaultView
14439
+ defaultView,
14440
+ backend
14583
14441
  }) => {
14584
- const i18n = useI18nContext8();
14442
+ const i18n = useI18nContext7();
14585
14443
  return /* @__PURE__ */ React20.createElement(
14586
14444
  FormModalBase,
14587
14445
  {
@@ -14597,7 +14455,8 @@ var FormModal = ({
14597
14455
  selectedSavedView,
14598
14456
  setOpenEditCreateModal,
14599
14457
  onSelect,
14600
- defaultView
14458
+ defaultView,
14459
+ backend
14601
14460
  }
14602
14461
  );
14603
14462
  };
@@ -14614,7 +14473,7 @@ import {
14614
14473
  P as P3,
14615
14474
  spacing as spacing4,
14616
14475
  Typography as Typography3,
14617
- useI18nContext as useI18nContext9
14476
+ useI18nContext as useI18nContext8
14618
14477
  } from "@procore/core-react";
14619
14478
  import * as React21 from "react";
14620
14479
  var SharedViewFormModal = ({
@@ -14627,7 +14486,7 @@ var SharedViewFormModal = ({
14627
14486
  isCreating,
14628
14487
  resetCreateError
14629
14488
  }) => {
14630
- const I18n = useI18nContext9();
14489
+ const I18n = useI18nContext8();
14631
14490
  const NAME_MAX_LENGTH = 150;
14632
14491
  const errors = extractMessage(createError, I18n);
14633
14492
  const handleNameChange = () => {
@@ -14757,9 +14616,9 @@ var SharedViewFormModal = ({
14757
14616
  };
14758
14617
 
14759
14618
  // src/utils/hooks/useViewSelection.ts
14760
- import { useState as useState3, useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useMemo } from "react";
14619
+ import { useState as useState3, useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3, useMemo } from "react";
14761
14620
  import { useSearchParams } from "react-router-dom";
14762
- import { useI18nContext as useI18nContext10 } from "@procore/core-react";
14621
+ import { useI18nContext as useI18nContext9 } from "@procore/core-react";
14763
14622
 
14764
14623
  // src/utils/viewStorage.ts
14765
14624
  var ViewStorage = {
@@ -14822,11 +14681,11 @@ var restoreUrlParameter = (currentParam, previousParam, setSearchParams) => {
14822
14681
  }
14823
14682
  };
14824
14683
  var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) => {
14825
- const I18n = useI18nContext10();
14684
+ const I18n = useI18nContext9();
14826
14685
  const storageKey = `savedView_${config.domain}_${config.tableName}_${config.companyId}_${config.projectId}_${config.userId}`;
14827
14686
  const temporaryStorageKey = `${storageKey}-temporary`;
14828
14687
  const [searchParams, setSearchParams] = useSearchParams();
14829
- const previousSavedViewParamRef = useRef2(null);
14688
+ const previousSavedViewParamRef = useRef3(null);
14830
14689
  const [selectedSavedView, setSelectedSavedView] = useState3(() => {
14831
14690
  const stored = ViewStorage.load(storageKey, config.defaultView);
14832
14691
  return stored ?? config.defaultView;
@@ -14897,7 +14756,7 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) =>
14897
14756
  },
14898
14757
  [isViewAlreadySelected, openSharedViewModal, allViews, selectView]
14899
14758
  );
14900
- useEffect2(() => {
14759
+ useEffect3(() => {
14901
14760
  const savedViewId = searchParams.get("saved-view");
14902
14761
  restoreUrlParameter(
14903
14762
  savedViewId,
@@ -14921,6 +14780,177 @@ var useViewSelection = (config, savedViews, presetViews, openSharedViewModal) =>
14921
14780
  };
14922
14781
  };
14923
14782
 
14783
+ // node_modules/@procore/core-http/dist/modern/index.js
14784
+ function getCSRFToken() {
14785
+ const token = document.cookie.match("(^|;)\\s*csrf_token\\s*=\\s*([^;]+)");
14786
+ return token ? decodeURIComponent(token.pop() || "") : "";
14787
+ }
14788
+ function getCSRFHeader() {
14789
+ const csrfToken = getCSRFToken();
14790
+ return csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {};
14791
+ }
14792
+ function removeLeadingSlash(url) {
14793
+ return url.startsWith("/") ? url.substring(1, url.length) : url;
14794
+ }
14795
+ function removeTrailingSlash(url) {
14796
+ return url.endsWith("/") ? url.substring(0, url.length - 1) : url;
14797
+ }
14798
+ function applyBaseUrl(url, baseUrl) {
14799
+ return `${removeTrailingSlash(baseUrl)}/${removeLeadingSlash(url)}`;
14800
+ }
14801
+ function getOptions({ headers, ...options }) {
14802
+ const opts = {
14803
+ credentials: "same-origin",
14804
+ headers: {
14805
+ ...getCSRFHeader(),
14806
+ ...headers
14807
+ },
14808
+ mode: "same-origin",
14809
+ ...options
14810
+ };
14811
+ return opts;
14812
+ }
14813
+ function getUrl(url, baseUrl) {
14814
+ return baseUrl ? applyBaseUrl(url, baseUrl) : url;
14815
+ }
14816
+ function request(url, { baseUrl, ...options } = {}) {
14817
+ return fetch(getUrl(url, baseUrl), getOptions(options));
14818
+ }
14819
+ function requestJSON(url, requestParams = {}) {
14820
+ return request(url, requestParams).then(
14821
+ (response) => response.json()
14822
+ );
14823
+ }
14824
+
14825
+ // src/utils/api/queries.ts
14826
+ import { useQuery } from "@tanstack/react-query";
14827
+
14828
+ // src/utils/api/queriesHandler.ts
14829
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
14830
+ import { useI18nContext as useI18nContext10 } from "@procore/core-react";
14831
+ var useApiRequest = (props, method, mutationKey) => {
14832
+ const { projectId, companyId, domain, tableName } = props;
14833
+ const queryClient2 = useQueryClient();
14834
+ const { locale: locale2 } = useI18nContext10();
14835
+ return useMutation({
14836
+ mutationKey,
14837
+ mutationFn: async (savedView) => {
14838
+ let url = "";
14839
+ if (method === "DELETE" || method === "PUT") {
14840
+ url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedView.share_token}?permissions_domain=${domain}`;
14841
+ } else {
14842
+ url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
14843
+ }
14844
+ const response = await requestJSON(url, {
14845
+ method,
14846
+ body: JSON.stringify(savedView),
14847
+ headers: {
14848
+ "Content-Type": "application/json",
14849
+ "Accept-Language": locale2
14850
+ }
14851
+ });
14852
+ if (response.error) {
14853
+ throw response.error;
14854
+ }
14855
+ return response.data;
14856
+ },
14857
+ onSuccess: (savedView) => {
14858
+ if (method === "DELETE" || method === "POST") {
14859
+ queryClient2.invalidateQueries({
14860
+ queryKey: ["savedViews", domain, tableName]
14861
+ });
14862
+ return;
14863
+ } else {
14864
+ const oldData = queryClient2.getQueryData([
14865
+ "savedViews",
14866
+ domain,
14867
+ tableName
14868
+ ]);
14869
+ const oldView = oldData == null ? void 0 : oldData.find(
14870
+ (item) => item.share_token === savedView.share_token
14871
+ );
14872
+ if ((oldView == null ? void 0 : oldView.name) !== savedView.name) {
14873
+ queryClient2.invalidateQueries({
14874
+ queryKey: ["savedViews", domain, tableName]
14875
+ });
14876
+ return;
14877
+ }
14878
+ }
14879
+ queryClient2.setQueryData(
14880
+ ["savedViews", domain, tableName],
14881
+ (oldData) => {
14882
+ if (!oldData)
14883
+ return [savedView];
14884
+ return oldData.map(
14885
+ (item) => item.share_token === savedView.share_token ? savedView : item
14886
+ );
14887
+ }
14888
+ );
14889
+ }
14890
+ });
14891
+ };
14892
+
14893
+ // src/utils/api/queries.ts
14894
+ var PAGE_SIZE = 50 * VIEW_LEVELS.length;
14895
+ var useSavedViewsQuery = (props) => {
14896
+ const { projectId, companyId, domain, tableName } = props;
14897
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views?table_name=${tableName}&permissions_domain=${domain}`;
14898
+ return useQuery({
14899
+ queryKey: ["savedViews", domain, tableName],
14900
+ queryFn: async () => {
14901
+ const getUrl2 = `${url}&per_page=${PAGE_SIZE}`;
14902
+ const response = await requestJSON(getUrl2);
14903
+ return response.data;
14904
+ }
14905
+ });
14906
+ };
14907
+ var useSavedViewsPermissions = (props) => {
14908
+ const { projectId, companyId, domain } = props;
14909
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/permissions?permissions_domain=${domain}`;
14910
+ return useQuery({
14911
+ queryKey: ["savedViewsConfig", domain],
14912
+ queryFn: async () => {
14913
+ const response = await requestJSON(url);
14914
+ return response.data;
14915
+ }
14916
+ });
14917
+ };
14918
+ var useCreateSavedView = (props) => useApiRequest(props, "POST", [
14919
+ "createSavedView",
14920
+ props.domain,
14921
+ props.tableName
14922
+ ]);
14923
+ var useUpdateSavedView = (props) => useApiRequest(props, "PUT", [
14924
+ "updateSavedView",
14925
+ props.domain,
14926
+ props.tableName
14927
+ ]);
14928
+ var useDeleteSavedView = (props) => useApiRequest(props, "DELETE", [
14929
+ "deleteSavedView",
14930
+ props.domain,
14931
+ props.tableName
14932
+ ]);
14933
+ var useFetchSavedViewById = (savedViewToken, queryInput, enabled = true) => {
14934
+ const { projectId, companyId } = queryInput;
14935
+ return useQuery({
14936
+ enabled: enabled && Boolean(savedViewToken),
14937
+ queryKey: ["savedView", savedViewToken],
14938
+ queryFn: async () => {
14939
+ const url = `/rest/v2.0/companies/${companyId}/projects/${projectId}/saved_views/${savedViewToken}`;
14940
+ const response = await requestJSON(url);
14941
+ return response.data;
14942
+ }
14943
+ });
14944
+ };
14945
+ var createQueries = (customBackend) => ({
14946
+ useSavedViewsQuery: (customBackend == null ? void 0 : customBackend.useSavedViewsQuery) ?? useSavedViewsQuery,
14947
+ useSavedViewsPermissions: (customBackend == null ? void 0 : customBackend.useSavedViewsPermissions) ?? useSavedViewsPermissions,
14948
+ useCreateSavedView: (customBackend == null ? void 0 : customBackend.useCreateSavedView) ?? useCreateSavedView,
14949
+ useUpdateSavedView: (customBackend == null ? void 0 : customBackend.useUpdateSavedView) ?? useUpdateSavedView,
14950
+ useDeleteSavedView: (customBackend == null ? void 0 : customBackend.useDeleteSavedView) ?? useDeleteSavedView,
14951
+ useFetchSavedViewById: (customBackend == null ? void 0 : customBackend.useFetchSavedViewById) ?? useFetchSavedViewById
14952
+ });
14953
+
14924
14954
  // src/components/saved-views/SavedViews.tsx
14925
14955
  var StyledPanel = styled_components_esm_default.div`
14926
14956
  border: ${({ provider }) => provider === "data-table" ? "1px solid #d6dadc" : "none"};
@@ -14928,14 +14958,15 @@ var StyledPanel = styled_components_esm_default.div`
14928
14958
  var queryClient = new QueryClient();
14929
14959
  var SavedViewsContent = (props) => {
14930
14960
  const { projectId, companyId } = props;
14961
+ const backend = createQueries(props.backend);
14931
14962
  const queryInput = {
14932
14963
  domain: props.domain,
14933
14964
  tableName: props.tableName,
14934
14965
  projectId,
14935
14966
  companyId
14936
14967
  };
14937
- const { data: savedViews } = useSavedViewsQuery(queryInput);
14938
- const { mutate: deleteSavedView } = useDeleteSavedView(queryInput);
14968
+ const { data: savedViews } = backend.useSavedViewsQuery(queryInput);
14969
+ const { mutate: deleteSavedView } = backend.useDeleteSavedView(queryInput);
14939
14970
  const { showToast } = useToastAlertContext3();
14940
14971
  const i18n = useI18nContext11();
14941
14972
  const [activeModal, setActiveModal] = useState4(null);
@@ -14972,7 +15003,7 @@ var SavedViewsContent = (props) => {
14972
15003
  props.presetViews,
14973
15004
  openSharedViewModal
14974
15005
  );
14975
- const { data: fetchedView, isError: fetchError } = useFetchSavedViewById(
15006
+ const { data: fetchedView, isError: fetchError } = backend.useFetchSavedViewById(
14976
15007
  (modalData == null ? void 0 : modalData.viewId) ?? null,
14977
15008
  queryInput,
14978
15009
  Boolean(modalData == null ? void 0 : modalData.viewId)
@@ -14982,8 +15013,8 @@ var SavedViewsContent = (props) => {
14982
15013
  isPending: isCreating,
14983
15014
  error: createError,
14984
15015
  reset: resetCreateError
14985
- } = useCreateSavedView(queryInput);
14986
- useEffect3(() => {
15016
+ } = backend.useCreateSavedView(queryInput);
15017
+ useEffect4(() => {
14987
15018
  if (fetchError) {
14988
15019
  showToast.error(i18n.t("savedViews.errors.notFound"));
14989
15020
  selectView(selectedView ?? props.defaultView);
@@ -15069,7 +15100,8 @@ var SavedViewsContent = (props) => {
15069
15100
  savedViews: allViews,
15070
15101
  provider: props.provider,
15071
15102
  userId: props.userId,
15072
- onClearTemporary: clearTemporaryView
15103
+ onClearTemporary: clearTemporaryView,
15104
+ backend
15073
15105
  }
15074
15106
  ))
15075
15107
  ), (isModalOpen("create" /* CREATE */) || isModalOpen("update" /* UPDATE */)) && /* @__PURE__ */ React22.createElement(
@@ -15084,7 +15116,8 @@ var SavedViewsContent = (props) => {
15084
15116
  selectedSavedView: selectedView,
15085
15117
  onSelect: selectView,
15086
15118
  setOpenEditCreateModal: closeModal,
15087
- defaultView: props.defaultView
15119
+ defaultView: props.defaultView,
15120
+ backend
15088
15121
  }
15089
15122
  ), selectedView && isModalOpen("delete" /* DELETE */) && /* @__PURE__ */ React22.createElement(
15090
15123
  SavedViewsDeleteConfirmationModalShared,
@@ -15176,7 +15209,7 @@ var useNormalizedDefaultViews = (defaultViews, gridApi) => {
15176
15209
  };
15177
15210
 
15178
15211
  // src/components/adapters/smart-grid/useSmartGridConfig.ts
15179
- import { useState as useState5, useEffect as useEffect4 } from "react";
15212
+ import { useState as useState5, useEffect as useEffect5, useRef as useRef4 } from "react";
15180
15213
  var GRID_STATE_EVENTS = [
15181
15214
  "sortChanged",
15182
15215
  "filterOpened",
@@ -15195,10 +15228,14 @@ var useSmartGridConfig = (gridApi) => {
15195
15228
  const [config, setConfig] = useState5(
15196
15229
  () => getSmartGridConfig(gridApi)
15197
15230
  );
15198
- useEffect4(() => {
15231
+ const eventListenersDisabledRef = useRef4(false);
15232
+ useEffect5(() => {
15199
15233
  if (!gridApi)
15200
15234
  return;
15201
15235
  const updateConfig = () => {
15236
+ if (eventListenersDisabledRef.current) {
15237
+ return;
15238
+ }
15202
15239
  setConfig(getSmartGridConfig(gridApi));
15203
15240
  };
15204
15241
  GRID_STATE_EVENTS.forEach((event) => {
@@ -15210,7 +15247,13 @@ var useSmartGridConfig = (gridApi) => {
15210
15247
  });
15211
15248
  };
15212
15249
  }, [gridApi]);
15213
- return { config, setConfig };
15250
+ const disableEventListeners = () => {
15251
+ eventListenersDisabledRef.current = true;
15252
+ };
15253
+ const enableEventListeners = () => {
15254
+ eventListenersDisabledRef.current = false;
15255
+ };
15256
+ return { config, setConfig, disableEventListeners, enableEventListeners };
15214
15257
  };
15215
15258
 
15216
15259
  // src/components/adapters/smart-grid/SmartGridSavedViews.tsx
@@ -15254,7 +15297,8 @@ var SmartGridSavedViews = (props) => {
15254
15297
  defaultView,
15255
15298
  presetViews,
15256
15299
  tableName: props.tableName,
15257
- tableConfig
15300
+ tableConfig,
15301
+ backend: props.backend
15258
15302
  }
15259
15303
  );
15260
15304
  };