- file select files grouped by category;
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, pluck } from 'ramda';
|
||||
import { isEmpty, pathOr, pluck } from 'ramda';
|
||||
|
||||
// components
|
||||
import { ListBox } from 'primereact/listbox';
|
||||
@@ -98,20 +98,22 @@ const FileSelect = ({
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEmpty(options)) {
|
||||
console.log('options', options);
|
||||
const optionsDefault = [
|
||||
{
|
||||
label: __('Documenti dell\'Azienda', 'gepafin'),
|
||||
code: 'COMPANY_DOCUMENT',
|
||||
items: options.filter(o => o.type === 'COMPANY_DOCUMENT')
|
||||
},
|
||||
{
|
||||
label: __('Documenti del Rappresentante Legale', 'gepafin'),
|
||||
code: 'PERSONAL_DOCUMENT',
|
||||
items: options.filter(o => o.type === 'PERSONAL_DOCUMENT')
|
||||
const optionsDefault = options.reduce((acc, cur) => {
|
||||
const catName = pathOr('', ['category', 'categoryName'], cur);
|
||||
const catLabel = pathOr('', ['category', 'description'], cur);
|
||||
|
||||
if (!acc[catName]) {
|
||||
acc[catName] = {
|
||||
code: catName,
|
||||
label: catLabel,
|
||||
items: []
|
||||
};
|
||||
}
|
||||
];
|
||||
setOptionsTransformed(optionsDefault);
|
||||
acc[catName].items.push(cur)
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
setOptionsTransformed(Object.values(optionsDefault));
|
||||
}
|
||||
}, [options]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user