@visns-studio/visns-components 2.5.9 → 2.5.10

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.
@@ -1,15 +1,15 @@
1
- import React, { useEffect, useState, useCallback } from "react";
2
- import CustomFetch from "./Fetch";
3
- import SelectList from "./SelectList";
4
- import AsyncSelect from "react-select/async";
5
- import { debounce } from "lodash";
1
+ import React, { useEffect, useState, useCallback } from 'react';
2
+ import CustomFetch from './Fetch';
3
+ import SelectList from './SelectList';
4
+ import AsyncSelect from 'react-select/async';
5
+ import { debounce } from 'lodash';
6
6
 
7
7
  function VisnsAsyncSelect(props) {
8
8
  const { inputValue, onChange, settings, multi } = props;
9
9
 
10
10
  const loadSuggestedOptions = useCallback(
11
11
  debounce((inputValue, callback) => {
12
- if (inputValue !== "") {
12
+ if (inputValue !== '') {
13
13
  loadOptions(inputValue).then((options) => callback(options));
14
14
  }
15
15
  }, 500),
@@ -17,27 +17,38 @@ function VisnsAsyncSelect(props) {
17
17
  );
18
18
 
19
19
  const loadOptions = (inputValue) => {
20
- if (inputValue !== "") {
20
+ if (inputValue !== '') {
21
21
  return new Promise((resolve, reject) => {
22
22
  let data = [];
23
23
 
24
24
  CustomFetch(
25
25
  settings.url,
26
- "POST",
26
+ 'POST',
27
27
  {
28
28
  where: [
29
29
  {
30
- id: "async",
30
+ id: 'async',
31
31
  value: inputValue,
32
32
  },
33
33
  ],
34
34
  },
35
35
  function (result) {
36
36
  result.data.forEach((a) => {
37
- data.push({
37
+ let _optionItem = {
38
38
  value: a.id,
39
39
  label: a.label,
40
+ };
41
+
42
+ Object.keys(a).forEach((b) => {
43
+ if (b !== 'id') {
44
+ _optionItem = {
45
+ ..._optionItem,
46
+ [b]: a[b],
47
+ };
48
+ }
40
49
  });
50
+
51
+ data.push(_optionItem);
41
52
  });
42
53
 
43
54
  resolve(data);
@@ -157,6 +157,8 @@ function Form(props) {
157
157
  }));
158
158
  };
159
159
 
160
+ console.info(inputValue, action, id);
161
+
160
162
  switch (action.action) {
161
163
  case 'select-option':
162
164
  updateFormData({ [id]: inputValue });
@@ -2,7 +2,49 @@ import React from 'react';
2
2
 
3
3
  function TableFilter({ filters, setFilters, setSettings, type }) {
4
4
  const filterTable = (e) => {
5
- const { id, value, url } = e.target.dataset;
5
+ const { id, parent, type, url, value } = e.target.dataset;
6
+
7
+ const updateFilter = (filter) => {
8
+ let isActive = false;
9
+
10
+ if (filter.hasOwnProperty('value')) {
11
+ isActive = parseInt(value) === parseInt(filter.value);
12
+ } else {
13
+ isActive = filter.id === id;
14
+ }
15
+
16
+ const isParent =
17
+ parent && type === 'children' && filter.id === parent;
18
+
19
+ const updatedChildren = isParent
20
+ ? filter.children.map((child) => ({
21
+ ...child,
22
+ class: child.id === id ? 'subactivechildren' : '',
23
+ show: child.id === id ? true : false,
24
+ }))
25
+ : filter.children
26
+ ? filter.children.map((child, childKey) => ({
27
+ ...child,
28
+ class:
29
+ childKey === 0 && isActive ? 'subactivechildren' : '',
30
+ show: childKey === 0 && isActive ? true : false,
31
+ }))
32
+ : [];
33
+
34
+ return {
35
+ ...filter,
36
+ class:
37
+ isActive || isParent
38
+ ? type === 'simple'
39
+ ? 'activetab'
40
+ : 'subactive'
41
+ : '',
42
+ show: isActive || isParent,
43
+ children: updatedChildren,
44
+ };
45
+ };
46
+
47
+ setFilters((prevFilters) => prevFilters.map(updateFilter));
6
48
 
7
49
  if (url && url !== '') {
8
50
  window.open(url);
@@ -45,39 +87,6 @@ function TableFilter({ filters, setFilters, setSettings, type }) {
45
87
  });
46
88
  }
47
89
  }
48
-
49
- setFilters((prevFilters) => {
50
- const tempFilters = prevFilters.map((item, index) => {
51
- if (
52
- e.target.dataset.hasOwnProperty('value') &&
53
- parseInt(value) >= 0
54
- ) {
55
- return {
56
- ...item,
57
- class:
58
- parseInt(value) === parseInt(item.value)
59
- ? type === 'simple'
60
- ? 'activetab'
61
- : 'subactive'
62
- : '',
63
- show: parseInt(value) === parseInt(item.value),
64
- };
65
- } else {
66
- return {
67
- ...item,
68
- class:
69
- id === item.id
70
- ? type === 'simple'
71
- ? 'activetab'
72
- : 'subactive'
73
- : '',
74
- show: id === item.id,
75
- };
76
- }
77
- });
78
-
79
- return [...tempFilters];
80
- });
81
90
  };
82
91
 
83
92
  const renderContent = (d) => {
@@ -86,8 +95,9 @@ function TableFilter({ filters, setFilters, setSettings, type }) {
86
95
  <li className={d.class}>
87
96
  <button
88
97
  data-id={d.id}
89
- data-value={d.hasOwnProperty('value') ? d.value : ''}
98
+ data-type="parent"
90
99
  data-url={d.url || ''}
100
+ data-value={d.hasOwnProperty('value') ? d.value : ''}
91
101
  onClick={filterTable}
92
102
  >
93
103
  {d.label}
@@ -99,13 +109,37 @@ function TableFilter({ filters, setFilters, setSettings, type }) {
99
109
  <li>
100
110
  <a
101
111
  data-id={d.id}
102
- data-value={d.hasOwnProperty('value') ? d.value : ''}
112
+ data-type="parent"
103
113
  data-url={d.url || ''}
114
+ data-value={d.hasOwnProperty('value') ? d.value : ''}
104
115
  onClick={filterTable}
105
116
  className={d.class}
106
117
  >
107
118
  {d.label}
108
119
  </a>
120
+ {d.children && d.children.length > 0 ? (
121
+ <ul>
122
+ {d.children.map((child, key) => (
123
+ <li key={`table-filter-child-${d.id}-${key}`}>
124
+ <a
125
+ className={child.class}
126
+ data-id={child.id}
127
+ data-value={
128
+ child.hasOwnProperty('value')
129
+ ? child.value
130
+ : ''
131
+ }
132
+ data-url={child.url || ''}
133
+ data-type="children"
134
+ data-parent={d.id}
135
+ onClick={filterTable}
136
+ >
137
+ {child.label}
138
+ </a>
139
+ </li>
140
+ ))}
141
+ </ul>
142
+ ) : null}
109
143
  </li>
110
144
  );
111
145
  }
package/package.json CHANGED
@@ -42,7 +42,7 @@
42
42
  "react-dom": "^17.0.1"
43
43
  },
44
44
  "name": "@visns-studio/visns-components",
45
- "version": "2.5.9",
45
+ "version": "2.5.10",
46
46
  "description": "Various packages to assist in the development of our Custom Applications.",
47
47
  "main": "index.js",
48
48
  "scripts": {