@osdk/react-components 0.1.0-beta.3 → 0.1.0-beta.5
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 +28 -0
- package/build/browser/base-components/checkbox/Checkbox.module.css +11 -10
- package/build/browser/object-table/CellContextMenu.js +2 -2
- package/build/browser/object-table/CellContextMenu.js.map +1 -1
- package/build/browser/object-table/CellContextMenu.module.css +20 -0
- package/build/browser/object-table/ObjectTable.js +37 -10
- 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/Table.js +7 -16
- package/build/browser/object-table/Table.js.map +1 -1
- package/build/browser/object-table/Table.module.css +22 -0
- package/build/browser/object-table/TableBody.js +2 -2
- package/build/browser/object-table/TableBody.js.map +1 -1
- package/build/browser/object-table/TableBody.module.css +20 -0
- package/build/browser/object-table/TableCell.js +12 -7
- package/build/browser/object-table/TableCell.js.map +1 -1
- package/build/browser/object-table/TableCell.module.css +63 -0
- package/build/browser/object-table/TableHeader.js +35 -38
- package/build/browser/object-table/TableHeader.js.map +1 -1
- package/build/browser/object-table/TableHeader.module.css +95 -0
- package/build/browser/object-table/TableHeaderContent.js +27 -0
- package/build/browser/object-table/TableHeaderContent.js.map +1 -0
- package/build/browser/object-table/TableHeaderContent.module.css +30 -0
- package/build/browser/object-table/TableHeaderWithPopover.js +155 -0
- package/build/browser/object-table/TableHeaderWithPopover.js.map +1 -0
- package/build/browser/object-table/TableHeaderWithPopover.module.css +105 -0
- package/build/browser/object-table/TableRow.js +4 -3
- package/build/browser/object-table/TableRow.js.map +1 -1
- package/build/browser/object-table/TableRow.module.css +60 -0
- package/build/browser/object-table/hooks/__tests__/useColumnPinning.test.js +266 -0
- package/build/browser/object-table/hooks/__tests__/useColumnPinning.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/{useDefaultTableStates.test.js → useColumnVisibility.test.js} +16 -16
- package/build/browser/object-table/hooks/__tests__/useColumnVisibility.test.js.map +1 -0
- package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js +2 -1
- package/build/browser/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -1
- package/build/browser/object-table/hooks/__tests__/useTableSorting.test.js +211 -0
- package/build/browser/object-table/hooks/__tests__/useTableSorting.test.js.map +1 -0
- package/build/browser/object-table/hooks/useColumnPinning.js +95 -0
- package/build/browser/object-table/hooks/useColumnPinning.js.map +1 -0
- package/build/{esm/object-table/hooks/useDefaultTableStates.js → browser/object-table/hooks/useColumnVisibility.js} +3 -5
- package/build/browser/object-table/hooks/useColumnVisibility.js.map +1 -0
- package/build/browser/object-table/hooks/useObjectTableData.js +15 -3
- package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -1
- package/build/browser/object-table/hooks/useSelectionColumn.js +3 -2
- package/build/browser/object-table/hooks/useSelectionColumn.js.map +1 -1
- package/build/browser/object-table/hooks/useTableSorting.js +66 -0
- package/build/browser/object-table/hooks/useTableSorting.js.map +1 -0
- package/build/browser/object-table/utils/constants.js +18 -0
- package/build/browser/object-table/utils/constants.js.map +1 -0
- package/build/browser/object-table/utils/getColumnPinningStyles.js +27 -0
- package/build/browser/object-table/utils/getColumnPinningStyles.js.map +1 -0
- package/build/browser/public/experimental.js +4 -0
- package/build/browser/public/experimental.js.map +1 -1
- package/build/cjs/public/experimental.cjs +446 -129
- package/build/cjs/public/experimental.cjs.map +1 -1
- package/build/cjs/public/experimental.css +248 -4
- package/build/cjs/public/experimental.css.map +1 -1
- package/build/cjs/public/experimental.d.cts +26 -3
- package/build/esm/base-components/checkbox/Checkbox.module.css +11 -10
- package/build/esm/object-table/CellContextMenu.js +2 -2
- package/build/esm/object-table/CellContextMenu.js.map +1 -1
- package/build/esm/object-table/CellContextMenu.module.css +20 -0
- package/build/esm/object-table/ObjectTable.js +37 -10
- 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/Table.js +7 -16
- package/build/esm/object-table/Table.js.map +1 -1
- package/build/esm/object-table/Table.module.css +22 -0
- package/build/esm/object-table/TableBody.js +2 -2
- package/build/esm/object-table/TableBody.js.map +1 -1
- package/build/esm/object-table/TableBody.module.css +20 -0
- package/build/esm/object-table/TableCell.js +12 -7
- package/build/esm/object-table/TableCell.js.map +1 -1
- package/build/esm/object-table/TableCell.module.css +63 -0
- package/build/esm/object-table/TableHeader.js +35 -38
- package/build/esm/object-table/TableHeader.js.map +1 -1
- package/build/esm/object-table/TableHeader.module.css +95 -0
- package/build/esm/object-table/TableHeaderContent.js +27 -0
- package/build/esm/object-table/TableHeaderContent.js.map +1 -0
- package/build/esm/object-table/TableHeaderContent.module.css +30 -0
- package/build/esm/object-table/TableHeaderWithPopover.js +155 -0
- package/build/esm/object-table/TableHeaderWithPopover.js.map +1 -0
- package/build/esm/object-table/TableHeaderWithPopover.module.css +105 -0
- package/build/esm/object-table/TableRow.js +4 -3
- package/build/esm/object-table/TableRow.js.map +1 -1
- package/build/esm/object-table/TableRow.module.css +60 -0
- package/build/esm/object-table/hooks/__tests__/useColumnPinning.test.js +266 -0
- package/build/esm/object-table/hooks/__tests__/useColumnPinning.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/{useDefaultTableStates.test.js → useColumnVisibility.test.js} +16 -16
- package/build/esm/object-table/hooks/__tests__/useColumnVisibility.test.js.map +1 -0
- package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js +2 -1
- package/build/esm/object-table/hooks/__tests__/useSelectionColumn.test.js.map +1 -1
- package/build/esm/object-table/hooks/__tests__/useTableSorting.test.js +211 -0
- package/build/esm/object-table/hooks/__tests__/useTableSorting.test.js.map +1 -0
- package/build/esm/object-table/hooks/useColumnPinning.js +95 -0
- package/build/esm/object-table/hooks/useColumnPinning.js.map +1 -0
- package/build/{browser/object-table/hooks/useDefaultTableStates.js → esm/object-table/hooks/useColumnVisibility.js} +3 -5
- package/build/esm/object-table/hooks/useColumnVisibility.js.map +1 -0
- package/build/esm/object-table/hooks/useObjectTableData.js +15 -3
- package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -1
- package/build/esm/object-table/hooks/useSelectionColumn.js +3 -2
- package/build/esm/object-table/hooks/useSelectionColumn.js.map +1 -1
- package/build/esm/object-table/hooks/useTableSorting.js +66 -0
- package/build/esm/object-table/hooks/useTableSorting.js.map +1 -0
- package/build/esm/object-table/utils/constants.js +18 -0
- package/build/esm/object-table/utils/constants.js.map +1 -0
- package/build/esm/object-table/utils/getColumnPinningStyles.js +27 -0
- package/build/esm/object-table/utils/getColumnPinningStyles.js.map +1 -0
- package/build/esm/public/experimental.js +4 -0
- package/build/esm/public/experimental.js.map +1 -1
- package/build/types/object-table/CellContextMenu.d.ts.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 +11 -0
- package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
- package/build/types/object-table/Table.d.ts +3 -3
- package/build/types/object-table/Table.d.ts.map +1 -1
- package/build/types/object-table/TableBody.d.ts.map +1 -1
- package/build/types/object-table/TableCell.d.ts.map +1 -1
- package/build/types/object-table/TableHeader.d.ts.map +1 -1
- package/build/types/object-table/TableHeaderContent.d.ts +7 -0
- package/build/types/object-table/TableHeaderContent.d.ts.map +1 -0
- package/build/types/object-table/TableHeaderWithPopover.d.ts +13 -0
- package/build/types/object-table/TableHeaderWithPopover.d.ts.map +1 -0
- package/build/types/object-table/TableRow.d.ts.map +1 -1
- package/build/types/object-table/hooks/__tests__/useColumnPinning.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useColumnVisibility.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useColumnVisibility.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/__tests__/useTableSorting.test.d.ts +1 -0
- package/build/types/object-table/hooks/__tests__/useTableSorting.test.d.ts.map +1 -0
- package/build/types/object-table/hooks/useColumnPinning.d.ts +22 -0
- package/build/types/object-table/hooks/useColumnPinning.d.ts.map +1 -0
- package/build/types/object-table/hooks/{useDefaultTableStates.d.ts → useColumnVisibility.d.ts} +3 -6
- package/build/types/object-table/hooks/useColumnVisibility.d.ts.map +1 -0
- package/build/types/object-table/hooks/useObjectTableData.d.ts +2 -1
- package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -1
- package/build/types/object-table/hooks/useSelectionColumn.d.ts +0 -1
- package/build/types/object-table/hooks/useSelectionColumn.d.ts.map +1 -1
- package/build/types/object-table/hooks/useTableSorting.d.ts +22 -0
- package/build/types/object-table/hooks/useTableSorting.d.ts.map +1 -0
- package/build/types/object-table/utils/constants.d.ts +1 -0
- package/build/types/object-table/utils/constants.d.ts.map +1 -0
- package/build/types/object-table/utils/getColumnPinningStyles.d.ts +7 -0
- package/build/types/object-table/utils/getColumnPinningStyles.d.ts.map +1 -0
- package/build/types/public/experimental.d.ts +2 -0
- package/build/types/public/experimental.d.ts.map +1 -1
- package/package.json +8 -8
- package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +0 -1
- package/build/browser/object-table/hooks/useDefaultTableStates.js.map +0 -1
- package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +0 -1
- package/build/esm/object-table/hooks/useDefaultTableStates.js.map +0 -1
- package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts.map +0 -1
- package/build/types/object-table/hooks/useDefaultTableStates.d.ts.map +0 -1
- /package/build/types/object-table/hooks/__tests__/{useDefaultTableStates.test.d.ts → useColumnPinning.test.d.ts} +0 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { act, renderHook } from "@testing-library/react";
|
|
18
|
+
import { describe, expect, it, vi } from "vitest";
|
|
19
|
+
import { useTableSorting } from "../useTableSorting.js";
|
|
20
|
+
const TestObjectType = {
|
|
21
|
+
type: "object",
|
|
22
|
+
apiName: "TestObject"
|
|
23
|
+
};
|
|
24
|
+
describe("useTableSorting", () => {
|
|
25
|
+
describe("uncontrolled mode", () => {
|
|
26
|
+
it("initializes with empty sorting state when no defaultOrderBy provided", () => {
|
|
27
|
+
const {
|
|
28
|
+
result
|
|
29
|
+
} = renderHook(() => useTableSorting({}));
|
|
30
|
+
expect(result.current.sorting).toEqual([]);
|
|
31
|
+
});
|
|
32
|
+
it("initializes with defaultOrderBy when provided", () => {
|
|
33
|
+
const defaultOrderBy = [{
|
|
34
|
+
property: "name",
|
|
35
|
+
direction: "asc"
|
|
36
|
+
}, {
|
|
37
|
+
property: "age",
|
|
38
|
+
direction: "desc"
|
|
39
|
+
}];
|
|
40
|
+
const {
|
|
41
|
+
result
|
|
42
|
+
} = renderHook(() => useTableSorting({
|
|
43
|
+
defaultOrderBy
|
|
44
|
+
}));
|
|
45
|
+
expect(result.current.sorting).toEqual([{
|
|
46
|
+
id: "name",
|
|
47
|
+
desc: false
|
|
48
|
+
}, {
|
|
49
|
+
id: "age",
|
|
50
|
+
desc: true
|
|
51
|
+
}]);
|
|
52
|
+
});
|
|
53
|
+
it("updates internal sorting state when onSortingChange is called", () => {
|
|
54
|
+
const {
|
|
55
|
+
result
|
|
56
|
+
} = renderHook(() => useTableSorting({}));
|
|
57
|
+
expect(result.current.sorting).toEqual([]);
|
|
58
|
+
act(() => {
|
|
59
|
+
result.current.onSortingChange([{
|
|
60
|
+
id: "name",
|
|
61
|
+
desc: false
|
|
62
|
+
}]);
|
|
63
|
+
});
|
|
64
|
+
expect(result.current.sorting).toEqual([{
|
|
65
|
+
id: "name",
|
|
66
|
+
desc: false
|
|
67
|
+
}]);
|
|
68
|
+
});
|
|
69
|
+
it("calls onOrderByChanged with converted format when sorting changes", () => {
|
|
70
|
+
const onOrderByChanged = vi.fn();
|
|
71
|
+
const {
|
|
72
|
+
result
|
|
73
|
+
} = renderHook(() => useTableSorting({
|
|
74
|
+
onOrderByChanged
|
|
75
|
+
}));
|
|
76
|
+
act(() => {
|
|
77
|
+
result.current.onSortingChange([{
|
|
78
|
+
id: "name",
|
|
79
|
+
desc: false
|
|
80
|
+
}, {
|
|
81
|
+
id: "age",
|
|
82
|
+
desc: true
|
|
83
|
+
}]);
|
|
84
|
+
});
|
|
85
|
+
expect(onOrderByChanged).toHaveBeenCalledWith([{
|
|
86
|
+
property: "name",
|
|
87
|
+
direction: "asc"
|
|
88
|
+
}, {
|
|
89
|
+
property: "age",
|
|
90
|
+
direction: "desc"
|
|
91
|
+
}]);
|
|
92
|
+
});
|
|
93
|
+
it("handles clearing sorting", () => {
|
|
94
|
+
const onOrderByChanged = vi.fn();
|
|
95
|
+
const {
|
|
96
|
+
result
|
|
97
|
+
} = renderHook(() => useTableSorting({
|
|
98
|
+
defaultOrderBy: [{
|
|
99
|
+
property: "name",
|
|
100
|
+
direction: "asc"
|
|
101
|
+
}],
|
|
102
|
+
onOrderByChanged
|
|
103
|
+
}));
|
|
104
|
+
expect(result.current.sorting).toEqual([{
|
|
105
|
+
id: "name",
|
|
106
|
+
desc: false
|
|
107
|
+
}]);
|
|
108
|
+
act(() => {
|
|
109
|
+
result.current.onSortingChange([]);
|
|
110
|
+
});
|
|
111
|
+
expect(result.current.sorting).toEqual([]);
|
|
112
|
+
expect(onOrderByChanged).toHaveBeenCalledWith([]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe("controlled mode", () => {
|
|
116
|
+
it("uses orderBy prop for sorting state", () => {
|
|
117
|
+
const orderBy = [{
|
|
118
|
+
property: "name",
|
|
119
|
+
direction: "asc"
|
|
120
|
+
}];
|
|
121
|
+
const {
|
|
122
|
+
result
|
|
123
|
+
} = renderHook(() => useTableSorting({
|
|
124
|
+
orderBy
|
|
125
|
+
}));
|
|
126
|
+
expect(result.current.sorting).toEqual([{
|
|
127
|
+
id: "name",
|
|
128
|
+
desc: false
|
|
129
|
+
}]);
|
|
130
|
+
});
|
|
131
|
+
it("when both orderBy and defaultOrderBy are provided, orderBy takes precedence", () => {
|
|
132
|
+
const orderBy = [{
|
|
133
|
+
property: "name",
|
|
134
|
+
direction: "asc"
|
|
135
|
+
}];
|
|
136
|
+
const defaultOrderBy = [{
|
|
137
|
+
property: "age",
|
|
138
|
+
direction: "asc"
|
|
139
|
+
}];
|
|
140
|
+
const {
|
|
141
|
+
result
|
|
142
|
+
} = renderHook(() => useTableSorting({
|
|
143
|
+
orderBy,
|
|
144
|
+
defaultOrderBy
|
|
145
|
+
}));
|
|
146
|
+
expect(result.current.sorting).toEqual([{
|
|
147
|
+
id: "name",
|
|
148
|
+
desc: false
|
|
149
|
+
}]);
|
|
150
|
+
});
|
|
151
|
+
it("calls onOrderByChanged when sorting changes but does not update internal state", () => {
|
|
152
|
+
const onOrderByChanged = vi.fn();
|
|
153
|
+
const {
|
|
154
|
+
result,
|
|
155
|
+
rerender
|
|
156
|
+
} = renderHook(({
|
|
157
|
+
orderBy
|
|
158
|
+
}) => useTableSorting({
|
|
159
|
+
orderBy,
|
|
160
|
+
onOrderByChanged
|
|
161
|
+
}), {
|
|
162
|
+
initialProps: {
|
|
163
|
+
orderBy: [{
|
|
164
|
+
property: "name",
|
|
165
|
+
direction: "asc"
|
|
166
|
+
}]
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
expect(result.current.sorting).toEqual([{
|
|
170
|
+
id: "name",
|
|
171
|
+
desc: false
|
|
172
|
+
}]);
|
|
173
|
+
|
|
174
|
+
// Change sorting
|
|
175
|
+
act(() => {
|
|
176
|
+
result.current.onSortingChange([{
|
|
177
|
+
id: "age",
|
|
178
|
+
desc: true
|
|
179
|
+
}]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Callback is called
|
|
183
|
+
expect(onOrderByChanged).toHaveBeenCalledWith([{
|
|
184
|
+
property: "age",
|
|
185
|
+
direction: "desc"
|
|
186
|
+
}]);
|
|
187
|
+
|
|
188
|
+
// State doesn't change (controlled)
|
|
189
|
+
expect(result.current.sorting).toEqual([{
|
|
190
|
+
id: "name",
|
|
191
|
+
desc: false
|
|
192
|
+
}]);
|
|
193
|
+
|
|
194
|
+
// Parent updates prop
|
|
195
|
+
|
|
196
|
+
rerender({
|
|
197
|
+
orderBy: [{
|
|
198
|
+
property: "age",
|
|
199
|
+
direction: "desc"
|
|
200
|
+
}]
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
// Now state reflects the prop
|
|
204
|
+
expect(result.current.sorting).toEqual([{
|
|
205
|
+
id: "age",
|
|
206
|
+
desc: true
|
|
207
|
+
}]);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
//# sourceMappingURL=useTableSorting.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableSorting.test.js","names":["act","renderHook","describe","expect","it","vi","useTableSorting","TestObjectType","type","apiName","result","current","sorting","toEqual","defaultOrderBy","property","direction","id","desc","onSortingChange","onOrderByChanged","fn","toHaveBeenCalledWith","orderBy","rerender","initialProps"],"sources":["useTableSorting.test.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 { ObjectTypeDefinition, PropertyKeys } from \"@osdk/api\";\nimport { act, renderHook } from \"@testing-library/react\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport { useTableSorting } from \"../useTableSorting.js\";\n\nconst TestObjectType = {\n type: \"object\",\n apiName: \"TestObject\",\n} as const satisfies ObjectTypeDefinition;\n\ntype TestObject = typeof TestObjectType;\n\ndescribe(\"useTableSorting\", () => {\n describe(\"uncontrolled mode\", () => {\n it(\"initializes with empty sorting state when no defaultOrderBy provided\", () => {\n const { result } = renderHook(() => useTableSorting({}));\n\n expect(result.current.sorting).toEqual([]);\n });\n\n it(\"initializes with defaultOrderBy when provided\", () => {\n const defaultOrderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"name\" as PropertyKeys<TestObject>, direction: \"asc\" },\n { property: \"age\" as PropertyKeys<TestObject>, direction: \"desc\" },\n ];\n\n const { result } = renderHook(() =>\n useTableSorting<TestObject>({\n defaultOrderBy,\n })\n );\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n { id: \"age\", desc: true },\n ]);\n });\n\n it(\"updates internal sorting state when onSortingChange is called\", () => {\n const { result } = renderHook(() => useTableSorting<TestObject>({}));\n\n expect(result.current.sorting).toEqual([]);\n\n act(() => {\n result.current.onSortingChange([\n { id: \"name\", desc: false },\n ]);\n });\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n });\n\n it(\"calls onOrderByChanged with converted format when sorting changes\", () => {\n const onOrderByChanged = vi.fn();\n const { result } = renderHook(() =>\n useTableSorting<TestObject>({\n onOrderByChanged,\n })\n );\n\n act(() => {\n result.current.onSortingChange([\n { id: \"name\", desc: false },\n { id: \"age\", desc: true },\n ]);\n });\n\n expect(onOrderByChanged).toHaveBeenCalledWith([\n { property: \"name\", direction: \"asc\" },\n { property: \"age\", direction: \"desc\" },\n ]);\n });\n\n it(\"handles clearing sorting\", () => {\n const onOrderByChanged = vi.fn();\n const { result } = renderHook(() =>\n useTableSorting<TestObject>({\n defaultOrderBy: [\n { property: \"name\" as PropertyKeys<TestObject>, direction: \"asc\" },\n ],\n onOrderByChanged,\n })\n );\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n\n act(() => {\n result.current.onSortingChange([]);\n });\n\n expect(result.current.sorting).toEqual([]);\n expect(onOrderByChanged).toHaveBeenCalledWith([]);\n });\n });\n\n describe(\"controlled mode\", () => {\n it(\"uses orderBy prop for sorting state\", () => {\n const orderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"name\" as PropertyKeys<TestObject>, direction: \"asc\" },\n ];\n\n const { result } = renderHook(() =>\n useTableSorting<TestObject>({\n orderBy,\n })\n );\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n });\n\n it(\"when both orderBy and defaultOrderBy are provided, orderBy takes precedence\", () => {\n const orderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"name\" as PropertyKeys<TestObject>, direction: \"asc\" },\n ];\n\n const defaultOrderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"age\" as PropertyKeys<TestObject>, direction: \"asc\" },\n ];\n\n const { result } = renderHook(() =>\n useTableSorting<TestObject>({\n orderBy,\n defaultOrderBy,\n })\n );\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n });\n\n it(\"calls onOrderByChanged when sorting changes but does not update internal state\", () => {\n const onOrderByChanged = vi.fn();\n const orderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"name\" as PropertyKeys<TestObject>, direction: \"asc\" },\n ];\n\n const { result, rerender } = renderHook(\n ({ orderBy }) =>\n useTableSorting<TestObject>({\n orderBy,\n onOrderByChanged,\n }),\n {\n initialProps: { orderBy },\n },\n );\n\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n\n // Change sorting\n act(() => {\n result.current.onSortingChange([\n { id: \"age\", desc: true },\n ]);\n });\n\n // Callback is called\n expect(onOrderByChanged).toHaveBeenCalledWith([\n { property: \"age\", direction: \"desc\" },\n ]);\n\n // State doesn't change (controlled)\n expect(result.current.sorting).toEqual([\n { id: \"name\", desc: false },\n ]);\n\n // Parent updates prop\n const newOrderBy: Array<{\n property: PropertyKeys<TestObject>;\n direction: \"asc\" | \"desc\";\n }> = [\n { property: \"age\" as PropertyKeys<TestObject>, direction: \"desc\" },\n ];\n rerender({ orderBy: newOrderBy });\n\n // Now state reflects the prop\n expect(result.current.sorting).toEqual([\n { id: \"age\", desc: true },\n ]);\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,GAAG,EAAEC,UAAU,QAAQ,wBAAwB;AACxD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACjD,SAASC,eAAe,QAAQ,uBAAuB;AAEvD,MAAMC,cAAc,GAAG;EACrBC,IAAI,EAAE,QAAQ;EACdC,OAAO,EAAE;AACX,CAAyC;AAIzCP,QAAQ,CAAC,iBAAiB,EAAE,MAAM;EAChCA,QAAQ,CAAC,mBAAmB,EAAE,MAAM;IAClCE,EAAE,CAAC,sEAAsE,EAAE,MAAM;MAC/E,MAAM;QAAEM;MAAO,CAAC,GAAGT,UAAU,CAAC,MAAMK,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;MAExDH,MAAM,CAACO,MAAM,CAACC,OAAO,CAACC,OAAO,CAAC,CAACC,OAA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* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useEffect, useState } from "react";
|
|
18
|
+
import { SELECTION_COLUMN_ID } from "../utils/constants.js";
|
|
19
|
+
export const useColumnPinning = ({
|
|
20
|
+
columnDefinitions,
|
|
21
|
+
hasSelectionColumn,
|
|
22
|
+
onColumnsPinnedChanged
|
|
23
|
+
}) => {
|
|
24
|
+
const [columnPinning, setColumnPinning] = useState({
|
|
25
|
+
left: [],
|
|
26
|
+
right: []
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Update column pinning when columnDefinitions change
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const defaultState = getColumnPinningStateFromColumnDefs(columnDefinitions);
|
|
32
|
+
const selectionCol = hasSelectionColumn ? [SELECTION_COLUMN_ID] : [];
|
|
33
|
+
setColumnPinning({
|
|
34
|
+
left: [...selectionCol, ...(defaultState.left ?? [])],
|
|
35
|
+
right: [...(defaultState.right ?? [])]
|
|
36
|
+
});
|
|
37
|
+
}, [columnDefinitions, hasSelectionColumn]);
|
|
38
|
+
const onColumnPinningChange = useCallback(updater => {
|
|
39
|
+
setColumnPinning(prev => {
|
|
40
|
+
const newPinning = typeof updater === "function" ? updater(prev) : updater;
|
|
41
|
+
if (onColumnsPinnedChanged) {
|
|
42
|
+
const newStates = convertColumnPinningStateToArray(newPinning);
|
|
43
|
+
const stateWithoutSelectionCol = newStates.filter(state => state.columnId !== SELECTION_COLUMN_ID);
|
|
44
|
+
onColumnsPinnedChanged(stateWithoutSelectionCol);
|
|
45
|
+
}
|
|
46
|
+
return newPinning;
|
|
47
|
+
});
|
|
48
|
+
}, [onColumnsPinnedChanged]);
|
|
49
|
+
return {
|
|
50
|
+
columnPinning,
|
|
51
|
+
onColumnPinningChange
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const getColumnPinningStateFromColumnDefs = columnDefinitions => {
|
|
55
|
+
if (!columnDefinitions) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
const columnPinningState = columnDefinitions.reduce((acc, {
|
|
59
|
+
locator,
|
|
60
|
+
pinned
|
|
61
|
+
}) => {
|
|
62
|
+
const colKey = locator.id.toString();
|
|
63
|
+
if (!(pinned != null && pinned !== "none")) {
|
|
64
|
+
return acc;
|
|
65
|
+
}
|
|
66
|
+
if (pinned === "left") {
|
|
67
|
+
return {
|
|
68
|
+
...acc,
|
|
69
|
+
left: [...(acc.left ?? []), colKey]
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
...acc,
|
|
74
|
+
right: [...(acc.right ?? []), colKey]
|
|
75
|
+
};
|
|
76
|
+
}, {
|
|
77
|
+
left: [],
|
|
78
|
+
right: []
|
|
79
|
+
});
|
|
80
|
+
return columnPinningState;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Converts ColumnPinningState to array format for the callback
|
|
85
|
+
*/
|
|
86
|
+
function convertColumnPinningStateToArray(pinningState) {
|
|
87
|
+
return [...(pinningState.left ?? []).map(columnId => ({
|
|
88
|
+
columnId,
|
|
89
|
+
pinned: "left"
|
|
90
|
+
})), ...(pinningState.right ?? []).map(columnId => ({
|
|
91
|
+
columnId,
|
|
92
|
+
pinned: "right"
|
|
93
|
+
}))];
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=useColumnPinning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useColumnPinning.js","names":["useCallback","useEffect","useState","SELECTION_COLUMN_ID","useColumnPinning","columnDefinitions","hasSelectionColumn","onColumnsPinnedChanged","columnPinning","setColumnPinning","left","right","defaultState","getColumnPinningStateFromColumnDefs","selectionCol","onColumnPinningChange","updater","prev","newPinning","newStates","convertColumnPinningStateToArray","stateWithoutSelectionCol","filter","state","columnId","columnPinningState","reduce","acc","locator","pinned","colKey","id","toString","pinningState","map"],"sources":["useColumnPinning.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 ObjectTypeDefinition,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { ColumnPinningState, OnChangeFn } from \"@tanstack/react-table\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport type { ObjectTableProps } from \"../ObjectTableApi.js\";\nimport { SELECTION_COLUMN_ID } from \"../utils/constants.js\";\n\ninterface UseColumnPinningProps<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n columnDefinitions: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"columnDefinitions\"];\n\n hasSelectionColumn?: boolean;\n\n onColumnsPinnedChanged?: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"onColumnsPinnedChanged\"];\n}\n\ninterface UseColumnPinningResults {\n columnPinning: ColumnPinningState;\n onColumnPinningChange: OnChangeFn<ColumnPinningState>;\n}\n\nexport const useColumnPinning = <\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n columnDefinitions,\n hasSelectionColumn,\n onColumnsPinnedChanged,\n}: UseColumnPinningProps<\n Q,\n RDPs,\n FunctionColumns\n>): UseColumnPinningResults => {\n const [columnPinning, setColumnPinning] = useState<ColumnPinningState>({\n left: [],\n right: [],\n });\n\n // Update column pinning when columnDefinitions change\n useEffect(() => {\n const defaultState = getColumnPinningStateFromColumnDefs(columnDefinitions);\n const selectionCol = hasSelectionColumn ? [SELECTION_COLUMN_ID] : [];\n setColumnPinning({\n left: [...selectionCol, ...(defaultState.left ?? [])],\n right: [...(defaultState.right ?? [])],\n });\n }, [columnDefinitions, hasSelectionColumn]);\n\n const onColumnPinningChange: OnChangeFn<ColumnPinningState> = useCallback(\n (updater) => {\n setColumnPinning((prev) => {\n const newPinning = typeof updater === \"function\"\n ? updater(prev)\n : updater;\n\n if (onColumnsPinnedChanged) {\n const newStates = convertColumnPinningStateToArray(newPinning);\n const stateWithoutSelectionCol = newStates.filter(\n (state) => state.columnId !== SELECTION_COLUMN_ID,\n );\n onColumnsPinnedChanged(stateWithoutSelectionCol);\n }\n\n return newPinning;\n });\n },\n [onColumnsPinnedChanged],\n );\n\n return { columnPinning, onColumnPinningChange };\n};\n\nconst getColumnPinningStateFromColumnDefs = <\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n columnDefinitions: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"columnDefinitions\"],\n): ColumnPinningState => {\n if (!columnDefinitions) {\n return {};\n }\n const columnPinningState: ColumnPinningState = columnDefinitions.reduce<\n ColumnPinningState\n >(\n (acc, { locator, pinned }) => {\n const colKey: string = locator.id.toString();\n const isPinned = pinned != null && pinned !== \"none\";\n if (!isPinned) {\n return acc;\n }\n\n if (pinned === \"left\") {\n return {\n ...acc,\n left: [...(acc.left ?? []), colKey],\n };\n }\n\n return {\n ...acc,\n right: [...(acc.right ?? []), colKey],\n };\n },\n { left: [], right: [] },\n );\n return columnPinningState;\n};\n\n/**\n * Converts ColumnPinningState to array format for the callback\n */\nfunction convertColumnPinningStateToArray(\n pinningState: ColumnPinningState,\n): Array<{ columnId: string; pinned: \"left\" | \"right\" | \"none\" }> {\n return [\n ...(pinningState.left ?? []).map((columnId) => ({\n columnId,\n pinned: \"left\" as const,\n })),\n ...(pinningState.right ?? []).map((columnId) => ({\n columnId,\n pinned: \"right\" as const,\n })),\n ];\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAExD,SAASC,mBAAmB,QAAQ,uBAAuB;AA8B3D,OAAO,MAAMC,gBAAgB,GAAGA,CAO9B;EACAC,iBAAiB;EACjBC,kBAAkB;EAClBC;AAKF,CAAC,KAA8B;EAC7B,MAAM,CAACC,aAAa,EAAEC,gBAAgB,CAAC,GAAGP,QAAQ,CAAqB;IACrEQ,IAAI,EAAE,EAAE;IACRC,KAAK,EAAE;EACT,CAAC,CAAC;;EAEF;EACAV,SAAS,CAAC,MAAM;IACd,MAAMW,YAAY,GAAGC,mCAAmC,CAACR,iBAAiB,CAAC;IAC3E,MAAMS,YAAY,GAAGR,kBAAkB,GAAG,CAACH,mBAAmB,CAAC,GAAG,EAAE;IACpEM,gBAAgB,CAAC;MACfC,IAAI,EAAE,CAAC,GAAGI,YAAY,EAAE,IAAIF,YAAY,CAACF,IAAI,IAAI,EAAE,CAAC,CAAC;MACrDC,KAAK,EAAE,CAAC,IAAIC,YAAY,CAACD,KAAK,IAAI,EAAE,CAAC;IACvC,CAAC,CAAC;EACJ,CAAC,EAAE,CAACN,iBAAiB,EAAE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,CAAC,EAAEmB,MAAM;IACtC,CAAC;EACH,CAAC,EACD;IAAEpB,IAAI,EAAE,EAAE;IAAEC,KAAK,EAAE;EAAG,CACxB,CAAC;EACD,OAAOc,kBAAkB;AAC3B,CAAC;;AAED;AACA;AACA;AACA,SAASL,gCAAgCA,CACvCa,YAAgC,EACgC;EAChE,OAAO,CACL,GAAG,CAACA,YAAY,CAACvB,IAAI,IAAI,EAAE,EAAEwB,GAAG,CAAEV,QAAQ,KAAM;IAC9CA,QAAQ;IACRK,MAAM,EAAE;EACV,CAAC,CAAC,CAAC,EACH,GAAG,CAACI,YAAY,CAACtB,KAAK,IAAI,EAAE,EAAEuB,GAAG,CAAEV,QAAQ,KAAM;IAC/CA,QAAQ;IACRK,MAAM,EAAE;EACV,CAAC,CAAC,CAAC,CACJ;AACH","ignoreList":[]}
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { useMemo } from "react";
|
|
18
|
-
export const
|
|
18
|
+
export const useColumnVisibility = ({
|
|
19
19
|
columnDefinitions
|
|
20
20
|
}) => {
|
|
21
21
|
const columnVisibility = useMemo(() => {
|
|
@@ -36,8 +36,6 @@ export const useDefaultTableStates = ({
|
|
|
36
36
|
return colVisibility;
|
|
37
37
|
}
|
|
38
38
|
}, [columnDefinitions]);
|
|
39
|
-
return
|
|
40
|
-
columnVisibility
|
|
41
|
-
};
|
|
39
|
+
return columnVisibility;
|
|
42
40
|
};
|
|
43
|
-
//# sourceMappingURL=
|
|
41
|
+
//# sourceMappingURL=useColumnVisibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useColumnVisibility.js","names":["useMemo","useColumnVisibility","columnDefinitions","columnVisibility","colVisibility","reduce","acc","colDef","isVisible","undefined","locator","colKey","id"],"sources":["useColumnVisibility.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 ObjectTypeDefinition,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { VisibilityState } from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\nimport type { ObjectTableProps } from \"../ObjectTableApi.js\";\n\ninterface UseColumnVisibilityProps<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n columnDefinitions: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"columnDefinitions\"];\n}\n\nexport const useColumnVisibility = <\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n { columnDefinitions }: UseColumnVisibilityProps<\n Q,\n RDPs,\n FunctionColumns\n >,\n): VisibilityState | undefined => {\n const columnVisibility = useMemo(() => {\n if (columnDefinitions) {\n const colVisibility: VisibilityState = columnDefinitions.reduce(\n (acc, colDef) => {\n if (colDef.isVisible !== undefined) {\n const { locator } = colDef;\n const colKey = locator.id;\n\n return {\n ...acc,\n [colKey]: colDef.isVisible,\n };\n }\n return acc;\n },\n {},\n );\n\n return colVisibility;\n }\n }, [columnDefinitions]);\n\n return columnVisibility;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,SAASA,OAAO,QAAQ,OAAO;AAkB/B,OAAO,MAAMC,mBAAmB,GAAGA,CAQjC;EAAEC;AAIF,CAAC,KAC+B;EAChC,MAAMC,gBAAgB,GAAGH,OAAO,CAAC,MAAM;IACrC,IAAIE,iBAAiB,EAAE;MACrB,MAAME,aAA8B,GAAGF,iBAAiB,CAACG,MAAM,CAC7D,CAACC,GAAG,EAAEC,MAAM,KAAK;QACf,IAAIA,MAAM,CAACC,SAAS,KAAKC,SAAS,EAAE;UAClC,MAAM;YAAEC;UAAQ,CAAC,GAAGH,MAAM;UAC1B,MAAMI,MAAM,GAAGD,OAAO,CAACE,EAAE;UAEzB,OAAO;YACL,GAAGN,GAAG;YACN,CAACK,MAAM,GAAGJ,MAAM,CAACC;UACnB,CAAC;QACH;QACA,OAAOF,GAAG;MACZ,CAAC,EACD,CAAC,CACH,CAAC;MAED,OAAOF,aAAa;IACtB;EACF,CAAC,EAAE,CAACF,iBAAiB,CAAC,CAAC;EAEvB,OAAOC,gBAAgB;AACzB,CAAC","ignoreList":[]}
|
|
@@ -24,8 +24,19 @@ const PAGE_SIZE = 50;
|
|
|
24
24
|
* to return data containing the derived properties.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
export function useObjectTableData(objectSet, columnDefinitions, filter) {
|
|
28
|
-
//
|
|
27
|
+
export function useObjectTableData(objectSet, columnDefinitions, filter, sorting) {
|
|
28
|
+
// Convert React Table sorting state to OSDK orderBy format
|
|
29
|
+
const orderBy = useMemo(() => {
|
|
30
|
+
if (!sorting || sorting.length === 0) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return sorting.reduce((acc, sort) => {
|
|
34
|
+
acc[sort.id] = sort.desc ? "desc" : "asc";
|
|
35
|
+
return acc;
|
|
36
|
+
}, {});
|
|
37
|
+
}, [sorting]);
|
|
38
|
+
|
|
39
|
+
// Extract derived properties definition
|
|
29
40
|
const withProperties = useMemo(() => {
|
|
30
41
|
if (!columnDefinitions) {
|
|
31
42
|
return;
|
|
@@ -43,7 +54,8 @@ export function useObjectTableData(objectSet, columnDefinitions, filter) {
|
|
|
43
54
|
return useObjectSet(objectSet, {
|
|
44
55
|
withProperties,
|
|
45
56
|
pageSize: PAGE_SIZE,
|
|
46
|
-
where: filter
|
|
57
|
+
where: filter,
|
|
58
|
+
orderBy
|
|
47
59
|
});
|
|
48
60
|
}
|
|
49
61
|
//# sourceMappingURL=useObjectTableData.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObjectTableData.js","names":["useObjectSet","useMemo","PAGE_SIZE","useObjectTableData","objectSet","columnDefinitions","filter","
|
|
1
|
+
{"version":3,"file":"useObjectTableData.js","names":["useObjectSet","useMemo","PAGE_SIZE","useObjectTableData","objectSet","columnDefinitions","filter","sorting","orderBy","length","undefined","reduce","acc","sort","id","desc","withProperties","rdpColumns","map","colDef","locator","colLocator","type","cur","creator","pageSize","where"],"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 ObjectSet,\n ObjectTypeDefinition,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n WhereClause,\n} from \"@osdk/api\";\nimport { useObjectSet } from \"@osdk/react/experimental\";\nimport type { SortingState } from \"@tanstack/react-table\";\nimport { useMemo } from \"react\";\nimport type { ColumnDefinition } from \"../ObjectTableApi.js\";\n\nconst PAGE_SIZE = 50;\n\n/**\n * This hook is a wrapper around useObjectSet\n * It extracts RDP locators from columnDefinitions and calls useObjectSet + withProperties\n * to return data containing the derived properties.\n */\n\nexport function useObjectTableData<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef>,\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>(\n objectSet: ObjectSet<Q>,\n columnDefinitions?: Array<ColumnDefinition<Q, RDPs, FunctionColumns>>,\n filter?: WhereClause<Q, RDPs>,\n sorting?: SortingState,\n): ReturnType<typeof useObjectSet<Q, never, RDPs>> {\n // Convert React Table sorting state to OSDK orderBy format\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.map(colDef => colDef.locator).filter(\n (colLocator) => {\n return colLocator.type === \"rdp\";\n },\n );\n\n return rdpColumns.reduce<\n { [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]> }\n >(\n (acc, cur) => {\n return {\n ...acc,\n [cur.id]: cur.creator,\n };\n },\n {} as {\n [K in keyof RDPs]: DerivedProperty.Creator<Q, RDPs[K]>;\n },\n );\n }, [columnDefinitions]);\n\n return useObjectSet<Q, never, RDPs>(\n objectSet,\n {\n withProperties,\n pageSize: PAGE_SIZE,\n where: filter,\n orderBy,\n },\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA,SAASA,YAAY,QAAQ,0BAA0B;AAEvD,SAASC,OAAO,QAAQ,OAAO;AAG/B,MAAMC,SAAS,GAAG,EAAE;;AAEpB;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,kBAAkBA,CAQhCC,SAAuB,EACvBC,iBAAqE,EACrEC,MAA6B,EAC7BC,OAAsB,EAC2B;EACjD;EACA,MAAMC,OAAO,GAAGP,OAAO,CAAC,MAAM;IAC5B,IAAI,CAACM,OAAO,IAAIA,OAAO,CAACE,MAAM,KAAK,CAAC,EAAE;MACpC,OAAOC,SAAS;IAClB;IAEA,OAAOH,OAAO,CAACI,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,CAACL,OAAO,CAAC,CAAC;;EAEb;EACA,MAAMS,cAAc,GAAGf,OAAO,CAAC,MAAM;IACnC,IAAI,CAACI,iBAAiB,EAAE;MACtB;IACF;IAEA,MAAMY,UAAU,GAAGZ,iBAAiB,CAACa,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACC,OAAO,CAAC,CAACd,MAAM,CACtEe,UAAU,IAAK;MACd,OAAOA,UAAU,CAACC,IAAI,KAAK,KAAK;IAClC,CACF,CAAC;IAED,OAAOL,UAAU,CAACN,MAAM,CAGtB,CAACC,GAAG,EAAEW,GAAG,KAAK;MACZ,OAAO;QACL,GAAGX,GAAG;QACN,CAACW,GAAG,CAACT,EAAE,GAAGS,GAAG,CAACC;MAChB,CAAC;IACH,CAAC,EACD,CAAC,CAGH,CAAC;EACH,CAAC,EAAE,CAACnB,iBAAiB,CAAC,CAAC;EAEvB,OAAOL,YAAY,CACjBI,SAAS,EACT;IACEY,cAAc;IACdS,QAAQ,EAAEvB,SAAS;IACnBwB,KAAK,EAAEpB,MAAM;IACbE;EACF,CACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
|
|
17
17
|
import React, { useMemo } from "react";
|
|
18
18
|
import { SelectionCell, SelectionHeaderCell } from "../SelectionCells.js";
|
|
19
|
-
|
|
19
|
+
import { SELECTION_COLUMN_ID } from "../utils/constants.js";
|
|
20
20
|
export const useSelectionColumn = ({
|
|
21
21
|
selectionMode,
|
|
22
22
|
isAllSelected,
|
|
@@ -43,7 +43,8 @@ export const useSelectionColumn = ({
|
|
|
43
43
|
minSize: 50,
|
|
44
44
|
maxSize: 50,
|
|
45
45
|
enableSorting: false,
|
|
46
|
-
enableResizing: false
|
|
46
|
+
enableResizing: false,
|
|
47
|
+
enablePinning: false
|
|
47
48
|
};
|
|
48
49
|
}, [selectionMode, isAllSelected, hasSelection, onToggleAll, onToggleRow]);
|
|
49
50
|
return selectionColumn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelectionColumn.js","names":["React","useMemo","SelectionCell","SelectionHeaderCell","SELECTION_COLUMN_ID","useSelectionColumn","selectionMode","isAllSelected","hasSelection","onToggleAll","onToggleRow","selectionColumn","id","header","createElement","cell","row","size","minSize","maxSize","enableSorting","enableResizing"],"sources":["useSelectionColumn.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 ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { ColumnDef } from \"@tanstack/react-table\";\nimport React, { useMemo } from \"react\";\nimport { SelectionCell, SelectionHeaderCell } from \"../SelectionCells.js\";\n\ninterface UseSelectionColumnProps {\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n isAllSelected: boolean;\n hasSelection: boolean;\n onToggleAll: () => void;\n onToggleRow: (id: string, rowIndex: number, isShiftClick: boolean) => void;\n}\n\nexport const
|
|
1
|
+
{"version":3,"file":"useSelectionColumn.js","names":["React","useMemo","SelectionCell","SelectionHeaderCell","SELECTION_COLUMN_ID","useSelectionColumn","selectionMode","isAllSelected","hasSelection","onToggleAll","onToggleRow","selectionColumn","id","header","createElement","cell","row","size","minSize","maxSize","enableSorting","enableResizing","enablePinning"],"sources":["useSelectionColumn.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 ObjectTypeDefinition,\n Osdk,\n PropertyKeys,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { ColumnDef } from \"@tanstack/react-table\";\nimport React, { useMemo } from \"react\";\nimport { SelectionCell, SelectionHeaderCell } from \"../SelectionCells.js\";\nimport { SELECTION_COLUMN_ID } from \"../utils/constants.js\";\n\ninterface UseSelectionColumnProps {\n selectionMode?: \"single\" | \"multiple\" | \"none\";\n isAllSelected: boolean;\n hasSelection: boolean;\n onToggleAll: () => void;\n onToggleRow: (id: string, rowIndex: number, isShiftClick: boolean) => void;\n}\n\nexport const useSelectionColumn = <\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\n>({\n selectionMode,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n}: UseSelectionColumnProps):\n | ColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n >\n | null =>\n{\n const selectionColumn = useMemo(() => {\n if (selectionMode === \"none\") return null;\n\n const colDef: ColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n id: SELECTION_COLUMN_ID,\n header: () => (\n selectionMode === \"multiple\"\n ? (\n <SelectionHeaderCell\n isAllSelected={isAllSelected}\n hasSelection={hasSelection}\n onToggleAll={onToggleAll}\n />\n )\n : null\n ),\n cell: ({ row }: { row: any }) => (\n <SelectionCell\n row={row}\n onToggleRow={onToggleRow}\n />\n ),\n size: 50,\n minSize: 50,\n maxSize: 50,\n enableSorting: false,\n enableResizing: false,\n enablePinning: false,\n };\n\n return colDef;\n }, [\n selectionMode,\n isAllSelected,\n hasSelection,\n onToggleAll,\n onToggleRow,\n ]);\n\n return selectionColumn;\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO;AACtC,SAASC,aAAa,EAAEC,mBAAmB,QAAQ,sBAAsB;AACzE,SAASC,mBAAmB,QAAQ,uBAAuB;AAU3D,OAAO,MAAMC,kBAAkB,GAAGA,CAMhC;EACAC,aAAa;EACbC,aAAa;EACbC,YAAY;EACZC,WAAW;EACXC;AACuB,CAAC,KAK1B;EACE,MAAMC,eAAe,GAAGV,OAAO,CAAC,MAAM;IACpC,IAAIK,aAAa,KAAK,MAAM,EAAE,OAAO,IAAI;IA+BzC,OA3BI;MACFM,EAAE,EAAER,mBAAmB;MACvBS,MAAM,EAAEA,CAAA,KACNP,aAAa,KAAK,UAAU,gBAExBN,KAAA,CAAAc,aAAA,CAACX,mBAAmB;QAClBI,aAAa,EAAEA,aAAc;QAC7BC,YAAY,EAAEA,YAAa;QAC3BC,WAAW,EAAEA;MAAY,CAC1B,CAAC,GAEF,IACL;MACDM,IAAI,EAAEA,CAAC;QAAEC;MAAkB,CAAC,kBAC1BhB,KAAA,CAAAc,aAAA,CAACZ,aAAa;QACZc,GAAG,EAAEA,GAAI;QACTN,WAAW,EAAEA;MAAY,CAC1B,CACF;MACDO,IAAI,EAAE,EAAE;MACRC,OAAO,EAAE,EAAE;MACXC,OAAO,EAAE,EAAE;MACXC,aAAa,EAAE,KAAK;MACpBC,cAAc,EAAE,KAAK;MACrBC,aAAa,EAAE;IACjB,CAAC;EAGH,CAAC,EAAE,CACDhB,aAAa,EACbC,aAAa,EACbC,YAAY,EACZC,WAAW,EACXC,WAAW,CACZ,CAAC;EAEF,OAAOC,eAAe;AACxB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useCallback, useMemo, useState } from "react";
|
|
18
|
+
export const useTableSorting = ({
|
|
19
|
+
orderBy,
|
|
20
|
+
defaultOrderBy,
|
|
21
|
+
onOrderByChanged
|
|
22
|
+
}) => {
|
|
23
|
+
// The sorting state in uncontrolled mode
|
|
24
|
+
const [internalSorting, setInternalSorting] = useState(() => defaultOrderBy ? convertOrderByToSortingState(defaultOrderBy) : []);
|
|
25
|
+
const isControlled = orderBy !== undefined;
|
|
26
|
+
|
|
27
|
+
// Sorting state
|
|
28
|
+
// If controlled mode, return the state from orderBy prop
|
|
29
|
+
// If uncontrolled, return the internalSorting state
|
|
30
|
+
const sortingState = useMemo(() => orderBy ? convertOrderByToSortingState(orderBy) : internalSorting, [orderBy, internalSorting]);
|
|
31
|
+
const onSortingChange = useCallback(updater => {
|
|
32
|
+
const newSorting = typeof updater === "function" ? updater(sortingState) : updater;
|
|
33
|
+
|
|
34
|
+
// Update internal state if uncontrolled
|
|
35
|
+
if (!isControlled) {
|
|
36
|
+
setInternalSorting(newSorting);
|
|
37
|
+
}
|
|
38
|
+
if (onOrderByChanged) {
|
|
39
|
+
const newOrderBy = convertSortingStateToOrderBy(newSorting);
|
|
40
|
+
onOrderByChanged(newOrderBy);
|
|
41
|
+
}
|
|
42
|
+
}, [isControlled, sortingState, onOrderByChanged]);
|
|
43
|
+
return {
|
|
44
|
+
sorting: sortingState,
|
|
45
|
+
onSortingChange
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
function convertOrderByToSortingState(orderBy) {
|
|
49
|
+
return orderBy.map(({
|
|
50
|
+
property,
|
|
51
|
+
direction
|
|
52
|
+
}) => ({
|
|
53
|
+
id: property,
|
|
54
|
+
desc: direction === "desc"
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
function convertSortingStateToOrderBy(sorting) {
|
|
58
|
+
return sorting.map(({
|
|
59
|
+
id,
|
|
60
|
+
desc
|
|
61
|
+
}) => ({
|
|
62
|
+
property: id,
|
|
63
|
+
direction: desc ? "desc" : "asc"
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=useTableSorting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTableSorting.js","names":["useCallback","useMemo","useState","useTableSorting","orderBy","defaultOrderBy","onOrderByChanged","internalSorting","setInternalSorting","convertOrderByToSortingState","isControlled","undefined","sortingState","onSortingChange","updater","newSorting","newOrderBy","convertSortingStateToOrderBy","sorting","map","property","direction","id","desc"],"sources":["useTableSorting.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 ObjectTypeDefinition,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { OnChangeFn, SortingState } from \"@tanstack/react-table\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport type { ObjectTableProps } from \"../ObjectTableApi.js\";\n\ninterface UseTableSortingProps<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n> {\n orderBy?: ObjectTableProps<Q, RDPs, FunctionColumns>[\"orderBy\"];\n\n defaultOrderBy?: ObjectTableProps<Q, RDPs, FunctionColumns>[\"defaultOrderBy\"];\n\n onOrderByChanged?: ObjectTableProps<\n Q,\n RDPs,\n FunctionColumns\n >[\"onOrderByChanged\"];\n}\n\ninterface UseTableSortingResults {\n sorting: SortingState;\n onSortingChange: OnChangeFn<SortingState>;\n}\n\nexport const useTableSorting = <\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = {},\n FunctionColumns extends Record<string, QueryDefinition<{}>> = Record<\n string,\n never\n >,\n>({\n orderBy,\n defaultOrderBy,\n onOrderByChanged,\n}: UseTableSortingProps<Q, RDPs, FunctionColumns>): UseTableSortingResults => {\n // The sorting state in uncontrolled mode\n const [internalSorting, setInternalSorting] = useState<SortingState>(() =>\n defaultOrderBy ? convertOrderByToSortingState(defaultOrderBy) : []\n );\n\n const isControlled = orderBy !== undefined;\n\n // Sorting state\n // If controlled mode, return the state from orderBy prop\n // If uncontrolled, return the internalSorting state\n const sortingState: SortingState = useMemo(\n () => (orderBy ? convertOrderByToSortingState(orderBy) : internalSorting),\n [orderBy, internalSorting],\n );\n\n const onSortingChange: OnChangeFn<SortingState> = useCallback(\n (updater) => {\n const newSorting = typeof updater === \"function\"\n ? updater(sortingState)\n : updater;\n\n // Update internal state if uncontrolled\n if (!isControlled) {\n setInternalSorting(newSorting);\n }\n\n if (onOrderByChanged) {\n const newOrderBy = convertSortingStateToOrderBy<Q>(newSorting);\n onOrderByChanged(newOrderBy);\n }\n },\n [isControlled, sortingState, onOrderByChanged],\n );\n\n return { sorting: sortingState, onSortingChange };\n};\n\nfunction convertOrderByToSortingState<Q extends ObjectTypeDefinition>(\n orderBy: Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n }>,\n): SortingState {\n return orderBy.map(({ property, direction }) => ({\n id: property,\n desc: direction === \"desc\",\n }));\n}\n\nfunction convertSortingStateToOrderBy<Q extends ObjectTypeDefinition>(\n sorting: SortingState,\n): Array<{\n property: PropertyKeys<Q>;\n direction: \"asc\" | \"desc\";\n}> {\n return sorting.map(({ id, desc }) => ({\n property: id as PropertyKeys<Q>,\n direction: desc ? \"desc\" : \"asc\",\n }));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AA2BtD,OAAO,MAAMC,eAAe,GAAGA,CAO7B;EACAC,OAAO;EACPC,cAAc;EACdC;AAC8C,CAAC,KAA6B;EAC5E;EACA,MAAM,CAACC,eAAe,EAAEC,kBAAkB,CAAC,GAAGN,QAAQ,CAAe,MACnEG,cAAc,GAAGI,4BAA4B,CAACJ,cAAc,CAAC,GAAG,EAClE,CAAC;EAED,MAAMK,YAAY,GAAGN,OAAO,KAAKO,SAAS;;EAE1C;EACA;EACA;EACA,MAAMC,YAA0B,GAAGX,OAAO,CACxC,MAAOG,OAAO,GAAGK,4BAA4B,CAACL,OAAO,CAAC,GAAGG,eAAgB,EACzE,CAACH,OAAO,EAAEG,eAAe,CAC3B,CAAC;EAED,MAAMM,eAAyC,GAAGb,WAAW,CAC1Dc,OAAO,IAAK;IACX,MAAMC,UAAU,GAAG,OAAOD,OAAO,KAAK,UAAU,GAC5CA,OAAO,CAACF,YAAY,CAAC,GACrBE,OAAO;;IAEX;IACA,IAAI,CAACJ,YAAY,EAAE;MACjBF,kBAAkB,CAACO,UAAU,CAAC;IAChC;IAEA,IAAIT,gBAAgB,EAAE;MACpB,MAAMU,UAAU,GAAGC,4BAA4B,CAAIF,UAAU,CAAC;MAC9DT,gBAAgB,CAACU,UAAU,CAAC;IAC9B;EACF,CAAC,EACD,CAACN,YAAY,EAAEE,YAAY,EAAEN,gBAAgB,CAC/C,CAAC;EAED,OAAO;IAAEY,OAAO,EAAEN,YAAY;IAAEC;EAAgB,CAAC;AACnD,CAAC;AAED,SAASJ,4BAA4BA,CACnCL,OAGE,EACY;EACd,OAAOA,OAAO,CAACe,GAAG,CAAC,CAAC;IAAEC,QAAQ;IAAEC;EAAU,CAAC,MAAM;IAC/CC,EAAE,EAAEF,QAAQ;IACZG,IAAI,EAAEF,SAAS,KAAK;EACtB,CAAC,CAAC,CAAC;AACL;AAEA,SAASJ,4BAA4BA,CACnCC,OAAqB,EAIpB;EACD,OAAOA,OAAO,CAACC,GAAG,CAAC,CAAC;IAAEG,EAAE;IAAEC;EAAK,CAAC,MAAM;IACpCH,QAAQ,EAAEE,EAAqB;IAC/BD,SAAS,EAAEE,IAAI,GAAG,MAAM,GAAG;EAC7B,CAAC,CAAC,CAAC;AACL","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const SELECTION_COLUMN_ID = "__selection__";
|
|
18
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","names":["SELECTION_COLUMN_ID"],"sources":["constants.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\nexport const SELECTION_COLUMN_ID = \"__selection__\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,MAAMA,mBAAmB,GAAG,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function getColumnPinningStyles(column) {
|
|
18
|
+
const isPinned = column.getIsPinned();
|
|
19
|
+
return {
|
|
20
|
+
columnStyles: {
|
|
21
|
+
left: isPinned === "left" ? `${column.getStart("left")}px` : undefined,
|
|
22
|
+
right: isPinned === "right" ? `${column.getAfter("right")}px` : undefined,
|
|
23
|
+
width: column.getSize()
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=getColumnPinningStyles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getColumnPinningStyles.js","names":["getColumnPinningStyles","column","isPinned","getIsPinned","columnStyles","left","getStart","undefined","right","getAfter","width","getSize"],"sources":["getColumnPinningStyles.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 { Column } from \"@tanstack/react-table\";\nimport type React from \"react\";\n\ninterface PinningStyles {\n columnStyles: React.CSSProperties;\n}\n\nexport function getColumnPinningStyles<TData>(\n column: Column<TData, unknown>,\n): PinningStyles {\n const isPinned = column.getIsPinned();\n\n return {\n columnStyles: {\n left: isPinned === \"left\" ? `${column.getStart(\"left\")}px` : undefined,\n right: isPinned === \"right\" ? `${column.getAfter(\"right\")}px` : undefined,\n width: column.getSize(),\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,OAAO,SAASA,sBAAsBA,CACpCC,MAA8B,EACf;EACf,MAAMC,QAAQ,GAAGD,MAAM,CAACE,WAAW,CAAC,CAAC;EAErC,OAAO;IACLC,YAAY,EAAE;MACZC,IAAI,EAAEH,QAAQ,KAAK,MAAM,GAAG,GAAGD,MAAM,CAACK,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAGC,SAAS;MACtEC,KAAK,EAAEN,QAAQ,KAAK,OAAO,GAAG,GAAGD,MAAM,CAACQ,QAAQ,CAAC,OAAO,CAAC,IAAI,GAAGF,SAAS;MACzEG,KAAK,EAAET,MAAM,CAACU,OAAO,CAAC;IACxB;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -16,4 +16,8 @@
|
|
|
16
16
|
|
|
17
17
|
// ObjectTable that loads and displays data for a given objectSet
|
|
18
18
|
export { ObjectTable } from "../object-table/ObjectTable.js";
|
|
19
|
+
|
|
20
|
+
// BaseTable that does not handle data fetching
|
|
21
|
+
|
|
22
|
+
export { BaseTable } from "../object-table/Table.js";
|
|
19
23
|
//# sourceMappingURL=experimental.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"experimental.js","names":["ObjectTable"],"sources":["experimental.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\nexport type { FilterListProps } from \"../filter-list/FilterListApi.js\";\nexport type { FilterListItemProps } from \"../filter-list/FilterListItemApi.js\";\n\n// ObjectTable that loads and displays data for a given objectSet\nexport { ObjectTable } from \"../object-table/ObjectTable.js\";\nexport type {\n ColumnDefinition,\n ColumnDefinitionLocator,\n ObjectTableProps,\n} from \"../object-table/ObjectTableApi.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA,SAASA,WAAW,QAAQ,gCAAgC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"experimental.js","names":["ObjectTable","BaseTable"],"sources":["experimental.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\nexport type { FilterListProps } from \"../filter-list/FilterListApi.js\";\nexport type { FilterListItemProps } from \"../filter-list/FilterListItemApi.js\";\n\n// ObjectTable that loads and displays data for a given objectSet\nexport { ObjectTable } from \"../object-table/ObjectTable.js\";\nexport type {\n ColumnDefinition,\n ColumnDefinitionLocator,\n ObjectTableProps,\n} from \"../object-table/ObjectTableApi.js\";\n\n// BaseTable that does not handle data fetching\nexport type { BaseTableProps } from \"../object-table/Table.js\";\nexport { BaseTable } from \"../object-table/Table.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA,SAASA,WAAW,QAAQ,gCAAgC;;AAO5D;;AAEA,SAASC,SAAS,QAAQ,0BAA0B","ignoreList":[]}
|