@osdk/react-components 0.0.0 → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +56 -6
  3. package/build/browser/object-table/ObjectTable.js +70 -0
  4. package/build/browser/object-table/ObjectTable.js.map +1 -0
  5. package/build/browser/object-table/ObjectTableApi.js.map +1 -1
  6. package/build/browser/object-table/Table.js +77 -0
  7. package/build/browser/object-table/Table.js.map +1 -0
  8. package/build/browser/object-table/TableBody.js +54 -0
  9. package/build/browser/object-table/TableBody.js.map +1 -0
  10. package/build/browser/object-table/TableHeader.js +47 -0
  11. package/build/browser/object-table/TableHeader.js.map +1 -0
  12. package/build/browser/object-table/TableRow.js +44 -0
  13. package/build/browser/object-table/TableRow.js.map +1 -0
  14. package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
  15. package/build/browser/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
  16. package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
  17. package/build/browser/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
  18. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js +217 -0
  19. package/build/browser/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
  20. package/build/browser/object-table/hooks/useColumnDefs.js +87 -0
  21. package/build/browser/object-table/hooks/useColumnDefs.js.map +1 -0
  22. package/build/browser/object-table/hooks/useDefaultTableStates.js +43 -0
  23. package/build/browser/object-table/hooks/useDefaultTableStates.js.map +1 -0
  24. package/build/browser/object-table/hooks/useObjectTableData.js +48 -0
  25. package/build/browser/object-table/hooks/useObjectTableData.js.map +1 -0
  26. package/build/browser/public/experimental.js +17 -1
  27. package/build/browser/public/experimental.js.map +1 -1
  28. package/build/cjs/public/experimental.cjs +3880 -0
  29. package/build/cjs/public/experimental.cjs.map +1 -1
  30. package/build/cjs/public/experimental.d.cts +36 -9
  31. package/build/esm/object-table/ObjectTable.js +70 -0
  32. package/build/esm/object-table/ObjectTable.js.map +1 -0
  33. package/build/esm/object-table/ObjectTableApi.js.map +1 -1
  34. package/build/esm/object-table/Table.js +77 -0
  35. package/build/esm/object-table/Table.js.map +1 -0
  36. package/build/esm/object-table/TableBody.js +54 -0
  37. package/build/esm/object-table/TableBody.js.map +1 -0
  38. package/build/esm/object-table/TableHeader.js +47 -0
  39. package/build/esm/object-table/TableHeader.js.map +1 -0
  40. package/build/esm/object-table/TableRow.js +44 -0
  41. package/build/esm/object-table/TableRow.js.map +1 -0
  42. package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js +508 -0
  43. package/build/esm/object-table/hooks/__tests__/useColumnDefs.test.js.map +1 -0
  44. package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js +178 -0
  45. package/build/esm/object-table/hooks/__tests__/useDefaultTableStates.test.js.map +1 -0
  46. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js +217 -0
  47. package/build/esm/object-table/hooks/__tests__/useObjectTableData.test.js.map +1 -0
  48. package/build/esm/object-table/hooks/useColumnDefs.js +87 -0
  49. package/build/esm/object-table/hooks/useColumnDefs.js.map +1 -0
  50. package/build/esm/object-table/hooks/useDefaultTableStates.js +43 -0
  51. package/build/esm/object-table/hooks/useDefaultTableStates.js.map +1 -0
  52. package/build/esm/object-table/hooks/useObjectTableData.js +48 -0
  53. package/build/esm/object-table/hooks/useObjectTableData.js.map +1 -0
  54. package/build/esm/public/experimental.js +17 -1
  55. package/build/esm/public/experimental.js.map +1 -1
  56. package/build/types/object-table/ObjectTable.d.ts +16 -0
  57. package/build/types/object-table/ObjectTable.d.ts.map +1 -0
  58. package/build/types/object-table/ObjectTableApi.d.ts +27 -12
  59. package/build/types/object-table/ObjectTableApi.d.ts.map +1 -1
  60. package/build/types/object-table/Table.d.ts +11 -0
  61. package/build/types/object-table/Table.d.ts.map +1 -0
  62. package/build/types/object-table/TableBody.d.ts +10 -0
  63. package/build/types/object-table/TableBody.d.ts.map +1 -0
  64. package/build/types/object-table/TableHeader.d.ts +7 -0
  65. package/build/types/object-table/TableHeader.d.ts.map +1 -0
  66. package/build/types/object-table/TableRow.d.ts +10 -0
  67. package/build/types/object-table/TableRow.d.ts.map +1 -0
  68. package/build/types/object-table/hooks/__tests__/useColumnDefs.test.d.ts.map +1 -0
  69. package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts +1 -0
  70. package/build/types/object-table/hooks/__tests__/useDefaultTableStates.test.d.ts.map +1 -0
  71. package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts +1 -0
  72. package/build/types/object-table/hooks/__tests__/useObjectTableData.test.d.ts.map +1 -0
  73. package/build/types/object-table/hooks/useColumnDefs.d.ts +20 -0
  74. package/build/types/object-table/hooks/useColumnDefs.d.ts.map +1 -0
  75. package/build/types/object-table/hooks/useDefaultTableStates.d.ts +19 -0
  76. package/build/types/object-table/hooks/useDefaultTableStates.d.ts.map +1 -0
  77. package/build/types/object-table/hooks/useObjectTableData.d.ts +13 -0
  78. package/build/types/object-table/hooks/useObjectTableData.d.ts.map +1 -0
  79. package/build/types/public/experimental.d.ts +2 -1
  80. package/build/types/public/experimental.d.ts.map +1 -1
  81. package/package.json +9 -4
  82. package/build/browser/junk.test.js +0 -23
  83. package/build/browser/junk.test.js.map +0 -1
  84. package/build/esm/junk.test.js +0 -23
  85. package/build/esm/junk.test.js.map +0 -1
  86. package/build/types/junk.test.d.ts.map +0 -1
  87. /package/build/types/{junk.test.d.ts → object-table/hooks/__tests__/useColumnDefs.test.d.ts} +0 -0
