@fixefy/fixefy-ui-utils 0.0.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.
- package/dist-cjs/commander/commander.jsx +284 -0
- package/dist-cjs/commander/index.js +4 -0
- package/dist-cjs/constants/index.js +87 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/page_context/index.js +494 -0
- package/dist-es/commander/commander.jsx +254 -0
- package/dist-es/commander/index.js +1 -0
- package/dist-es/constants/index.js +84 -0
- package/dist-es/package.json +3 -0
- package/dist-es/page_context/index.js +511 -0
- package/dist-types/commander/commander.d.ts +33 -0
- package/dist-types/commander/index.d.ts +1 -0
- package/dist-types/constants/index.d.ts +6 -0
- package/dist-types/page_context/index.d.ts +248 -0
- package/package.json +60 -0
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import NumericHelper from '@fixefy/fixefy-numeric';
|
|
2
|
+
import { format } from "date-fns";
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import { EntityTypes } from "../constants";
|
|
5
|
+
export function buildCode(obj, level = 0, name) {
|
|
6
|
+
const toRender = [];
|
|
7
|
+
const keys = Object.keys(obj);
|
|
8
|
+
if (keys.length < 1) {
|
|
9
|
+
toRender.push(lineString(level, name) + "{}");
|
|
10
|
+
return toRender;
|
|
11
|
+
}
|
|
12
|
+
toRender.push(lineString(level, name) + "{");
|
|
13
|
+
keys.forEach((key) => {
|
|
14
|
+
if (key === "__typename")
|
|
15
|
+
return;
|
|
16
|
+
if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
17
|
+
toRender.push(...buildCode(obj[key], level + 1, key));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const val = getVal(obj[key]);
|
|
21
|
+
toRender.push(lineString(level + 1, key) + val);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
toRender.push(lineString(level) + "}");
|
|
25
|
+
return toRender;
|
|
26
|
+
}
|
|
27
|
+
export const copyToClipboard = (str) => {
|
|
28
|
+
if (window == undefined)
|
|
29
|
+
return;
|
|
30
|
+
const el = document.createElement("textarea");
|
|
31
|
+
el.value = str;
|
|
32
|
+
el.setAttribute("readonly", "");
|
|
33
|
+
el.style.position = "absolute";
|
|
34
|
+
el.style.left = "-9999px";
|
|
35
|
+
document.body.appendChild(el);
|
|
36
|
+
el.select();
|
|
37
|
+
document.execCommand("copy");
|
|
38
|
+
document.body.removeChild(el);
|
|
39
|
+
};
|
|
40
|
+
export function convertToString(input) {
|
|
41
|
+
if (input) {
|
|
42
|
+
return typeof input === "string" ? input : String(input);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export const determineIconByEvent = (event) => {
|
|
46
|
+
let rv;
|
|
47
|
+
if (event) {
|
|
48
|
+
switch (event.type) {
|
|
49
|
+
case "charged":
|
|
50
|
+
rv = "../../static/images/transactions/billing.svg";
|
|
51
|
+
break;
|
|
52
|
+
case "packed":
|
|
53
|
+
rv = "../../static/images/transactions/system.svg";
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
rv = "../../static/images/transactions/user.svg";
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return rv;
|
|
61
|
+
};
|
|
62
|
+
export function formatNumberWithCommas(number) {
|
|
63
|
+
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
64
|
+
}
|
|
65
|
+
export function getNormalizationKeyForEntity(entity_type) {
|
|
66
|
+
let rv;
|
|
67
|
+
switch (entity_type.toLowerCase()) {
|
|
68
|
+
case EntityTypes.User:
|
|
69
|
+
rv = "username";
|
|
70
|
+
break;
|
|
71
|
+
case EntityTypes.Pricing:
|
|
72
|
+
rv = "value";
|
|
73
|
+
break;
|
|
74
|
+
case EntityTypes.Metadata:
|
|
75
|
+
rv = "title";
|
|
76
|
+
break;
|
|
77
|
+
case EntityTypes.Transaction:
|
|
78
|
+
case EntityTypes.Transmission:
|
|
79
|
+
rv = "readable_id";
|
|
80
|
+
break;
|
|
81
|
+
default:
|
|
82
|
+
rv = "title";
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
return rv;
|
|
86
|
+
}
|
|
87
|
+
export const getStringValueByValueType = ({ value, name }) => {
|
|
88
|
+
let rv;
|
|
89
|
+
switch (typeof value) {
|
|
90
|
+
case "boolean":
|
|
91
|
+
rv = value === true ? "YES" : "NO";
|
|
92
|
+
break;
|
|
93
|
+
case "number":
|
|
94
|
+
if (isValidTimestamp(value)) {
|
|
95
|
+
rv = normalizeTimestamp(value, false);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
let _rv = Number(value) === value && value % 1 === 0 ? value : value.toFixed(2);
|
|
99
|
+
if (name === "variance") {
|
|
100
|
+
_rv = (_rv * 100).toFixed(1);
|
|
101
|
+
rv = `${_rv}%`;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
rv = _rv;
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
case "object":
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
rv = value.join(", ");
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const entity_type = value && value.__typename && value.__typename.toLowerCase();
|
|
113
|
+
rv = titleCase(value[getNormalizationKeyForEntity(entity_type)]);
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
case "string":
|
|
117
|
+
rv = titleCase(value);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
return rv;
|
|
121
|
+
};
|
|
122
|
+
export function getVal(val) {
|
|
123
|
+
if (typeof val === "number")
|
|
124
|
+
return val;
|
|
125
|
+
if (typeof val === "string")
|
|
126
|
+
return `"${val}"`;
|
|
127
|
+
return val;
|
|
128
|
+
}
|
|
129
|
+
export const isInServer = () => typeof window === "undefined";
|
|
130
|
+
export const isValidTimestamp = (_timestamp) => {
|
|
131
|
+
const parsedNumber = typeof _timestamp == "string" ? parseInt(_timestamp) : _timestamp;
|
|
132
|
+
const newTimestamp = new Date(parsedNumber).getTime();
|
|
133
|
+
const rv = NumericHelper.isFloat(newTimestamp) && newTimestamp.toString().length >= 10;
|
|
134
|
+
return rv;
|
|
135
|
+
};
|
|
136
|
+
export function lineString(level, name) {
|
|
137
|
+
let str = "";
|
|
138
|
+
for (let i = 0; i < level; i++) {
|
|
139
|
+
str += " ";
|
|
140
|
+
}
|
|
141
|
+
if (name) {
|
|
142
|
+
str += name + ": ";
|
|
143
|
+
}
|
|
144
|
+
return str;
|
|
145
|
+
}
|
|
146
|
+
export function makeString(len = 5) {
|
|
147
|
+
var text = "";
|
|
148
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
149
|
+
for (var i = 0; i < len; i++)
|
|
150
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
151
|
+
return text;
|
|
152
|
+
}
|
|
153
|
+
export const nest = ({ items }) => {
|
|
154
|
+
let mappedArray = Object.create(null);
|
|
155
|
+
items.forEach((item) => (mappedArray[item.id] = { ...item, children: [] }));
|
|
156
|
+
let nestedArray = [];
|
|
157
|
+
items.forEach((item) => {
|
|
158
|
+
if (item) {
|
|
159
|
+
if (item.parent)
|
|
160
|
+
mappedArray[item.parent] &&
|
|
161
|
+
mappedArray[item.parent].children.push(mappedArray[item.id]);
|
|
162
|
+
else
|
|
163
|
+
nestedArray.push(mappedArray[item.id]);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return nestedArray;
|
|
167
|
+
};
|
|
168
|
+
export function normalizeTimestamp(timestamp, options) {
|
|
169
|
+
const { dateOnly, format: _format } = options || {};
|
|
170
|
+
const _timestamp = typeof timestamp == "string" ? parseInt(timestamp) : timestamp;
|
|
171
|
+
const rv = format(new Date(_timestamp), _format ? _format : dateOnly ? "dd/MM/yyyy" : "dd/MM/yyyy hh:mm");
|
|
172
|
+
return rv;
|
|
173
|
+
}
|
|
174
|
+
export function normalizeStringBodyRaw(key, body) {
|
|
175
|
+
return typeof body[key] === "string" && (key === "body" || key === "raw")
|
|
176
|
+
? JSON.parse(body[key])
|
|
177
|
+
: body[key];
|
|
178
|
+
}
|
|
179
|
+
export function titleCase(str = "") {
|
|
180
|
+
return str && toPascalCase(str.toString(), true);
|
|
181
|
+
}
|
|
182
|
+
export function toCamelCase(inputArray) {
|
|
183
|
+
let result = "";
|
|
184
|
+
for (let i = 0, len = inputArray?.length ?? 0; i < len; i++) {
|
|
185
|
+
let currentStr = inputArray?.at(i);
|
|
186
|
+
let tempStr = currentStr.toLowerCase();
|
|
187
|
+
if (i != 0) {
|
|
188
|
+
tempStr = tempStr.substr(0, 1).toUpperCase() + tempStr.substr(1);
|
|
189
|
+
}
|
|
190
|
+
result += tempStr;
|
|
191
|
+
}
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
export function toCamelCaseString(input) {
|
|
195
|
+
const words = toWords(input);
|
|
196
|
+
return toCamelCase(words);
|
|
197
|
+
}
|
|
198
|
+
export const toCurrency = (input) => {
|
|
199
|
+
return input ? input.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") : input;
|
|
200
|
+
};
|
|
201
|
+
export const toInitials = (str) => {
|
|
202
|
+
if (str === "")
|
|
203
|
+
return str;
|
|
204
|
+
var matches = str.match(/\b(\w)/g);
|
|
205
|
+
return matches?.join("").toUpperCase();
|
|
206
|
+
};
|
|
207
|
+
export function toPascalCase(string, title = false) {
|
|
208
|
+
return (string &&
|
|
209
|
+
string.replace(/(_[a-z])?(^[a-z])?(_|\s[a-z])?/g, ($1) => $1.toUpperCase().replace("_", title ? " " : "")));
|
|
210
|
+
}
|
|
211
|
+
export function toWords(input) {
|
|
212
|
+
input = convertToString(input);
|
|
213
|
+
const regex = /[A-Z\xC0-\xD6\xD8-\xDE]?[a-z\xDF-\xF6\xF8-\xFF]+|[A-Z\xC0-\xD6\xD8-\xDE]+(?![a-z\xDF-\xF6\xF8-\xFF])|\d+/g;
|
|
214
|
+
return input?.match(regex);
|
|
215
|
+
}
|
|
216
|
+
export function trimRuleCode(input) {
|
|
217
|
+
const stringefied = typeof input == "string" ? input : JSON.stringify(input);
|
|
218
|
+
let match = stringefied.substring(stringefied.indexOf("{") + 1, stringefied.lastIndexOf("}"));
|
|
219
|
+
return match ? match : "";
|
|
220
|
+
}
|
|
221
|
+
export const useStatePromisify = (_state) => {
|
|
222
|
+
const [state, setState] = useState(_state);
|
|
223
|
+
const resolverRef = useRef(null);
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (resolverRef.current) {
|
|
226
|
+
resolverRef.current(state);
|
|
227
|
+
resolverRef.current = null;
|
|
228
|
+
}
|
|
229
|
+
}, [resolverRef.current, state]);
|
|
230
|
+
const handleSetState = useCallback((stateAction) => {
|
|
231
|
+
setState(stateAction);
|
|
232
|
+
return new Promise((resolve) => {
|
|
233
|
+
resolverRef.current = resolve;
|
|
234
|
+
});
|
|
235
|
+
}, [setState]);
|
|
236
|
+
return [state, handleSetState];
|
|
237
|
+
};
|
|
238
|
+
export const getScoreColor = (value) => {
|
|
239
|
+
if (value <= 20) {
|
|
240
|
+
return "bad";
|
|
241
|
+
}
|
|
242
|
+
else if (value <= 40) {
|
|
243
|
+
return "low";
|
|
244
|
+
}
|
|
245
|
+
else if (value <= 60) {
|
|
246
|
+
return "medium";
|
|
247
|
+
}
|
|
248
|
+
else if (value <= 80) {
|
|
249
|
+
return "high";
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
return "excellent";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './commander';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export const ColumnInputTypes = {
|
|
2
|
+
Array: "array",
|
|
3
|
+
Avatar: "avatar",
|
|
4
|
+
Country: "country",
|
|
5
|
+
Currency: "currency",
|
|
6
|
+
Date: "date",
|
|
7
|
+
Done: "done",
|
|
8
|
+
ID: "id",
|
|
9
|
+
IncoTerm: "incoterm",
|
|
10
|
+
Link: "link",
|
|
11
|
+
Percentage: "percentage",
|
|
12
|
+
Price: "price",
|
|
13
|
+
Progress: "progress",
|
|
14
|
+
Score: "score",
|
|
15
|
+
Status: "status",
|
|
16
|
+
String: "string",
|
|
17
|
+
Measure: "measure",
|
|
18
|
+
};
|
|
19
|
+
export const ComponentTypes = {
|
|
20
|
+
ActionTrey: "action_trey",
|
|
21
|
+
AsyncDropdown: "async_dropdown",
|
|
22
|
+
Chip: "chip",
|
|
23
|
+
ClickableLabel: "clickable_label",
|
|
24
|
+
CollapsableDropdown: "collapsable_dropdown",
|
|
25
|
+
Container: "container",
|
|
26
|
+
DateRange: "date_range",
|
|
27
|
+
Dropdown: "dropdown",
|
|
28
|
+
Label: "label",
|
|
29
|
+
Modal: "modal",
|
|
30
|
+
RangeSlider: "range_slider",
|
|
31
|
+
TableColumn: "table_column",
|
|
32
|
+
Textfield: "textfield",
|
|
33
|
+
StaticDropdown: "static_dropdown",
|
|
34
|
+
dropdownOptions: "dropdownOptions",
|
|
35
|
+
clear: "clear",
|
|
36
|
+
};
|
|
37
|
+
export const DataTypes = {
|
|
38
|
+
CSV: "csv",
|
|
39
|
+
EDI: "edi",
|
|
40
|
+
JSON: "json",
|
|
41
|
+
PDF: "pdf",
|
|
42
|
+
XLS: "xls",
|
|
43
|
+
XML: "xml",
|
|
44
|
+
};
|
|
45
|
+
export const EntityTypes = {
|
|
46
|
+
Block: "block",
|
|
47
|
+
Charge: "charge",
|
|
48
|
+
Contract: "contract",
|
|
49
|
+
Event: "event",
|
|
50
|
+
Metadata: "metadata",
|
|
51
|
+
Notification: "notification",
|
|
52
|
+
Pricing: "pricing",
|
|
53
|
+
Service: "service",
|
|
54
|
+
Structure: "structure",
|
|
55
|
+
Transaction: "transaction",
|
|
56
|
+
Transmission: "transmission",
|
|
57
|
+
User: "user",
|
|
58
|
+
Workspace: "workspace",
|
|
59
|
+
};
|
|
60
|
+
export const FilterOperatorType = {
|
|
61
|
+
Contains: "contains",
|
|
62
|
+
NotContains: "NotContains",
|
|
63
|
+
Equals: "equals",
|
|
64
|
+
EndsWith: "endsWith",
|
|
65
|
+
IsAfter: "after",
|
|
66
|
+
IsBefore: "before",
|
|
67
|
+
Is: "is",
|
|
68
|
+
IsNot: "not",
|
|
69
|
+
In: "in",
|
|
70
|
+
NotIn: "notIn",
|
|
71
|
+
StartsWith: "startsWith",
|
|
72
|
+
GreaterThan: ">",
|
|
73
|
+
GreaterThanEqual: ">=",
|
|
74
|
+
LessThan: "<",
|
|
75
|
+
LessThanEqual: "<=",
|
|
76
|
+
};
|
|
77
|
+
export const InputTypes = {
|
|
78
|
+
Currency: "currency",
|
|
79
|
+
Date: "date",
|
|
80
|
+
Link: "link",
|
|
81
|
+
Password: "password",
|
|
82
|
+
Percent: "percent",
|
|
83
|
+
Text: "text",
|
|
84
|
+
};
|