@trackunit/iris-app 2.11.11 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +0 -17
- package/package.json +7 -7
- package/src/generators/preset/files/.agents/skills/browser-testing/SKILL.md +36 -174
- package/src/generators/preset/files/.agents/skills/create-app/SKILL.md +22 -180
- package/src/generators/preset/files/.agents/skills/customfields/SKILL.md +38 -140
- package/src/generators/preset/files/.agents/skills/databricks-unity-catalog/SKILL.md +43 -90
- package/src/generators/preset/files/.agents/skills/graphql/SKILL.md +25 -122
- package/src/generators/preset/files/.agents/skills/graphql-timeseries/SKILL.md +27 -142
- package/src/generators/preset/files/.agents/skills/irisx-app-sdk/SKILL.md +11 -88
- package/src/generators/preset/files/.agents/skills/react-core-hooks/SKILL.md +21 -157
- package/src/generators/preset/files/.agents/skills/set-up-react-map/SKILL.md +8 -18
- package/src/generators/preset/files/.agents/skills/tables-and-sorting/SKILL.md +63 -63
- package/src/generators/preset/files/.agents/skills/widget-extensions/SKILL.md +53 -180
|
@@ -3,143 +3,56 @@ name: react-core-hooks
|
|
|
3
3
|
description: Use when needing asset/site/customer runtime data, user context, navigation, toasts, or confirmation dialogs in IrisX Apps.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# React
|
|
6
|
+
# React core hooks
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Hooks from `@trackunit/react-core-hooks`. The IrisX App SDK sets up their providers for extensions.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## When to Use
|
|
13
|
-
|
|
14
|
-
- Accessing current asset/site/customer context
|
|
15
|
-
- Getting user information or preferences
|
|
16
|
-
- Navigating within Trackunit Manager
|
|
17
|
-
- Showing toasts or confirmation dialogs
|
|
18
|
-
- Managing widget configuration
|
|
19
|
-
|
|
20
|
-
## Runtime Hooks
|
|
21
|
-
|
|
22
|
-
### useAssetRuntime
|
|
23
|
-
|
|
24
|
-
Access asset information in asset-scoped extensions.
|
|
25
|
-
|
|
26
|
-
```typescript
|
|
27
|
-
const { assetInfo, loading, error } = useAssetRuntime();
|
|
28
|
-
// assetInfo.assetId, assetInfo.name, etc.
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
### useCustomerRuntime
|
|
32
|
-
|
|
33
|
-
Access customer information.
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
const { customerInfo, loading, error } = useCustomerRuntime();
|
|
37
|
-
// customerInfo.customerId, customerInfo.name, etc.
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### useEventRuntime
|
|
41
|
-
|
|
42
|
-
Access event information in event-scoped extensions.
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
const { eventInfo, loading, error } = useEventRuntime();
|
|
46
|
-
// eventInfo.eventId, eventInfo.type, etc.
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### useSiteRuntime
|
|
50
|
-
|
|
51
|
-
Access site information in site-scoped extensions.
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
const { siteInfo, loading, error } = useSiteRuntime();
|
|
55
|
-
// siteInfo.siteId, siteInfo.name, etc.
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### useIrisAppName
|
|
59
|
-
|
|
60
|
-
Get current app name.
|
|
10
|
+
## Runtime context
|
|
61
11
|
|
|
62
12
|
```typescript
|
|
13
|
+
const { assetInfo, loading, error } = useAssetRuntime(); // asset-scoped extensions: assetInfo.assetId, .name, …
|
|
14
|
+
const { siteInfo, loading, error } = useSiteRuntime(); // site-scoped extensions: siteInfo.siteId, .name, …
|
|
15
|
+
const { customerInfo, loading, error } = useCustomerRuntime(); // customerInfo.customerId, .name, …
|
|
16
|
+
const { eventInfo, loading, error } = useEventRuntime(); // event-scoped extensions: eventInfo.eventId, .type, …
|
|
63
17
|
const { appName, loading, error } = useIrisAppName();
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### useIrisAppId
|
|
67
|
-
|
|
68
|
-
Get current app ID.
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
18
|
const { irisAppId, loading, error } = useIrisAppId();
|
|
72
19
|
```
|
|
73
20
|
|
|
74
|
-
## Navigation
|
|
75
|
-
|
|
76
|
-
### useNavigateInHost
|
|
77
|
-
|
|
78
|
-
Navigate within Trackunit Manager.
|
|
21
|
+
## Navigation and access
|
|
79
22
|
|
|
80
23
|
```typescript
|
|
81
24
|
const { gotoAssetHome, gotoSiteHome } = useNavigateInHost();
|
|
82
25
|
gotoAssetHome(assetId);
|
|
83
|
-
gotoSiteHome(siteId);
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### useHasAccessTo
|
|
87
26
|
|
|
88
|
-
Check user access to pages or asset-scoped pages.
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
27
|
const hasAccess = useHasAccessTo({ page: "sites" });
|
|
92
28
|
const hasAssetAccess = useHasAccessTo({ assetId, page: "asset-home" });
|
|
93
29
|
```
|
|
94
30
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Access current user information. Returns flat properties directly.
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
const { email, name, accountId, userId } = useCurrentUser();
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### useCurrentUserLanguage
|
|
104
|
-
|
|
105
|
-
Get/set user language preference.
|
|
31
|
+
## User
|
|
106
32
|
|
|
107
33
|
```typescript
|
|
34
|
+
const { email, name, accountId, userId } = useCurrentUser(); // flat properties
|
|
108
35
|
const { language, setLanguage } = useCurrentUserLanguage();
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### useCurrentUserTimeZonePreference
|
|
112
|
-
|
|
113
|
-
Get/set user timezone preference.
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
36
|
const { timeZonePreference, setTimeZonePreference } = useCurrentUserTimeZonePreference();
|
|
37
|
+
const { token } = useToken();
|
|
117
38
|
```
|
|
118
39
|
|
|
119
|
-
|
|
40
|
+
## Dates and time zones
|
|
120
41
|
|
|
121
|
-
|
|
42
|
+
`timeZonePreference` is only the user's mode. For day boundaries and date labels, use `useDateAndTime` from `@trackunit/react-date-and-time-hooks`: it applies the user's Manager time zone. Don't use the browser's local time or `new Date("YYYY-MM-DD")`, which parses as UTC.
|
|
122
43
|
|
|
123
44
|
```typescript
|
|
124
|
-
const {
|
|
45
|
+
const { nowDate, startOf, subtract, formatDate } = useDateAndTime();
|
|
46
|
+
const today = startOf(nowDate, "day");
|
|
47
|
+
const from = subtract(today, 30, "days");
|
|
125
48
|
```
|
|
126
49
|
|
|
127
|
-
## UI
|
|
128
|
-
|
|
129
|
-
### useToast
|
|
130
|
-
|
|
131
|
-
Show toast notifications.
|
|
50
|
+
## UI
|
|
132
51
|
|
|
133
52
|
```typescript
|
|
134
53
|
const { addToast } = useToast();
|
|
135
54
|
addToast({ intent: "success", title: "Operation completed" });
|
|
136
|
-
```
|
|
137
55
|
|
|
138
|
-
### useConfirmationDialog
|
|
139
|
-
|
|
140
|
-
Show confirmation dialogs.
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
56
|
const { confirm } = useConfirmationDialog();
|
|
144
57
|
const confirmed = await confirm({
|
|
145
58
|
title: "Confirm Action",
|
|
@@ -148,68 +61,19 @@ const confirmed = await confirm({
|
|
|
148
61
|
primaryActionLabel: "Delete",
|
|
149
62
|
secondaryActionLabel: "Cancel"
|
|
150
63
|
});
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### useModalDialogContext
|
|
154
64
|
|
|
155
|
-
Manage modal dialogs.
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
65
|
const { openModal, closeModal } = useModalDialogContext();
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### useErrorHandler
|
|
162
|
-
|
|
163
|
-
Handle errors consistently.
|
|
164
66
|
|
|
165
|
-
```typescript
|
|
166
67
|
const { logError } = useErrorHandler();
|
|
167
68
|
logError(new Error("Something went wrong"));
|
|
168
69
|
```
|
|
169
70
|
|
|
170
|
-
## Data
|
|
171
|
-
|
|
172
|
-
### useAssetSorting
|
|
173
|
-
|
|
174
|
-
Asset sorting functionality.
|
|
175
|
-
|
|
176
|
-
```typescript
|
|
177
|
-
const { sortingState, setSortBy } = useAssetSorting();
|
|
178
|
-
// sortingState.sortBy, sortingState.order
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### useFilterBarContext
|
|
182
|
-
|
|
183
|
-
Filter bar state management. Provides domain-specific filter values.
|
|
71
|
+
## Data and state
|
|
184
72
|
|
|
185
73
|
```typescript
|
|
74
|
+
const { sortingState, setSortBy } = useAssetSorting(); // sortingState.sortBy, sortingState.order
|
|
186
75
|
const { assetsFilterBarValues, customersFilterBarValues } = useFilterBarContext();
|
|
76
|
+
const { timeRange, temporalPeriod } = useTimeRange(); // read-only
|
|
187
77
|
```
|
|
188
78
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
Time range context (read-only).
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
const { timeRange, temporalPeriod } = useTimeRange();
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## Widget Configuration
|
|
198
|
-
|
|
199
|
-
### useWidgetConfig
|
|
200
|
-
|
|
201
|
-
Access widget configuration, filters, time range, and edit mode state.
|
|
202
|
-
|
|
203
|
-
```typescript
|
|
204
|
-
const {
|
|
205
|
-
data, setData, dataVersion, loadingData,
|
|
206
|
-
title, setTitle,
|
|
207
|
-
filters, timeRange,
|
|
208
|
-
isEditMode, openEditMode, closeEditMode,
|
|
209
|
-
pollInterval, setLoadingState
|
|
210
|
-
} = useWidgetConfig();
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## Note
|
|
214
|
-
|
|
215
|
-
All hooks require their respective providers to be set up in your app's component tree. IrisX App SDK handles this automatically for extensions.
|
|
79
|
+
For `useWidgetConfig`, see the `widget-extensions` skill.
|
|
@@ -12,24 +12,18 @@ Use `@trackunit/react-map` with one Trackunit adapter. Do not use `google.maps`,
|
|
|
12
12
|
|
|
13
13
|
## Ensure a UI extension exists
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npx nx g @trackunit/iris-app:extend --name=<extension-name> --app=<app-name> --directory=<directory> --type=<extension-type>
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Do not choose an extension point without user confirmation.
|
|
15
|
+
The map needs a UI extension. If none exists, ask the user which extension point should contain it, then create one with the extension command in `AGENTS.md`. Never choose the extension point without their confirmation.
|
|
22
16
|
|
|
23
17
|
## Choose the provider
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
Ask which adapter to use unless the request names one:
|
|
26
20
|
|
|
27
|
-
- `@trackunit/react-map-adapter-google`: Google Maps
|
|
28
|
-
- `@trackunit/react-map-adapter-mapbox`:
|
|
21
|
+
- `@trackunit/react-map-adapter-google`: Google Maps, the provider Trackunit currently uses and supports. Use it when the user has no preference or asks for Trackunit's supported adapter.
|
|
22
|
+
- `@trackunit/react-map-adapter-mapbox`: only when the user selects Mapbox. Trackunit has no Mapbox access token, so the user must supply one.
|
|
29
23
|
|
|
30
24
|
## Install
|
|
31
25
|
|
|
32
|
-
Use
|
|
26
|
+
Use npm, and install only the selected adapter.
|
|
33
27
|
|
|
34
28
|
Google:
|
|
35
29
|
|
|
@@ -44,11 +38,7 @@ Mapbox:
|
|
|
44
38
|
npm install @trackunit/react-map @trackunit/react-map-adapter-mapbox
|
|
45
39
|
```
|
|
46
40
|
|
|
47
|
-
Then read the
|
|
48
|
-
|
|
49
|
-
- [`@trackunit/react-map` README](../../../node_modules/@trackunit/react-map/README.md)
|
|
50
|
-
- [`@trackunit/react-map-adapter-google` README](../../../node_modules/@trackunit/react-map-adapter-google/README.md)
|
|
51
|
-
- [`@trackunit/react-map-adapter-mapbox` README](../../../node_modules/@trackunit/react-map-adapter-mapbox/README.md)
|
|
41
|
+
Then read the current public API in `node_modules/@trackunit/react-map/README.md` and the installed adapter's README, `node_modules/@trackunit/react-map-adapter-google/README.md` or `node_modules/@trackunit/react-map-adapter-mapbox/README.md`.
|
|
52
42
|
|
|
53
43
|
## Configure CSP
|
|
54
44
|
|
|
@@ -84,7 +74,7 @@ If the manifest already declares the same directives, merge their arrays without
|
|
|
84
74
|
|
|
85
75
|
## Render the base map
|
|
86
76
|
|
|
87
|
-
|
|
77
|
+
Every map ancestor needs a resolved height. Scaffold the adapter with an empty credential, then ask the user for it once the scaffold is ready. Add a credential-management dependency only if the user asks for one, in a version compatible with the workspace.
|
|
88
78
|
|
|
89
79
|
Google:
|
|
90
80
|
|
|
@@ -117,7 +107,7 @@ return (
|
|
|
117
107
|
);
|
|
118
108
|
```
|
|
119
109
|
|
|
120
|
-
Import the Mapbox CSS once in the app entry
|
|
110
|
+
Import the Mapbox CSS once, in the app entry.
|
|
121
111
|
|
|
122
112
|
## Verify
|
|
123
113
|
|
|
@@ -3,68 +3,72 @@ name: tables-and-sorting
|
|
|
3
3
|
description: Use when building data tables with filtering, sorting, pagination, or displaying lists of assets, users, or other entities.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Tables with
|
|
6
|
+
# Tables with filtering and sorting
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Build tables with `@trackunit/react-table`, filters with `@trackunit/filters-filter-bar`, and server-side pagination with GraphQL. For simple lists without filtering, use standard components.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
- Implementing reporting interfaces with large datasets
|
|
18
|
-
|
|
19
|
-
**Not for:** Simple lists without filtering (use standard components).
|
|
20
|
-
|
|
21
|
-
## Required Imports
|
|
10
|
+
- Put the filter bar, sorting, query and columns in a hook next to the table component. The component calls the hook and renders `FilterBar` and `Table`.
|
|
11
|
+
- Wrap data transformations and column definitions in `useMemo`.
|
|
12
|
+
- Spread the filter bar's GraphQL variables into the query variables.
|
|
13
|
+
- Use `manualSorting: true` for server-side sorting of large data sets (over 1000 items).
|
|
14
|
+
- Keep filters, sorting, and the GraphQL query variables in sync, so a filter or sort change reaches the query.
|
|
15
|
+
- Render cells with Trackunit cell components (`TextCell`, `DateTimeCell`, `PlainDateCell`), not `getValue()`.
|
|
16
|
+
- Add `onRowClick` for navigation or a detail view.
|
|
22
17
|
|
|
23
18
|
```typescript
|
|
24
|
-
|
|
19
|
+
// useAssetTable.tsx
|
|
20
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
21
|
+
import { useTable } from '@trackunit/react-table';
|
|
25
22
|
import { TextCell, DateTimeCell } from '@trackunit/react-table-base-components';
|
|
26
|
-
import {
|
|
27
|
-
import { useAssetQueryFilters } from '@trackunit/filters-
|
|
23
|
+
import { useFilterBar } from '@trackunit/filters-filter-bar';
|
|
24
|
+
import { useAssetQueryFilters } from '@trackunit/filters-graphql-hook';
|
|
28
25
|
import { usePaginationQuery } from '@trackunit/react-graphql-hooks';
|
|
29
|
-
import { createColumnHelper, SortingState } from '@tanstack/react-table';
|
|
26
|
+
import { createColumnHelper, Row, SortingState } from '@tanstack/react-table';
|
|
30
27
|
import { useBrandFilter, useModelsFilter } from '@trackunit/filters-asset-filter-definitions';
|
|
31
|
-
|
|
28
|
+
import { useNavigateInHost } from '@trackunit/react-core-hooks';
|
|
29
|
+
import { AssetSortInput, GetAssetsDocument } from './generated/graphql-api/graphql';
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
type Asset = { id: string; name: string; createdAt: string };
|
|
31
|
+
type Asset = { id: string; assetId: string; name: string; createdAt: string };
|
|
37
32
|
const columnHelper = createColumnHelper<Asset>();
|
|
33
|
+
const sortProperties: Partial<Record<string, AssetSortInput["property"]>> = { name: "NAME" };
|
|
38
34
|
|
|
39
|
-
const
|
|
40
|
-
// Setup filters with proper naming
|
|
35
|
+
export const useAssetTable = () => {
|
|
41
36
|
const filterBar = useFilterBar({
|
|
42
37
|
name: "assetFilters",
|
|
43
|
-
filterBarDefinition: {
|
|
38
|
+
filterBarDefinition: {
|
|
44
39
|
brand: useBrandFilter(),
|
|
45
|
-
model: useModelsFilter()
|
|
40
|
+
model: useModelsFilter()
|
|
46
41
|
}
|
|
47
42
|
});
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
const filterVariables = useAssetQueryFilters(filterBar.filterBarConfig.values);
|
|
44
|
+
const { assetQueryVariables } = useAssetQueryFilters({ filters: filterBar.filterBarConfig.values });
|
|
51
45
|
|
|
52
|
-
|
|
53
|
-
const [sorting, setSorting] = useState<SortingState>([]);
|
|
46
|
+
const { gotoAssetHome } = useNavigateInHost();
|
|
47
|
+
const [sorting, setSorting] = useState<SortingState>([{ id: "name", desc: false }]);
|
|
48
|
+
const [sortColumn] = sorting;
|
|
49
|
+
const sortProperty = sortColumn ? sortProperties[sortColumn.id] : undefined;
|
|
50
|
+
const sort = sortColumn && sortProperty ? { property: sortProperty, order: sortColumn.desc ? "DESC" : "ASC" } as const : undefined;
|
|
54
51
|
|
|
55
|
-
// GraphQL query with filters
|
|
56
52
|
const { data, loading, pagination } = usePaginationQuery(GetAssetsDocument, {
|
|
57
|
-
variables: { first: 50
|
|
53
|
+
variables: { ...assetQueryVariables, sort, first: 50 },
|
|
58
54
|
pageSize: 50,
|
|
55
|
+
updateQuery: (previous, newData, { unionEdgesByNodeKey }) => ({
|
|
56
|
+
data: {
|
|
57
|
+
...newData,
|
|
58
|
+
assets: {
|
|
59
|
+
...newData.assets,
|
|
60
|
+
edges: unionEdgesByNodeKey("id", previous?.assets.edges, newData.assets.edges) ?? [],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
pageInfo: newData.assets.pageInfo,
|
|
64
|
+
}),
|
|
59
65
|
});
|
|
60
66
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
data?.assets.edges.map(edge => ({ ...edge.node, id: edge.node.id })) ?? [],
|
|
67
|
+
const assets = useMemo(() =>
|
|
68
|
+
data?.assets.edges.map(edge => ({ ...edge.node, id: edge.node.id })) ?? [],
|
|
64
69
|
[data]
|
|
65
70
|
);
|
|
66
71
|
|
|
67
|
-
// Define columns with proper cell components
|
|
68
72
|
const columns = useMemo(() => [
|
|
69
73
|
columnHelper.accessor('name', {
|
|
70
74
|
cell: ({ row: { original } }) => <TextCell content={original.name} />,
|
|
@@ -74,12 +78,11 @@ const AssetTable = () => {
|
|
|
74
78
|
columnHelper.accessor('createdAt', {
|
|
75
79
|
cell: ({ row: { original } }) => <DateTimeCell date={new Date(original.createdAt)} />,
|
|
76
80
|
header: "Created",
|
|
77
|
-
enableSorting:
|
|
81
|
+
enableSorting: false, // the assets query has no sort option for it
|
|
78
82
|
}),
|
|
79
83
|
], []);
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
const table = useTable({
|
|
85
|
+
const { table } = useTable({
|
|
83
86
|
data: assets,
|
|
84
87
|
columns,
|
|
85
88
|
enableSorting: true,
|
|
@@ -88,35 +91,32 @@ const AssetTable = () => {
|
|
|
88
91
|
onSortingChange: setSorting,
|
|
89
92
|
});
|
|
90
93
|
|
|
94
|
+
const onRowClick = useCallback((row: Row<Asset>) => gotoAssetHome(row.original.assetId), [gotoAssetHome]);
|
|
95
|
+
|
|
96
|
+
return { filterBar, table, loading, pagination, onRowClick };
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// AssetTable.tsx
|
|
102
|
+
import { Table } from '@trackunit/react-table';
|
|
103
|
+
import { FilterBar } from '@trackunit/filters-filter-bar';
|
|
104
|
+
import { useAssetTable } from './useAssetTable';
|
|
105
|
+
|
|
106
|
+
export const AssetTable = () => {
|
|
107
|
+
const { filterBar, table, loading, pagination, onRowClick } = useAssetTable();
|
|
108
|
+
|
|
91
109
|
return (
|
|
92
110
|
<>
|
|
93
111
|
<FilterBar {...filterBar} />
|
|
94
|
-
<Table
|
|
95
|
-
{...table}
|
|
96
|
-
loading={loading}
|
|
97
|
-
pagination={pagination}
|
|
98
|
-
onRowClick={(row) => navigateToAsset(row.original.id)}
|
|
99
|
-
/>
|
|
112
|
+
<Table {...table} loading={loading} onRowClick={onRowClick} pagination={pagination} />
|
|
100
113
|
</>
|
|
101
114
|
);
|
|
102
115
|
};
|
|
103
116
|
```
|
|
104
117
|
|
|
105
|
-
## Common
|
|
106
|
-
|
|
107
|
-
| Mistake | Fix |
|
|
108
|
-
|---------|-----|
|
|
109
|
-
| Missing `useMemo` for columns/data | Wrap in `useMemo` to prevent re-renders |
|
|
110
|
-
| `manualSorting: false` on large datasets | Use `manualSorting: true` for server-side sorting |
|
|
111
|
-
| Missing filter variables in query | Spread `filterVariables` into GraphQL variables |
|
|
112
|
-
| Using `getValue()` in cells | Use Trackunit cell components (`TextCell`, `DateTimeCell`) |
|
|
113
|
-
| No `onRowClick` handler | Add navigation or detail view on row click |
|
|
114
|
-
|
|
115
|
-
## Key Requirements
|
|
118
|
+
## Common mistakes
|
|
116
119
|
|
|
117
|
-
- **
|
|
118
|
-
- **
|
|
119
|
-
- **
|
|
120
|
-
- **Use Trackunit cell components** (`TextCell`, `DateTimeCell`, `PlainDateCell`) for consistency
|
|
121
|
-
- **Implement `onRowClick`** for navigation or detail views
|
|
122
|
-
- **Sync state properly** between filters, sorting, and GraphQL queries
|
|
120
|
+
- **Sorting rows in the browser on a server-paginated table.** It only orders the loaded rows. Pass the sorting state to the query's `sort` variable, and only enable sorting on columns the query can sort.
|
|
121
|
+
- **Passing `Asset.id` to navigation.** `id` is the global GraphQL ID. `gotoAssetHome` takes `assetId`, so select it in the query.
|
|
122
|
+
- **Loading every page to compute a fleet total.** Each page costs API budget (see `graphql-timeseries`). Use a field the API already aggregates. If there is none, say so in your report instead of looping over pages.
|