@osdk/react-components 0.49.0-main-e9d7ffac18c24515538279658b853d6d4457db79 → 0.49.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/CHANGELOG.md +3 -8
- package/build/browser/object-table/ObjectTable.js.map +1 -1
- package/build/browser/object-table/ObjectTableApi.js.map +1 -1
- package/build/browser/object-table/hooks/useColumnDefs.js +16 -3
- package/build/browser/object-table/hooks/useColumnDefs.js.map +1 -1
- package/build/browser/object-table/hooks/useEditableTable.js.map +1 -1
- package/build/browser/object-table/hooks/useFunctionColumnsData.js.map +1 -1
- package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -1
- package/build/browser/object-table/hooks/useRowSelection.js.map +1 -1
- package/build/browser/object-table/hooks/useSelectionColumn.js.map +1 -1
- package/build/browser/object-table/utils/deriveSelectionObjectSet.js.map +1 -1
- package/build/browser/object-table/utils/functionColumns.js.map +1 -1
- package/build/browser/object-table/utils/getRowId.js.map +1 -1
- package/build/browser/util/UserAgent.js +1 -1
- package/build/browser/util/UserAgent.js.map +1 -1
- package/build/cjs/{chunk-QQUE2WBQ.cjs → chunk-2RG3GPGR.cjs} +4 -4
- package/build/cjs/{chunk-QQUE2WBQ.cjs.map → chunk-2RG3GPGR.cjs.map} +1 -1
- package/build/cjs/{chunk-D7MEIVXD.cjs → chunk-3CXY3XVX.cjs} +4 -4
- package/build/cjs/{chunk-D7MEIVXD.cjs.map → chunk-3CXY3XVX.cjs.map} +1 -1
- package/build/cjs/{chunk-LTLWATP3.cjs → chunk-3QV5V3EM.cjs} +4 -4
- package/build/cjs/{chunk-LTLWATP3.cjs.map → chunk-3QV5V3EM.cjs.map} +1 -1
- package/build/cjs/{chunk-JWWPLCNY.cjs → chunk-4J74GCJE.cjs} +4 -4
- package/build/cjs/{chunk-JWWPLCNY.cjs.map → chunk-4J74GCJE.cjs.map} +1 -1
- package/build/cjs/chunk-A7JAFDYS.cjs +11 -0
- package/build/cjs/{chunk-X3CHSUAO.cjs.map → chunk-A7JAFDYS.cjs.map} +1 -1
- package/build/cjs/chunk-B2JJHLEB.cjs +11 -0
- package/build/cjs/{chunk-LNM32CE6.cjs.map → chunk-B2JJHLEB.cjs.map} +1 -1
- package/build/cjs/chunk-EFDPVL2Q.cjs +11 -0
- package/build/cjs/{chunk-W5TJGKSH.cjs.map → chunk-EFDPVL2Q.cjs.map} +1 -1
- package/build/cjs/{chunk-EJVUO6E2.cjs → chunk-HSWSSM3Q.cjs} +4 -4
- package/build/cjs/{chunk-EJVUO6E2.cjs.map → chunk-HSWSSM3Q.cjs.map} +1 -1
- package/build/cjs/{chunk-DHP6DLAU.cjs → chunk-HYSB5XC7.cjs} +4 -4
- package/build/cjs/{chunk-DHP6DLAU.cjs.map → chunk-HYSB5XC7.cjs.map} +1 -1
- package/build/cjs/{chunk-E54YCUSE.cjs → chunk-IDPY2J4H.cjs} +4 -4
- package/build/cjs/{chunk-E54YCUSE.cjs.map → chunk-IDPY2J4H.cjs.map} +1 -1
- package/build/cjs/{chunk-JYOU7XEH.cjs → chunk-KETQ47GR.cjs} +13 -7
- package/build/cjs/chunk-KETQ47GR.cjs.map +1 -0
- package/build/cjs/{chunk-J5LIOKTQ.cjs → chunk-MS2NCB4W.cjs} +4 -4
- package/build/cjs/{chunk-J5LIOKTQ.cjs.map → chunk-MS2NCB4W.cjs.map} +1 -1
- package/build/cjs/chunk-QV4ZPQCM.cjs +11 -0
- package/build/cjs/{chunk-3UBGAIKZ.cjs.map → chunk-QV4ZPQCM.cjs.map} +1 -1
- package/build/cjs/{chunk-SOJQJ5OA.cjs → chunk-RIJBNG4S.cjs} +3 -3
- package/build/cjs/chunk-RIJBNG4S.cjs.map +1 -0
- package/build/cjs/public/experimental/action-form.cjs +4 -4
- package/build/cjs/public/experimental/cbac-picker.cjs +11 -11
- package/build/cjs/public/experimental/document-viewer.cjs +4 -4
- package/build/cjs/public/experimental/email-viewer.cjs +3 -3
- package/build/cjs/public/experimental/filter-list.cjs +15 -15
- package/build/cjs/public/experimental/image-viewer.cjs +3 -3
- package/build/cjs/public/experimental/markdown-renderer.cjs +3 -3
- package/build/cjs/public/experimental/object-table.cjs +21 -21
- package/build/cjs/public/experimental/object-table.d.cts +97 -32
- package/build/cjs/public/experimental/pdf-viewer.cjs +7 -7
- package/build/cjs/public/experimental/spreadsheet-viewer.cjs +3 -3
- package/build/cjs/public/experimental/tiff-renderer.cjs +3 -3
- package/build/cjs/public/experimental/video-viewer.cjs +3 -3
- package/build/cjs/public/experimental/xml-viewer.cjs +3 -3
- package/build/cjs/public/experimental.cjs +71 -71
- package/build/esm/object-table/ObjectTable.js.map +1 -1
- package/build/esm/object-table/ObjectTableApi.js.map +1 -1
- package/build/esm/object-table/hooks/useColumnDefs.js +16 -3
- package/build/esm/object-table/hooks/useColumnDefs.js.map +1 -1
- package/build/esm/object-table/hooks/useEditableTable.js.map +1 -1
- package/build/esm/object-table/hooks/useFunctionColumnsData.js.map +1 -1
- package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -1
- package/build/esm/object-table/hooks/useRowSelection.js.map +1 -1
- package/build/esm/object-table/hooks/useSelectionColumn.js.map +1 -1
- package/build/esm/object-table/utils/deriveSelectionObjectSet.js.map +1 -1
- package/build/esm/object-table/utils/functionColumns.js.map +1 -1
- package/build/esm/object-table/utils/getRowId.js.map +1 -1
- package/build/esm/util/UserAgent.js +1 -1
- package/build/esm/util/UserAgent.js.map +1 -1
- package/build/types/object-table/ObjectTable.d.ts +1 -1
- package/build/types/object-table/ObjectTable.d.ts.map +1 -1
- package/build/types/object-table/ObjectTableApi.d.ts +108 -25
- package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
- package/build/types/object-table/hooks/useColumnDefs.d.ts +2 -2
- package/build/types/object-table/hooks/useColumnDefs.d.ts.map +1 -1
- package/build/types/object-table/hooks/useEditableTable.d.ts +2 -2
- package/build/types/object-table/hooks/useEditableTable.d.ts.map +1 -1
- package/build/types/object-table/hooks/useFunctionColumnsData.d.ts +2 -2
- package/build/types/object-table/hooks/useFunctionColumnsData.d.ts.map +1 -1
- package/build/types/object-table/hooks/useObjectTableData.d.ts +3 -3
- package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -1
- package/build/types/object-table/hooks/useRowSelection.d.ts +3 -3
- package/build/types/object-table/hooks/useRowSelection.d.ts.map +1 -1
- package/build/types/object-table/hooks/useSelectionColumn.d.ts +1 -1
- package/build/types/object-table/hooks/useSelectionColumn.d.ts.map +1 -1
- package/build/types/object-table/utils/deriveSelectionObjectSet.d.ts +1 -1
- package/build/types/object-table/utils/deriveSelectionObjectSet.d.ts.map +1 -1
- package/build/types/object-table/utils/functionColumns.d.ts +3 -3
- package/build/types/object-table/utils/functionColumns.d.ts.map +1 -1
- package/build/types/object-table/utils/getRowId.d.ts +1 -1
- package/build/types/object-table/utils/getRowId.d.ts.map +1 -1
- package/docs/ObjectTable.md +21 -19
- package/docs/ObjectTableOverview.md +1 -1
- package/package.json +8 -8
- package/build/cjs/chunk-3UBGAIKZ.cjs +0 -11
- package/build/cjs/chunk-JYOU7XEH.cjs.map +0 -1
- package/build/cjs/chunk-LNM32CE6.cjs +0 -11
- package/build/cjs/chunk-SOJQJ5OA.cjs.map +0 -1
- package/build/cjs/chunk-W5TJGKSH.cjs +0 -11
- package/build/cjs/chunk-X3CHSUAO.cjs +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
# @osdk/react-components
|
|
2
2
|
|
|
3
|
-
## 0.49.0
|
|
3
|
+
## 0.49.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- a129672: FilterList: fire `onFilterVisibilityChange` on drag-reorder in controlled mode, not just uncontrolled. Previously a drag in `addFilterMode="controlled"` fired no callback at all and the row snapped back, so reordering was impossible to observe or persist. Deprecate `addFilterMode`: it is going away, and visibility will always be managed internally, i.e. today's `"uncontrolled"` behavior. Deprecate the `newDefinitions` argument of `onFilterAdded`, which is the caller's own unchanged `filterDefinitions` rather than the post-add state — it is still passed, so existing handlers keep working, but read `onFilterVisibilityChange` for the resulting visibility and order instead. No breaking changes.
|
|
8
|
-
|
|
9
|
-
### Patch Changes
|
|
10
|
-
|
|
11
7
|
- 3370c61: Type ActionForm's `onSubmit` `applyAction` argument as `FormState<Q>`, remove the never-emitted `"validation"` variant from `FormError`, and add a theme token for ObjectSet fallback icons.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- @osdk/react@2.57.0-main-e9d7ffac18c24515538279658b853d6d4457db79
|
|
8
|
+
- a129672: FilterList: fire `onFilterVisibilityChange` on drag-reorder in controlled mode, not just uncontrolled. Previously a drag in `addFilterMode="controlled"` fired no callback at all and the row snapped back, so reordering was impossible to observe or persist. Deprecate `addFilterMode`: it is going away, and visibility will always be managed internally, i.e. today's `"uncontrolled"` behavior. Deprecate the `newDefinitions` argument of `onFilterAdded`, which is the caller's own unchanged `filterDefinitions` rather than the post-add state — it is still passed, so existing handlers keep working, but read `onFilterVisibilityChange` for the resulting visibility and order instead. No breaking changes.
|
|
9
|
+
- 4e85b63: Add `getCellValue` and `cellValueType` to ObjectTable column definitions, pass the cell value to `renderCell`, and type `getCellValue`'s return against the declared `cellValueType`. `cellValueType` is now required whenever `getCellValue` is provided. The `RDPs` type parameter of the object-table types now defaults to `{}`, matching the rest of the SDK.
|
|
15
10
|
|
|
16
11
|
## 0.48.0
|
|
17
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectTable.js","names":["getCoreRowModel","useReactTable","React","useCallback","useImperativeHandle","useMemo","useColumnDefs","useColumnPinning","useColumnResize","useColumnVisibility","useEditableTable","useObjectTableData","useObjectTableSnapshot","useRowSelection","useSelectionColumn","useTableSorting","BaseTable","deriveSelectionObjectSet","getRowId","getRowIdFromPrimaryKey","EMPTY_ARRAY","ObjectTable","objectType","objectSet","columnDefinitions","filter","objectSetOptions","dedupeIntervalMs","pageSize","streamUpdates","orderBy","defaultOrderBy","onOrderByChanged","onColumnsPinnedChanged","onColumnResize","onRowSelectionChanged","onColumnHeaderClick","renderCellContextMenu","selectionMode","selectedRows","isAllSelected","isAllSelectedProp","onColumnVisibilityChanged","onCellValueChanged","onSubmitEdits","enableOrdering","enableColumnPinning","enableColumnResizing","enableColumnConfig","editMode","focusedRow","onFocusedRowChanged","tableRef","labels","props","columnSizing","onColumnSizingChange","sorting","onSortingChange","orderByState","data","fetchMore","isLoading","error","totalCount","resultingObjectSet","objectOrInterfaceType","columns","loading","isColumnsLoading","handleRowSelectionChanged","change","isSelectAll","rowSelection","hasSelection","onToggleAll","onToggleRow","enableRowSelection","selectionColumn","columnVisibility","onColumnVisibilityChange","columnOrder","onColumnOrderChange","allColumns","columnPinning","onColumnPinningChange","hasSelectionColumn","editableConfig","table","state","enableSorting","columnResizeMode","columnResizeDirection","manualSorting","defaultColumn","minSize","meta","onCellEdit","onCellValidationError","clearCellValidationError","cellEdits","isInEditMode","editModeState","isActive","validationErrors","getSnapshot","onRenderCellContextMenu","row","cell","getValue","handleColumnHeaderClick","columnId","undefined","headerMenuFeatureFlags","showSortingItems","showPinningItems","showResizeItem","showConfigItem","createElement","fetchNextPage","onRowClick","rowHeight","renderEmptyState","className","getRowAttributes","showEditFooter","focusedRowId"],"sources":["ObjectTable.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { Cell } from \"@tanstack/react-table\";\nimport { getCoreRowModel, useReactTable } from \"@tanstack/react-table\";\nimport React, { useCallback, useImperativeHandle, useMemo } from \"react\";\n\nimport { useColumnDefs } from \"./hooks/useColumnDefs.js\";\nimport { useColumnPinning } from \"./hooks/useColumnPinning.js\";\nimport { useColumnResize } from \"./hooks/useColumnResize.js\";\nimport { useColumnVisibility } from \"./hooks/useColumnVisibility.js\";\nimport { useEditableTable } from \"./hooks/useEditableTable.js\";\nimport { useObjectTableData } from \"./hooks/useObjectTableData.js\";\nimport { useObjectTableSnapshot } from \"./hooks/useObjectTableSnapshot.js\";\nimport type { UseRowSelectionChange } from \"./hooks/useRowSelection.js\";\nimport { useRowSelection } from \"./hooks/useRowSelection.js\";\nimport { useSelectionColumn } from \"./hooks/useSelectionColumn.js\";\nimport { useTableSorting } from \"./hooks/useTableSorting.js\";\nimport type { ObjectTableProps } from \"./ObjectTableApi.js\";\nimport { BaseTable } from \"./Table.js\";\nimport type { HeaderMenuFeatureFlags } from \"./TableHeaderWithPopover.js\";\nimport { deriveSelectionObjectSet } from \"./utils/deriveSelectionObjectSet.js\";\nimport { getRowId, getRowIdFromPrimaryKey } from \"./utils/getRowId.js\";\nimport type { EditableConfig } from \"./utils/types.js\";\n\nconst EMPTY_ARRAY: [] = [];\n\nexport function ObjectTable<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectType,\n objectSet,\n columnDefinitions,\n filter,\n objectSetOptions,\n dedupeIntervalMs,\n pageSize,\n streamUpdates,\n orderBy,\n defaultOrderBy,\n onOrderByChanged,\n onColumnsPinnedChanged,\n onColumnResize,\n onRowSelectionChanged,\n onColumnHeaderClick,\n renderCellContextMenu,\n selectionMode = \"none\",\n selectedRows,\n isAllSelected: isAllSelectedProp,\n onColumnVisibilityChanged,\n onCellValueChanged,\n onSubmitEdits,\n enableOrdering = true,\n enableColumnPinning = true,\n enableColumnResizing = true,\n enableColumnConfig = true,\n editMode = \"manual\",\n focusedRow,\n onFocusedRowChanged,\n tableRef,\n labels,\n ...props\n}: ObjectTableProps<Q, RDPs, FunctionColumns>): React.ReactElement {\n const { columnSizing, onColumnSizingChange } = useColumnResize({\n onColumnResize,\n });\n\n const { sorting, onSortingChange, orderByState } = useTableSorting<\n Q,\n RDPs,\n FunctionColumns\n >({\n orderBy,\n defaultOrderBy,\n onOrderByChanged,\n });\n\n const {\n data,\n fetchMore,\n isLoading,\n error,\n totalCount,\n objectSet: resultingObjectSet,\n } = useObjectTableData<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType: objectType,\n columnDefinitions,\n filter,\n sorting,\n objectSet,\n objectSetOptions,\n dedupeIntervalMs,\n pageSize,\n streamUpdates,\n });\n\n const { columns, loading: isColumnsLoading } = useColumnDefs<\n Q,\n RDPs,\n FunctionColumns\n >(objectType, columnDefinitions);\n\n const handleRowSelectionChanged = useCallback(\n (change: UseRowSelectionChange<Q, RDPs>) => {\n if (!onRowSelectionChanged) return;\n\n onRowSelectionChanged({\n selectedRows: change.selectedRows,\n isSelectAll: change.isSelectAll,\n objectSet: deriveSelectionObjectSet(resultingObjectSet, change),\n });\n },\n [onRowSelectionChanged, resultingObjectSet],\n );\n\n const {\n rowSelection,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n enableRowSelection,\n } = useRowSelection<Q, RDPs>({\n selectionMode,\n selectedRows,\n isAllSelected: isAllSelectedProp,\n onRowSelectionChanged: handleRowSelectionChanged,\n data,\n });\n\n const selectionColumn = useSelectionColumn<Q, RDPs>({\n selectionMode,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n });\n\n const {\n columnVisibility,\n onColumnVisibilityChange,\n columnOrder,\n onColumnOrderChange,\n } = useColumnVisibility({\n allColumns: columns,\n onColumnVisibilityChanged,\n });\n\n const { columnPinning, onColumnPinningChange } = useColumnPinning({\n columnDefinitions,\n hasSelectionColumn: enableRowSelection,\n onColumnsPinnedChanged,\n });\n\n const allColumns = useMemo(() => {\n return selectionColumn ? [selectionColumn, ...columns] : columns;\n }, [selectionColumn, columns]);\n\n const editableConfig: EditableConfig<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n > = useEditableTable({\n editMode,\n onCellValueChanged,\n onSubmitEdits,\n });\n\n const table = useReactTable<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >({\n data: data ?? EMPTY_ARRAY,\n columns: allColumns,\n getCoreRowModel: getCoreRowModel(),\n state: {\n columnVisibility,\n columnOrder,\n rowSelection,\n sorting,\n columnSizing,\n columnPinning,\n },\n onSortingChange,\n onColumnSizingChange,\n onColumnPinningChange,\n onColumnVisibilityChange,\n onColumnOrderChange,\n enableRowSelection,\n enableSorting: enableOrdering,\n columnResizeMode: \"onChange\",\n columnResizeDirection: \"ltr\",\n manualSorting: true, // Enable manual sorting to indicate server-side sorting\n defaultColumn: {\n minSize: 80,\n },\n getRowId,\n meta: {\n onCellEdit: editableConfig.onCellEdit,\n onCellValidationError: editableConfig.onCellValidationError,\n clearCellValidationError: editableConfig.clearCellValidationError,\n cellEdits: editableConfig.cellEdits,\n isInEditMode: editableConfig.editModeState.isActive,\n validationErrors: editableConfig.validationErrors,\n },\n });\n\n const { getSnapshot } = useObjectTableSnapshot<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType: objectType,\n table,\n columnDefinitions,\n objectSet: resultingObjectSet,\n pageSize,\n totalCount,\n orderBy: orderByState,\n });\n\n useImperativeHandle(tableRef, () => ({ getSnapshot }), [getSnapshot]);\n\n const onRenderCellContextMenu = useCallback(\n (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cell: Cell<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => {\n return renderCellContextMenu?.(row, cell.getValue());\n },\n [renderCellContextMenu],\n );\n\n const handleColumnHeaderClick = useMemo(\n () =>\n onColumnHeaderClick\n ? (columnId: string) =>\n onColumnHeaderClick(\n columnId as PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n )\n : undefined,\n [onColumnHeaderClick],\n );\n\n const isTableLoading = isLoading || isColumnsLoading;\n\n const headerMenuFeatureFlags: HeaderMenuFeatureFlags = useMemo(\n () => ({\n showSortingItems: enableOrdering,\n showPinningItems: enableColumnPinning,\n showResizeItem: enableColumnResizing,\n showConfigItem: enableColumnConfig,\n }),\n [\n enableOrdering,\n enableColumnPinning,\n enableColumnResizing,\n enableColumnConfig,\n ],\n );\n\n return (\n <BaseTable<Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>>\n table={table}\n isLoading={isTableLoading}\n fetchNextPage={fetchMore}\n onRowClick={props.onRowClick}\n onColumnHeaderClick={handleColumnHeaderClick}\n rowHeight={props.rowHeight}\n renderCellContextMenu={onRenderCellContextMenu}\n renderEmptyState={props.renderEmptyState}\n className={props.className}\n error={error}\n headerMenuFeatureFlags={headerMenuFeatureFlags}\n editableConfig={editableConfig}\n getRowAttributes={props.getRowAttributes}\n showEditFooter={props.showEditFooter}\n focusedRowId={\n focusedRow == null ? focusedRow : getRowIdFromPrimaryKey<Q>(focusedRow)\n }\n onFocusedRowChanged={onFocusedRowChanged}\n labels={labels}\n />\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,SAASA,eAAe,EAAEC,aAAa,QAAQ,uBAAuB;AACtE,OAAOC,KAAK,IAAIC,WAAW,EAAEC,mBAAmB,EAAEC,OAAO,QAAQ,OAAO;AAExE,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,mBAAmB,QAAQ,gCAAgC;AACpE,SAASC,gBAAgB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AK,CAACqE,SAAU;IAC3B5D,KAAK,EAAEA,KAAM;IACbkD,sBAAsB,EAAEA,sBAAuB;IAC/C1B,cAAc,EAAEA,cAAe;IAC/BqC,gBAAgB,EAAEtE,KAAK,CAACsE,gBAAiB;IACzCC,cAAc,EAAEvE,KAAK,CAACuE,cAAe;IACrCC,YAAY,EACV5E,UAAU,IAAI,IAAI,GAAGA,UAAU,GAAG/B,sBAAsB,CAAI+B,UAAU,CACvE;IACDC,mBAAmB,EAAEA,mBAAoB;IACzCE,MAAM,EAAEA;EAAO,CAChB,CAAC;AAEN","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ObjectTable.js","names":["getCoreRowModel","useReactTable","React","useCallback","useImperativeHandle","useMemo","useColumnDefs","useColumnPinning","useColumnResize","useColumnVisibility","useEditableTable","useObjectTableData","useObjectTableSnapshot","useRowSelection","useSelectionColumn","useTableSorting","BaseTable","deriveSelectionObjectSet","getRowId","getRowIdFromPrimaryKey","EMPTY_ARRAY","ObjectTable","objectType","objectSet","columnDefinitions","filter","objectSetOptions","dedupeIntervalMs","pageSize","streamUpdates","orderBy","defaultOrderBy","onOrderByChanged","onColumnsPinnedChanged","onColumnResize","onRowSelectionChanged","onColumnHeaderClick","renderCellContextMenu","selectionMode","selectedRows","isAllSelected","isAllSelectedProp","onColumnVisibilityChanged","onCellValueChanged","onSubmitEdits","enableOrdering","enableColumnPinning","enableColumnResizing","enableColumnConfig","editMode","focusedRow","onFocusedRowChanged","tableRef","labels","props","columnSizing","onColumnSizingChange","sorting","onSortingChange","orderByState","data","fetchMore","isLoading","error","totalCount","resultingObjectSet","objectOrInterfaceType","columns","loading","isColumnsLoading","handleRowSelectionChanged","change","isSelectAll","rowSelection","hasSelection","onToggleAll","onToggleRow","enableRowSelection","selectionColumn","columnVisibility","onColumnVisibilityChange","columnOrder","onColumnOrderChange","allColumns","columnPinning","onColumnPinningChange","hasSelectionColumn","editableConfig","table","state","enableSorting","columnResizeMode","columnResizeDirection","manualSorting","defaultColumn","minSize","meta","onCellEdit","onCellValidationError","clearCellValidationError","cellEdits","isInEditMode","editModeState","isActive","validationErrors","getSnapshot","onRenderCellContextMenu","row","cell","getValue","handleColumnHeaderClick","columnId","undefined","headerMenuFeatureFlags","showSortingItems","showPinningItems","showResizeItem","showConfigItem","createElement","fetchNextPage","onRowClick","rowHeight","renderEmptyState","className","getRowAttributes","showEditFooter","focusedRowId"],"sources":["ObjectTable.tsx"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { Cell } from \"@tanstack/react-table\";\nimport { getCoreRowModel, useReactTable } from \"@tanstack/react-table\";\nimport React, { useCallback, useImperativeHandle, useMemo } from \"react\";\n\nimport { useColumnDefs } from \"./hooks/useColumnDefs.js\";\nimport { useColumnPinning } from \"./hooks/useColumnPinning.js\";\nimport { useColumnResize } from \"./hooks/useColumnResize.js\";\nimport { useColumnVisibility } from \"./hooks/useColumnVisibility.js\";\nimport { useEditableTable } from \"./hooks/useEditableTable.js\";\nimport { useObjectTableData } from \"./hooks/useObjectTableData.js\";\nimport { useObjectTableSnapshot } from \"./hooks/useObjectTableSnapshot.js\";\nimport type { UseRowSelectionChange } from \"./hooks/useRowSelection.js\";\nimport { useRowSelection } from \"./hooks/useRowSelection.js\";\nimport { useSelectionColumn } from \"./hooks/useSelectionColumn.js\";\nimport { useTableSorting } from \"./hooks/useTableSorting.js\";\nimport type { ObjectTableProps } from \"./ObjectTableApi.js\";\nimport { BaseTable } from \"./Table.js\";\nimport type { HeaderMenuFeatureFlags } from \"./TableHeaderWithPopover.js\";\nimport { deriveSelectionObjectSet } from \"./utils/deriveSelectionObjectSet.js\";\nimport { getRowId, getRowIdFromPrimaryKey } from \"./utils/getRowId.js\";\nimport type { EditableConfig } from \"./utils/types.js\";\n\nconst EMPTY_ARRAY: [] = [];\n\nexport function ObjectTable<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectType,\n objectSet,\n columnDefinitions,\n filter,\n objectSetOptions,\n dedupeIntervalMs,\n pageSize,\n streamUpdates,\n orderBy,\n defaultOrderBy,\n onOrderByChanged,\n onColumnsPinnedChanged,\n onColumnResize,\n onRowSelectionChanged,\n onColumnHeaderClick,\n renderCellContextMenu,\n selectionMode = \"none\",\n selectedRows,\n isAllSelected: isAllSelectedProp,\n onColumnVisibilityChanged,\n onCellValueChanged,\n onSubmitEdits,\n enableOrdering = true,\n enableColumnPinning = true,\n enableColumnResizing = true,\n enableColumnConfig = true,\n editMode = \"manual\",\n focusedRow,\n onFocusedRowChanged,\n tableRef,\n labels,\n ...props\n}: ObjectTableProps<Q, RDPs, FunctionColumns>): React.ReactElement {\n const { columnSizing, onColumnSizingChange } = useColumnResize({\n onColumnResize,\n });\n\n const { sorting, onSortingChange, orderByState } = useTableSorting<\n Q,\n RDPs,\n FunctionColumns\n >({\n orderBy,\n defaultOrderBy,\n onOrderByChanged,\n });\n\n const {\n data,\n fetchMore,\n isLoading,\n error,\n totalCount,\n objectSet: resultingObjectSet,\n } = useObjectTableData<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType: objectType,\n columnDefinitions,\n filter,\n sorting,\n objectSet,\n objectSetOptions,\n dedupeIntervalMs,\n pageSize,\n streamUpdates,\n });\n\n const { columns, loading: isColumnsLoading } = useColumnDefs<\n Q,\n RDPs,\n FunctionColumns\n >(objectType, columnDefinitions);\n\n const handleRowSelectionChanged = useCallback(\n (change: UseRowSelectionChange<Q, RDPs>) => {\n if (!onRowSelectionChanged) return;\n\n onRowSelectionChanged({\n selectedRows: change.selectedRows,\n isSelectAll: change.isSelectAll,\n objectSet: deriveSelectionObjectSet(resultingObjectSet, change),\n });\n },\n [onRowSelectionChanged, resultingObjectSet],\n );\n\n const {\n rowSelection,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n enableRowSelection,\n } = useRowSelection<Q, RDPs>({\n selectionMode,\n selectedRows,\n isAllSelected: isAllSelectedProp,\n onRowSelectionChanged: handleRowSelectionChanged,\n data,\n });\n\n const selectionColumn = useSelectionColumn<Q, RDPs>({\n selectionMode,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n });\n\n const {\n columnVisibility,\n onColumnVisibilityChange,\n columnOrder,\n onColumnOrderChange,\n } = useColumnVisibility({\n allColumns: columns,\n onColumnVisibilityChanged,\n });\n\n const { columnPinning, onColumnPinningChange } = useColumnPinning({\n columnDefinitions,\n hasSelectionColumn: enableRowSelection,\n onColumnsPinnedChanged,\n });\n\n const allColumns = useMemo(() => {\n return selectionColumn ? [selectionColumn, ...columns] : columns;\n }, [selectionColumn, columns]);\n\n const editableConfig: EditableConfig<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n > = useEditableTable({\n editMode,\n onCellValueChanged,\n onSubmitEdits,\n });\n\n const table = useReactTable<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >({\n data: data ?? EMPTY_ARRAY,\n columns: allColumns,\n getCoreRowModel: getCoreRowModel(),\n state: {\n columnVisibility,\n columnOrder,\n rowSelection,\n sorting,\n columnSizing,\n columnPinning,\n },\n onSortingChange,\n onColumnSizingChange,\n onColumnPinningChange,\n onColumnVisibilityChange,\n onColumnOrderChange,\n enableRowSelection,\n enableSorting: enableOrdering,\n columnResizeMode: \"onChange\",\n columnResizeDirection: \"ltr\",\n manualSorting: true, // Enable manual sorting to indicate server-side sorting\n defaultColumn: {\n minSize: 80,\n },\n getRowId,\n meta: {\n onCellEdit: editableConfig.onCellEdit,\n onCellValidationError: editableConfig.onCellValidationError,\n clearCellValidationError: editableConfig.clearCellValidationError,\n cellEdits: editableConfig.cellEdits,\n isInEditMode: editableConfig.editModeState.isActive,\n validationErrors: editableConfig.validationErrors,\n },\n });\n\n const { getSnapshot } = useObjectTableSnapshot<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType: objectType,\n table,\n columnDefinitions,\n objectSet: resultingObjectSet,\n pageSize,\n totalCount,\n orderBy: orderByState,\n });\n\n useImperativeHandle(tableRef, () => ({ getSnapshot }), [getSnapshot]);\n\n const onRenderCellContextMenu = useCallback(\n (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cell: Cell<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => {\n return renderCellContextMenu?.(row, cell.getValue());\n },\n [renderCellContextMenu],\n );\n\n const handleColumnHeaderClick = useMemo(\n () =>\n onColumnHeaderClick\n ? (columnId: string) =>\n onColumnHeaderClick(\n columnId as PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n )\n : undefined,\n [onColumnHeaderClick],\n );\n\n const isTableLoading = isLoading || isColumnsLoading;\n\n const headerMenuFeatureFlags: HeaderMenuFeatureFlags = useMemo(\n () => ({\n showSortingItems: enableOrdering,\n showPinningItems: enableColumnPinning,\n showResizeItem: enableColumnResizing,\n showConfigItem: enableColumnConfig,\n }),\n [\n enableOrdering,\n enableColumnPinning,\n enableColumnResizing,\n enableColumnConfig,\n ],\n );\n\n return (\n <BaseTable<Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>>\n table={table}\n isLoading={isTableLoading}\n fetchNextPage={fetchMore}\n onRowClick={props.onRowClick}\n onColumnHeaderClick={handleColumnHeaderClick}\n rowHeight={props.rowHeight}\n renderCellContextMenu={onRenderCellContextMenu}\n renderEmptyState={props.renderEmptyState}\n className={props.className}\n error={error}\n headerMenuFeatureFlags={headerMenuFeatureFlags}\n editableConfig={editableConfig}\n getRowAttributes={props.getRowAttributes}\n showEditFooter={props.showEditFooter}\n focusedRowId={\n focusedRow == null ? focusedRow : getRowIdFromPrimaryKey<Q>(focusedRow)\n }\n onFocusedRowChanged={onFocusedRowChanged}\n labels={labels}\n />\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,SAASA,eAAe,EAAEC,aAAa,QAAQ,uBAAuB;AACtE,OAAOC,KAAK,IAAIC,WAAW,EAAEC,mBAAmB,EAAEC,OAAO,QAAQ,OAAO;AAExE,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,mBAAmB,QAAQ,gCAAgC;AACpE,SAASC,gBAAgB,QAAQ,6BAA6B;AAC9D,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,sBAAsB,QAAQ,mCAAmC;AAE1E,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,eAAe,QAAQ,4BAA4B;AAE5D,SAASC,SAAS,QAAQ,YAAY;AAEtC,SAASC,wBAAwB,QAAQ,qCAAqC;AAC9E,SAASC,QAAQ,EAAEC,sBAAsB,QAAQ,qBAAqB;AAGtE,MAAMC,WAAe,GAAG,EAAE;AAE1B,OAAO,SAASC,WAAWA,CAOzB;EACAC,UAAU;EACVC,SAAS;EACTC,iBAAiB;EACjBC,MAAM;EACNC,gBAAgB;EAChBC,gBAAgB;EAChBC,QAAQ;EACRC,aAAa;EACbC,OAAO;EACPC,cAAc;EACdC,gBAAgB;EAChBC,sBAAsB;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2E,QACF,CAAC,GACHC,SAAS,EACf,CAAC5E,mBAAmB,CACtB,CAAC;EAID,MAAM6E,sBAA8C,GAAG5G,OAAO,CAC5D,OAAO;IACL6G,gBAAgB,EAAErE,cAAc;IAChCsE,gBAAgB,EAAErE,mBAAmB;IACrCsE,cAAc,EAAErE,oBAAoB;IACpCsE,cAAc,EAAErE;EAClB,CAAC,CAAC,EACF,CACEH,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,kBAAkB,CAEtB,CAAC;EAED,oBACE9C,KAAA,CAAAoH,aAAA,CAACtG,SAAS;IACRwE,KAAK,EAAEA,KAAM;IACb1B,SAAS,EApBUA,SAAS,IAAIO,gBAoBN;IAC1BkD,aAAa,EAAE1D,SAAU;IACzB2D,UAAU,EAAElE,KAAK,CAACkE,UAAW;IAC7BpF,mBAAmB,EAAE0E,uBAAwB;IAC7CW,SAAS,EAAEnE,KAAK,CAACmE,SAAU;IAC3BpF,qBAAqB,EAAEqE,uBAAwB;IAC/CgB,gBAAgB,EAAEpE,KAAK,CAACoE,gBAAiB;IACzCC,SAAS,EAAErE,KAAK,CAACqE,SAAU;IAC3B5D,KAAK,EAAEA,KAAM;IACbkD,sBAAsB,EAAEA,sBAAuB;IAC/C1B,cAAc,EAAEA,cAAe;IAC/BqC,gBAAgB,EAAEtE,KAAK,CAACsE,gBAAiB;IACzCC,cAAc,EAAEvE,KAAK,CAACuE,cAAe;IACrCC,YAAY,EACV5E,UAAU,IAAI,IAAI,GAAGA,UAAU,GAAG/B,sBAAsB,CAAI+B,UAAU,CACvE;IACDC,mBAAmB,EAAEA,mBAAoB;IACzCE,MAAM,EAAEA;EAAO,CAChB,CAAC;AAEN","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ObjectTableApi.js","names":[],"sources":["ObjectTableApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n CompileTimeMetadata,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { QueryParameterType } from \"@osdk/client/observable\";\nimport type * as React from \"react\";\n\nimport type { ObjectTableLabels } from \"./ObjectTableLabels.js\";\nimport type { CellEditInfo, EditFieldConfig } from \"./utils/types.js\";\n\nexport type { EditFieldConfig } from \"./utils/types.js\";\n\nexport type ColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n | EditableColumnDefinition<Q, RDPs, FunctionColumns>\n | ReadonlyColumnDefinition<Q, RDPs, FunctionColumns>;\n\ninterface SharedColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * Defines what the column shows:\n * an object/interface property, a linked object property (derived property), a function\n * column, or a custom column — and carries that locator's configuration.\n */\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>;\n\n /**\n * @default true\n */\n isVisible?: boolean;\n\n /**\n * @default none\n */\n pinned?: \"left\" | \"right\" | \"none\";\n width?: number;\n minWidth?: number;\n maxWidth?: number;\n resizable?: boolean;\n orderable?: boolean;\n\n /**\n * Custom renderer for the cell value.\n *\n * Interaction with `editable` columns:\n * - When `editMode: \"manual\"` (default), `renderCell` is used while the\n * table is read-only (Edit Table button visible) and the editable cell\n * takes over once the user enters edit mode.\n * - When `editMode: \"always\"`, the editable cell always wins on editable\n * columns and `renderCell` is ignored — `editMode: \"always\"` opts the\n * column into a permanently-editable surface, leaving no read-only\n * state for `renderCell` to render. Use `editMode: \"manual\"` if you\n * need a custom display alongside editing.\n */\n renderCell?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => React.ReactNode;\n\n /**\n * If provided, this will be used in the column header.\n * If both columnName and renderHeader are provided, renderHeader will take precedence in the table header.\n * columnName will still be used in other parts where the column name is displayed.\n *\n * If not provided,\n * for a property column, the property displayName will be used\n * for other columns, the id will be used.\n */\n columnName?: string;\n\n /**\n * If provided, this will be used to render the header component.\n * When both columnName and renderHeader are provided, renderHeader will take precedence in the table header.\n */\n renderHeader?: () => React.ReactNode;\n}\n\ninterface EditableColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> extends SharedColumnDefinition<Q, RDPs, FunctionColumns> {\n /**\n * `editable` can be a boolean or a predicate that receives the row's object\n * and returns whether the cell is editable\n */\n editable:\n | true\n | ((\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => boolean);\n\n /**\n * Configuration for the cell editor component.\n *\n * When provided, the column uses the specified field component\n * (e.g. dropdown) instead of the default auto-detected text/number input.\n *\n * `getFieldComponentProps` receives the row's object and a map of any\n * pending edits for that row (keyed by column id), and returns the props to\n * pass to the field component. Editor configuration can depend on the\n * current row or on other in-progress edits within the row.\n */\n editFieldConfig?: EditFieldConfig<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >;\n\n /**\n * Additional function to validate the cell value during edit.\n *\n * @param value the current cell value\n * @returns a promise that resolves to an error message string if validation fails, or undefined if validation succeeds\n */\n validateEdit?: (value: unknown) => Promise<string | undefined>;\n}\n\n/**\n * Column definition for a read-only column (default).\n * `editFieldConfig` and `validateEdit` are not available.\n */\ninterface ReadonlyColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> extends SharedColumnDefinition<Q, RDPs, FunctionColumns> {\n editable?: false;\n}\n\nexport type ExtractQueryParameters<Q extends QueryDefinition> =\n CompileTimeMetadata<Q>[\"parameters\"] extends Record<string, never>\n ? undefined\n : QueryParameterType<CompileTimeMetadata<Q>[\"parameters\"]>;\n\nexport interface PropertyColumnLocator<Q extends ObjectOrInterfaceDefinition> {\n type: \"property\";\n id: PropertyKeys<Q>;\n}\n\n/**\n * Concrete function column locator for a single key K.\n * Correlates the id, queryDefinition, and getFunctionParams types.\n */\ninterface FunctionColumnLocatorForKey<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n FunctionColumns extends Record<string, QueryDefinition<{}>>,\n K extends keyof FunctionColumns,\n> {\n /**\n * This is equivalent to workshop's function-backed columns.\n * The function needs to meet the specifications stated in https://www.palantir.com/docs/foundry/workshop/widgets-object-table/#function-backed-columns\n */\n type: \"function\";\n id: K;\n queryDefinition: FunctionColumns[K];\n\n /**\n * The function will be called with the current object set to get the input parameters for the function query.\n * @param objectSet - The current object set.\n * @returns - The function's input parameters including the object set.\n */\n getFunctionParams: (\n objectSet: ObjectSet<Q, RDPs>,\n ) => ExtractQueryParameters<FunctionColumns[K]>;\n\n /**\n * Function to generate keys for looking up results in the FunctionsMap.\n * @param object - The object instance\n * @returns - The key to use for looking up this object's result in the FunctionsMap\n */\n getKey: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => string;\n\n /**\n * Function to extract the cell value from the raw cell data returned by the function.\n * This is useful when functions return custom types with multiple properties.\n * @param cellData - The raw data returned by the function for this object\n * @returns - The value to display in the cell\n */\n getValue?: (cellData?: unknown) => unknown;\n\n /**\n * Minimum time between re-fetches of the same function with the same parameters, in milliseconds.\n * Defaults to 5 minutes as it is expensive to fetch function columns for a large object set\n * and they are expected to be relatively static in the context of an object table\n *\n * @default 300_000 (5 minutes)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Object type apiNames the function reads but doesn't take as a parameter (e.g.\n * linked object types the function traverses internally). The column auto-revalidates\n * when an action edits an object of any of these types. Param-derived types are\n * tracked automatically and don't need to be listed here.\n */\n dependsOn?: string[];\n}\n\n/**\n * Distributes over each key in FunctionColumns so that id, queryDefinition,\n * and getFunctionParams are correlated per key.\n */\nexport type FunctionColumnLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = keyof FunctionColumns extends infer K\n ? K extends keyof FunctionColumns\n ? FunctionColumnLocatorForKey<Q, RDPs, FunctionColumns, K>\n : never\n : never;\n\nexport interface RdpColumnLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n type: \"rdp\";\n id: keyof RDPs;\n creator: DerivedProperty.Creator<Q, RDPs[keyof RDPs]>;\n}\n\nexport interface CustomColumnLocator {\n type: \"custom\";\n id: string;\n}\n\nexport type ColumnDefinitionLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n | PropertyColumnLocator<Q>\n | FunctionColumnLocator<Q, RDPs, FunctionColumns>\n | RdpColumnLocator<Q, RDPs>\n | CustomColumnLocator;\n\nexport interface ObjectTableProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * The object or interface type of the object\n * If objectSet is not provided, objects will be fetched based on this type.\n */\n objectType: Q;\n\n /**\n * The set of objects to show in the table.\n * If provided, the table fetches through this object set instead of fetching based on\n * objectType. Supported for both object and interface types.\n *\n * For an interface object set, rows expose the interface's declared properties;\n * the underlying concrete object's non-interface properties are not loaded.\n * Use objectType-based fetching if you need those.\n */\n objectSet?: ObjectSet<Q>;\n\n /**\n * Ordered list of column definitions to show in the table\n *\n * If not provided, all of the properties of the object type will be shown in default order.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n\n objectSetOptions?: ObjectSetOptions<Q>;\n\n /**\n * Minimum time between fetch requests in milliseconds.\n * Increasing this value reduces redundant network calls when the same data\n * is requested multiple times in quick succession.\n *\n * @default 60_000 1 minute\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the table will automatically update when matching\n * objects are added, updated, or removed in Foundry.\n *\n * Limitations: `streamUpdates` cannot be used together with `pivotTo` or\n * `withProperties`. The server does not support websocket subscriptions\n * for link-traversal or derived-property queries. Those queries still\n * fetch data normally but won't receive real-time updates.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Number of objects to fetch per page.\n *\n * @default 50\n */\n pageSize?: number;\n\n /**\n * The current where clause to filter the objects in the table.\n * If provided, the filter is controlled.\n */\n filter?: WhereClause<Q, RDPs>;\n\n /**\n * Whether the column configuration dialog for column visibility and ordering is available to the user.\n *\n * @default true\n */\n enableColumnConfig?: boolean;\n\n /**\n * Whether columns can be pinned by the user.\n *\n * @default true\n */\n enableColumnPinning?: boolean;\n\n /**\n * Whether columns can be resized by the user.\n *\n * @default true\n */\n enableColumnResizing?: boolean;\n\n /**\n * Called when the column visibility or ordering changed.\n *\n * If provided, the table will allow the user to show/hide columns.\n *\n * @param newStates The columns sorted in their display order in the table and their visibility state.\n */\n onColumnVisibilityChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n isVisible: boolean;\n }>,\n ) => void;\n\n /**\n * Called when the pinned columns change.\n *\n * If provided, the table will allow the user to pin/unpin columns.\n *\n * @param newStates The new list of column pin states\n */\n onColumnsPinnedChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n pinned: \"left\" | \"right\" | \"none\";\n }>,\n ) => void;\n\n /**\n * Called when a column is resized.\n *\n * @param columnId The ID of the resized column\n * @param newWidth The new width of the column. When newWidth = null, the column size is reset.\n */\n onColumnResize?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n newWidth: number | null,\n ) => void;\n\n /**\n * Called when a column header is clicked.\n *\n * The columnId matches the `locator.id` configured on the column definition.\n * The dropdown menu trigger is excluded — clicking the chevron opens the\n * header menu instead of firing this callback.\n *\n * @param columnId The id of the clicked column\n */\n onColumnHeaderClick?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n ) => void;\n\n /**\n * Whether the table is sortable by the user.\n *\n * @default true\n */\n enableOrdering?: boolean;\n\n /**\n * The default order by clause to sort the objects in the table.\n * If provided without orderBy prop, the sorting is uncontrolled.\n * If both orderBy and defaultOrderBy are provided, orderBy takes precedence.\n */\n defaultOrderBy?: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * The current order by clause to sort the objects in the table.\n * If provided, the sorting is controlled.\n * If both orderBy and defaultOrderBy are provided, orderBy takes precedence.\n */\n orderBy?: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * Called when the order by clause is changed.\n * Required when sorting is controlled.\n *\n * @param newOrderBy The new order by clause\n */\n onOrderByChanged?: (\n newOrderBy: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>,\n ) => void;\n\n /**\n * Selection mode for the table rows.\n *\n * If multiple, a checkbox will be shown for each row to allow selecting multiple rows\n * as well as a top-level checkbox in the header to select all rows.\n *\n * @default \"none\"\n */\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n\n /**\n * The currently selected rows in the table.\n * If provided, the row selection is controlled.\n */\n selectedRows?: PrimaryKeyType<Q>[];\n\n /**\n * Indicates whether all rows are selected in controlled mode.\n * When true, the table will show all rows as selected regardless of the selectedRows array.\n */\n isAllSelected?: boolean;\n\n /**\n * Called when the row selection changes, with a {@link RowSelectionChange}\n * payload describing the new state.\n *\n * @param change The new selection state. See {@link RowSelectionChange}.\n */\n onRowSelectionChanged?: (change: RowSelectionChange<Q, RDPs>) => void;\n\n /**\n * The primary key of the row to render as visually focused (the\n * \"last interacted\" row). When provided, focus state is controlled by\n * the caller.\n *\n * Stored as a primary key rather than a full object so the focus does\n * not go stale when the underlying row data changes.\n *\n * Pass `null` to render no row as focused.\n */\n focusedRow?: PrimaryKeyType<Q> | null;\n\n /**\n * Called when the focused row changes — fires in both controlled and\n * uncontrolled modes so callers can observe focus without taking it\n * over.\n *\n * @param row The newly-focused row object, or `null` if focus was\n * cleared\n */\n onFocusedRowChanged?: (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs> | null,\n ) => void;\n\n /**\n * Controls the edit mode behavior of the table.\n * - \"always\": Editable cells are immediately in edit mode on row clicked.\n * - \"manual\": User can toggle edit mode on/off via the Edit Table button.\n *\n * @default \"manual\"\n */\n editMode?: \"always\" | \"manual\";\n\n /**\n * Whether to render the bottom edit footer that hosts the\n * \"Edit Table\" / \"Cancel\" / \"Submit Edits\" buttons and the edit-state\n * indicators (modification count, validation errors).\n *\n * @default true whenever the table has at least one column declared\n * editable (i.e. any column with `editable: true` or `editable: (object) => boolean`).\n * When `false`, the \"Edit Table\" and \"Submit Edits\" buttons will not be shown.\n */\n showEditFooter?: boolean;\n\n /**\n * Called after the value of a cell is edited and committed by the user.\n *\n * @param info An object containing details about the cell that was edited,\n * including the rowId, columnId, new and old values, and the row data before the edit\n */\n onCellValueChanged?: (\n info: CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => void;\n\n /**\n * If provided, the \"Submit Edits\" button will be shown in the edit footer.\n *\n * @param edits an array of edit info containing details about the edited cells\n * including the rowId, columnId, new and old values, and the row data before the edit\n * @return a promise that resolves to true if the edits were successfully submitted\n */\n onSubmitEdits?: (\n edits: CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >[],\n ) => Promise<boolean>;\n\n /**\n * Called when a row is clicked.\n *\n * @param object The object representing the clicked row\n */\n onRowClick?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => void;\n\n /**\n * If provided, will render this context menu when right clicking on a cell\n */\n renderCellContextMenu?: (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cellValue: unknown,\n ) => React.ReactNode;\n\n /**\n * The height of each row in pixels.\n *\n * @default 40\n */\n rowHeight?: number;\n\n /**\n * Render override for the empty state. Called when the table has no\n * rows and no error. When omitted, a default \"No Data\" indicator is\n * rendered.\n */\n renderEmptyState?: () => React.ReactNode;\n\n /**\n * Returns extra HTML attributes (typically `data-*`) to apply to each\n * row element. Use this to drive conditional row styling\n */\n getRowAttributes?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => Record<string, string | undefined>;\n\n /**\n * Imperative handle for programmatic table actions. Pass a ref\n * (`useRef<ObjectTableHandle<Q, RDPs>>(null)`) to call\n * {@link ObjectTableHandle} methods such as\n * {@link ObjectTableHandle.getSnapshot}.\n */\n tableRef?: React.Ref<ObjectTableHandle<Q, RDPs>>;\n\n className?: string;\n\n /**\n * Overrides for the table's user-facing strings. Provide any subset; unset keys fall\n * back to the built-in English defaults. Use this to localize the table or\n * adjust wording. See {@link ObjectTableLabels}.\n *\n * @default undefined (built-in English strings)\n */\n labels?: Partial<ObjectTableLabels>;\n}\n\n/**\n * Imperative handle exposing programmatic actions on an {@link ObjectTable}.\n * Obtain it by passing {@link ObjectTableProps.tableRef}.\n */\nexport interface ObjectTableHandle<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n /**\n * Loads every row matching the object set and returns a format-agnostic\n * snapshot of the table's columns, row values, and total count. The caller\n * is responsible for turning the snapshot into a downloadable artifact\n * (CSV, Spreadsheet, JSON, clipboard, …).\n *\n * Property, derived-property, and function-backed columns are included.\n * Function-backed cells are fetched per page during snapshot collection;\n * when a page's fetch fails, `row.getValue(columnId)` returns the thrown\n * `Error` instance for the affected cells while the rest of the snapshot\n * resolves normally.\n * Columns defined with `locator.type === \"custom\"` are omitted because\n * they have no underlying value to export.\n *\n * The returned promise rejects up front when the object set's `totalCount`\n * exceeds `rowLimit`. When `totalCount` is unavailable, it instead rejects\n * mid-load once more than `rowLimit` rows have been pulled, so an unknown\n * count can't drain an unbounded set into the client. Otherwise every\n * matching row is loaded.\n *\n * @param options See {@link ObjectTableSnapshotOptions}.\n */\n getSnapshot: (\n options?: ObjectTableSnapshotOptions,\n ) => Promise<ObjectTableSnapshot<Q, RDPs>>;\n}\n\n/**\n * Options for {@link ObjectTableHandle[\"getSnapshot\"]}.\n */\nexport interface ObjectTableSnapshotOptions {\n /**\n * Upper bound on how many rows the snapshot may contain. When the object\n * set's total row count exceeds this value, `getSnapshot` rejects;\n * otherwise every matching row is loaded.\n *\n * @default 10_000\n */\n rowLimit?: number;\n}\n\n/**\n * A point-in-time capture of an {@link ObjectTable}'s columns and row values,\n * returned by {@link ObjectTableHandle.getSnapshot}.\n */\nexport interface ObjectTableSnapshot<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n columns: ObjectTableDataColumn[];\n rows: ObjectTableDataRow<Q, RDPs>[];\n /**\n * Total number of objects matching the underlying object set, as reported\n * by the API. `undefined` when the API did not provide a count. Encoded as\n * a string to match the underlying list-payload representation.\n */\n totalCount: string | undefined;\n}\n\n/**\n * A single column in an {@link ObjectTableSnapshot}.\n */\nexport interface ObjectTableDataColumn {\n /** Column id, matching the `locator.id` of the column definition. */\n id: string;\n /** Display name shown in the table header. */\n name: string;\n}\n\n/**\n * A single row in an {@link ObjectTableSnapshot}.\n */\nexport interface ObjectTableDataRow<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n /** Row id (the underlying object's `$primaryKey` rendered as a string). */\n id: string;\n /** The underlying loaded object. */\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>;\n /**\n * Returns the cell value for a given column id, or `undefined` when the\n * column is not part of the snapshot. Function-backed cells whose query\n * failed surface the thrown `Error` instance as their value.\n */\n getValue: (columnId: string) => unknown;\n}\n\n/**\n * Payload for {@link ObjectTableProps.onRowSelectionChanged}. Consolidates\n * the loaded row instances, the `isSelectAll` semantic intent, and an\n * `ObjectSet` covering the selection.\n */\nexport interface RowSelectionChange<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n /**\n * Loaded row instances currently selected. When `isSelectAll` is true,\n * this reflects only the rows currently in the table — pages not yet\n * fetched are absent. Use `objectSet` for the cross-page view, and\n * `selectedRows.map(r => r.$primaryKey)` if you need the primary keys.\n */\n selectedRows: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[];\n\n /**\n * True when the user invoked \"select all\" (header checkbox) or when\n * controlled mode supplies `isAllSelected={true}`. Distinct from \"every\n * loaded row happens to be selected\" — that condition is reflected by\n * `selectedRows.length` matching the visible row count but does not set\n * this flag.\n */\n isSelectAll: boolean;\n\n /**\n * An `ObjectSet` representing the selection.\n *\n * - \"Select all\" → the underlying `ObjectSet` (`objectSet` prop if\n * provided, otherwise derived from `objectType` via `client(...)`).\n * This includes rows not yet loaded into the table.\n * - Partial selection → the underlying `ObjectSet` narrowed to\n * `{ $primaryKey: { $in: selectedRows.map(r => r.$primaryKey) } }`.\n * - \"Deselect all\" → an empty `ObjectSet` (`$in: []`).\n *\n * Works for both object and interface types, since the `$primaryKey`\n * special property does not require resolving the underlying primary key\n * property name. `undefined` only when there is no underlying `ObjectSet`\n * to derive from.\n */\n objectSet: ObjectSet<Q, RDPs> | undefined;\n}\n\nexport interface ObjectSetOptions<Q extends ObjectOrInterfaceDefinition> {\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"ObjectTableApi.js","names":[],"sources":["ObjectTableApi.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n BaseWirePropertyTypes,\n CompileTimeMetadata,\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n Osdk,\n PrimaryKeyType,\n PropertyKeys,\n PropertyValueWireToClient,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport type { QueryParameterType } from \"@osdk/client/observable\";\nimport type * as React from \"react\";\n\nimport type { ObjectTableLabels } from \"./ObjectTableLabels.js\";\nimport type { CellEditInfo, EditFieldConfig } from \"./utils/types.js\";\n\nexport type { EditFieldConfig } from \"./utils/types.js\";\n\nexport type ColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n | EditableColumnDefinition<Q, RDPs, FunctionColumns>\n | EditableFunctionColumnDefinition<Q, RDPs, FunctionColumns>\n | ReadonlyColumnDefinition<Q, RDPs, FunctionColumns>\n | ReadonlyFunctionColumnDefinition<Q, RDPs, FunctionColumns>;\n\n/** A column whose value comes from the row's object. */\ntype DerivableValueColumn<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = {\n /**\n * What the column shows — a property, a linked object property (derived\n * property), or a custom column — and that locator's configuration.\n */\n locator:\n | PropertyColumnLocator<Q>\n | RdpColumnLocator<Q, RDPs>\n | CustomColumnLocator;\n} & CellValueOverride<Q, RDPs, FunctionColumns>;\n\n/**\n * The cell's value and the type it's declared to have.\n *\n * `cellValueType` is required whenever `getCellValue` is provided — declaring\n * the type constrains what `getCellValue` may return, so a column can't\n * advertise one type and hand the cell a value of another. `cellValueType` may\n * also be declared on its own to pick the editor without transforming the\n * value.\n */\ntype CellValueOverride<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n // Use cellValueType + typed getCellValue together\n | {\n [T in BaseWirePropertyTypes]: {\n /**\n * The cell value's data type. Constrains what `getCellValue` may\n * return, and selects the editor for an `editable` column.\n */\n cellValueType: T;\n\n /**\n * Derives the cell's value from the row's object. Without it the column\n * reads the property named by `locator.id`.\n *\n * Use this to change what the cell's value *is* — what it returns is\n * the value the table renders, edits, and passes on to `renderCell`.\n * Use `renderCell` to change only how that value is displayed. The two\n * can be combined.\n */\n getCellValue: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n ) => PropertyValueWireToClient[T] | null | undefined;\n };\n }[BaseWirePropertyTypes]\n // Using cellValueType alone.\n | {\n [T in BaseWirePropertyTypes]: {\n cellValueType: T;\n getCellValue?: never;\n };\n }[BaseWirePropertyTypes]\n // Neither\n | {\n cellValueType?: undefined;\n getCellValue?: never;\n };\n\n/** A column whose value comes from a function query rather than the row. */\ninterface FunctionValueColumn<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /** What the column shows, and that locator's configuration. */\n locator: FunctionColumnLocator<Q, RDPs, FunctionColumns>;\n\n /** The cell value's data type. */\n cellValueType?: BaseWirePropertyTypes;\n\n /**\n * Use {@link FunctionColumnLocator}'s own `getValue` instead.\n */\n getCellValue?: never;\n}\n\ninterface SharedColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * @default true\n */\n isVisible?: boolean;\n\n /**\n * @default none\n */\n pinned?: \"left\" | \"right\" | \"none\";\n width?: number;\n minWidth?: number;\n maxWidth?: number;\n resizable?: boolean;\n orderable?: boolean;\n\n /**\n * Custom renderer for the cell value.\n *\n * This changes only how the cell's value is displayed; the value itself is\n * unchanged. To change the value, use `getCellValue` (and declare its\n * `cellValueType`) — `renderCell` then receives that value as its third\n * argument. The two can be combined.\n *\n * Interaction with `editable` columns:\n * - When `editMode: \"manual\"` (default), `renderCell` is used while the\n * table is read-only (Edit Table button visible) and the editable cell\n * takes over once the user enters edit mode.\n * - When `editMode: \"always\"`, the editable cell always wins on editable\n * columns and `renderCell` is ignored — `editMode: \"always\"` opts the\n * column into a permanently-editable surface, leaving no read-only\n * state for `renderCell` to render. Use `editMode: \"manual\"` if you\n * need a custom display alongside editing.\n *\n * @param value - The cell's value, so there's no need to recompute what\n * `getCellValue` (or the property lookup) already produced.\n */\n renderCell?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n locator: ColumnDefinitionLocator<Q, RDPs, FunctionColumns>,\n value: unknown,\n ) => React.ReactNode;\n\n /**\n * If provided, this will be used in the column header.\n * If both columnName and renderHeader are provided, renderHeader will take precedence in the table header.\n * columnName will still be used in other parts where the column name is displayed.\n *\n * If not provided,\n * for a property column, the property displayName will be used\n * for other columns, the id will be used.\n */\n columnName?: string;\n\n /**\n * If provided, this will be used to render the header component.\n * When both columnName and renderHeader are provided, renderHeader will take precedence in the table header.\n */\n renderHeader?: () => React.ReactNode;\n}\n\ninterface EditableColumnOptions<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * `editable` can be a boolean or a predicate that receives the row's object\n * and returns whether the cell is editable\n */\n editable:\n | true\n | ((\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => boolean);\n\n /**\n * Configuration for the cell editor component.\n *\n * When provided, the column uses the specified field component\n * (e.g. dropdown) instead of the default auto-detected text/number input.\n *\n * `getFieldComponentProps` receives the row's object and a map of any\n * pending edits for that row (keyed by column id), and returns the props to\n * pass to the field component. Editor configuration can depend on the\n * current row or on other in-progress edits within the row.\n */\n editFieldConfig?: EditFieldConfig<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >;\n\n /**\n * Additional function to validate the cell value during edit.\n *\n * @param value the current cell value\n * @returns a promise that resolves to an error message string if validation fails, or undefined if validation succeeds\n */\n validateEdit?: (value: unknown) => Promise<string | undefined>;\n}\n\ntype EditableColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = SharedColumnDefinition<Q, RDPs, FunctionColumns> &\n EditableColumnOptions<Q, RDPs> &\n DerivableValueColumn<Q, RDPs, FunctionColumns>;\n\n/** Editable column backed by a function query. */\ninterface EditableFunctionColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>\n extends\n SharedColumnDefinition<Q, RDPs, FunctionColumns>,\n EditableColumnOptions<Q, RDPs>,\n FunctionValueColumn<Q, RDPs, FunctionColumns> {}\n\n/**\n * Column definition for a read-only column (default).\n * `editFieldConfig` and `validateEdit` are not available.\n */\ntype ReadonlyColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = SharedColumnDefinition<Q, RDPs, FunctionColumns> &\n DerivableValueColumn<Q, RDPs, FunctionColumns> & { editable?: false };\n\n/** Read-only column backed by a function query. */\ninterface ReadonlyFunctionColumnDefinition<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>\n extends\n SharedColumnDefinition<Q, RDPs, FunctionColumns>,\n FunctionValueColumn<Q, RDPs, FunctionColumns> {\n editable?: false;\n}\n\nexport type ExtractQueryParameters<Q extends QueryDefinition> =\n CompileTimeMetadata<Q>[\"parameters\"] extends Record<string, never>\n ? undefined\n : QueryParameterType<CompileTimeMetadata<Q>[\"parameters\"]>;\n\nexport interface PropertyColumnLocator<Q extends ObjectOrInterfaceDefinition> {\n type: \"property\";\n id: PropertyKeys<Q>;\n}\n\n/**\n * Concrete function column locator for a single key K.\n * Correlates the id, queryDefinition, and getFunctionParams types.\n */\ninterface FunctionColumnLocatorForKey<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n FunctionColumns extends Record<string, QueryDefinition<{}>>,\n K extends keyof FunctionColumns,\n> {\n /**\n * This is equivalent to workshop's function-backed columns.\n * The function needs to meet the specifications stated in https://www.palantir.com/docs/foundry/workshop/widgets-object-table/#function-backed-columns\n */\n type: \"function\";\n id: K;\n queryDefinition: FunctionColumns[K];\n\n /**\n * The function will be called with the current object set to get the input parameters for the function query.\n * @param objectSet - The current object set.\n * @returns - The function's input parameters including the object set.\n */\n getFunctionParams: (\n objectSet: ObjectSet<Q, RDPs>,\n ) => ExtractQueryParameters<FunctionColumns[K]>;\n\n /**\n * Function to generate keys for looking up results in the FunctionsMap.\n * @param object - The object instance\n * @returns - The key to use for looking up this object's result in the FunctionsMap\n */\n getKey: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => string;\n\n /**\n * Function to extract the cell value from the raw cell data returned by the function.\n * This is useful when functions return custom types with multiple properties.\n * @param cellData - The raw data returned by the function for this object\n * @returns - The value to display in the cell\n */\n getValue?: (cellData?: unknown) => unknown;\n\n /**\n * Minimum time between re-fetches of the same function with the same parameters, in milliseconds.\n * Defaults to 5 minutes as it is expensive to fetch function columns for a large object set\n * and they are expected to be relatively static in the context of an object table\n *\n * @default 300_000 (5 minutes)\n */\n dedupeIntervalMs?: number;\n\n /**\n * Object type apiNames the function reads but doesn't take as a parameter (e.g.\n * linked object types the function traverses internally). The column auto-revalidates\n * when an action edits an object of any of these types. Param-derived types are\n * tracked automatically and don't need to be listed here.\n */\n dependsOn?: string[];\n}\n\n/**\n * Distributes over each key in FunctionColumns so that id, queryDefinition,\n * and getFunctionParams are correlated per key.\n */\nexport type FunctionColumnLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> = keyof FunctionColumns extends infer K\n ? K extends keyof FunctionColumns\n ? FunctionColumnLocatorForKey<Q, RDPs, FunctionColumns, K>\n : never\n : never;\n\nexport interface RdpColumnLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n type: \"rdp\";\n id: keyof RDPs;\n creator: DerivedProperty.Creator<Q, RDPs[keyof RDPs]>;\n}\n\nexport interface CustomColumnLocator {\n type: \"custom\";\n id: string;\n}\n\nexport type ColumnDefinitionLocator<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> =\n | PropertyColumnLocator<Q>\n | FunctionColumnLocator<Q, RDPs, FunctionColumns>\n | RdpColumnLocator<Q, RDPs>\n | CustomColumnLocator;\n\nexport interface ObjectTableProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /**\n * The object or interface type of the object\n * If objectSet is not provided, objects will be fetched based on this type.\n */\n objectType: Q;\n\n /**\n * The set of objects to show in the table.\n * If provided, the table fetches through this object set instead of fetching based on\n * objectType. Supported for both object and interface types.\n *\n * For an interface object set, rows expose the interface's declared properties;\n * the underlying concrete object's non-interface properties are not loaded.\n * Use objectType-based fetching if you need those.\n */\n objectSet?: ObjectSet<Q>;\n\n /**\n * Ordered list of column definitions to show in the table\n *\n * If not provided, all of the properties of the object type will be shown in default order.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n\n objectSetOptions?: ObjectSetOptions<Q>;\n\n /**\n * Minimum time between fetch requests in milliseconds.\n * Increasing this value reduces redundant network calls when the same data\n * is requested multiple times in quick succession.\n *\n * @default 60_000 1 minute\n */\n dedupeIntervalMs?: number;\n\n /**\n * Enable streaming updates via websocket subscription.\n * When true, the table will automatically update when matching\n * objects are added, updated, or removed in Foundry.\n *\n * Limitations: `streamUpdates` cannot be used together with `pivotTo` or\n * `withProperties`. The server does not support websocket subscriptions\n * for link-traversal or derived-property queries. Those queries still\n * fetch data normally but won't receive real-time updates.\n *\n * @default false\n */\n streamUpdates?: boolean;\n\n /**\n * Number of objects to fetch per page.\n *\n * @default 50\n */\n pageSize?: number;\n\n /**\n * The current where clause to filter the objects in the table.\n * If provided, the filter is controlled.\n */\n filter?: WhereClause<Q, RDPs>;\n\n /**\n * Whether the column configuration dialog for column visibility and ordering is available to the user.\n *\n * @default true\n */\n enableColumnConfig?: boolean;\n\n /**\n * Whether columns can be pinned by the user.\n *\n * @default true\n */\n enableColumnPinning?: boolean;\n\n /**\n * Whether columns can be resized by the user.\n *\n * @default true\n */\n enableColumnResizing?: boolean;\n\n /**\n * Called when the column visibility or ordering changed.\n *\n * If provided, the table will allow the user to show/hide columns.\n *\n * @param newStates The columns sorted in their display order in the table and their visibility state.\n */\n onColumnVisibilityChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n isVisible: boolean;\n }>,\n ) => void;\n\n /**\n * Called when the pinned columns change.\n *\n * If provided, the table will allow the user to pin/unpin columns.\n *\n * @param newStates The new list of column pin states\n */\n onColumnsPinnedChanged?: (\n newStates: Array<{\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns;\n pinned: \"left\" | \"right\" | \"none\";\n }>,\n ) => void;\n\n /**\n * Called when a column is resized.\n *\n * @param columnId The ID of the resized column\n * @param newWidth The new width of the column. When newWidth = null, the column size is reset.\n */\n onColumnResize?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n newWidth: number | null,\n ) => void;\n\n /**\n * Called when a column header is clicked.\n *\n * The columnId matches the `locator.id` configured on the column definition.\n * The dropdown menu trigger is excluded — clicking the chevron opens the\n * header menu instead of firing this callback.\n *\n * @param columnId The id of the clicked column\n */\n onColumnHeaderClick?: (\n columnId: PropertyKeys<Q> | keyof RDPs | keyof FunctionColumns,\n ) => void;\n\n /**\n * Whether the table is sortable by the user.\n *\n * @default true\n */\n enableOrdering?: boolean;\n\n /**\n * The default order by clause to sort the objects in the table.\n * If provided without orderBy prop, the sorting is uncontrolled.\n * If both orderBy and defaultOrderBy are provided, orderBy takes precedence.\n */\n defaultOrderBy?: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * The current order by clause to sort the objects in the table.\n * If provided, the sorting is controlled.\n * If both orderBy and defaultOrderBy are provided, orderBy takes precedence.\n */\n orderBy?: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>;\n\n /**\n * Called when the order by clause is changed.\n * Required when sorting is controlled.\n *\n * @param newOrderBy The new order by clause\n */\n onOrderByChanged?: (\n newOrderBy: Array<{\n property: PropertyKeys<Q> | keyof RDPs;\n direction: \"asc\" | \"desc\";\n }>,\n ) => void;\n\n /**\n * Selection mode for the table rows.\n *\n * If multiple, a checkbox will be shown for each row to allow selecting multiple rows\n * as well as a top-level checkbox in the header to select all rows.\n *\n * @default \"none\"\n */\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n\n /**\n * The currently selected rows in the table.\n * If provided, the row selection is controlled.\n */\n selectedRows?: PrimaryKeyType<Q>[];\n\n /**\n * Indicates whether all rows are selected in controlled mode.\n * When true, the table will show all rows as selected regardless of the selectedRows array.\n */\n isAllSelected?: boolean;\n\n /**\n * Called when the row selection changes, with a {@link RowSelectionChange}\n * payload describing the new state.\n *\n * @param change The new selection state. See {@link RowSelectionChange}.\n */\n onRowSelectionChanged?: (change: RowSelectionChange<Q, RDPs>) => void;\n\n /**\n * The primary key of the row to render as visually focused (the\n * \"last interacted\" row). When provided, focus state is controlled by\n * the caller.\n *\n * Stored as a primary key rather than a full object so the focus does\n * not go stale when the underlying row data changes.\n *\n * Pass `null` to render no row as focused.\n */\n focusedRow?: PrimaryKeyType<Q> | null;\n\n /**\n * Called when the focused row changes — fires in both controlled and\n * uncontrolled modes so callers can observe focus without taking it\n * over.\n *\n * @param row The newly-focused row object, or `null` if focus was\n * cleared\n */\n onFocusedRowChanged?: (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs> | null,\n ) => void;\n\n /**\n * Controls the edit mode behavior of the table.\n * - \"always\": Editable cells are immediately in edit mode on row clicked.\n * - \"manual\": User can toggle edit mode on/off via the Edit Table button.\n *\n * @default \"manual\"\n */\n editMode?: \"always\" | \"manual\";\n\n /**\n * Whether to render the bottom edit footer that hosts the\n * \"Edit Table\" / \"Cancel\" / \"Submit Edits\" buttons and the edit-state\n * indicators (modification count, validation errors).\n *\n * @default true whenever the table has at least one column declared\n * editable (i.e. any column with `editable: true` or `editable: (object) => boolean`).\n * When `false`, the \"Edit Table\" and \"Submit Edits\" buttons will not be shown.\n */\n showEditFooter?: boolean;\n\n /**\n * Called after the value of a cell is edited and committed by the user.\n *\n * @param info An object containing details about the cell that was edited,\n * including the rowId, columnId, new and old values, and the row data before the edit\n */\n onCellValueChanged?: (\n info: CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => void;\n\n /**\n * If provided, the \"Submit Edits\" button will be shown in the edit footer.\n *\n * @param edits an array of edit info containing details about the edited cells\n * including the rowId, columnId, new and old values, and the row data before the edit\n * @return a promise that resolves to true if the edits were successfully submitted\n */\n onSubmitEdits?: (\n edits: CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >[],\n ) => Promise<boolean>;\n\n /**\n * Called when a row is clicked.\n *\n * @param object The object representing the clicked row\n */\n onRowClick?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => void;\n\n /**\n * If provided, will render this context menu when right clicking on a cell\n */\n renderCellContextMenu?: (\n row: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n cellValue: unknown,\n ) => React.ReactNode;\n\n /**\n * The height of each row in pixels.\n *\n * @default 40\n */\n rowHeight?: number;\n\n /**\n * Render override for the empty state. Called when the table has no\n * rows and no error. When omitted, a default \"No Data\" indicator is\n * rendered.\n */\n renderEmptyState?: () => React.ReactNode;\n\n /**\n * Returns extra HTML attributes (typically `data-*`) to apply to each\n * row element. Use this to drive conditional row styling\n */\n getRowAttributes?: (\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n ) => Record<string, string | undefined>;\n\n /**\n * Imperative handle for programmatic table actions. Pass a ref\n * (`useRef<ObjectTableHandle<Q, RDPs>>(null)`) to call\n * {@link ObjectTableHandle} methods such as\n * {@link ObjectTableHandle.getSnapshot}.\n */\n tableRef?: React.Ref<ObjectTableHandle<Q, RDPs>>;\n\n className?: string;\n\n /**\n * Overrides for the table's user-facing strings. Provide any subset; unset keys fall\n * back to the built-in English defaults. Use this to localize the table or\n * adjust wording. See {@link ObjectTableLabels}.\n *\n * @default undefined (built-in English strings)\n */\n labels?: Partial<ObjectTableLabels>;\n}\n\n/**\n * Imperative handle exposing programmatic actions on an {@link ObjectTable}.\n * Obtain it by passing {@link ObjectTableProps.tableRef}.\n */\nexport interface ObjectTableHandle<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Loads every row matching the object set and returns a format-agnostic\n * snapshot of the table's columns, row values, and total count. The caller\n * is responsible for turning the snapshot into a downloadable artifact\n * (CSV, Spreadsheet, JSON, clipboard, …).\n *\n * Property, derived-property, and function-backed columns are included.\n * Function-backed cells are fetched per page during snapshot collection;\n * when a page's fetch fails, `row.getValue(columnId)` returns the thrown\n * `Error` instance for the affected cells while the rest of the snapshot\n * resolves normally.\n * Columns defined with `locator.type === \"custom\"` are omitted because\n * they have no underlying value to export.\n *\n * The returned promise rejects up front when the object set's `totalCount`\n * exceeds `rowLimit`. When `totalCount` is unavailable, it instead rejects\n * mid-load once more than `rowLimit` rows have been pulled, so an unknown\n * count can't drain an unbounded set into the client. Otherwise every\n * matching row is loaded.\n *\n * @param options See {@link ObjectTableSnapshotOptions}.\n */\n getSnapshot: (\n options?: ObjectTableSnapshotOptions,\n ) => Promise<ObjectTableSnapshot<Q, RDPs>>;\n}\n\n/**\n * Options for {@link ObjectTableHandle[\"getSnapshot\"]}.\n */\nexport interface ObjectTableSnapshotOptions {\n /**\n * Upper bound on how many rows the snapshot may contain. When the object\n * set's total row count exceeds this value, `getSnapshot` rejects;\n * otherwise every matching row is loaded.\n *\n * @default 10_000\n */\n rowLimit?: number;\n}\n\n/**\n * A point-in-time capture of an {@link ObjectTable}'s columns and row values,\n * returned by {@link ObjectTableHandle.getSnapshot}.\n */\nexport interface ObjectTableSnapshot<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n columns: ObjectTableDataColumn[];\n rows: ObjectTableDataRow<Q, RDPs>[];\n /**\n * Total number of objects matching the underlying object set, as reported\n * by the API. `undefined` when the API did not provide a count. Encoded as\n * a string to match the underlying list-payload representation.\n */\n totalCount: string | undefined;\n}\n\n/**\n * A single column in an {@link ObjectTableSnapshot}.\n */\nexport interface ObjectTableDataColumn {\n /** Column id, matching the `locator.id` of the column definition. */\n id: string;\n /** Display name shown in the table header. */\n name: string;\n}\n\n/**\n * A single row in an {@link ObjectTableSnapshot}.\n */\nexport interface ObjectTableDataRow<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /** Row id (the underlying object's `$primaryKey` rendered as a string). */\n id: string;\n /** The underlying loaded object. */\n object: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>;\n /**\n * Returns the cell value for a given column id, or `undefined` when the\n * column is not part of the snapshot. Function-backed cells whose query\n * failed surface the thrown `Error` instance as their value.\n */\n getValue: (columnId: string) => unknown;\n}\n\n/**\n * Payload for {@link ObjectTableProps.onRowSelectionChanged}. Consolidates\n * the loaded row instances, the `isSelectAll` semantic intent, and an\n * `ObjectSet` covering the selection.\n */\nexport interface RowSelectionChange<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n /**\n * Loaded row instances currently selected. When `isSelectAll` is true,\n * this reflects only the rows currently in the table — pages not yet\n * fetched are absent. Use `objectSet` for the cross-page view, and\n * `selectedRows.map(r => r.$primaryKey)` if you need the primary keys.\n */\n selectedRows: Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[];\n\n /**\n * True when the user invoked \"select all\" (header checkbox) or when\n * controlled mode supplies `isAllSelected={true}`. Distinct from \"every\n * loaded row happens to be selected\" — that condition is reflected by\n * `selectedRows.length` matching the visible row count but does not set\n * this flag.\n */\n isSelectAll: boolean;\n\n /**\n * An `ObjectSet` representing the selection.\n *\n * - \"Select all\" → the underlying `ObjectSet` (`objectSet` prop if\n * provided, otherwise derived from `objectType` via `client(...)`).\n * This includes rows not yet loaded into the table.\n * - Partial selection → the underlying `ObjectSet` narrowed to\n * `{ $primaryKey: { $in: selectedRows.map(r => r.$primaryKey) } }`.\n * - \"Deselect all\" → an empty `ObjectSet` (`$in: []`).\n *\n * Works for both object and interface types, since the `$primaryKey`\n * special property does not require resolving the underlying primary key\n * property name. `undefined` only when there is no underlying `ObjectSet`\n * to derive from.\n */\n objectSet: ObjectSet<Q, RDPs> | undefined;\n}\n\nexport interface ObjectSetOptions<Q extends ObjectOrInterfaceDefinition> {\n /**\n * Object sets to union with\n */\n union?: ObjectSet<Q>[];\n\n /**\n * Object sets to intersect with\n */\n intersect?: ObjectSet<Q>[];\n\n /**\n * Object sets to subtract from\n */\n subtract?: ObjectSet<Q>[];\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -53,6 +53,7 @@ function getColumnsFromColumnDefinitions(columnDefinitions, objectProperties) {
|
|
|
53
53
|
resizable,
|
|
54
54
|
orderable,
|
|
55
55
|
editable,
|
|
56
|
+
getCellValue,
|
|
56
57
|
renderCell,
|
|
57
58
|
renderHeader,
|
|
58
59
|
columnName
|
|
@@ -61,11 +62,23 @@ function getColumnsFromColumnDefinitions(columnDefinitions, objectProperties) {
|
|
|
61
62
|
const validateEdit = col.editable ? col.validateEdit : undefined;
|
|
62
63
|
const propertyMetadata = locator.type === "property" ? objectProperties?.[locator.id] : undefined;
|
|
63
64
|
const colKey = locator.id;
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
// An explicit cellValueType wins: custom and derived columns have no
|
|
67
|
+
// ontology metadata to fall back on.
|
|
68
|
+
const dataType = col.cellValueType ?? getDataType(propertyMetadata);
|
|
65
69
|
const markingType = propertyMetadata?.typeMetadata?.type === "marking" ? propertyMetadata.typeMetadata.markingType : undefined;
|
|
70
|
+
|
|
71
|
+
// `accessorFn` routes the value through `getCellValue`, so everything
|
|
72
|
+
// downstream that reads `cellContext.getValue()` — default rendering, the
|
|
73
|
+
// editor, the context menu — picks it up without further plumbing.
|
|
74
|
+
const accessor = getCellValue ? {
|
|
75
|
+
accessorFn: object => getCellValue(object, locator)
|
|
76
|
+
} : {
|
|
77
|
+
accessorKey: colKey
|
|
78
|
+
};
|
|
66
79
|
const colDef = {
|
|
67
80
|
id: colKey,
|
|
68
|
-
|
|
81
|
+
...accessor,
|
|
69
82
|
header: renderHeader ?? (columnName || propertyMetadata?.displayName),
|
|
70
83
|
meta: {
|
|
71
84
|
columnName: columnName || propertyMetadata?.displayName,
|
|
@@ -92,7 +105,7 @@ function getColumnsFromColumnDefinitions(columnDefinitions, objectProperties) {
|
|
|
92
105
|
const meta = cellContext.table.options.meta;
|
|
93
106
|
const isEditable = shouldShowEditableCell(editable, meta?.onCellEdit, meta?.isInEditMode);
|
|
94
107
|
if (renderCell && !isEditable) {
|
|
95
|
-
return renderCell(object, locator);
|
|
108
|
+
return renderCell(object, locator, cellContext.getValue());
|
|
96
109
|
}
|
|
97
110
|
return renderDefaultCell(cellContext);
|
|
98
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useColumnDefs.js","names":["useOsdkMetadata","useMemo","renderDefaultCell","shouldShowEditableCell","useColumnDefs","objectType","columnDefinitions","metadata","loading","error","columns","objectProperties","properties","getColumnsFromColumnDefinitions","getDefaultColumns","map","col","locator","width","minWidth","maxWidth","resizable","orderable","editable","renderCell","renderHeader","columnName","editFieldConfig","undefined","validateEdit","propertyMetadata","type","id","colKey","dataType","getDataType","markingType","typeMetadata","colDef","accessorKey","header","displayName","meta","isAsyncColumn","isVisible","size","minSize","maxSize","enableResizing","enableSorting","cell","cellContext","object","row","original","table","options","isEditable","onCellEdit","isInEditMode","Object","entries","key","property","length"],"sources":["useColumnDefs.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectMetadata,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { useOsdkMetadata } from \"@osdk/react\";\nimport type { AccessorColumnDef } from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\n\nimport { renderDefaultCell } from \"../DefaultCellRenderer.js\";\nimport type { ColumnDefinition } from \"../ObjectTableApi.js\";\nimport { shouldShowEditableCell } from \"../utils/shouldShowEditableCell.js\";\n\nexport interface UseColumnDefsResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> {\n columns: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >[];\n\n loading: boolean;\n\n error: string | undefined;\n}\n\n/**\n * Hook which builds column definitions for tanstack-table given the objectSet\n */\nexport function useColumnDefs<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n objectType: Q,\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>,\n): UseColumnDefsResult<Q, RDPs> {\n const { metadata, loading, error } = useOsdkMetadata(objectType);\n\n const columns: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >[] = useMemo(() => {\n const objectProperties = metadata?.properties;\n // If columnDefinitions is provided, construct colDefs with it\n if (columnDefinitions) {\n return getColumnsFromColumnDefinitions<Q, RDPs, FunctionColumns>(\n columnDefinitions,\n objectProperties,\n );\n }\n\n // If not, return the default columns from the object properties\n return getDefaultColumns<Q, RDPs>(objectProperties);\n }, [columnDefinitions, metadata?.properties]);\n\n return { columns, loading, error };\n}\n\nfunction getColumnsFromColumnDefinitions<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n columnDefinitions: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>,\n objectProperties?: Record<any, ObjectMetadata.Property>,\n): Array<\n AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >\n> {\n return columnDefinitions.map((col) => {\n const {\n locator,\n width,\n minWidth,\n maxWidth,\n resizable,\n orderable,\n editable,\n renderCell,\n renderHeader,\n columnName,\n } = col;\n\n const editFieldConfig = col.editable ? col.editFieldConfig : undefined;\n const validateEdit = col.editable ? col.validateEdit : undefined;\n\n const propertyMetadata =\n locator.type === \"property\" ? objectProperties?.[locator.id] : undefined;\n\n const colKey = locator.id as string;\n\n const dataType = getDataType(propertyMetadata);\n\n const markingType =\n propertyMetadata?.typeMetadata?.type === \"marking\"\n ? propertyMetadata.typeMetadata.markingType\n : undefined;\n\n const colDef: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n id: colKey,\n accessorKey: colKey,\n header: renderHeader ?? (columnName || propertyMetadata?.displayName),\n meta: {\n columnName: columnName || propertyMetadata?.displayName,\n isAsyncColumn: locator.type === \"function\",\n isVisible: col.isVisible !== false,\n editable,\n editFieldConfig,\n dataType,\n markingType,\n validateEdit,\n },\n size: width,\n ...(minWidth ? { minSize: minWidth } : {}),\n ...(maxWidth ? { maxSize: maxWidth } : {}),\n enableResizing: resizable,\n // Function-backed columns must be sorted on the frontend, so disable sorting for now\n enableSorting: locator.type === \"function\" ? false : orderable,\n cell: (cellContext) => {\n const object: Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n > = cellContext.row.original;\n\n const meta = cellContext.table.options.meta;\n const isEditable = shouldShowEditableCell<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >(editable, meta?.onCellEdit, meta?.isInEditMode);\n\n if (renderCell && !isEditable) {\n return renderCell(object, locator);\n }\n\n return renderDefaultCell(cellContext);\n },\n };\n\n return colDef;\n });\n}\n\nfunction getDefaultColumns<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n>(\n objectProperties?: Record<any, ObjectMetadata.Property>,\n): Array<\n AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >\n> {\n if (!objectProperties) return [];\n\n return Object.entries(objectProperties).map(([key, property]) => {\n const colDef: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n accessorKey: key,\n header: property.displayName ?? key,\n meta: {\n dataType: getDataType(property),\n },\n };\n return colDef;\n });\n}\n\n/**\n * The property's `WirePropertyTypes` value, used for type-aware rendering such\n * as the header's and multi-sort dialog's sort icons.\n *\n * Structured types (arrays, structs) carry an object rather than a wire type\n * string, and a column may have no metadata at all (e.g. function-backed\n * columns), so both yield `undefined`.\n */\nfunction getDataType(\n property: ObjectMetadata.Property | undefined,\n): string | undefined {\n return typeof property?.type === \"string\" && property.type.length > 0\n ? property.type\n : undefined;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,SAASA,eAAe,QAAQ,aAAa;AAE7C,SAASC,OAAO,QAAQ,OAAO;AAE/B,SAASC,iBAAiB,QAAQ,2BAA2B;AAE7D,SAASC,sBAAsB,QAAQ,oCAAoC;AAe3E;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAQ3BC,UAAa,EACbC,iBAAqE,EACvC;EAC9B,MAAM;IAAEC,QAAQ;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGT,eAAe,CAACK,UAAU,CAAC;EAEhE,MAAMK,OAEH,GAAGT,OAAO,CAAC,MAAM;IAClB,MAAMU,gBAAgB,GAAGJ,QAAQ,EAAEK,UAAU;IAC7C;IACA,IAAIN,iBAAiB,EAAE;MACrB,OAAOO,+BAA+B,CACpCP,iBAAiB,EACjBK,gBACF,CAAC;IACH;;IAEA;IACA,OAAOG,iBAAiB,CAAUH,gBAAgB,CAAC;EACrD,CAAC,EAAE,CAACL,iBAAiB,EAAEC,QAAQ,EAAEK,UAAU,CAAC,CAAC;EAE7C,OAAO;IAAEF,OAAO;IAAEF,OAAO;IAAEC;EAAM,CAAC;AACpC;AAEA,SAASI,+BAA+BA,CAQtCP,iBAAoE,EACpEK,gBAAuD,EAKvD;EACA,OAAOL,iBAAiB,CAACS,GAAG,CAAEC,GAAG,IAAK;IACpC,MAAM;MACJC,OAAO;MACPC,KAAK;MACLC,QAAQ;MACRC,QAAQ;MACRC,SAAS;MACT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S;AACf","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useColumnDefs.js","names":["useOsdkMetadata","useMemo","renderDefaultCell","shouldShowEditableCell","useColumnDefs","objectType","columnDefinitions","metadata","loading","error","columns","objectProperties","properties","getColumnsFromColumnDefinitions","getDefaultColumns","map","col","locator","width","minWidth","maxWidth","resizable","orderable","editable","getCellValue","renderCell","renderHeader","columnName","editFieldConfig","undefined","validateEdit","propertyMetadata","type","id","colKey","dataType","cellValueType","getDataType","markingType","typeMetadata","accessor","accessorFn","object","accessorKey","colDef","header","displayName","meta","isAsyncColumn","isVisible","size","minSize","maxSize","enableResizing","enableSorting","cell","cellContext","row","original","table","options","isEditable","onCellEdit","isInEditMode","getValue","Object","entries","key","property","length"],"sources":["useColumnDefs.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectMetadata,\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { useOsdkMetadata } from \"@osdk/react\";\nimport type {\n AccessorColumnDef,\n AccessorFnColumnDef,\n AccessorKeyColumnDef,\n} from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\n\nimport { renderDefaultCell } from \"../DefaultCellRenderer.js\";\nimport type { ColumnDefinition } from \"../ObjectTableApi.js\";\nimport { shouldShowEditableCell } from \"../utils/shouldShowEditableCell.js\";\n\nexport interface UseColumnDefsResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> {\n columns: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >[];\n\n loading: boolean;\n\n error: string | undefined;\n}\n\n/**\n * Hook which builds column definitions for tanstack-table given the objectSet\n */\nexport function useColumnDefs<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n objectType: Q,\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>,\n): UseColumnDefsResult<Q, RDPs> {\n const { metadata, loading, error } = useOsdkMetadata(objectType);\n\n const columns: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >[] = useMemo(() => {\n const objectProperties = metadata?.properties;\n // If columnDefinitions is provided, construct colDefs with it\n if (columnDefinitions) {\n return getColumnsFromColumnDefinitions<Q, RDPs, FunctionColumns>(\n columnDefinitions,\n objectProperties,\n );\n }\n\n // If not, return the default columns from the object properties\n return getDefaultColumns<Q, RDPs>(objectProperties);\n }, [columnDefinitions, metadata?.properties]);\n\n return { columns, loading, error };\n}\n\nfunction getColumnsFromColumnDefinitions<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n columnDefinitions: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>,\n objectProperties?: Record<any, ObjectMetadata.Property>,\n): Array<\n AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >\n> {\n return columnDefinitions.map((col) => {\n const {\n locator,\n width,\n minWidth,\n maxWidth,\n resizable,\n orderable,\n editable,\n getCellValue,\n renderCell,\n renderHeader,\n columnName,\n } = col;\n\n const editFieldConfig = col.editable ? col.editFieldConfig : undefined;\n const validateEdit = col.editable ? col.validateEdit : undefined;\n\n const propertyMetadata =\n locator.type === \"property\" ? objectProperties?.[locator.id] : undefined;\n\n const colKey = locator.id as string;\n\n // An explicit cellValueType wins: custom and derived columns have no\n // ontology metadata to fall back on.\n const dataType = col.cellValueType ?? getDataType(propertyMetadata);\n\n const markingType =\n propertyMetadata?.typeMetadata?.type === \"marking\"\n ? propertyMetadata.typeMetadata.markingType\n : undefined;\n\n // `accessorFn` routes the value through `getCellValue`, so everything\n // downstream that reads `cellContext.getValue()` — default rendering, the\n // editor, the context menu — picks it up without further plumbing.\n const accessor:\n | Pick<\n AccessorFnColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >,\n \"accessorFn\"\n >\n | Pick<\n AccessorKeyColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >,\n \"accessorKey\"\n > = getCellValue\n ? { accessorFn: (object) => getCellValue(object, locator) }\n : { accessorKey: colKey };\n\n const colDef: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n id: colKey,\n ...accessor,\n header: renderHeader ?? (columnName || propertyMetadata?.displayName),\n meta: {\n columnName: columnName || propertyMetadata?.displayName,\n isAsyncColumn: locator.type === \"function\",\n isVisible: col.isVisible !== false,\n editable,\n editFieldConfig,\n dataType,\n markingType,\n validateEdit,\n },\n size: width,\n ...(minWidth ? { minSize: minWidth } : {}),\n ...(maxWidth ? { maxSize: maxWidth } : {}),\n enableResizing: resizable,\n // Function-backed columns must be sorted on the frontend, so disable sorting for now\n enableSorting: locator.type === \"function\" ? false : orderable,\n cell: (cellContext) => {\n const object: Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n > = cellContext.row.original;\n\n const meta = cellContext.table.options.meta;\n const isEditable = shouldShowEditableCell<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >(editable, meta?.onCellEdit, meta?.isInEditMode);\n\n if (renderCell && !isEditable) {\n return renderCell(object, locator, cellContext.getValue());\n }\n\n return renderDefaultCell(cellContext);\n },\n };\n\n return colDef;\n });\n}\n\nfunction getDefaultColumns<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n objectProperties?: Record<any, ObjectMetadata.Property>,\n): Array<\n AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >\n> {\n if (!objectProperties) return [];\n\n return Object.entries(objectProperties).map(([key, property]) => {\n const colDef: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n accessorKey: key,\n header: property.displayName ?? key,\n meta: {\n dataType: getDataType(property),\n },\n };\n return colDef;\n });\n}\n\n/**\n * The property's `WirePropertyTypes` value, used for type-aware rendering such\n * as the header's and multi-sort dialog's sort icons.\n *\n * Structured types (arrays, structs) carry an object rather than a wire type\n * string, and a column may have no metadata at all (e.g. function-backed\n * columns), so both yield `undefined`.\n */\nfunction getDataType(\n property: ObjectMetadata.Property | undefined,\n): string | undefined {\n return typeof property?.type === \"string\" && property.type.length > 0\n ? property.type\n : undefined;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,SAASA,eAAe,QAAQ,aAAa;AAM7C,SAASC,OAAO,QAAQ,OAAO;AAE/B,SAASC,iBAAiB,QAAQ,2BAA2B;AAE7D,SAASC,sBAAsB,QAAQ,oCAAoC;AAe3E;AACA;AACA;AACA,OAAO,SAASC,aAAaA,CAQ3BC,UAAa,EACbC,iBAAqE,EACvC;EAC9B,MAAM;IAAEC,QAAQ;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGT,eAAe,CAACK,UAAU,CAAC;EAEhE,MAAMK,OAEH,GAAGT,OAAO,CAAC,MAAM;IAClB,MAAMU,gBAAgB,GAAGJ,QAAQ,EAAEK,UA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,WAAW,CAAC;MACvC;IACF,CAAC;IAED,OAAOZ,MAAM;EACf,CAAC,CAAC;AACJ;AAEA,SAAS9B,iBAAiBA,CAIxBH,gBAAuD,EAKvD;EACA,IAAI,CAACA,gBAAgB,EAAE,OAAO,EAAE;EAEhC,OAAOsD,MAAM,CAACC,OAAO,CAACvD,gBAAgB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACoD,GAAG,EAAEC,QAAQ,CAAC,KAAK;IAC/D,MAAMxB,MAEL,GAAG;MACFD,WAAW,EAAEwB,GAAG;MAChBtB,MAAM,EAAEuB,QAAQ,CAACtB,WAAW,IAAIqB,GAAG;MACnCpB,IAAI,EAAE;QACJZ,QAAQ,EAAEE,WAAW,CAAC+B,QAAQ;MAChC;IACF,CAAC;IACD,OAAOxB,MAAM;EACf,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASP,WAAWA,CAClB+B,QAA6C,EACzB;EACpB,OAAO,OAAOA,QAAQ,EAAEpC,IAAI,KAAK,QAAQ,IAAIoC,QAAQ,CAACpC,IAAI,CAACqC,MAAM,GAAG,CAAC,GACjED,QAAQ,CAACpC,IAAI,GACbH,SAAS;AACf","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditableTable.js","names":["useCallback","useState","cellValuesEqual","useEditableTable","editMode","onCellValueChanged","onSubmitEdits","isActive","setActive","cellEdits","setCellEdits","validationErrors","setValidationErrors","Map","clearCellValidationError","cellId","prev","newErrors","delete","handleCellEdit","info","newValue","oldValue","_","rest","clearEdits","handleSubmitEdits","edits","Object","values","onCellValidationError","error","set","editModeState","type","onCellEdit","undefined"],"sources":["useEditableTable.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { useCallback, useState } from \"react\";\n\nimport type { ObjectTableProps } from \"../ObjectTableApi.js\";\nimport { cellValuesEqual } from \"../utils/editableUtils.js\";\nimport type {\n CellEditInfo,\n EditableConfig,\n EditModeState,\n} from \"../utils/types.js\";\n\nexport interface UseEditableTableProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> =
|
|
1
|
+
{"version":3,"file":"useEditableTable.js","names":["useCallback","useState","cellValuesEqual","useEditableTable","editMode","onCellValueChanged","onSubmitEdits","isActive","setActive","cellEdits","setCellEdits","validationErrors","setValidationErrors","Map","clearCellValidationError","cellId","prev","newErrors","delete","handleCellEdit","info","newValue","oldValue","_","rest","clearEdits","handleSubmitEdits","edits","Object","values","onCellValidationError","error","set","editModeState","type","onCellEdit","undefined"],"sources":["useEditableTable.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { useCallback, useState } from \"react\";\n\nimport type { ObjectTableProps } from \"../ObjectTableApi.js\";\nimport { cellValuesEqual } from \"../utils/editableUtils.js\";\nimport type {\n CellEditInfo,\n EditableConfig,\n EditModeState,\n} from \"../utils/types.js\";\n\nexport interface UseEditableTableProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n editMode?: \"always\" | \"manual\";\n\n onCellValueChanged?: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"onCellValueChanged\"];\n\n onSubmitEdits?: ObjectTableProps<Q, RDPs, FunctionColumns>[\"onSubmitEdits\"];\n}\n\nexport function useEditableTable<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n editMode = \"manual\",\n onCellValueChanged,\n onSubmitEdits,\n}: UseEditableTableProps<Q, RDPs, FunctionColumns>): EditableConfig<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n> {\n const [isActive, setActive] = useState<boolean>(editMode === \"always\");\n const [cellEdits, setCellEdits] = useState<\n Record<\n string,\n CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >\n >\n >({});\n const [validationErrors, setValidationErrors] = useState<Map<string, string>>(\n new Map(),\n );\n\n const clearCellValidationError = useCallback((cellId: string) => {\n setValidationErrors((prev) => {\n const newErrors = new Map(prev);\n newErrors.delete(cellId);\n return newErrors;\n });\n }, []);\n\n const handleCellEdit = useCallback(\n (\n cellId: string,\n info: CellEditInfo<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>,\n unknown\n >,\n ) => {\n // If value is changed back to original, remove it from edits. null\n // and undefined are treated as the same empty state so clearing a\n // never-set cell doesn't leave a phantom \"edited\" indicator. \"\" stays\n // a distinct value.\n if (cellValuesEqual(info.newValue, info.oldValue)) {\n setCellEdits((prev) => {\n const { [cellId]: _, ...rest } = prev;\n return rest;\n });\n } else {\n setCellEdits((prev) => ({\n ...prev,\n [cellId]: info,\n }));\n }\n\n onCellValueChanged?.(info);\n },\n [onCellValueChanged],\n );\n\n const clearEdits = useCallback(() => {\n setCellEdits({});\n setValidationErrors(new Map());\n }, []);\n\n // TODO(oxc type-aware): the type-aware typescript/require-await rule does not flag this (it returns a Promise); remove this disable once type-aware linting is enabled.\n // oxlint-disable-next-line require-await -- intentionally async: returns a Promise to satisfy its declared/contract type; no await needed\n const handleSubmitEdits = useCallback(async () => {\n const edits = Object.values(cellEdits);\n return onSubmitEdits ? onSubmitEdits(edits) : false;\n }, [cellEdits, onSubmitEdits]);\n\n const onCellValidationError = useCallback((cellId: string, error: string) => {\n setValidationErrors((prev) => {\n const newErrors = new Map(prev);\n newErrors.set(cellId, error);\n return newErrors;\n });\n }, []);\n\n const editModeState: EditModeState =\n editMode === \"always\"\n ? { type: \"always\", isActive: true }\n : { type: \"manual\", isActive, setActive };\n\n return {\n cellEdits,\n onCellEdit: handleCellEdit,\n onSubmitEdits: onSubmitEdits ? handleSubmitEdits : undefined,\n clearEdits,\n editModeState,\n onCellValidationError,\n validationErrors,\n clearCellValidationError,\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,OAAO;AAG7C,SAASC,eAAe,QAAQ,2BAA2B;AA0B3D,OAAO,SAASC,gBAAgBA,CAO9B;EACAC,QAAQ,GAAG,QAAQ;EACnBC,kBAAkB;EAClBC;AAC+C,CAAC,EAGhD;EACA,MAAM,CAACC,QAAQ,EAAEC,SAAS,CAAC,GAAGP,QAAQ,CAAUG,QAAQ,KAAK,QAAQ,CAAC;EACtE,MAAM,CAACK,SAAS,EAAEC,YAAY,CAAC,GAAGT,QAAQ,CAQxC,CAAC,CAAC,CAAC;EACL,MAAM,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AAC,EAAE,CAAClB,SAAS,EAAEH,aAAa,CAAC,CAAC;EAE9B,MAAMwB,qBAAqB,GAAG9B,WAAW,CAAC,CAACe,MAAc,EAAEgB,KAAa,KAAK;IAC3EnB,mBAAmB,CAAEI,IAAI,IAAK;MAC5B,MAAMC,SAAS,GAAG,IAAIJ,GAAG,CAACG,IAAI,CAAC;MAC/BC,SAAS,CAACe,GAAG,CAACjB,MAAM,EAAEgB,KAAK,CAAC;MAC5B,OAAOd,SAAS;IAClB,CAAC,CAAC;EACJ,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMgB,aAA4B,GAChC7B,QAAQ,KAAK,QAAQ,GACjB;IAAE8B,IAAI,EAAE,QAAQ;IAAE3B,QAAQ,EAAE;EAAK,CAAC,GAClC;IAAE2B,IAAI,EAAE,QAAQ;IAAE3B,QAAQ;IAAEC;EAAU,CAAC;EAE7C,OAAO;IACLC,SAAS;IACT0B,UAAU,EAAEhB,cAAc;IAC1Bb,aAAa,EAAEA,aAAa,GAAGoB,iBAAiB,GAAGU,SAAS;IAC5DX,UAAU;IACVQ,aAAa;IACbH,qBAAqB;IACrBnB,gBAAgB;IAChBG;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFunctionColumnsData.js","names":["useOsdkClient","useOsdkFunctions","useMemo","useRef","createAsyncCellData","DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS","DEFAULT_MAX_CONCURRENT_REQUESTS","DEFAULT_PAGE_SIZE","buildPagedObjectSets","extractFunctionLocators","useFunctionColumnsData","objectOrInterfaceType","objects","columnDefinitions","pageSize","client","prevDataRef","stableObjects","useStableObjects","functionColDefs","pagedObjectSets","length","disabled","queryGrid","EMPTY_QUERY_GRID","buildQueryGrid","results","queries","enabled","maxConcurrent","mergedResults","mergePagedResults","numColumns","data","columnData","buildFunctionColumnData","current","pagedObjects","objectSet","pagedObjectSet","pageObjects","locator","push","queryDefinition","options","params","getFunctionParams","dedupeIntervalMs","dependsOn","dependsOnObjects","merged","Array","from","isLoading","error","undefined","functionsMap","forEach","result","index","entry","pageData","Object","assign","prevColumnData","columnId","String","id","obj","key","$primaryKey","prevData","resolveCell","getKey","getValue","objectKey","rawData","JSON","stringify","map","item","$apiName","sort","a","b","localeCompare"],"sources":["useFunctionColumnsData.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport {\n type FunctionQueryParams,\n useOsdkClient,\n useOsdkFunctions,\n type UseOsdkFunctionsResult,\n} from \"@osdk/react\";\nimport { useMemo, useRef } from \"react\";\n\nimport type {\n ColumnDefinition,\n FunctionColumnLocator,\n} from \"../ObjectTableApi.js\";\nimport {\n type AsyncCellData,\n createAsyncCellData,\n} from \"../utils/AsyncCellData.js\";\nimport {\n DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS,\n DEFAULT_MAX_CONCURRENT_REQUESTS,\n DEFAULT_PAGE_SIZE,\n} from \"../utils/constants.js\";\nimport {\n buildPagedObjectSets,\n extractFunctionLocators,\n type PagedObjects,\n} from \"../utils/functionColumns.js\";\n\nexport interface FunctionColumnData {\n [columnId: string]: {\n [objectPrimaryKey: string]: AsyncCellData;\n };\n}\n\nexport interface UseFunctionColumnsDataProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n objectOrInterfaceType: Q;\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n pageSize?: number;\n}\n\nexport function useFunctionColumnsData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectOrInterfaceType,\n objects,\n columnDefinitions,\n pageSize = DEFAULT_PAGE_SIZE,\n}: UseFunctionColumnsDataProps<Q, RDPs, FunctionColumns>): FunctionColumnData {\n const client = useOsdkClient();\n const prevDataRef = useRef<FunctionColumnData>({});\n\n const stableObjects = useStableObjects(objects);\n\n const functionColDefs = useMemo(\n () => extractFunctionLocators<Q, RDPs, FunctionColumns>(columnDefinitions),\n [columnDefinitions],\n );\n\n // Construct an object set per page (base set filtered to each page's\n // primary keys). `buildPagedObjectSets` returns `[]` for interfaces and\n // when there's no work to do, which short-circuits the downstream queries.\n //\n // When a new page loads, only that page's queries fire — old pages hit the\n // dedupeIntervalMs cache since their params are unchanged.\n const pagedObjectSets = useMemo(() => {\n if (!stableObjects?.length) return [];\n return buildPagedObjectSets<Q, RDPs>(\n client,\n objectOrInterfaceType,\n stableObjects,\n pageSize,\n );\n }, [client, objectOrInterfaceType, stableObjects, pageSize]);\n\n const disabled = pagedObjectSets.length === 0 || functionColDefs.length === 0;\n\n const queryGrid = useMemo(() => {\n if (pagedObjectSets.length === 0 || functionColDefs.length === 0) {\n return EMPTY_QUERY_GRID;\n }\n return buildQueryGrid<Q, RDPs, FunctionColumns>(\n pagedObjectSets,\n functionColDefs,\n );\n }, [pagedObjectSets, functionColDefs]);\n\n const results = useOsdkFunctions({\n queries: queryGrid.queries,\n enabled: !disabled,\n maxConcurrent: DEFAULT_MAX_CONCURRENT_REQUESTS,\n });\n\n const mergedResults = useMemo(\n () => mergePagedResults(results, queryGrid.numColumns),\n [results, queryGrid.numColumns],\n );\n\n const data = useMemo(() => {\n const columnData = buildFunctionColumnData(\n mergedResults,\n functionColDefs,\n stableObjects,\n disabled,\n prevDataRef.current,\n );\n prevDataRef.current = columnData;\n return columnData;\n }, [mergedResults, functionColDefs, stableObjects, disabled]);\n\n return data;\n}\n\n/**\n * Pairs a flat queries array with the layout metadata needed to recover per-column\n * results back into per-column groups. The numColumns value is produced by\n * the same function that builds the queries, so the two are always in sync.\n */\ninterface QueryGrid {\n queries: FunctionQueryParams<QueryDefinition<unknown>>[];\n numColumns: number;\n}\n\ninterface MergedResult {\n isLoading: boolean;\n error: unknown;\n functionsMap: Record<string, unknown>;\n}\n\nconst EMPTY_QUERY_GRID: QueryGrid = { queries: [], numColumns: 0 };\n\n/**\n * Builds a flat query array and the layout metadata needed to recover per-column results.\n *\n * Layout: [page0_col0, page0_col1, ..., page1_col0, page1_col1, ...]\n * Page-first ordering ensures first concurrent queries prioritizes the first page,\n * so visible rows get all their columns populated before later pages.\n *\n * Each query carries `dependsOnObjects` (the page's row instances) so that\n * editing any of those rows fans out to invalidate this function query, and\n * `dependsOn` from the locator so that linked-type edits also invalidate.\n */\nfunction buildQueryGrid<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n pagedObjects: PagedObjects<Q, RDPs>[],\n functionColDefs: FunctionColumnLocator<Q, RDPs, FunctionColumns>[],\n): QueryGrid {\n const queries: FunctionQueryParams<QueryDefinition<unknown>>[] = [];\n\n for (const {\n objectSet: pagedObjectSet,\n objects: pageObjects,\n } of pagedObjects) {\n for (const locator of functionColDefs) {\n queries.push({\n queryDefinition: locator.queryDefinition,\n options: {\n params: locator.getFunctionParams(pagedObjectSet),\n dedupeIntervalMs:\n locator.dedupeIntervalMs ??\n DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS,\n dependsOn: locator.dependsOn,\n dependsOnObjects: pageObjects,\n } as FunctionQueryParams<QueryDefinition<unknown>>[\"options\"],\n });\n }\n }\n\n return { queries, numColumns: functionColDefs.length };\n}\n\n/**\n * Merges paged results into one merged result per column.\n * Each column has results spread across pages — this combines their\n * functionsMaps so buildFunctionColumnData can look up any object by key.\n *\n * Relies on QueryGrid layout: results[i] belongs to column (i % numColumns).\n * i.e. the first N results are the first page of each column, the next N results are the second page, etc.\n */\nfunction mergePagedResults(\n results: UseOsdkFunctionsResult,\n numColumns: number,\n): MergedResult[] {\n if (numColumns === 0) return [];\n\n const merged: MergedResult[] = Array.from({ length: numColumns }, () => ({\n isLoading: false,\n error: undefined,\n functionsMap: {},\n }));\n\n results.forEach((result, index) => {\n const columnIndex = index % numColumns;\n const entry = merged[columnIndex];\n\n if (result.isLoading) {\n entry.isLoading = true;\n }\n if (result.error) {\n entry.error = result.error;\n }\n const pageData = result.data as Record<string, unknown> | undefined;\n if (pageData) {\n Object.assign(entry.functionsMap, pageData);\n }\n });\n\n return merged;\n}\n\nfunction buildFunctionColumnData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n results: MergedResult[],\n functionColDefs: FunctionColumnLocator<Q, RDPs, FunctionColumns>[],\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined,\n disabled: boolean,\n prevColumnData: FunctionColumnData,\n): FunctionColumnData {\n const columnData: FunctionColumnData = {};\n\n if (disabled || !objects) return columnData;\n\n results.forEach((result, index) => {\n const locator = functionColDefs[index];\n if (!locator) return;\n\n const columnId = String(locator.id);\n\n columnData[columnId] = {};\n\n objects.forEach((obj) => {\n const key = String(obj.$primaryKey);\n const prevData = prevColumnData[columnId]?.[key]?.data;\n\n columnData[columnId][key] = createAsyncCellData(\n resolveCell(result, locator.getKey(obj), locator.getValue, prevData),\n );\n });\n });\n\n return columnData;\n}\n\n/** Resolves the cell state: error, loaded, or loading with previous data. */\nfunction resolveCell(\n result: MergedResult,\n objectKey: string,\n getValue: ((cellData: unknown) => unknown) | undefined,\n prevData: unknown,\n): Omit<AsyncCellData, \"__asyncCell\"> {\n if (result.error) {\n return { isLoading: false, error: result.error };\n }\n if (objectKey in result.functionsMap) {\n const rawData = result.functionsMap[objectKey];\n return { isLoading: false, data: getValue ? getValue(rawData) : rawData };\n }\n // Key not in results. While the query is still loading, keep showing the\n // previous data so the cell doesn't flash empty during a refetch. Once the\n // query has resolved without an entry for this object, its value is gone —\n // clear the cell instead of retaining the stale previous value (otherwise a\n // cell whose derived value became null keeps displaying the old value).\n return {\n isLoading: result.isLoading,\n data: result.isLoading ? prevData : undefined,\n };\n}\n\nconst useStableObjects = <\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n>(\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined,\n):\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(\n () => objects,\n [\n // eslint-disable-next-line react-hooks/exhaustive-deps\n JSON.stringify(\n (objects ?? [])\n .map((item) => ({\n $apiName: item.$apiName,\n $primaryKey: item.$primaryKey,\n }))\n .sort((a, b) => {\n if (a.$apiName !== b.$apiName) {\n return a.$apiName.localeCompare(b.$apiName);\n }\n return String(a.$primaryKey).localeCompare(String(b.$primaryKey));\n }),\n ),\n ],\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAEEA,aAAa,EACbC,gBAAgB,QAEX,aAAa;AACpB,SAASC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAMvC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AAEK,MAAM,CAACL,SAAS;IAC3BpB,IAAI,EAAEyB,MAAM,CAACL,SAAS,GAAGkB,QAAQ,GAAGhB;EACtC,CAAC;AACH;AAEA,MAAMrC,gBAAgB,GAIpBN,OAEa,IAGE;EACf;EACA,OAAOV,OAAO,CACZ,MAAMU,OAAO,EACb;EACE;EACAiE,IAAI,CAACC,SAAS,CACZ,CAAClE,OAAO,IAAI,EAAE,EACXmE,GAAG,CAAEC,IAAI,KAAM;IACdC,QAAQ,EAAED,IAAI,CAACC,QAAQ;IACvBX,WAAW,EAAEU,IAAI,CAACV;EACpB,CAAC,CAAC,CAAC,CACFY,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAK;IACd,IAAID,CAAC,CAACF,QAAQ,KAAKG,CAAC,CAACH,QAAQ,EAAE;MAC7B,OAAOE,CAAC,CAACF,QAAQ,CAACI,aAAa,CAACD,CAAC,CAACH,QAAQ,CAAC;IAC7C;IACA,OAAOf,MAAM,CAACiB,CAAC,CAACb,WAAW,CAAC,CAACe,aAAa,CAACnB,MAAM,CAACkB,CAAC,CAACd,WAAW,CAAC,CAAC;EACnE,CAAC,CACL,CAAC,CAEL,CAAC;AACH,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useFunctionColumnsData.js","names":["useOsdkClient","useOsdkFunctions","useMemo","useRef","createAsyncCellData","DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS","DEFAULT_MAX_CONCURRENT_REQUESTS","DEFAULT_PAGE_SIZE","buildPagedObjectSets","extractFunctionLocators","useFunctionColumnsData","objectOrInterfaceType","objects","columnDefinitions","pageSize","client","prevDataRef","stableObjects","useStableObjects","functionColDefs","pagedObjectSets","length","disabled","queryGrid","EMPTY_QUERY_GRID","buildQueryGrid","results","queries","enabled","maxConcurrent","mergedResults","mergePagedResults","numColumns","data","columnData","buildFunctionColumnData","current","pagedObjects","objectSet","pagedObjectSet","pageObjects","locator","push","queryDefinition","options","params","getFunctionParams","dedupeIntervalMs","dependsOn","dependsOnObjects","merged","Array","from","isLoading","error","undefined","functionsMap","forEach","result","index","entry","pageData","Object","assign","prevColumnData","columnId","String","id","obj","key","$primaryKey","prevData","resolveCell","getKey","getValue","objectKey","rawData","JSON","stringify","map","item","$apiName","sort","a","b","localeCompare"],"sources":["useFunctionColumnsData.ts"],"sourcesContent":["/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n ObjectOrInterfaceDefinition,\n Osdk,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport {\n type FunctionQueryParams,\n useOsdkClient,\n useOsdkFunctions,\n type UseOsdkFunctionsResult,\n} from \"@osdk/react\";\nimport { useMemo, useRef } from \"react\";\n\nimport type {\n ColumnDefinition,\n FunctionColumnLocator,\n} from \"../ObjectTableApi.js\";\nimport {\n type AsyncCellData,\n createAsyncCellData,\n} from \"../utils/AsyncCellData.js\";\nimport {\n DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS,\n DEFAULT_MAX_CONCURRENT_REQUESTS,\n DEFAULT_PAGE_SIZE,\n} from \"../utils/constants.js\";\nimport {\n buildPagedObjectSets,\n extractFunctionLocators,\n type PagedObjects,\n} from \"../utils/functionColumns.js\";\n\nexport interface FunctionColumnData {\n [columnId: string]: {\n [objectPrimaryKey: string]: AsyncCellData;\n };\n}\n\nexport interface UseFunctionColumnsDataProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n objectOrInterfaceType: Q;\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined;\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n pageSize?: number;\n}\n\nexport function useFunctionColumnsData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectOrInterfaceType,\n objects,\n columnDefinitions,\n pageSize = DEFAULT_PAGE_SIZE,\n}: UseFunctionColumnsDataProps<Q, RDPs, FunctionColumns>): FunctionColumnData {\n const client = useOsdkClient();\n const prevDataRef = useRef<FunctionColumnData>({});\n\n const stableObjects = useStableObjects(objects);\n\n const functionColDefs = useMemo(\n () => extractFunctionLocators<Q, RDPs, FunctionColumns>(columnDefinitions),\n [columnDefinitions],\n );\n\n // Construct an object set per page (base set filtered to each page's\n // primary keys). `buildPagedObjectSets` returns `[]` for interfaces and\n // when there's no work to do, which short-circuits the downstream queries.\n //\n // When a new page loads, only that page's queries fire — old pages hit the\n // dedupeIntervalMs cache since their params are unchanged.\n const pagedObjectSets = useMemo(() => {\n if (!stableObjects?.length) return [];\n return buildPagedObjectSets<Q, RDPs>(\n client,\n objectOrInterfaceType,\n stableObjects,\n pageSize,\n );\n }, [client, objectOrInterfaceType, stableObjects, pageSize]);\n\n const disabled = pagedObjectSets.length === 0 || functionColDefs.length === 0;\n\n const queryGrid = useMemo(() => {\n if (pagedObjectSets.length === 0 || functionColDefs.length === 0) {\n return EMPTY_QUERY_GRID;\n }\n return buildQueryGrid<Q, RDPs, FunctionColumns>(\n pagedObjectSets,\n functionColDefs,\n );\n }, [pagedObjectSets, functionColDefs]);\n\n const results = useOsdkFunctions({\n queries: queryGrid.queries,\n enabled: !disabled,\n maxConcurrent: DEFAULT_MAX_CONCURRENT_REQUESTS,\n });\n\n const mergedResults = useMemo(\n () => mergePagedResults(results, queryGrid.numColumns),\n [results, queryGrid.numColumns],\n );\n\n const data = useMemo(() => {\n const columnData = buildFunctionColumnData(\n mergedResults,\n functionColDefs,\n stableObjects,\n disabled,\n prevDataRef.current,\n );\n prevDataRef.current = columnData;\n return columnData;\n }, [mergedResults, functionColDefs, stableObjects, disabled]);\n\n return data;\n}\n\n/**\n * Pairs a flat queries array with the layout metadata needed to recover per-column\n * results back into per-column groups. The numColumns value is produced by\n * the same function that builds the queries, so the two are always in sync.\n */\ninterface QueryGrid {\n queries: FunctionQueryParams<QueryDefinition<unknown>>[];\n numColumns: number;\n}\n\ninterface MergedResult {\n isLoading: boolean;\n error: unknown;\n functionsMap: Record<string, unknown>;\n}\n\nconst EMPTY_QUERY_GRID: QueryGrid = { queries: [], numColumns: 0 };\n\n/**\n * Builds a flat query array and the layout metadata needed to recover per-column results.\n *\n * Layout: [page0_col0, page0_col1, ..., page1_col0, page1_col1, ...]\n * Page-first ordering ensures first concurrent queries prioritizes the first page,\n * so visible rows get all their columns populated before later pages.\n *\n * Each query carries `dependsOnObjects` (the page's row instances) so that\n * editing any of those rows fans out to invalidate this function query, and\n * `dependsOn` from the locator so that linked-type edits also invalidate.\n */\nfunction buildQueryGrid<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n pagedObjects: PagedObjects<Q, RDPs>[],\n functionColDefs: FunctionColumnLocator<Q, RDPs, FunctionColumns>[],\n): QueryGrid {\n const queries: FunctionQueryParams<QueryDefinition<unknown>>[] = [];\n\n for (const {\n objectSet: pagedObjectSet,\n objects: pageObjects,\n } of pagedObjects) {\n for (const locator of functionColDefs) {\n queries.push({\n queryDefinition: locator.queryDefinition,\n options: {\n params: locator.getFunctionParams(pagedObjectSet),\n dedupeIntervalMs:\n locator.dedupeIntervalMs ??\n DEFAULT_FUNCTION_COLUMN_DEDUPE_INTERVAL_MS,\n dependsOn: locator.dependsOn,\n dependsOnObjects: pageObjects,\n } as FunctionQueryParams<QueryDefinition<unknown>>[\"options\"],\n });\n }\n }\n\n return { queries, numColumns: functionColDefs.length };\n}\n\n/**\n * Merges paged results into one merged result per column.\n * Each column has results spread across pages — this combines their\n * functionsMaps so buildFunctionColumnData can look up any object by key.\n *\n * Relies on QueryGrid layout: results[i] belongs to column (i % numColumns).\n * i.e. the first N results are the first page of each column, the next N results are the second page, etc.\n */\nfunction mergePagedResults(\n results: UseOsdkFunctionsResult,\n numColumns: number,\n): MergedResult[] {\n if (numColumns === 0) return [];\n\n const merged: MergedResult[] = Array.from({ length: numColumns }, () => ({\n isLoading: false,\n error: undefined,\n functionsMap: {},\n }));\n\n results.forEach((result, index) => {\n const columnIndex = index % numColumns;\n const entry = merged[columnIndex];\n\n if (result.isLoading) {\n entry.isLoading = true;\n }\n if (result.error) {\n entry.error = result.error;\n }\n const pageData = result.data as Record<string, unknown> | undefined;\n if (pageData) {\n Object.assign(entry.functionsMap, pageData);\n }\n });\n\n return merged;\n}\n\nfunction buildFunctionColumnData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n results: MergedResult[],\n functionColDefs: FunctionColumnLocator<Q, RDPs, FunctionColumns>[],\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined,\n disabled: boolean,\n prevColumnData: FunctionColumnData,\n): FunctionColumnData {\n const columnData: FunctionColumnData = {};\n\n if (disabled || !objects) return columnData;\n\n results.forEach((result, index) => {\n const locator = functionColDefs[index];\n if (!locator) return;\n\n const columnId = String(locator.id);\n\n columnData[columnId] = {};\n\n objects.forEach((obj) => {\n const key = String(obj.$primaryKey);\n const prevData = prevColumnData[columnId]?.[key]?.data;\n\n columnData[columnId][key] = createAsyncCellData(\n resolveCell(result, locator.getKey(obj), locator.getValue, prevData),\n );\n });\n });\n\n return columnData;\n}\n\n/** Resolves the cell state: error, loaded, or loading with previous data. */\nfunction resolveCell(\n result: MergedResult,\n objectKey: string,\n getValue: ((cellData: unknown) => unknown) | undefined,\n prevData: unknown,\n): Omit<AsyncCellData, \"__asyncCell\"> {\n if (result.error) {\n return { isLoading: false, error: result.error };\n }\n if (objectKey in result.functionsMap) {\n const rawData = result.functionsMap[objectKey];\n return { isLoading: false, data: getValue ? getValue(rawData) : rawData };\n }\n // Key not in results. While the query is still loading, keep showing the\n // previous data so the cell doesn't flash empty during a refetch. Once the\n // query has resolved without an entry for this object, its value is gone —\n // clear the cell instead of retaining the stale previous value (otherwise a\n // cell whose derived value became null keeps displaying the old value).\n return {\n isLoading: result.isLoading,\n data: result.isLoading ? prevData : undefined,\n };\n}\n\nconst useStableObjects = <\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n>(\n objects:\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined,\n):\n | Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>[]\n | undefined => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(\n () => objects,\n [\n // eslint-disable-next-line react-hooks/exhaustive-deps\n JSON.stringify(\n (objects ?? [])\n .map((item) => ({\n $apiName: item.$apiName,\n $primaryKey: item.$primaryKey,\n }))\n .sort((a, b) => {\n if (a.$apiName !== b.$apiName) {\n return a.$apiName.localeCompare(b.$apiName);\n }\n return String(a.$primaryKey).localeCompare(String(b.$primaryKey));\n }),\n ),\n ],\n );\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAEEA,aAAa,EACbC,gBAAgB,QAEX,aAAa;AACpB,SAASC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAMvC,SAEEC,mBAAmB,QACd,2BAA2B;AAClC,SACEC,0CAA0C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AAM,CAACL,SAAS,GAAGkB,QAAQ,GAAGhB;EACtC,CAAC;AACH;AAEA,MAAMrC,gBAAgB,GAIpBN,OAEa,IAGE;EACf;EACA,OAAOV,OAAO,CACZ,MAAMU,OAAO,EACb;EACE;EACAiE,IAAI,CAACC,SAAS,CACZ,CAAClE,OAAO,IAAI,EAAE,EACXmE,GAAG,CAAEC,IAAI,KAAM;IACdC,QAAQ,EAAED,IAAI,CAACC,QAAQ;IACvBX,WAAW,EAAEU,IAAI,CAACV;EACpB,CAAC,CAAC,CAAC,CACFY,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAK;IACd,IAAID,CAAC,CAACF,QAAQ,KAAKG,CAAC,CAACH,QAAQ,EAAE;MAC7B,OAAOE,CAAC,CAACF,QAAQ,CAACI,aAAa,CAACD,CAAC,CAACH,QAAQ,CAAC;IAC7C;IACA,OAAOf,MAAM,CAACiB,CAAC,CAACb,WAAW,CAAC,CAACe,aAAa,CAACnB,MAAM,CAACkB,CAAC,CAACd,WAAW,CAAC,CAAC;EACnE,CAAC,CACL,CAAC,CAEL,CAAC;AACH,CAAC","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectTableData.js","names":["useObjectSet","useOsdkObjects","useMemo","DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS","DEFAULT_PAGE_SIZE","useFunctionColumnsData","useObjectTableData","objectOrInterfaceType","columnDefinitions","filter","sorting","objectSet","objectSetOptions","dedupeIntervalMs","pageSize","streamUpdates","orderBy","length","undefined","reduce","acc","sort","id","desc","withProperties","rdpColumns","map","colDef","locator","colLocator","type","cur","creator","shouldUseObjectSet","objectSetResult","where","enabled","osdkObjectsResult","baseResult","functionColumnData","objects","data","mergedData","obj","objKey","String","$primaryKey","functionData","Object","entries","forEach","columnId","columnData"],"sources":["useObjectTableData.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport {\n useObjectSet,\n type UseOsdkListResult,\n useOsdkObjects,\n} from \"@osdk/react\";\nimport type { SortingState } from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\n\nimport type { ColumnDefinition, ObjectSetOptions } from \"../ObjectTableApi.js\";\nimport type { AsyncCellData } from \"../utils/AsyncCellData.js\";\nimport {\n DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS,\n DEFAULT_PAGE_SIZE,\n} from \"../utils/constants.js\";\nimport { useFunctionColumnsData } from \"./useFunctionColumnsData.js\";\n\ntype WithProperties<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> = {\n [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]>;\n};\n\nexport interface UseObjectTableDataProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /** The object or interface type to load rows for. */\n objectOrInterfaceType: Q;\n /**\n * Column definitions. Used to extract derived-property (`rdp`) and\n * function-column locators so the correct `withProperties` / function data\n * is fetched. Optional — omit to load the type's base properties only.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n /** Server-side `where` clause applied to the query. */\n filter?: WhereClause<Q, RDPs>;\n /** TanStack sorting state, converted to an OSDK `orderBy` internally. */\n sorting?: SortingState;\n /**\n * A pre-built object set to page through instead of fetching by type. When\n * provided, rows come from this set (filter / ordering still applied).\n */\n objectSet?: ObjectSet<Q>;\n /** Extra options forwarded to `useObjectSet` when `objectSet` is provided. */\n objectSetOptions?: ObjectSetOptions<Q>;\n /**\n * Minimum interval between duplicate requests, in milliseconds.\n * @default 60000\n */\n dedupeIntervalMs?: number;\n /**\n * Number of rows to request per page.\n * @default 50\n */\n pageSize?: number;\n /** Whether to subscribe to live updates for the loaded objects. */\n streamUpdates?: boolean;\n}\n\nexport interface UseObjectTableDataResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n> extends Omit<UseOsdkListResult<Q, RDPs>, \"isOptimistic\"> {}\n/**\n * This hook is a wrapper that conditionally uses either useObjectSet or useOsdkObjects\n * based on whether an objectSet prop is provided.\n * It extracts RDP locators from columnDefinitions and applies withProperties\n * to return data containing the derived properties.\n */\nexport function useObjectTableData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<string, never>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectOrInterfaceType,\n columnDefinitions,\n filter,\n sorting,\n objectSet,\n objectSetOptions,\n dedupeIntervalMs = DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS,\n pageSize = DEFAULT_PAGE_SIZE,\n streamUpdates,\n}: UseObjectTableDataProps<Q, RDPs, FunctionColumns>): UseObjectTableDataResult<\n Q,\n RDPs\n> {\n const orderBy = useMemo(() => {\n if (!sorting || sorting.length === 0) {\n return undefined;\n }\n\n return sorting.reduce<{ [K in PropertyKeys<Q>]?: \"asc\" | \"desc\" }>(\n (acc, sort) => {\n acc[sort.id as PropertyKeys<Q>] = sort.desc ? \"desc\" : \"asc\";\n return acc;\n },\n {},\n );\n }, [sorting]);\n\n // Extract derived properties definition\n const withProperties = useMemo(() => {\n if (!columnDefinitions) {\n return;\n }\n\n const rdpColumns = columnDefinitions\n .map((colDef) => colDef.locator)\n .filter((colLocator) => {\n return colLocator.type === \"rdp\";\n });\n\n if (!rdpColumns.length) {\n return;\n }\n\n return rdpColumns.reduce<WithProperties<Q, RDPs>>(\n (acc, cur) => {\n return {\n ...acc,\n [cur.id]: cur.creator,\n };\n },\n {} as WithProperties<Q, RDPs>,\n );\n }, [columnDefinitions]);\n\n // Use the caller's objectSet whenever provided (object or interface types), else fetch\n // by type. For an interface objectSet, rows carry interface-declared props (+ withProperties)\n // only, not the full underlying object — see the objectSet prop docs.\n const shouldUseObjectSet = !!objectSet;\n\n const objectSetResult = useObjectSet(\n shouldUseObjectSet ? (objectSet as ObjectSet<Q, RDPs>) : (undefined as any),\n {\n ...(objectSetOptions as ObjectSetOptions<Q>),\n withProperties: withProperties as WithProperties<Q, RDPs>,\n where: filter,\n orderBy,\n pageSize,\n enabled: shouldUseObjectSet,\n dedupeIntervalMs,\n streamUpdates,\n },\n );\n\n const osdkObjectsResult = useOsdkObjects<Q, RDPs>(objectOrInterfaceType, {\n withProperties,\n pageSize,\n where: filter,\n orderBy,\n enabled: !shouldUseObjectSet,\n dedupeIntervalMs,\n streamUpdates,\n });\n\n // Get the result from the appropriate hook\n const baseResult = shouldUseObjectSet ? objectSetResult : osdkObjectsResult;\n\n // Call useFunctionColumnsData to get function column data\n const functionColumnData = useFunctionColumnsData<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType,\n objects: baseResult.data,\n columnDefinitions,\n pageSize,\n });\n\n // Merge function column data into each object\n const mergedData = useMemo(() => {\n if (!baseResult.data) return baseResult.data;\n\n return baseResult.data.map((obj) => {\n const objKey = String(obj.$primaryKey);\n const functionData: Record<string, AsyncCellData> = {};\n\n // Collect all function column data for this object\n Object.entries(functionColumnData).forEach(([columnId, columnData]) => {\n if (columnData[objKey]) {\n functionData[columnId] = columnData[objKey];\n }\n });\n\n // Return object with function data merged in\n return {\n ...obj,\n ...functionData,\n };\n });\n }, [baseResult.data, functionColumnData]);\n\n // Return the result with merged data\n return {\n ...baseResult,\n data: mergedData,\n } as UseObjectTableDataResult<Q, RDPs>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SACEA,YAAY,EAEZC,cAAc,QACT,aAAa;AAEpB,SAASC,OAAO,QAAQ,OAAO;AAI/B,SACEC,uCAAuC,EACvCC,iBAAiB,QACZ,uBAAuB;AAC9B,SAASC,sBAAsB,QAAQ,6BAA6B;AAsDpE;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAOhC;EACAC,qBAAqB;EACrBC,iBAAiB;EACjBC,MAAM;EACNC,OAAO;EACPC,SAAS;EACTC,gBAAgB;EAChBC,gBAAgB,GAAGV,uCAAuC;EAC1DW,QAAQ,GAAGV,iBAAiB;EAC5BW;AACiD,CAAC,EAGlD;EACA,MAAMC,OAAO,GAAGd,OAAO,CAAC,MAAM;IAC5B,IAAI,CAACQ,OAAO,IAAIA,OAAO,CAACO,MAAM,KAAK,CAAC,EAAE;MACpC,OAAOC,SAAS;IAClB;IAEA,OAAOR,OAAO,CAACS,MAAM,CACnB,CAACC,GAAG,EAAEC,IAAI,KAAK;MACbD,GAAG,CAACC,IAAI,CAACC,EAAE,CAAoB,GAAGD,IAAI,CAACE,IAAI,GAAG,MAAM,GAAG,KAAK;MAC5D,OAAOH,GAAG;IACZ,CAAC,EACD,CAAC,CACH,CAAC;EACH,CAAC,EAAE,CAACV,OAAO,CAAC,CAAC;;EAEb;EACA,MAAMc,cAAc,GAAGtB,OAAO,CAAC,MAAM;IACnC,IAAI,CAACM,iBAAiB,EAAE;MACtB;IACF;IAEA,MAAMiB,UAAU,GAAGjB,iBAAiB,CACjCkB,GAAG,CAAEC,MAAM,IAAKA,MAAM,CAACC,OAAO,CAAC,CAC/BnB,MAAM,CAAEoB,UAAU,IAAK;MACtB,OAAOA,UAAU,CAACC,IAAI,KAA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CAAEiB,GAAG,IAAK;MAClC,MAAMC,MAAM,GAAGC,MAAM,CAACF,GAAG,CAACG,WAAW,CAAC;MACtC,MAAMC,YAA2C,GAAG,CAAC,CAAC;;MAEtD;MACAC,MAAM,CAACC,OAAO,CAACV,kBAAkB,CAAC,CAACW,OAAO,CAAC,CAAC,CAACC,QAAQ,EAAEC,UAAU,CAAC,KAAK;QACrE,IAAIA,UAAU,CAACR,MAAM,CAAC,EAAE;UACtBG,YAAY,CAACI,QAAQ,CAAC,GAAGC,UAAU,CAACR,MAAM,CAAC;QAC7C;MACF,CAAC,CAAC;;MAEF;MACA,OAAO;QACL,GAAGD,GAAG;QACN,GAAGI;MACL,CAAC;IACH,CAAC,CAAC;EACJ,CAAC,EAAE,CAACT,UAAU,CAACG,IAAI,EAAEF,kBAAkB,CAAC,CAAC;;EAEzC;EACA,OAAO;IACL,GAAGD,UAAU;IACbG,IAAI,EAAEC;EACR,CAAC;AACH","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"useObjectTableData.js","names":["useObjectSet","useOsdkObjects","useMemo","DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS","DEFAULT_PAGE_SIZE","useFunctionColumnsData","useObjectTableData","objectOrInterfaceType","columnDefinitions","filter","sorting","objectSet","objectSetOptions","dedupeIntervalMs","pageSize","streamUpdates","orderBy","length","undefined","reduce","acc","sort","id","desc","withProperties","rdpColumns","map","colDef","locator","colLocator","type","cur","creator","shouldUseObjectSet","objectSetResult","where","enabled","osdkObjectsResult","baseResult","functionColumnData","objects","data","mergedData","obj","objKey","String","$primaryKey","functionData","Object","entries","forEach","columnId","columnData"],"sources":["useObjectTableData.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n DerivedProperty,\n ObjectOrInterfaceDefinition,\n ObjectSet,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport {\n useObjectSet,\n type UseOsdkListResult,\n useOsdkObjects,\n} from \"@osdk/react\";\nimport type { SortingState } from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\n\nimport type { ColumnDefinition, ObjectSetOptions } from \"../ObjectTableApi.js\";\nimport type { AsyncCellData } from \"../utils/AsyncCellData.js\";\nimport {\n DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS,\n DEFAULT_PAGE_SIZE,\n} from \"../utils/constants.js\";\nimport { useFunctionColumnsData } from \"./useFunctionColumnsData.js\";\n\ntype WithProperties<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> = {\n [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]>;\n};\n\nexport interface UseObjectTableDataProps<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n /** The object or interface type to load rows for. */\n objectOrInterfaceType: Q;\n /**\n * Column definitions. Used to extract derived-property (`rdp`) and\n * function-column locators so the correct `withProperties` / function data\n * is fetched. Optional — omit to load the type's base properties only.\n */\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>;\n /** Server-side `where` clause applied to the query. */\n filter?: WhereClause<Q, RDPs>;\n /** TanStack sorting state, converted to an OSDK `orderBy` internally. */\n sorting?: SortingState;\n /**\n * A pre-built object set to page through instead of fetching by type. When\n * provided, rows come from this set (filter / ordering still applied).\n */\n objectSet?: ObjectSet<Q>;\n /** Extra options forwarded to `useObjectSet` when `objectSet` is provided. */\n objectSetOptions?: ObjectSetOptions<Q>;\n /**\n * Minimum interval between duplicate requests, in milliseconds.\n * @default 60000\n */\n dedupeIntervalMs?: number;\n /**\n * Number of rows to request per page.\n * @default 50\n */\n pageSize?: number;\n /** Whether to subscribe to live updates for the loaded objects. */\n streamUpdates?: boolean;\n}\n\nexport interface UseObjectTableDataResult<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n> extends Omit<UseOsdkListResult<Q, RDPs>, \"isOptimistic\"> {}\n/**\n * This hook is a wrapper that conditionally uses either useObjectSet or useOsdkObjects\n * based on whether an objectSet prop is provided.\n * It extracts RDP locators from columnDefinitions and applies withProperties\n * to return data containing the derived properties.\n */\nexport function useObjectTableData<\n Q extends ObjectOrInterfaceDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n objectOrInterfaceType,\n columnDefinitions,\n filter,\n sorting,\n objectSet,\n objectSetOptions,\n dedupeIntervalMs = DEFAULT_OBJECT_TABLE_DEDUPE_INTERVAL_MS,\n pageSize = DEFAULT_PAGE_SIZE,\n streamUpdates,\n}: UseObjectTableDataProps<Q, RDPs, FunctionColumns>): UseObjectTableDataResult<\n Q,\n RDPs\n> {\n const orderBy = useMemo(() => {\n if (!sorting || sorting.length === 0) {\n return undefined;\n }\n\n return sorting.reduce<{ [K in PropertyKeys<Q>]?: \"asc\" | \"desc\" }>(\n (acc, sort) => {\n acc[sort.id as PropertyKeys<Q>] = sort.desc ? \"desc\" : \"asc\";\n return acc;\n },\n {},\n );\n }, [sorting]);\n\n // Extract derived properties definition\n const withProperties = useMemo(() => {\n if (!columnDefinitions) {\n return;\n }\n\n const rdpColumns = columnDefinitions\n .map((colDef) => colDef.locator)\n .filter((colLocator) => {\n return colLocator.type === \"rdp\";\n });\n\n if (!rdpColumns.length) {\n return;\n }\n\n return rdpColumns.reduce<WithProperties<Q, RDPs>>(\n (acc, cur) => {\n return {\n ...acc,\n [cur.id]: cur.creator,\n };\n },\n {} as WithProperties<Q, RDPs>,\n );\n }, [columnDefinitions]);\n\n // Use the caller's objectSet whenever provided (object or interface types), else fetch\n // by type. For an interface objectSet, rows carry interface-declared props (+ withProperties)\n // only, not the full underlying object — see the objectSet prop docs.\n const shouldUseObjectSet = !!objectSet;\n\n const objectSetResult = useObjectSet(\n shouldUseObjectSet ? (objectSet as ObjectSet<Q, RDPs>) : (undefined as any),\n {\n ...(objectSetOptions as ObjectSetOptions<Q>),\n withProperties: withProperties as WithProperties<Q, RDPs>,\n where: filter,\n orderBy,\n pageSize,\n enabled: shouldUseObjectSet,\n dedupeIntervalMs,\n streamUpdates,\n },\n );\n\n const osdkObjectsResult = useOsdkObjects<Q, RDPs>(objectOrInterfaceType, {\n withProperties,\n pageSize,\n where: filter,\n orderBy,\n enabled: !shouldUseObjectSet,\n dedupeIntervalMs,\n streamUpdates,\n });\n\n // Get the result from the appropriate hook\n const baseResult = shouldUseObjectSet ? objectSetResult : osdkObjectsResult;\n\n // Call useFunctionColumnsData to get function column data\n const functionColumnData = useFunctionColumnsData<Q, RDPs, FunctionColumns>({\n objectOrInterfaceType,\n objects: baseResult.data,\n columnDefinitions,\n pageSize,\n });\n\n // Merge function column data into each object\n const mergedData = useMemo(() => {\n if (!baseResult.data) return baseResult.data;\n\n return baseResult.data.map((obj) => {\n const objKey = String(obj.$primaryKey);\n const functionData: Record<string, AsyncCellData> = {};\n\n // Collect all function column data for this object\n Object.entries(functionColumnData).forEach(([columnId, columnData]) => {\n if (columnData[objKey]) {\n functionData[columnId] = columnData[objKey];\n }\n });\n\n // Return object with function data merged in\n return {\n ...obj,\n ...functionData,\n };\n });\n }, [baseResult.data, functionColumnData]);\n\n // Return the result with merged data\n return {\n ...baseResult,\n data: mergedData,\n } as UseObjectTableDataResult<Q, RDPs>;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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