@balena/ui-shared-components 12.2.1-build-improve-rjst-typings-556eb04390faa8be7ac5c845763edd6bf0926b8e-1 → 12.2.1-build-renovate-virtua-48af6816917c550320373eae466a06c1e8f31c16-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.
|
@@ -112,33 +112,31 @@ const TableRenderer = ({ filtered, selected, properties, hasUpdateActions, check
|
|
|
112
112
|
onSort === null || onSort === void 0 ? void 0 : onSort(sortPref);
|
|
113
113
|
return sortPref;
|
|
114
114
|
}, [sort, model, columns, onSort]);
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
? (selectedTagColumns) => {
|
|
118
|
-
if (!(selectedTagColumns === null || selectedTagColumns === void 0 ? void 0 : selectedTagColumns.length)) {
|
|
119
|
-
setShowAddTagDialog(false);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const additionalColumns = selectedTagColumns.map((key, index) => {
|
|
123
|
-
return {
|
|
124
|
-
title: key,
|
|
125
|
-
label: `Tag: ${key}`,
|
|
126
|
-
key: `${TAG_COLUMN_PREFIX}${key}`,
|
|
127
|
-
selected: true,
|
|
128
|
-
type: 'predefined',
|
|
129
|
-
field: tagField,
|
|
130
|
-
sortable: pagination.serverSide
|
|
131
|
-
? `${tagField}(tag_key='${key}')/value`
|
|
132
|
-
: true,
|
|
133
|
-
index: index + 1 + columns.length,
|
|
134
|
-
priority: '',
|
|
135
|
-
render: tagKeyRender(key),
|
|
136
|
-
};
|
|
137
|
-
});
|
|
138
|
-
setColumns(columns.concat(additionalColumns));
|
|
115
|
+
const handleAddTagClose = (selectedTagColumns) => {
|
|
116
|
+
if (!(selectedTagColumns === null || selectedTagColumns === void 0 ? void 0 : selectedTagColumns.length)) {
|
|
139
117
|
setShowAddTagDialog(false);
|
|
118
|
+
return;
|
|
140
119
|
}
|
|
141
|
-
|
|
120
|
+
const additionalColumns = selectedTagColumns.map((key, index) => {
|
|
121
|
+
const field = rjstContext.tagField;
|
|
122
|
+
return {
|
|
123
|
+
title: key,
|
|
124
|
+
label: `Tag: ${key}`,
|
|
125
|
+
key: `${TAG_COLUMN_PREFIX}${key}`,
|
|
126
|
+
selected: true,
|
|
127
|
+
type: 'predefined',
|
|
128
|
+
field,
|
|
129
|
+
sortable: pagination.serverSide
|
|
130
|
+
? `${field}(tag_key='${key}')/value`
|
|
131
|
+
: true,
|
|
132
|
+
index: index + 1 + columns.length,
|
|
133
|
+
priority: '',
|
|
134
|
+
render: tagKeyRender(key),
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
setColumns(columns.concat(additionalColumns));
|
|
138
|
+
setShowAddTagDialog(false);
|
|
139
|
+
};
|
|
142
140
|
useEffect(() => {
|
|
143
141
|
var _a;
|
|
144
142
|
(_a = analytics.webTracker) === null || _a === void 0 ? void 0 : _a.track('View table - columns', {
|
|
@@ -168,7 +166,7 @@ const TableRenderer = ({ filtered, selected, properties, hasUpdateActions, check
|
|
|
168
166
|
(_a = analytics.webTracker) === null || _a === void 0 ? void 0 : _a.track('Open manage columns', {
|
|
169
167
|
resource: model.resource,
|
|
170
168
|
});
|
|
171
|
-
} })), showAddTagDialog && (tagKeys === null || tagKeys === void 0 ? void 0 : tagKeys.length) &&
|
|
169
|
+
} })), showAddTagDialog && (tagKeys === null || tagKeys === void 0 ? void 0 : tagKeys.length) && (_jsx(AddTagHandler, { columns: columns, tagKeys: tagKeys, onClose: handleAddTagClose }))] }));
|
|
172
170
|
};
|
|
173
171
|
export const table = {
|
|
174
172
|
slug: 'table',
|
|
@@ -3,7 +3,7 @@ export type Order = 'asc' | 'desc';
|
|
|
3
3
|
export type CheckedState = 'none' | 'some' | 'all';
|
|
4
4
|
export interface TableSortOptions<T> {
|
|
5
5
|
direction: Order;
|
|
6
|
-
field:
|
|
6
|
+
field: string;
|
|
7
7
|
key: string;
|
|
8
8
|
sortable: RJSTEntityPropertyDefinition<T>['sortable'];
|
|
9
9
|
refScheme?: string;
|
|
@@ -9,7 +9,7 @@ import { Tags } from './Actions/Tags';
|
|
|
9
9
|
import { Update } from './Actions/Update';
|
|
10
10
|
import { Create } from './Actions/Create';
|
|
11
11
|
import { rjstDefaultPermissions, rjstGetModelForCollection, rjstRunTransformers, } from './models/helpers';
|
|
12
|
-
import { rjstGetDisabledReason, getFromLocalStorage, getTagsDisabledReason, setToLocalStorage, getSortingFunction, DEFAULT_ITEMS_PER_PAGE, } from './utils';
|
|
12
|
+
import { rjstGetDisabledReason, getFromLocalStorage, getTagsDisabledReason, setToLocalStorage, getSelected, getSortingFunction, DEFAULT_ITEMS_PER_PAGE, } from './utils';
|
|
13
13
|
import { getLenses } from './Lenses';
|
|
14
14
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
15
15
|
import pickBy from 'lodash/pickBy';
|
|
@@ -311,19 +311,12 @@ const hasPropertyEnabled = (value, propertyKey) => {
|
|
|
311
311
|
: false;
|
|
312
312
|
};
|
|
313
313
|
const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, priorities, formats, }) => {
|
|
314
|
-
var _a
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
secondary: new Set((_b = priorities === null || priorities === void 0 ? void 0 : priorities.secondary) !== null && _b !== void 0 ? _b : []),
|
|
318
|
-
};
|
|
319
|
-
return Object.entries((_c = schema.properties) !== null && _c !== void 0 ? _c : {})
|
|
320
|
-
.filter((entry) => {
|
|
321
|
-
const [_key, val] = entry;
|
|
322
|
-
return isJSONSchema(val);
|
|
323
|
-
})
|
|
314
|
+
var _a;
|
|
315
|
+
return Object.entries((_a = schema.properties) !== null && _a !== void 0 ? _a : {})
|
|
316
|
+
.filter(([_keyBy, val]) => isJSONSchema(val))
|
|
324
317
|
.flatMap(([key, val]) => {
|
|
325
318
|
const refScheme = getPropertyScheme(val);
|
|
326
|
-
if (!refScheme || refScheme.length <= 1) {
|
|
319
|
+
if (!refScheme || refScheme.length <= 1 || typeof val !== 'object') {
|
|
327
320
|
return [[key, val]];
|
|
328
321
|
}
|
|
329
322
|
const entityFilterOnly = parseDescriptionProperty(val, 'x-filter-only');
|
|
@@ -345,11 +338,15 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
|
|
|
345
338
|
})
|
|
346
339
|
.map(([key, val], index) => {
|
|
347
340
|
var _a;
|
|
341
|
+
if (typeof val !== 'object') {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
348
344
|
const xNoSort = parseDescriptionProperty(val, 'x-no-sort');
|
|
345
|
+
const definedPriorities = priorities !== null && priorities !== void 0 ? priorities : {};
|
|
349
346
|
const refScheme = getPropertyScheme(val);
|
|
350
|
-
const priority =
|
|
347
|
+
const priority = definedPriorities.primary.find((prioritizedKey) => prioritizedKey === key)
|
|
351
348
|
? 'primary'
|
|
352
|
-
:
|
|
349
|
+
: definedPriorities.secondary.find((prioritizedKey) => prioritizedKey === key)
|
|
353
350
|
? 'secondary'
|
|
354
351
|
: 'tertiary';
|
|
355
352
|
const widgetSchema = Object.assign(Object.assign({}, val), { title: undefined });
|
|
@@ -372,7 +369,7 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
|
|
|
372
369
|
}
|
|
373
370
|
return Object.assign(Object.assign({}, getTitleAndLabel(t, val, key, refScheme === null || refScheme === void 0 ? void 0 : refScheme[0])), { field: key,
|
|
374
371
|
// This is used for storing columns and views
|
|
375
|
-
key: refScheme ? `${key}_${refScheme[0]}_${index}` : `${key}_${index}`, selected:
|
|
372
|
+
key: refScheme ? `${key}_${refScheme[0]}_${index}` : `${key}_${index}`, selected: getSelected(key, priorities), priority, type: 'predefined', refScheme: refScheme === null || refScheme === void 0 ? void 0 : refScheme[0], index, sortable: xNoSort || val.format === 'tag'
|
|
376
373
|
? false
|
|
377
374
|
: typeof fieldCustomSort === 'function'
|
|
378
375
|
? fieldCustomSort
|
|
@@ -380,5 +377,6 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
|
|
|
380
377
|
const calculatedField = rjstAdaptRefScheme(fieldVal, val);
|
|
381
378
|
return (_jsx(Widget, { extraFormats: [...(formats !== null && formats !== void 0 ? formats : []), ...defaultFormats], schema: widgetSchema, value: calculatedField, extraContext: entry }));
|
|
382
379
|
} });
|
|
383
|
-
})
|
|
380
|
+
})
|
|
381
|
+
.filter((columnDef) => !!columnDef);
|
|
384
382
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RJSTBaseResource, Permissions, RJSTTagsSdk } from './schemaOps';
|
|
1
|
+
import type { RJSTBaseResource, Permissions, Priorities, RJSTTagsSdk } from './schemaOps';
|
|
2
2
|
import type { JSONSchema7 as JSONSchema } from 'json-schema';
|
|
3
3
|
import type { CheckedState } from './components/Table/utils';
|
|
4
4
|
import type { TFunction } from '../../hooks/useTranslations';
|
|
@@ -12,3 +12,4 @@ export declare const getTagsDisabledReason: <T extends RJSTBaseResource<T>>(sele
|
|
|
12
12
|
export declare const getCreateDisabledReason: <T extends RJSTBaseResource<T>>(permissions: Permissions<T>, hasOngoingAction: boolean, t: TFunction) => string | undefined;
|
|
13
13
|
export declare const rjstGetDisabledReason: <T extends RJSTBaseResource<T>>(selected: T[] | undefined, checkedState: CheckedState | undefined, hasOngoingAction: boolean, actionType: "update" | "delete" | null, t: TFunction) => string | undefined;
|
|
14
14
|
export declare const getSortingFunction: <T>(schemaKey: keyof T, schemaValue: JSONSchema) => (a: T, b: T) => number;
|
|
15
|
+
export declare const getSelected: <T, K extends keyof T>(key: K, priorities?: Priorities<T>) => boolean;
|
|
@@ -133,3 +133,9 @@ export const getSortingFunction = (schemaKey, schemaValue) => {
|
|
|
133
133
|
}
|
|
134
134
|
return (a, b) => diff(a[schemaKey], b[schemaKey]);
|
|
135
135
|
};
|
|
136
|
+
export const getSelected = (key, priorities) => {
|
|
137
|
+
if (!priorities) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
return priorities.primary.includes(key) || priorities.secondary.includes(key);
|
|
141
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balena/ui-shared-components",
|
|
3
|
-
"version": "12.2.1-build-
|
|
3
|
+
"version": "12.2.1-build-renovate-virtua-48af6816917c550320373eae466a06c1e8f31c16-1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"rimraf": "^6.0.0",
|
|
51
51
|
"ts-jest": "^29.2.5",
|
|
52
52
|
"typescript": "^5.8.2",
|
|
53
|
-
"virtua": "^0.
|
|
53
|
+
"virtua": "^0.40.0",
|
|
54
54
|
"zxcvbn": "^4.4.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@balena/lint": "^9.
|
|
57
|
+
"@balena/lint": "^9.2.1",
|
|
58
58
|
"@storybook/addon-essentials": "^8.6.12",
|
|
59
59
|
"@storybook/addon-interactions": "^8.6.12",
|
|
60
60
|
"@storybook/addon-links": "^8.6.12",
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"test": "jest",
|
|
90
90
|
"prepack": "npm run build",
|
|
91
91
|
"lint": "balena-lint src",
|
|
92
|
-
"lint
|
|
92
|
+
"lint:fix": "balena-lint --fix src",
|
|
93
93
|
"prepare": "husky",
|
|
94
94
|
"storybook": "storybook dev -p 6006",
|
|
95
95
|
"build-storybook": "storybook build --docs",
|
|
@@ -138,6 +138,6 @@
|
|
|
138
138
|
},
|
|
139
139
|
"homepage": "https://github.com/balena-io/ui-shared-components#readme",
|
|
140
140
|
"versionist": {
|
|
141
|
-
"publishedAt": "2025-04-15T14:
|
|
141
|
+
"publishedAt": "2025-04-15T14:58:46.414Z"
|
|
142
142
|
}
|
|
143
143
|
}
|