@balena/ui-shared-components 12.2.0-build-add-manage-columns-tracking-57187862023acb4b29b7aad932ba7521b790a439-1 → 12.2.1-build-improve-rjst-typings-556eb04390faa8be7ac5c845763edd6bf0926b8e-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,31 +112,33 @@ 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 handleAddTagClose = (selectedTagColumns) => {
116
- if (!(selectedTagColumns === null || selectedTagColumns === void 0 ? void 0 : selectedTagColumns.length)) {
115
+ const { tagField } = rjstContext;
116
+ const handleAddTagClose = tagField != null
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));
117
139
  setShowAddTagDialog(false);
118
- return;
119
140
  }
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
- };
141
+ : undefined;
140
142
  useEffect(() => {
141
143
  var _a;
142
144
  (_a = analytics.webTracker) === null || _a === void 0 ? void 0 : _a.track('View table - columns', {
@@ -166,7 +168,7 @@ const TableRenderer = ({ filtered, selected, properties, hasUpdateActions, check
166
168
  (_a = analytics.webTracker) === null || _a === void 0 ? void 0 : _a.track('Open manage columns', {
167
169
  resource: model.resource,
168
170
  });
169
- } })), showAddTagDialog && (tagKeys === null || tagKeys === void 0 ? void 0 : tagKeys.length) && (_jsx(AddTagHandler, { columns: columns, tagKeys: tagKeys, onClose: handleAddTagClose }))] }));
171
+ } })), showAddTagDialog && (tagKeys === null || tagKeys === void 0 ? void 0 : tagKeys.length) && handleAddTagClose != null && (_jsx(AddTagHandler, { columns: columns, tagKeys: tagKeys, onClose: handleAddTagClose }))] }));
170
172
  };
171
173
  export const table = {
172
174
  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: string;
6
+ field: Extract<keyof T, 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, getSelected, getSortingFunction, DEFAULT_ITEMS_PER_PAGE, } from './utils';
12
+ import { rjstGetDisabledReason, getFromLocalStorage, getTagsDisabledReason, setToLocalStorage, 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,12 +311,19 @@ const hasPropertyEnabled = (value, propertyKey) => {
311
311
  : false;
312
312
  };
313
313
  const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, priorities, formats, }) => {
314
- var _a;
315
- return Object.entries((_a = schema.properties) !== null && _a !== void 0 ? _a : {})
316
- .filter(([_keyBy, val]) => isJSONSchema(val))
314
+ var _a, _b, _c;
315
+ const prioritySets = {
316
+ primary: new Set((_a = priorities === null || priorities === void 0 ? void 0 : priorities.primary) !== null && _a !== void 0 ? _a : []),
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
+ })
317
324
  .flatMap(([key, val]) => {
318
325
  const refScheme = getPropertyScheme(val);
319
- if (!refScheme || refScheme.length <= 1 || typeof val !== 'object') {
326
+ if (!refScheme || refScheme.length <= 1) {
320
327
  return [[key, val]];
321
328
  }
322
329
  const entityFilterOnly = parseDescriptionProperty(val, 'x-filter-only');
@@ -338,15 +345,11 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
338
345
  })
339
346
  .map(([key, val], index) => {
340
347
  var _a;
341
- if (typeof val !== 'object') {
342
- return;
343
- }
344
348
  const xNoSort = parseDescriptionProperty(val, 'x-no-sort');
345
- const definedPriorities = priorities !== null && priorities !== void 0 ? priorities : {};
346
349
  const refScheme = getPropertyScheme(val);
347
- const priority = definedPriorities.primary.find((prioritizedKey) => prioritizedKey === key)
350
+ const priority = prioritySets.primary.has(key)
348
351
  ? 'primary'
349
- : definedPriorities.secondary.find((prioritizedKey) => prioritizedKey === key)
352
+ : prioritySets.secondary.has(key)
350
353
  ? 'secondary'
351
354
  : 'tertiary';
352
355
  const widgetSchema = Object.assign(Object.assign({}, val), { title: undefined });
@@ -369,7 +372,7 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
369
372
  }
370
373
  return Object.assign(Object.assign({}, getTitleAndLabel(t, val, key, refScheme === null || refScheme === void 0 ? void 0 : refScheme[0])), { field: key,
371
374
  // This is used for storing columns and views
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'
375
+ key: refScheme ? `${key}_${refScheme[0]}_${index}` : `${key}_${index}`, selected: !priorities || priority === 'primary' || priority === 'secondary', priority, type: 'predefined', refScheme: refScheme === null || refScheme === void 0 ? void 0 : refScheme[0], index, sortable: xNoSort || val.format === 'tag'
373
376
  ? false
374
377
  : typeof fieldCustomSort === 'function'
375
378
  ? fieldCustomSort
@@ -377,6 +380,5 @@ const getColumnsFromSchema = ({ t, schema, idField, isServerSide, customSort, pr
377
380
  const calculatedField = rjstAdaptRefScheme(fieldVal, val);
378
381
  return (_jsx(Widget, { extraFormats: [...(formats !== null && formats !== void 0 ? formats : []), ...defaultFormats], schema: widgetSchema, value: calculatedField, extraContext: entry }));
379
382
  } });
380
- })
381
- .filter((columnDef) => !!columnDef);
383
+ });
382
384
  };
@@ -1,4 +1,4 @@
1
- import type { RJSTBaseResource, Permissions, Priorities, RJSTTagsSdk } from './schemaOps';
1
+ import type { RJSTBaseResource, Permissions, 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,4 +12,3 @@ 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,9 +133,3 @@ 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.0-build-add-manage-columns-tracking-57187862023acb4b29b7aad932ba7521b790a439-1",
3
+ "version": "12.2.1-build-improve-rjst-typings-556eb04390faa8be7ac5c845763edd6bf0926b8e-1",
4
4
  "main": "./dist/index.js",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -54,7 +54,7 @@
54
54
  "zxcvbn": "^4.4.2"
55
55
  },
56
56
  "devDependencies": {
57
- "@balena/lint": "^9.2.1",
57
+ "@balena/lint": "^9.3.0",
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:fix": "balena-lint --fix src",
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-15T13:56:03.369Z"
141
+ "publishedAt": "2025-04-15T14:54:10.459Z"
142
142
  }
143
143
  }