@trackunit/react-table-helpers 0.0.186 → 0.0.187
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/index.cjs.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
|
+
var customFieldComponents = require('@trackunit/custom-field-components');
|
|
7
8
|
var reactTable = require('@trackunit/react-table');
|
|
8
9
|
var react = require('react');
|
|
9
10
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
@@ -54,7 +55,7 @@ const setupLibraryTranslations = () => {
|
|
|
54
55
|
/**
|
|
55
56
|
* Takes a custom fields data object and returns a react node that can be used as a cell in a table.
|
|
56
57
|
*/
|
|
57
|
-
const customFieldToCell = (customField, unitPreference, language) => {
|
|
58
|
+
const customFieldToCell = (customField, unitTranslation, unitPreference, language) => {
|
|
58
59
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
59
60
|
const type = customField.type;
|
|
60
61
|
switch (type) {
|
|
@@ -82,10 +83,10 @@ const customFieldToCell = (customField, unitPreference, language) => {
|
|
|
82
83
|
case "JSON":
|
|
83
84
|
return jsxRuntime.jsx(reactTableBaseComponents.TextCell, { content: (_g = (_f = customField.jsonValue) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : "" });
|
|
84
85
|
case "NUMBER": {
|
|
85
|
-
const
|
|
86
|
+
const unitType = unitPreference === "SI" ? customField.definition.unitSi : customField.definition.unitUs;
|
|
86
87
|
const value = customField.numberValue ? customField.numberValue + "" : undefined;
|
|
87
|
-
const updatedValue = irisAppRuntimeCore.CustomFieldRuntime.getCustomFieldValueForDisplayInUI(value,
|
|
88
|
-
return jsxRuntime.jsx(reactTableBaseComponents.NumberCell, { value: updatedValue, unit:
|
|
88
|
+
const updatedValue = irisAppRuntimeCore.CustomFieldRuntime.getCustomFieldValueForDisplayInUI(value, unitType, unitPreference, language);
|
|
89
|
+
return jsxRuntime.jsx(reactTableBaseComponents.NumberCell, { value: updatedValue, unit: unitTranslation(unitType) });
|
|
89
90
|
}
|
|
90
91
|
case "MONETARY":
|
|
91
92
|
return jsxRuntime.jsx(reactTableBaseComponents.NumberCell, { value: (_j = (_h = customField.numberValue) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : "" });
|
|
@@ -105,6 +106,7 @@ function assertNever(value) {
|
|
|
105
106
|
* @returns {ColumnDef<TDataType, CustomFieldData | undefined>[]} - An array of column definitions.
|
|
106
107
|
*/
|
|
107
108
|
const useColumnDefinitionsFromCustomFieldDefinition = ({ customFieldDefinitions, unitPreference, language, }) => {
|
|
109
|
+
const { unitTranslation } = customFieldComponents.useUnitTranslation();
|
|
108
110
|
return react.useMemo(() => {
|
|
109
111
|
const columnHelper = reactTable.createColumnHelper();
|
|
110
112
|
const result = [];
|
|
@@ -125,14 +127,14 @@ const useColumnDefinitionsFromCustomFieldDefinition = ({ customFieldDefinitions,
|
|
|
125
127
|
},
|
|
126
128
|
cell: cell => {
|
|
127
129
|
const cellValue = cell.getValue();
|
|
128
|
-
return cellValue ? customFieldToCell(cellValue, unitPreference, language) : "";
|
|
130
|
+
return cellValue ? customFieldToCell(cellValue, unitTranslation, unitPreference, language) : "";
|
|
129
131
|
},
|
|
130
132
|
});
|
|
131
133
|
result.push(column);
|
|
132
134
|
}
|
|
133
135
|
});
|
|
134
136
|
return result;
|
|
135
|
-
}, [customFieldDefinitions, unitPreference, language]);
|
|
137
|
+
}, [customFieldDefinitions, unitPreference, unitTranslation, language]);
|
|
136
138
|
};
|
|
137
139
|
|
|
138
140
|
/*
|
package/index.esm.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations } from '@trackunit/i18n-library-translation';
|
|
3
|
+
import { useUnitTranslation } from '@trackunit/custom-field-components';
|
|
3
4
|
import { createColumnHelper } from '@trackunit/react-table';
|
|
4
5
|
import { useMemo } from 'react';
|
|
5
6
|
import { CustomFieldRuntime } from '@trackunit/iris-app-runtime-core';
|
|
@@ -50,7 +51,7 @@ const setupLibraryTranslations = () => {
|
|
|
50
51
|
/**
|
|
51
52
|
* Takes a custom fields data object and returns a react node that can be used as a cell in a table.
|
|
52
53
|
*/
|
|
53
|
-
const customFieldToCell = (customField, unitPreference, language) => {
|
|
54
|
+
const customFieldToCell = (customField, unitTranslation, unitPreference, language) => {
|
|
54
55
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
55
56
|
const type = customField.type;
|
|
56
57
|
switch (type) {
|
|
@@ -78,10 +79,10 @@ const customFieldToCell = (customField, unitPreference, language) => {
|
|
|
78
79
|
case "JSON":
|
|
79
80
|
return jsx(TextCell, { content: (_g = (_f = customField.jsonValue) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : "" });
|
|
80
81
|
case "NUMBER": {
|
|
81
|
-
const
|
|
82
|
+
const unitType = unitPreference === "SI" ? customField.definition.unitSi : customField.definition.unitUs;
|
|
82
83
|
const value = customField.numberValue ? customField.numberValue + "" : undefined;
|
|
83
|
-
const updatedValue = CustomFieldRuntime.getCustomFieldValueForDisplayInUI(value,
|
|
84
|
-
return jsx(NumberCell, { value: updatedValue, unit:
|
|
84
|
+
const updatedValue = CustomFieldRuntime.getCustomFieldValueForDisplayInUI(value, unitType, unitPreference, language);
|
|
85
|
+
return jsx(NumberCell, { value: updatedValue, unit: unitTranslation(unitType) });
|
|
85
86
|
}
|
|
86
87
|
case "MONETARY":
|
|
87
88
|
return jsx(NumberCell, { value: (_j = (_h = customField.numberValue) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : "" });
|
|
@@ -101,6 +102,7 @@ function assertNever(value) {
|
|
|
101
102
|
* @returns {ColumnDef<TDataType, CustomFieldData | undefined>[]} - An array of column definitions.
|
|
102
103
|
*/
|
|
103
104
|
const useColumnDefinitionsFromCustomFieldDefinition = ({ customFieldDefinitions, unitPreference, language, }) => {
|
|
105
|
+
const { unitTranslation } = useUnitTranslation();
|
|
104
106
|
return useMemo(() => {
|
|
105
107
|
const columnHelper = createColumnHelper();
|
|
106
108
|
const result = [];
|
|
@@ -121,14 +123,14 @@ const useColumnDefinitionsFromCustomFieldDefinition = ({ customFieldDefinitions,
|
|
|
121
123
|
},
|
|
122
124
|
cell: cell => {
|
|
123
125
|
const cellValue = cell.getValue();
|
|
124
|
-
return cellValue ? customFieldToCell(cellValue, unitPreference, language) : "";
|
|
126
|
+
return cellValue ? customFieldToCell(cellValue, unitTranslation, unitPreference, language) : "";
|
|
125
127
|
},
|
|
126
128
|
});
|
|
127
129
|
result.push(column);
|
|
128
130
|
}
|
|
129
131
|
});
|
|
130
132
|
return result;
|
|
131
|
-
}, [customFieldDefinitions, unitPreference, language]);
|
|
133
|
+
}, [customFieldDefinitions, unitPreference, unitTranslation, language]);
|
|
132
134
|
};
|
|
133
135
|
|
|
134
136
|
/*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table-helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.187",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"react": "^18.2.0",
|
|
14
14
|
"@trackunit/i18n-library-translation": "*",
|
|
15
15
|
"@trackunit/iris-app-runtime-core": "*",
|
|
16
|
-
"@trackunit/react-table-base-components": "*"
|
|
16
|
+
"@trackunit/react-table-base-components": "*",
|
|
17
|
+
"@trackunit/custom-field-components": "*"
|
|
17
18
|
},
|
|
18
19
|
"module": "./index.esm.js",
|
|
19
20
|
"main": "./index.cjs.js"
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { UnitType } from "@trackunit/custom-field-components";
|
|
1
2
|
import { SystemOfMeasurementType } from "@trackunit/react-core-contexts-api";
|
|
2
3
|
import { CustomFieldData } from "./types";
|
|
3
4
|
/**
|
|
4
5
|
* Takes a custom fields data object and returns a react node that can be used as a cell in a table.
|
|
5
6
|
*/
|
|
6
|
-
export declare const customFieldToCell: (customField: CustomFieldData, unitPreference?: SystemOfMeasurementType, language?: string) => React.ReactNode;
|
|
7
|
+
export declare const customFieldToCell: (customField: CustomFieldData, unitTranslation: (unit: UnitType) => string | null, unitPreference?: SystemOfMeasurementType, language?: string) => React.ReactNode;
|