@webitel/ui-sdk 24.10.46 → 24.10.48

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.
@@ -16,15 +16,15 @@ export const kebabToSnake = (str) =>
16
16
  export const snakeToKebab = (str) =>
17
17
  str.replace(/([-_][a-z])/g, (group) => group.replace('_', '-'));
18
18
 
19
- export const objSnakeToCamel = (obj, skipKeys = []) => {
19
+ const convertObject = ({ self, converter }) => (obj, skipKeys) => {
20
20
  if (!obj) return obj;
21
21
  const newObj = {};
22
22
  if (Array.isArray(obj)) {
23
23
  return obj.map((value) => {
24
24
  if (typeof value === 'object') {
25
- return objSnakeToCamel(value, skipKeys);
25
+ return self(value, skipKeys);
26
26
  }
27
- if (typeof value === 'string') return snakeToCamel(value);
27
+ if (typeof value === 'string') return converter(value);
28
28
  return value; // number
29
29
  });
30
30
  }
@@ -32,13 +32,13 @@ export const objSnakeToCamel = (obj, skipKeys = []) => {
32
32
  if (skipKeys.includes(oldKey)) {
33
33
  newObj[oldKey] = obj[oldKey];
34
34
  } else {
35
- const newKey = snakeToCamel(oldKey);
35
+ const newKey = converter(oldKey);
36
36
  let value = obj[oldKey];
37
37
  if (
38
38
  Array.isArray(value) ||
39
39
  (value !== null && value !== undefined && value.constructor === Object)
40
40
  ) {
41
- value = objSnakeToCamel(value, skipKeys);
41
+ value = self(value, skipKeys);
42
42
  }
43
43
  newObj[newKey] = value;
44
44
  }
@@ -47,33 +47,23 @@ export const objSnakeToCamel = (obj, skipKeys = []) => {
47
47
  return newObj;
48
48
  };
49
49
 
50
+ export const objSnakeToCamel = (obj, skipKeys = []) => {
51
+ return convertObject({
52
+ self: objSnakeToCamel,
53
+ converter: snakeToCamel,
54
+ })(obj, skipKeys);
55
+ };
56
+
50
57
  export const objCamelToSnake = (obj, skipKeys = []) => {
51
- if (!obj) return obj;
52
- const newObj = {};
53
- if (Array.isArray(obj)) {
54
- return obj.map((value) => {
55
- if (typeof value === 'object') {
56
- return objCamelToSnake(value, skipKeys);
57
- }
58
- if (typeof value === 'string') return camelToSnake(value);
59
- return value; // number
60
- });
61
- }
62
- Object.keys(obj).forEach((oldKey) => {
63
- if (skipKeys.includes(oldKey)) {
64
- newObj[oldKey] = obj[oldKey];
65
- } else {
66
- const newKey = camelToSnake(oldKey);
67
- let value = obj[oldKey];
68
- if (
69
- Array.isArray(value) ||
70
- (value !== null && value !== undefined && value.constructor === Object)
71
- ) {
72
- value = objCamelToSnake(value, skipKeys);
73
- }
74
- newObj[newKey] = value;
75
- }
76
- });
58
+ return convertObject({
59
+ self: objCamelToSnake,
60
+ converter: camelToSnake,
61
+ })(obj, skipKeys);
62
+ };
77
63
 
78
- return newObj;
64
+ export const objCamelToKebab = (obj, skipKeys = []) => {
65
+ return convertObject({
66
+ self: objCamelToKebab,
67
+ converter: camelToKebab,
68
+ })(obj, skipKeys);
79
69
  };
@@ -1,4 +1,5 @@
1
1
  import FilterEvent from '../../../../modules/Filters/enums/FilterEvent.enum.js';
2
+ import isEmpty from '../../../../scripts/isEmpty.js';
2
3
  import {
3
4
  queryToSortAdapter,
4
5
  sortToQueryAdapter,
@@ -17,7 +18,7 @@ const getters = {
17
18
  PARENT_ID: () => null, // override me
18
19
 
19
20
  // FIXME: maybe move to filters module?
20
- FILTERS: (state, getters) => getters['filters/GET_FILTERS'],
21
+ FILTERS: (state, getters) => () => getters['filters/GET_FILTERS'](),
21
22
 
22
23
  REQUIRED_FIELDS: () => ['id'], // override me
23
24
 
@@ -30,7 +31,33 @@ const getters = {
30
31
  return [...new Set([...getters.REQUIRED_FIELDS, ...fields])];
31
32
  },
32
33
 
33
- // main GET_LIST params collector
34
+ EMPTY_STATE: (state, getters) => {
35
+ if (state.isLoading) {
36
+ return { value: false };
37
+ }
38
+
39
+ if (state.error) {
40
+ return { value: true, cause: 'error' };
41
+ }
42
+
43
+ if (!state.dataList.length) {
44
+ const filters = getters.FILTERS();
45
+ const uncheckedFilters = ['page', 'size', 'sort', 'fields'];
46
+ const filtersApplied = Object.entries(filters).some(
47
+ ([filterValue, filterName]) =>
48
+ !isEmpty(filterValue) && !uncheckedFilters.includes(filterName),
49
+ );
50
+
51
+ if (filtersApplied) {
52
+ return { value: true, cause: 'filters' };
53
+ }
54
+
55
+ return { value: true, cause: 'empty' };
56
+ }
57
+
58
+ return { value: false };
59
+ },
60
+
34
61
  GET_LIST_PARAMS: (state, getters) => (overrides) => {
35
62
  const filters = getters.FILTERS();
36
63
  const fields = getters.FIELDS;
@@ -148,7 +175,7 @@ const actions = {
148
175
  } finally {
149
176
  setTimeout(() => {
150
177
  context.commit('SET', { path: 'isLoading', value: false });
151
- }, 100); // why 1s? https://ux.stackexchange.com/a/104782
178
+ }, 100); // why 1s? https://ux.stackexchange.com/a/104782
152
179
  }
153
180
  },
154
181