@@ -0,0 +1,178 @@
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 { renderHook, waitFor } from "@testing-library/react";
18
+ import { describe, expect, it } from "vitest";
19
+ import { useDefaultTableStates } from "../useDefaultTableStates.js";
20
+ const TestObjectType = {
21
+ type: "object",
22
+ apiName: "TestObject"
23
+ };
24
+ describe(useDefaultTableStates, () => {
25
+ it("returns undefined columnVisibility when no columnDefinitions provided", () => {
26
+ const {
27
+ result
28
+ } = renderHook(() => useDefaultTableStates({
29
+ columnDefinitions: undefined
30
+ }));
31
+ expect(result.current.columnVisibility).toBeUndefined();
32
+ });
33
+ it("returns empty columnVisibility when columnDefinitions have no isVisible properties", () => {
34
+ const columnDefinitions = [{
35
+ locator: {
36
+ type: "property",
37
+ id: "name"
38
+ }
39
+ }, {
40
+ locator: {
41
+ type: "property",
42
+ id: "email"
43
+ }
44
+ }];
45
+ const {
46
+ result
47
+ } = renderHook(() => useDefaultTableStates({
48
+ columnDefinitions
49
+ }));
50
+ expect(result.current.columnVisibility).toEqual({});
51
+ });
52
+ it("handles mixed column types with different visibility states", async () => {
53
+ const columnDefinitions = [{
54
+ locator: {
55
+ type: "property",
56
+ id: "name"
57
+ },
58
+ isVisible: true
59
+ }, {
60
+ locator: {
61
+ type: "function",
62
+ id: "myFunction"
63
+ },
64
+ isVisible: false
65
+ }, {
66
+ locator: {
67
+ type: "rdp",
68
+ id: "myRdp",
69
+ creator: () => ({})
70
+ },
71
+ isVisible: true
72
+ }, {
73
+ locator: {
74
+ type: "property",
75
+ id: "email"
76
+ }
77
+ }];
78
+ const {
79
+ result
80
+ } = renderHook(() => useDefaultTableStates({
81
+ columnDefinitions
82
+ }));
83
+ await waitFor(() => {
84
+ expect(result.current.columnVisibility).toEqual({
85
+ name: true,
86
+ myFunction: false,
87
+ myRdp: true
88
+ });
89
+ });
90
+ });
91
+ it("updates columnVisibility when columnDefinitions change", async () => {
92
+ const {
93
+ result,
94
+ rerender
95
+ } = renderHook(({
96
+ columnDefinitions
97
+ }) => useDefaultTableStates({
98
+ columnDefinitions
99
+ }), {
100
+ initialProps: {
101
+ columnDefinitions: [{
102
+ locator: {
103
+ type: "property",
104
+ id: "name"
105
+ },
106
+ isVisible: true
107
+ }]
108
+ }
109
+ });
110
+ await waitFor(() => {
111
+ expect(result.current.columnVisibility).toEqual({
112
+ name: true
113
+ });
114
+ });
115
+ rerender({
116
+ columnDefinitions: [{
117
+ locator: {
118
+ type: "property",
119
+ id: "name"
120
+ },
121
+ isVisible: false
122
+ }, {
123
+ locator: {
124
+ type: "property",
125
+ id: "email"
126
+ },
127
+ isVisible: true
128
+ }]
129
+ });
130
+ await waitFor(() => {
131
+ expect(result.current.columnVisibility).toEqual({
132
+ name: false,
133
+ email: true
134
+ });
135
+ });
136
+ });
137
+ it("only includes columns with explicit isVisible in the visibility state", async () => {
138
+ const columnDefinitions = [{
139
+ locator: {
140
+ type: "property",
141
+ id: "name"
142
+ },
143
+ isVisible: true
144
+ }, {
145
+ locator: {
146
+ type: "property",
147
+ id: "email"
148
+ }
149
+ }, {
150
+ locator: {
151
+ type: "property",
152
+ id: "age"
153
+ },
154
+ isVisible: false
155
+ }, {
156
+ locator: {
157
+ type: "property",
158
+ id: "id"
159
+ }
160
+ }];
161
+ const {
162
+ result
163
+ } = renderHook(() => useDefaultTableStates({
164
+ columnDefinitions
165
+ }));
166
+ await waitFor(() => {
167
+ expect(result.current.columnVisibility).toEqual({
168
+ name: true,
169
+ age: false
170
+ });
171
+ });
172
+
173
+ // Verify that columns without isVisible are not in the state
174
+ expect(result.current.columnVisibility).not.toHaveProperty("email");
175
+ expect(result.current.columnVisibility).not.toHaveProperty("id");
176
+ });
177
+ });
178
+ //# sourceMappingURL=useDefaultTableStates.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDefaultTableStates.test.js","names":["renderHook","waitFor","describe","expect","it","useDefaultTableStates","TestObjectType","type","apiName","result","columnDefinitions","undefined","current","columnVisibility","toBeUndefined","locator","id","toEqual","isVisible","creator","name","myFunction","myRdp","rerender","initialProps","email","age","not","toHaveProperty"],"sources":["useDefaultTableStates.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 {\n DerivedProperty,\n ObjectTypeDefinition,\n PropertyKeys,\n QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { renderHook, waitFor } from \"@testing-library/react\";\nimport { describe, expect, it } from \"vitest\";\nimport type { ColumnDefinition } from \"../../ObjectTableApi.js\";\nimport { useDefaultTableStates } from \"../useDefaultTableStates.js\";\n\nconst TestObjectType = {\n type: \"object\",\n apiName: \"TestObject\",\n} as const satisfies ObjectTypeDefinition;\n\ntype TestObject = typeof TestObjectType;\ntype TestObjectKeys = PropertyKeys<TestObject>;\n\ndescribe(useDefaultTableStates, () => {\n it(\"returns undefined columnVisibility when no columnDefinitions provided\", () => {\n const { result } = renderHook(() =>\n useDefaultTableStates({\n columnDefinitions: undefined,\n })\n );\n\n expect(result.current.columnVisibility).toBeUndefined();\n });\n\n it(\"returns empty columnVisibility when columnDefinitions have no isVisible properties\", () => {\n const columnDefinitions: Array<ColumnDefinition<TestObject, {}, {}>> = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n },\n {\n locator: { type: \"property\", id: \"email\" as TestObjectKeys },\n },\n ];\n\n const { result } = renderHook(() =>\n useDefaultTableStates({\n columnDefinitions,\n })\n );\n\n expect(result.current.columnVisibility).toEqual({});\n });\n\n it(\"handles mixed column types with different visibility states\", async () => {\n const mockRdpCreator = (() => ({})) as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n\n const columnDefinitions: Array<\n ColumnDefinition<\n TestObject,\n { myRdp: SimplePropertyDef },\n { myFunction: QueryDefinition<{}> }\n >\n > = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n isVisible: true,\n },\n {\n locator: { type: \"function\", id: \"myFunction\" },\n isVisible: false,\n },\n {\n locator: { type: \"rdp\", id: \"myRdp\", creator: mockRdpCreator },\n isVisible: true,\n },\n {\n locator: { type: \"property\", id: \"email\" as TestObjectKeys },\n },\n ];\n\n const { result } = renderHook(() =>\n useDefaultTableStates({\n columnDefinitions,\n })\n );\n\n await waitFor(() => {\n expect(result.current.columnVisibility).toEqual({\n name: true,\n myFunction: false,\n myRdp: true,\n });\n });\n });\n\n it(\"updates columnVisibility when columnDefinitions change\", async () => {\n const initialColumnDefinitions: Array<\n ColumnDefinition<TestObject, {}, {}>\n > = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n isVisible: true,\n },\n ];\n\n const { result, rerender } = renderHook(\n ({ columnDefinitions }) =>\n useDefaultTableStates({\n columnDefinitions,\n }),\n {\n initialProps: { columnDefinitions: initialColumnDefinitions },\n },\n );\n\n await waitFor(() => {\n expect(result.current.columnVisibility).toEqual({\n name: true,\n });\n });\n\n const updatedColumnDefinitions: Array<\n ColumnDefinition<TestObject, {}, {}>\n > = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n isVisible: false,\n },\n {\n locator: { type: \"property\", id: \"email\" as TestObjectKeys },\n isVisible: true,\n },\n ];\n\n rerender({ columnDefinitions: updatedColumnDefinitions });\n\n await waitFor(() => {\n expect(result.current.columnVisibility).toEqual({\n name: false,\n email: true,\n });\n });\n });\n\n it(\"only includes columns with explicit isVisible in the visibility state\", async () => {\n const columnDefinitions: Array<ColumnDefinition<TestObject, {}, {}>> = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n isVisible: true,\n },\n {\n locator: { type: \"property\", id: \"email\" as TestObjectKeys },\n },\n {\n locator: { type: \"property\", id: \"age\" as TestObjectKeys },\n isVisible: false,\n },\n {\n locator: { type: \"property\", id: \"id\" as TestObjectKeys },\n },\n ];\n\n const { result } = renderHook(() =>\n useDefaultTableStates({\n columnDefinitions,\n })\n );\n\n await waitFor(() => {\n expect(result.current.columnVisibility).toEqual({\n name: true,\n age: false,\n });\n });\n\n // Verify that columns without isVisible are not in the state\n expect(result.current.columnVisibility).not.toHaveProperty(\"email\");\n expect(result.current.columnVisibility).not.toHaveProperty(\"id\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,UAAU,EAAEC,OAAO,QAAQ,wBAAwB;AAC5D,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,SAASC,qBAAqB,QAAQ,6BAA6B;AAEnE,MAAMC,cAAc,GAAG;EACrBC,IAAI,EAAE,QAAQ;EACdC,OAAO,EAAE;AACX,CAAyC;AAKzCN,QAAQ,CAACG,qBAAqB,EAAE,MAAM;EACpCD,EAAE,CAAC,uEAAuE,EAAE,MAAM;IAChF,MAAM;MAAEK;IAAO,CAAC,GAAGT,UAAU,CAAC,MAC5BK,qBAAqB,CAAC;MACpBK,iBAAiB,EAAEC;IACrB,CAAC,CACH,CAAC;IAEDR,MAAM,CAACM,MAAM,CAACG,OAAO,CAACC,gBAAgB,CAAC,CAACC,aAAa,CAAC,CAAC;EACzD,CAAC,CAAC;EAEFV,EAAE,CAAC,oFAAoF,EAAE,MAAM;IAC7F,MAAMM,iBAA8D,GAAG,CACrE;MACEK,OAAO,EAAE;QAAER,IAAI,EAAE,UAAU;QAAES,EAAE,EAAE;MAAyB;IAC5D,CAAC,EACD;MACED,OAAO,EAAE;Q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AU;QAAES,EAAE,EAAE;MAAwB,CAAC;MAC1DE,SAAS,EAAE;IACb,CAAC,EACD;MACEH,OAAO,EAAE;QAAER,IAAI,EAAE,UAAU;QAAES,EAAE,EAAE;MAAuB;IAC1D,CAAC,CACF;IAED,MAAM;MAAEP;IAAO,CAAC,GAAGT,UAAU,CAAC,MAC5BK,qBAAqB,CAAC;MACpBK;IACF,CAAC,CACH,CAAC;IAED,MAAMT,OAAO,CAAC,MAAM;MAClBE,MAAM,CAACM,MAAM,CAACG,OAAO,CAACC,gBAAgB,CAAC,CAACI,OAAO,CAAC;QAC9CG,IAAI,EAAE,IAAI;QACVM,GAAG,EAAE;MACP,CAAC,CAAC;IACJ,CAAC,CAAC;;IAEF;IACAvB,MAAM,CAACM,MAAM,CAACG,OAAO,CAACC,gBAAgB,CAAC,CAACc,GAAG,CAACC,cAAc,CAAC,OAAO,CAAC;IACnEzB,MAAM,CAACM,MAAM,CAACG,OAAO,CAACC,gBAAgB,CAAC,CAACc,GAAG,CAACC,cAAc,CAAC,IAAI,CAAC;EAClE,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,217 @@
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 { OsdkProvider } from "@osdk/react";
18
+ import { renderHook } from "@testing-library/react";
19
+ import * as React from "react";
20
+ import { describe, expect, it, vi } from "vitest";
21
+ import { useObjectTableData } from "../useObjectTableData.js";
22
+ vi.mock("@osdk/react/experimental", () => ({
23
+ useObjectSet: vi.fn((objectSet, options) => {
24
+ return {
25
+ data: [],
26
+ isLoading: false,
27
+ error: undefined,
28
+ fetchNextPage: vi.fn(),
29
+ hasNextPage: false,
30
+ isFetchingNextPage: false,
31
+ // Return the options to verify they were passed correctly
32
+ _testOptions: options
33
+ };
34
+ })
35
+ }));
36
+ const TestObjectType = {
37
+ type: "object",
38
+ apiName: "TestObject"
39
+ };
40
+ const mockObjectSet = {
41
+ objectType: TestObjectType
42
+ };
43
+ describe(useObjectTableData, () => {
44
+ const wrapper = (client => {
45
+ return ({
46
+ children
47
+ }) => {
48
+ return /*#__PURE__*/React.createElement(OsdkProvider, {
49
+ client: client
50
+ }, children);
51
+ };
52
+ })({});
53
+ it("calls useObjectSet with pageSize of 50", () => {
54
+ const {
55
+ result
56
+ } = renderHook(() => useObjectTableData(mockObjectSet), {
57
+ wrapper
58
+ });
59
+ const mockResult = result.current;
60
+ expect(mockResult._testOptions).toEqual({
61
+ withProperties: undefined,
62
+ pageSize: 50
63
+ });
64
+ });
65
+ it("calls useObjectSet without withProperties when no columnDefinitions provided", () => {
66
+ const {
67
+ result
68
+ } = renderHook(() => useObjectTableData(mockObjectSet, undefined), {
69
+ wrapper
70
+ });
71
+ const mockResult = result.current;
72
+ expect(mockResult._testOptions.withProperties).toBeUndefined();
73
+ expect(mockResult._testOptions.pageSize).toBe(50);
74
+ });
75
+ it("calls useObjectSet without withProperties when columnDefinitions have no RDP columns", () => {
76
+ const columnDefinitions = [{
77
+ locator: {
78
+ type: "property",
79
+ id: "name"
80
+ }
81
+ }, {
82
+ locator: {
83
+ type: "property",
84
+ id: "email"
85
+ }
86
+ }];
87
+ const {
88
+ result
89
+ } = renderHook(() => useObjectTableData(mockObjectSet, columnDefinitions), {
90
+ wrapper
91
+ });
92
+ const mockResult = result.current;
93
+ expect(mockResult._testOptions.withProperties).toEqual({});
94
+ expect(mockResult._testOptions.pageSize).toBe(50);
95
+ });
96
+ it("extracts RDP creators and passes them to useObjectSet", () => {
97
+ const mockRdpCreator1 = vi.fn();
98
+ const mockRdpCreator2 = vi.fn();
99
+ const columnDefinitions = [{
100
+ locator: {
101
+ type: "property",
102
+ id: "name"
103
+ }
104
+ }, {
105
+ locator: {
106
+ type: "rdp",
107
+ id: "rdp1",
108
+ creator: mockRdpCreator1
109
+ }
110
+ }, {
111
+ locator: {
112
+ type: "rdp",
113
+ id: "rdp2",
114
+ creator: mockRdpCreator2
115
+ }
116
+ }, {
117
+ locator: {
118
+ type: "function",
119
+ id: "myFunction"
120
+ }
121
+ }];
122
+ const {
123
+ result
124
+ } = renderHook(() => useObjectTableData(mockObjectSet, columnDefinitions), {
125
+ wrapper
126
+ });
127
+ const mockResult = result.current;
128
+ expect(mockResult._testOptions.withProperties).toEqual({
129
+ rdp1: mockRdpCreator1,
130
+ rdp2: mockRdpCreator2
131
+ });
132
+ });
133
+ it("memoizes withProperties based on columnDefinitions", () => {
134
+ const mockRdpCreator = vi.fn();
135
+ const columnDefinitions = [{
136
+ locator: {
137
+ type: "rdp",
138
+ id: "myRdp",
139
+ creator: mockRdpCreator
140
+ }
141
+ }];
142
+ const {
143
+ result,
144
+ rerender
145
+ } = renderHook(({
146
+ colDefs
147
+ }) => useObjectTableData(mockObjectSet, colDefs), {
148
+ initialProps: {
149
+ colDefs: columnDefinitions
150
+ },
151
+ wrapper
152
+ });
153
+ const firstMockResult = result.current;
154
+ const firstWithProperties = firstMockResult._testOptions.withProperties;
155
+
156
+ // Rerender with same columnDefinitions reference
157
+ rerender({
158
+ colDefs: columnDefinitions
159
+ });
160
+
161
+ // Should be the same reference (memoized)
162
+ const secondMockResult = result.current;
163
+ expect(secondMockResult._testOptions.withProperties).toBe(firstWithProperties);
164
+ });
165
+ it("updates withProperties when columnDefinitions change", () => {
166
+ const mockRdpCreator1 = vi.fn();
167
+ const mockRdpCreator2 = vi.fn();
168
+ const {
169
+ result,
170
+ rerender
171
+ } = renderHook(({
172
+ colDefs
173
+ }) => useObjectTableData(mockObjectSet, colDefs), {
174
+ initialProps: {
175
+ colDefs: [{
176
+ locator: {
177
+ type: "rdp",
178
+ id: "rdp1",
179
+ creator: mockRdpCreator1
180
+ }
181
+ }]
182
+ },
183
+ wrapper
184
+ });
185
+ const firstMockResult = result.current;
186
+ expect(firstMockResult._testOptions.withProperties).toEqual({
187
+ rdp1: mockRdpCreator1
188
+ });
189
+ rerender({
190
+ colDefs: [{
191
+ locator: {
192
+ type: "rdp",
193
+ id: "rdp2",
194
+ creator: mockRdpCreator2
195
+ }
196
+ }]
197
+ });
198
+ const secondMockResult = result.current;
199
+ expect(secondMockResult._testOptions.withProperties).toEqual({
200
+ rdp2: mockRdpCreator2
201
+ });
202
+ });
203
+ it("returns useObjectSet result structure", () => {
204
+ const {
205
+ result
206
+ } = renderHook(() => useObjectTableData(mockObjectSet), {
207
+ wrapper
208
+ });
209
+ expect(result.current).toHaveProperty("data");
210
+ expect(result.current).toHaveProperty("isLoading");
211
+ expect(result.current).toHaveProperty("error");
212
+ expect(result.current).toHaveProperty("fetchNextPage");
213
+ expect(result.current).toHaveProperty("hasNextPage");
214
+ expect(result.current).toHaveProperty("isFetchingNextPage");
215
+ });
216
+ });
217
+ //# sourceMappingURL=useObjectTableData.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useObjectTableData.test.js","names":["OsdkProvider","renderHook","React","describe","expect","it","vi","useObjectTableData","mock","useObjectSet","fn","objectSet","options","data","isLoading","error","undefined","fetchNextPage","hasNextPage","isFetchingNextPage","_testOptions","TestObjectType","type","apiName","mockObjectSet","objectType","wrapper","client","children","createElement","result","mockResult","current","toEqual","withProperties","pageSize","toBeUndefined","toBe","columnDefinitions","locator","id","mockRdpCreator1","mockRdpCreator2","creator","rdp1","rdp2","mockRdpCreator","rerender","colDefs","initialProps","firstMockResult","firstWithProperties","secondMockResult","toHaveProperty"],"sources":["useObjectTableData.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 {\n DerivedProperty,\n ObjectSet,\n ObjectTypeDefinition,\n PropertyKeys,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport type { Client } from \"@osdk/client\";\nimport { OsdkProvider } from \"@osdk/react\";\nimport { renderHook } from \"@testing-library/react\";\nimport * as React from \"react\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport type { ColumnDefinition } from \"../../ObjectTableApi.js\";\nimport { useObjectTableData } from \"../useObjectTableData.js\";\n\ninterface MockUseObjectSetReturn {\n data: [];\n isLoading: false;\n error: undefined;\n fetchNextPage: ReturnType<typeof vi.fn>;\n hasNextPage: false;\n isFetchingNextPage: false;\n _testOptions: {\n withProperties?: Record<string, unknown>;\n pageSize: number;\n };\n}\n\nvi.mock(\"@osdk/react/experimental\", () => ({\n useObjectSet: vi.fn((objectSet, options): MockUseObjectSetReturn => {\n return {\n data: [],\n isLoading: false,\n error: undefined,\n fetchNextPage: vi.fn(),\n hasNextPage: false,\n isFetchingNextPage: false,\n // Return the options to verify they were passed correctly\n _testOptions: options,\n };\n }),\n}));\n\nconst TestObjectType = {\n type: \"object\",\n apiName: \"TestObject\",\n} as const satisfies ObjectTypeDefinition;\n\ntype TestObject = typeof TestObjectType;\ntype TestObjectKeys = PropertyKeys<TestObject>;\n\nconst mockObjectSet = {\n objectType: TestObjectType,\n} as unknown as ObjectSet<TestObject>;\n\ndescribe(useObjectTableData, () => {\n const createWrapper = (client: Client) => {\n return ({ children }: React.PropsWithChildren) => {\n return <OsdkProvider client={client}>{children}</OsdkProvider>;\n };\n };\n\n const fakeClient = {} as unknown as Client;\n const wrapper = createWrapper(fakeClient);\n\n it(\"calls useObjectSet with pageSize of 50\", () => {\n const { result } = renderHook(\n () => useObjectTableData(mockObjectSet),\n { wrapper },\n );\n\n const mockResult = result.current as unknown as MockUseObjectSetReturn;\n expect(mockResult._testOptions).toEqual({\n withProperties: undefined,\n pageSize: 50,\n });\n });\n\n it(\"calls useObjectSet without withProperties when no columnDefinitions provided\", () => {\n const { result } = renderHook(\n () => useObjectTableData(mockObjectSet, undefined),\n { wrapper },\n );\n\n const mockResult = result.current as unknown as MockUseObjectSetReturn;\n expect(mockResult._testOptions.withProperties).toBeUndefined();\n expect(mockResult._testOptions.pageSize).toBe(50);\n });\n\n it(\"calls useObjectSet without withProperties when columnDefinitions have no RDP columns\", () => {\n const columnDefinitions: Array<ColumnDefinition<TestObject, {}, {}>> = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n },\n {\n locator: { type: \"property\", id: \"email\" as TestObjectKeys },\n },\n ];\n\n const { result } = renderHook(\n () => useObjectTableData(mockObjectSet, columnDefinitions),\n { wrapper },\n );\n\n const mockResult = result.current as unknown as MockUseObjectSetReturn;\n expect(mockResult._testOptions.withProperties).toEqual({});\n expect(mockResult._testOptions.pageSize).toBe(50);\n });\n\n it(\"extracts RDP creators and passes them to useObjectSet\", () => {\n const mockRdpCreator1 = vi.fn() as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n const mockRdpCreator2 = vi.fn() as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n\n const columnDefinitions: Array<\n ColumnDefinition<\n TestObject,\n { rdp1: any; rdp2: any },\n { myFunction: any }\n >\n > = [\n {\n locator: { type: \"property\", id: \"name\" as TestObjectKeys },\n },\n {\n locator: { type: \"rdp\", id: \"rdp1\", creator: mockRdpCreator1 },\n },\n {\n locator: { type: \"rdp\", id: \"rdp2\", creator: mockRdpCreator2 },\n },\n {\n locator: { type: \"function\", id: \"myFunction\" },\n },\n ];\n\n const { result } = renderHook(\n () => useObjectTableData(mockObjectSet, columnDefinitions),\n { wrapper },\n );\n\n const mockResult = result.current as unknown as MockUseObjectSetReturn;\n expect(mockResult._testOptions.withProperties).toEqual({\n rdp1: mockRdpCreator1,\n rdp2: mockRdpCreator2,\n });\n });\n\n it(\"memoizes withProperties based on columnDefinitions\", () => {\n const mockRdpCreator = vi.fn() as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n\n const columnDefinitions: Array<\n ColumnDefinition<TestObject, { myRdp: any }, {}>\n > = [\n {\n locator: { type: \"rdp\", id: \"myRdp\", creator: mockRdpCreator },\n },\n ];\n\n const { result, rerender } = renderHook(\n ({ colDefs }) => useObjectTableData(mockObjectSet, colDefs),\n {\n initialProps: { colDefs: columnDefinitions },\n wrapper,\n },\n );\n\n const firstMockResult = result.current as unknown as MockUseObjectSetReturn;\n const firstWithProperties = firstMockResult._testOptions.withProperties;\n\n // Rerender with same columnDefinitions reference\n rerender({ colDefs: columnDefinitions });\n\n // Should be the same reference (memoized)\n const secondMockResult = result\n .current as unknown as MockUseObjectSetReturn;\n expect(secondMockResult._testOptions.withProperties).toBe(\n firstWithProperties,\n );\n });\n\n it(\"updates withProperties when columnDefinitions change\", () => {\n const mockRdpCreator1 = vi.fn() as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n const mockRdpCreator2 = vi.fn() as unknown as DerivedProperty.Creator<\n TestObject,\n SimplePropertyDef\n >;\n\n const initialColumnDefinitions: Array<\n ColumnDefinition<TestObject, { rdp1: any }, {}>\n > = [\n {\n locator: { type: \"rdp\", id: \"rdp1\", creator: mockRdpCreator1 },\n },\n ];\n\n type ColDefs =\n | Array<\n ColumnDefinition<TestObject, Record<string, SimplePropertyDef>, {}>\n >\n | undefined;\n\n const { result, rerender } = renderHook(\n ({ colDefs }: { colDefs: ColDefs }) =>\n useObjectTableData(mockObjectSet, colDefs),\n {\n initialProps: { colDefs: initialColumnDefinitions as ColDefs },\n wrapper,\n },\n );\n\n const firstMockResult = result.current as unknown as MockUseObjectSetReturn;\n expect(firstMockResult._testOptions.withProperties).toEqual({\n rdp1: mockRdpCreator1,\n });\n\n const updatedColumnDefinitions: Array<\n ColumnDefinition<TestObject, { rdp2: SimplePropertyDef }, {}>\n > = [\n {\n locator: { type: \"rdp\", id: \"rdp2\", creator: mockRdpCreator2 },\n },\n ];\n\n rerender({ colDefs: updatedColumnDefinitions as ColDefs });\n\n const secondMockResult = result\n .current as unknown as MockUseObjectSetReturn;\n expect(secondMockResult._testOptions.withProperties).toEqual({\n rdp2: mockRdpCreator2,\n });\n });\n\n it(\"returns useObjectSet result structure\", () => {\n const { result } = renderHook(\n () => useObjectTableData(mockObjectSet),\n { wrapper },\n );\n\n expect(result.current).toHaveProperty(\"data\");\n expect(result.current).toHaveProperty(\"isLoading\");\n expect(result.current).toHaveProperty(\"error\");\n expect(result.current).toHaveProperty(\"fetchNextPage\");\n expect(result.current).toHaveProperty(\"hasNextPage\");\n expect(result.current).toHaveProperty(\"isFetchingNextPage\");\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,SAASA,YAAY,QAAQ,aAAa;AAC1C,SAASC,UAAU,QAAQ,wBAAwB;AACnD,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AAEjD,SAASC,kBAAkB,QAAQ,0BAA0B;AAe7DD,EAAE,CAACE,IAAI,CAAC,0BAA0B,EAAE,OAAO;EACzCC,YAAY,EAAEH,EAAE,CAACI,EAAE,CAAC,CAACC,SAAS,EAAEC,OAAO,KAA6B;IAClE,OAAO;MACLC,IAAI,EAAE,EAAE;MACRC,SAAS,EAAE,KAAK;MAChBC,KAAK,EAAEC,SAAS;MAChBC,aAAa,EAAEX,EAAE,CAACI,EAAE,CAAC,CAAC;MACtBQ,WAAW,EAAE,KAAK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AO,CAAC,CAACqB,cAAc,CAAC,MAAM,CAAC;IAC7CjD,MAAM,CAAC0B,MAAM,CAACE,OAAO,CAAC,CAACqB,cAAc,CAAC,WAAW,CAAC;IAClDjD,MAAM,CAAC0B,MAAM,CAACE,OAAO,CAAC,CAACqB,cAAc,CAAC,OAAO,CAAC;IAC9CjD,MAAM,CAAC0B,MAAM,CAACE,OAAO,CAAC,CAACqB,cAAc,CAAC,eAAe,CAAC;IACtDjD,MAAM,CAAC0B,MAAM,CAACE,OAAO,CAAC,CAACqB,cAAc,CAAC,aAAa,CAAC;IACpDjD,MAAM,CAAC0B,MAAM,CAACE,OAAO,CAAC,CAACqB,cAAc,CAAC,oBAAoB,CAAC;EAC7D,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,87 @@
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 { useOsdkMetadata } from "@osdk/react";
18
+ import { useMemo } from "react";
19
+ /**
20
+ * Hook which builds column definitions for tanstack-table given the objectSet
21
+ */
22
+ export function useColumnDefs(objectType, columnDefinitions) {
23
+ const {
24
+ metadata,
25
+ loading,
26
+ error
27
+ } = useOsdkMetadata(objectType);
28
+ const columns = useMemo(() => {
29
+ const objectProperties = metadata?.properties;
30
+ // If columnDefinitions is provided, construct colDefs with it
31
+ if (columnDefinitions) {
32
+ return getColumnsFromColumnDefinitions(columnDefinitions, objectProperties);
33
+ }
34
+
35
+ // If not, return the default columns from the object properties
36
+ return getDefaultColumns(objectProperties);
37
+ }, [columnDefinitions, metadata?.properties]);
38
+ return {
39
+ columns,
40
+ loading,
41
+ error
42
+ };
43
+ }
44
+ function getColumnsFromColumnDefinitions(columnDefinitions, objectProperties) {
45
+ return columnDefinitions.map(col => {
46
+ const {
47
+ locator,
48
+ width,
49
+ minWidth,
50
+ maxWidth,
51
+ resizable,
52
+ orderable,
53
+ filterable,
54
+ renderCell,
55
+ renderHeader
56
+ } = col;
57
+ const propertyMetadata = locator.type === "property" ? objectProperties?.[locator.id] : undefined;
58
+ const colKey = locator.id;
59
+ const colDef = {
60
+ id: colKey,
61
+ accessorKey: colKey,
62
+ header: renderHeader ?? propertyMetadata?.displayName,
63
+ size: width,
64
+ minSize: minWidth,
65
+ maxSize: maxWidth,
66
+ enableResizing: resizable,
67
+ enableSorting: orderable,
68
+ enableColumnFilter: filterable,
69
+ cell: cellContext => {
70
+ const object = cellContext.row.original;
71
+ return renderCell ? renderCell(object, locator) : cellContext.getValue();
72
+ }
73
+ };
74
+ return colDef;
75
+ });
76
+ }
77
+ function getDefaultColumns(objectProperties) {
78
+ if (!objectProperties) return [];
79
+ return Object.entries(objectProperties).map(([key, property]) => {
80
+ const colDef = {
81
+ accessorKey: key,
82
+ header: property.displayName ?? key
83
+ };
84
+ return colDef;
85
+ });
86
+ }
87
+ //# sourceMappingURL=useColumnDefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useColumnDefs.js","names":["useOsdkMetadata","useMemo","useColumnDefs","objectType","columnDefinitions","metadata","loading","error","columns","objectProperties","properties","getColumnsFromColumnDefinitions","getDefaultColumns","map","col","locator","width","minWidth","maxWidth","resizable","orderable","filterable","renderCell","renderHeader","propertyMetadata","type","id","undefined","colKey","colDef","accessorKey","header","displayName","size","minSize","maxSize","enableResizing","enableSorting","enableColumnFilter","cell","cellContext","object","row","original","getValue","Object","entries","key","property"],"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 ObjectTypeDefinition,\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\";\nimport type { ColumnDefinition } from \"../ObjectTableApi.js\";\n\ninterface UseColumnDefsResult<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\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 ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\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 = 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 ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\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 filterable,\n renderCell,\n renderHeader,\n } = col;\n\n const propertyMetadata = locator.type === \"property\"\n ? objectProperties?.[locator.id]\n : undefined;\n\n const colKey = locator.id as string;\n\n const colDef: AccessorColumnDef<\n Osdk.Instance<Q, \"$allBaseProperties\", PropertyKeys<Q>, RDPs>\n > = {\n id: colKey,\n accessorKey: colKey,\n header: renderHeader ?? propertyMetadata?.displayName,\n size: width,\n minSize: minWidth,\n maxSize: maxWidth,\n enableResizing: resizable,\n enableSorting: orderable,\n enableColumnFilter: filterable,\n cell: (cellContext) => {\n const object: Osdk.Instance<\n Q,\n \"$allBaseProperties\",\n PropertyKeys<Q>,\n RDPs\n > = cellContext.row.original;\n\n return renderCell\n ? renderCell(object, locator)\n : cellContext.getValue();\n },\n };\n\n return colDef;\n });\n}\n\nfunction getDefaultColumns<\n Q extends ObjectTypeDefinition,\n RDPs extends Record<string, SimplePropertyDef> = Record<\n string,\n never\n >,\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 accessorK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AAM;MACnBG,MAAM,EAAER,YAAY,IAAIC,gBAAgB,EAAEQ,WAAW;MACrDC,IAAI,EAAEjB,KAAK;MACXkB,OAAO,EAAEjB,QAAQ;MACjBkB,OAAO,EAAEjB,QAAQ;MACjBkB,cAAc,EAAEjB,SAAS;MACzBkB,aAAa,EAAEjB,SAAS;MACxBkB,kBAAkB,EAAEjB,UAAU;MAC9BkB,IAAI,EAAGC,WAAW,IAAK;QACrB,MAAMC,MAKL,GAAGD,WAAW,CAACE,GAAG,CAACC,QAAQ;QAE5B,OAAOrB,UAAU,GACbA,UAAU,CAACmB,MAAM,EAAE1B,OAAO,CAAC,GAC3ByB,WAAW,CAACI,QAAQ,CAAC,CAAC;MAC5B;IACF,CAAC;IAED,OAAOf,MAAM;EACf,CAAC,CAAC;AACJ;AAEA,SAASjB,iBAAiBA,CAOxBH,gBAAuD,EAKvD;EACA,IAAI,CAACA,gBAAgB,EAAE,OAAO,EAAE;EAEhC,OAAOoC,MAAM,CAACC,OAAO,CAACrC,gBAAgB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACkC,GAAG,EAAEC,QAAQ,CAAC,KAAK;IAC/D,MAAMnB,MAEL,GAAG;MACFC,WAAW,EAAEiB,GAAG;MAChBhB,MAAM,EAAEiB,QAAQ,CAAChB,WAAW,IAAIe;IAClC,CAAC;IACD,OAAOlB,MAAM;EACf,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,43 @@
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 { useMemo } from "react";
18
+ export const useDefaultTableStates = ({
19
+ columnDefinitions
20
+ }) => {
21
+ const columnVisibility = useMemo(() => {
22
+ if (columnDefinitions) {
23
+ const colVisibility = columnDefinitions.reduce((acc, colDef) => {
24
+ if (colDef.isVisible !== undefined) {
25
+ const {
26
+ locator
27
+ } = colDef;
28
+ const colKey = locator.id;
29
+ return {
30
+ ...acc,
31
+ [colKey]: colDef.isVisible
32
+ };
33
+ }
34
+ return acc;
35
+ }, {});
36
+ return colVisibility;
37
+ }
38
+ }, [columnDefinitions]);
39
+ return {
40
+ columnVisibility
41
+ };
42
+ };
43
+ //# sourceMappingURL=useDefaultTableStates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDefaultTableStates.js","names":["useMemo","useDefaultTableStates","columnDefinitions","columnVisibility","colVisibility","reduce","acc","colDef","isVisible","undefined","locator","colKey","id"],"sources":["useDefaultTableStates.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 UseDefaultTableStatesProps<\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\ninterface UseDefaultTableStatesResult {\n columnVisibility: VisibilityState | undefined;\n}\n\nexport const useDefaultTableStates = <\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 }: UseDefaultTableStatesProps<\n Q,\n RDPs,\n FunctionColumns\n >,\n): UseDefaultTableStatesResult => {\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\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;AAsB/B,OAAO,MAAMC,qBAAqB,GAAGA,CAQnC;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;UAE1B,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,OAAO;IAAEC;EAAiB,CAAC;AAC7B,CAAC","ignoreList":[]}
@@ -0,0 +1,48 @@
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 { useObjectSet } from "@osdk/react/experimental";
18
+ import { useMemo } from "react";
19
+ const PAGE_SIZE = 50;
20
+
21
+ /**
22
+ * This hook is a wrapper around useObjectSet
23
+ * It extracts RDP locators from columnDefinitions and calls useObjectSet + withProperties
24
+ * to return data containing the derived properties.
25
+ */
26
+
27
+ export function useObjectTableData(objectSet, columnDefinitions) {
28
+ // Extract derived properties definition to be passed to useObjectSet hook
29
+ const withProperties = useMemo(() => {
30
+ if (!columnDefinitions) {
31
+ return;
32
+ }
33
+ const rdpColumns = columnDefinitions.map(colDef => colDef.locator).filter(colLocator => {
34
+ return colLocator.type === "rdp";
35
+ });
36
+ return rdpColumns.reduce((acc, cur) => {
37
+ return {
38
+ ...acc,
39
+ [cur.id]: cur.creator
40
+ };
41
+ }, {});
42
+ }, [columnDefinitions]);
43
+ return useObjectSet(objectSet, {
44
+ withProperties,
45
+ pageSize: PAGE_SIZE
46
+ });
47
+ }
48
+ //# sourceMappingURL=useObjectTableData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useObjectTableData.js","names":["useObjectSet","useMemo","PAGE_SIZE","useObjectTableData","objectSet","columnDefinitions","withProperties","rdpColumns","map","colDef","locator","filter","colLocator","type","reduce","acc","cur","id","creator","pageSize"],"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 QueryDefinition,\n SimplePropertyDef,\n} from \"@osdk/api\";\nimport { useObjectSet } from \"@osdk/react/experimental\";\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): ReturnType<typeof useObjectSet<Q, never, RDPs>> {\n // Extract derived properties definition to be passed to useObjectSet hook\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 },\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA,SAASA,YAAY,QAAQ,0BAA0B;AACvD,SAASC,OAAO,QAAQ,OAAO;AAG/B,MAAMC,SAAS,GAAG,EAAE;;AAEpB;AACA;AACA;AACA;AACA;;AAEA,OAAO,SAASC,kBAAkBA,CAQhCC,SAAuB,EACvBC,iBAAqE,EACpB;EACjD;EACA,MAAMC,cAAc,GAAGL,OAAO,CAAC,MAAM;IACnC,IAAI,CAACI,iBAAiB,EAAE;MACtB;IACF;IAEA,MAAME,UAAU,GAAGF,iBAAiB,CAACG,GAAG,CAACC,MAAM,IAAIA,MAAM,CAACC,OAAO,CAAC,CAACC,MAAM,CACtEC,UAAU,IAAK;MACd,OAAOA,UAAU,CAACC,IAAI,KAAK,KAAK;IAClC,CACF,CAAC;IAED,OAAON,UAAU,CAACO,MAAM,CAGtB,CAACC,GAAG,EAAEC,GAAG,KAAK;MACZ,OAAO;QACL,GAAGD,GAAG;QACN,CAACC,GAAG,CAACC,EAAE,GAAGD,GAAG,CAACE;MAChB,CAAC;IACH,CAAC,EACD,CAAC,CAGH,CAAC;EACH,CAAC,EAAE,CAACb,iBAAiB,CAAC,CAAC;EAEvB,OAAOL,YAAY,CACjBI,SAAS,EACT;IACEE,cAAc;IACda,QAAQ,EAAEjB;EACZ,CACF,CAAC;AACH","ignoreList":[]}