@visns-studio/visns-components 4.9.12 → 4.10.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/package.json CHANGED
@@ -75,7 +75,7 @@
75
75
  "react-dom": "^17.0.0 || ^18.0.0"
76
76
  },
77
77
  "name": "@visns-studio/visns-components",
78
- "version": "4.9.12",
78
+ "version": "4.10.1",
79
79
  "description": "Various packages to assist in the development of our Custom Applications.",
80
80
  "main": "src/index.js",
81
81
  "files": [
@@ -204,7 +204,7 @@ function Form({
204
204
  }
205
205
  };
206
206
 
207
- const handleChangeSelect = (inputValue, action, id) => {
207
+ const handleChangeSelect = async (inputValue, action, id) => {
208
208
  const updateFormData = (update) => {
209
209
  setFormData((prevState) => ({
210
210
  ...prevState,
@@ -212,59 +212,82 @@ function Form({
212
212
  }));
213
213
  };
214
214
 
215
- switch (action.action) {
216
- case 'select-option':
217
- updateFormData({ [id]: inputValue });
215
+ const handleSelectOption = () => {
216
+ updateFormData({ [id]: inputValue });
217
+
218
+ // Update any matching form data properties
219
+ Object.keys(inputValue).forEach((key) => {
220
+ if (formData.hasOwnProperty(key)) {
221
+ updateFormData({ [key]: inputValue[key] });
222
+ }
223
+ });
218
224
 
219
- Object.keys(inputValue).forEach((a) => {
220
- if (formData.hasOwnProperty(a)) {
221
- updateFormData({ [a]: inputValue[a] });
225
+ formSettings.fields.forEach((field) => {
226
+ if (field.id === id && field.trigger) {
227
+ switch (field.trigger.type) {
228
+ case 'addDays':
229
+ handleAddDaysTrigger(inputValue, field);
230
+ break;
231
+ case 'setContent':
232
+ handleSetContentTrigger(inputValue, field);
233
+ break;
222
234
  }
223
- });
235
+ }
236
+ });
237
+ };
224
238
 
225
- formSettings.fields.forEach((f) => {
226
- if (f.id === id && f.trigger) {
227
- switch (f.trigger.type) {
228
- case 'addDays':
229
- let newDate = moment();
230
- let add = false;
239
+ const handleAddDaysTrigger = (inputValue, field) => {
240
+ let newDate = moment();
241
+ let add = false;
231
242
 
232
- if (
233
- inputValue.no_of_days &&
234
- parseFloat(inputValue.no_of_days) > 0
235
- ) {
236
- newDate.add(
237
- parseFloat(inputValue.no_of_days),
238
- 'days'
239
- );
240
- add = true;
241
- }
243
+ if (
244
+ inputValue.no_of_days &&
245
+ parseFloat(inputValue.no_of_days) > 0
246
+ ) {
247
+ newDate.add(parseFloat(inputValue.no_of_days), 'days');
248
+ add = true;
249
+ }
242
250
 
243
- if (
244
- inputValue.no_of_hours &&
245
- parseFloat(inputValue.no_of_hours) > 0
246
- ) {
247
- newDate.add(
248
- parseFloat(inputValue.no_of_hours),
249
- 'hours'
250
- );
251
- add = true;
252
- }
251
+ if (
252
+ inputValue.no_of_hours &&
253
+ parseFloat(inputValue.no_of_hours) > 0
254
+ ) {
255
+ newDate.add(parseFloat(inputValue.no_of_hours), 'hours');
256
+ add = true;
257
+ }
253
258
 
254
- if (add) {
255
- updateFormData({
256
- [f.trigger.id]: newDate.toDate(),
257
- });
258
- }
259
- break;
260
- case 'setContent':
261
- updateFormData({
262
- [f.trigger.id]: inputValue[f.trigger.key],
263
- });
264
- break;
265
- }
266
- }
259
+ if (add) {
260
+ updateFormData({
261
+ [field.trigger.id]: newDate.toDate(),
262
+ });
263
+ }
264
+ };
265
+
266
+ const handleSetContentTrigger = async (inputValue, field) => {
267
+ let contentValue = inputValue[field.trigger.key];
268
+
269
+ if (field.trigger.url && field.trigger.payload) {
270
+ const res = await CustomFetch(field.trigger.url, 'POST', {
271
+ [field.trigger.payload.key.id]:
272
+ inputValue[field.trigger.payload.value.id],
273
+ [field.trigger.payload.key.content]:
274
+ inputValue[field.trigger.payload.value.content],
267
275
  });
276
+
277
+ if (res.data.content) {
278
+ contentValue = res.data.content;
279
+ }
280
+ }
281
+
282
+ updateFormData({
283
+ [field.trigger.id]: contentValue,
284
+ });
285
+ };
286
+
287
+ // Switch cases to handle different actions
288
+ switch (action.action) {
289
+ case 'select-option':
290
+ handleSelectOption();
268
291
  break;
269
292
  case 'clear':
270
293
  updateFormData({ [id]: '' });
@@ -27,6 +27,7 @@ import CustomFetch from '../Fetch';
27
27
  import Form from '../Form';
28
28
  import GenericDynamic from './GenericDynamic';
29
29
  import QrCode from '../QrCode';
30
+ import SortableList from '../sorting/List';
30
31
  import Table from '../DataGrid';
31
32
  import TableFilter from '../TableFilter';
32
33
 
@@ -316,6 +317,12 @@ function GenericDetail({
316
317
 
317
318
  const renderLatestNotes = () => formatNoteValue();
318
319
 
320
+ const renderLink = () => (
321
+ <Link to={item.href.url + data[item.href.key]}>
322
+ {truncatedValue}
323
+ </Link>
324
+ );
325
+
319
326
  const renderOptions = () => (options ? options[value] : '');
320
327
 
321
328
  const renderRichText = () => {
@@ -399,16 +406,18 @@ function GenericDetail({
399
406
  return renderJson();
400
407
  case 'latest_notes':
401
408
  return renderLatestNotes();
409
+ case 'link':
410
+ return renderLink();
402
411
  case 'options':
403
412
  return renderOptions();
404
- case 'richtext':
405
- return renderRichText();
406
- case 'total':
407
- return renderTotal();
408
413
  case 'password':
409
414
  return renderPassword();
410
415
  case 'relation':
411
416
  return renderRelation();
417
+ case 'richtext':
418
+ return renderRichText();
419
+ case 'total':
420
+ return renderTotal();
412
421
  default:
413
422
  return size === 'full' && truncatedValue
414
423
  ? parse(`<br /><p>${truncatedValue}</p>`)
@@ -952,6 +961,7 @@ function GenericDetail({
952
961
  )
953
962
  )}
954
963
  </div>
964
+
955
965
  {activeTabConfig.form && (
956
966
  <div className={styles.polActions}>
957
967
  <button
@@ -1473,9 +1473,9 @@ function GenericFormBuilder({ setting, urlParam, userProfile }) {
1473
1473
  dataField.type ===
1474
1474
  'table_text'
1475
1475
  ) {
1476
- // excludedKeywords.push(
1477
- // 'checkbox'
1478
- // );
1476
+ excludedKeywords.push(
1477
+ 'checkbox'
1478
+ );
1479
1479
  }
1480
1480
  return !excludedKeywords.some(
1481
1481
  (
@@ -1610,9 +1610,9 @@ function GenericFormBuilder({ setting, urlParam, userProfile }) {
1610
1610
  dataField.type ===
1611
1611
  'table_text'
1612
1612
  ) {
1613
- // excludedKeywords.push(
1614
- // 'checkbox'
1615
- // );
1613
+ excludedKeywords.push(
1614
+ 'checkbox'
1615
+ );
1616
1616
  }
1617
1617
  return !excludedKeywords.some(
1618
1618
  (