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