forstok-ui-lib 6.20.2 → 6.21.2
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/dist/index.d.ts +10 -49
- package/dist/index.js +571 -1167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +569 -1165
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/assets/javascripts/function.ts +21 -0
- package/src/assets/javascripts/helper.ts +11 -2
- package/src/components/index.ts +0 -1
- package/src/components/link/index.tsx +4 -1
- package/src/components/link/styles.ts +152 -144
- package/src/components/link/typed.ts +10 -0
- package/src/typeds/shares.typed.ts +26 -26
- package/src/components/masterTable/index.tsx +0 -649
- package/src/components/masterTable/partials/datas/confirm.tsx +0 -92
- package/src/components/masterTable/partials/datas/index.tsx +0 -81
- package/src/components/masterTable/partials/editors/date.bare.tsx +0 -39
- package/src/components/masterTable/partials/editors/date.tsx +0 -123
- package/src/components/masterTable/partials/editors/image.tsx +0 -61
- package/src/components/masterTable/partials/editors/input.bare.tsx +0 -127
- package/src/components/masterTable/partials/editors/input.tsx +0 -140
- package/src/components/masterTable/partials/editors/label.tsx +0 -128
- package/src/components/masterTable/partials/editors/select.bare.tsx +0 -104
- package/src/components/masterTable/partials/editors/select.tsx +0 -142
- package/src/components/masterTable/partials/editors/switch.tsx +0 -56
- package/src/components/masterTable/partials/editors/tag.tsx +0 -49
- package/src/components/masterTable/partials/editors/textarea.tsx +0 -7
- package/src/components/masterTable/styles.tsx +0 -1011
- package/src/components/masterTable/typed.ts +0 -87
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { JSX } from 'react';
|
|
2
|
-
import ImageComponent from '../../../image';
|
|
3
|
-
import LinkComponent from '../../../link';
|
|
4
|
-
import TextComponent from '../../../text';
|
|
5
|
-
import { currencyNumber } from '../../../../assets/javascripts/function';
|
|
6
|
-
import { colorCommonQuantity } from '../../../../assets/javascripts/helper';
|
|
7
|
-
import { MuteLabel, FigureWraper, InitialContainer } from '../../../../assets/stylesheets/shares.styles';
|
|
8
|
-
import { ProductByLabelContainer, ProductByLabelName, StoreContainer, ActionByLabelContainer, LabelContainer, AdjustedLabel } from '../../styles';
|
|
9
|
-
import type { TEditorProps } from '../../typed';
|
|
10
|
-
|
|
11
|
-
const LabelEditors = ({ head, value, height, idx, evOpenPopup, content, type }:Omit<TEditorProps, 'evChange' | 'evCloseEditor' | 'error'>) => {
|
|
12
|
-
const isObject = (x: any) => {
|
|
13
|
-
return typeof x === 'object' && !Array.isArray(x) && x !== null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let _value:string = value ? ((isObject(value) && Object.keys(value).length) ? value[Object.keys(value)[0]] : value) : (head.typeData === 'Integer' ? value.toString() : '');
|
|
17
|
-
let labelEl:JSX.Element;
|
|
18
|
-
|
|
19
|
-
if (head?.condition === 'product') {
|
|
20
|
-
const imageUrl:string = value.imageUrl ? ((Array.isArray(value.imageUrl) && value.imageUrl.length) ? value.imageUrl[0] : value.imageUrl) : '';
|
|
21
|
-
labelEl = (
|
|
22
|
-
<section className="cell-wrapper">
|
|
23
|
-
<ProductByLabelContainer>
|
|
24
|
-
<section>
|
|
25
|
-
<figure className="table-image-figure"><ImageComponent src={imageUrl} /></figure>
|
|
26
|
-
<div>
|
|
27
|
-
<ProductByLabelName>{value.name}</ProductByLabelName>
|
|
28
|
-
{value.totalVariant && <span className='counter-product-label'>{value.totalVariant} variants</span>}
|
|
29
|
-
</div>
|
|
30
|
-
</section>
|
|
31
|
-
<section>
|
|
32
|
-
<div><MuteLabel $size='medium'>Category: </MuteLabel> {value.category || 'No Category'}</div>
|
|
33
|
-
<div><MuteLabel $size='medium'>Brand: </MuteLabel> {value.brand || 'No Brand'}</div>
|
|
34
|
-
</section>
|
|
35
|
-
</ProductByLabelContainer>
|
|
36
|
-
</section>
|
|
37
|
-
);
|
|
38
|
-
} else if (head?.condition === 'addVariant') {
|
|
39
|
-
labelEl = (
|
|
40
|
-
<section className="cell-wrapper" data-detail={JSON.stringify({idx:idx, data: content})} data-popup='add-variant-master'>
|
|
41
|
-
<ActionByLabelContainer $mode='add'>
|
|
42
|
-
<div onClick={e=> evOpenPopup && evOpenPopup(e, 'cell-wrapper')}>
|
|
43
|
-
<TextComponent color='blue' title='Add Variant' style={{ fontWeight: 500 }}>+ Add</TextComponent>
|
|
44
|
-
</div>
|
|
45
|
-
</ActionByLabelContainer>
|
|
46
|
-
</section>
|
|
47
|
-
);
|
|
48
|
-
} else if (head?.condition === 'item') {
|
|
49
|
-
const imageUrl:string = value.imageUrl ? ((Array.isArray(value.imageUrl) && value.imageUrl.length) ? value.imageUrl[0] : value.imageUrl) : '';
|
|
50
|
-
labelEl = (
|
|
51
|
-
<section className="cell-wrapper">
|
|
52
|
-
<LabelContainer>
|
|
53
|
-
<FigureWraper $size='30px'>
|
|
54
|
-
<ImageComponent alt={value.name} $mode='product' src={imageUrl || ""}/>
|
|
55
|
-
</FigureWraper>
|
|
56
|
-
<div>
|
|
57
|
-
<ProductByLabelName><strong>{value.name}</strong></ProductByLabelName>
|
|
58
|
-
{value.sku && (
|
|
59
|
-
<MuteLabel $size='medium'>
|
|
60
|
-
<span>SKU:</span>
|
|
61
|
-
<LinkComponent target='_blank' href={`https://app.forstok.com/dashboard/items/master/${encodeURIComponent(value.sku)}?src=sku`}>{value.sku}</LinkComponent>
|
|
62
|
-
</MuteLabel>
|
|
63
|
-
)}
|
|
64
|
-
</div>
|
|
65
|
-
</LabelContainer>
|
|
66
|
-
</section>
|
|
67
|
-
);
|
|
68
|
-
} else if (head?.condition === 'productPicklist') {
|
|
69
|
-
const imageUrl:string = value.imageUrl ? ((Array.isArray(value.imageUrl) && value.imageUrl.length) ? value.imageUrl[0] : value.imageUrl) : '';
|
|
70
|
-
labelEl = (
|
|
71
|
-
<section className="cell-wrapper">
|
|
72
|
-
<LabelContainer>
|
|
73
|
-
<FigureWraper $size='30px'>
|
|
74
|
-
<ImageComponent alt={value.name} $mode='product' src={imageUrl || ""}/>
|
|
75
|
-
</FigureWraper>
|
|
76
|
-
<div style={{ display: 'grid', gridGap: '4px' }}>
|
|
77
|
-
<TextComponent style={{ fontWeight: 600 }}>{value.name}</TextComponent>
|
|
78
|
-
<MuteLabel $size='medium'>
|
|
79
|
-
<span>SKU:</span>{value.sku ?
|
|
80
|
-
<LinkComponent target='_blank' href={`https://app.forstok.com/dashboard/items/master/${encodeURIComponent(value.sku)}?src=sku`}>{value.sku}</LinkComponent> : '-'}
|
|
81
|
-
</MuteLabel>
|
|
82
|
-
<MuteLabel $size='medium'>
|
|
83
|
-
<span>UPC:</span>{value.barcode || '-'}
|
|
84
|
-
</MuteLabel>
|
|
85
|
-
</div>
|
|
86
|
-
</LabelContainer>
|
|
87
|
-
</section>
|
|
88
|
-
) ;
|
|
89
|
-
} else if (head?.condition === 'option') {
|
|
90
|
-
labelEl = <TextComponent $elipsis={false} className='multi-elipsis'>{value || '-'}</TextComponent>;
|
|
91
|
-
} else if (head?.condition === 'adjustment') {
|
|
92
|
-
let reValue:number|string = content.quantity - content.availableQuantity;
|
|
93
|
-
if (reValue > 0) {
|
|
94
|
-
reValue = '+'+ reValue;
|
|
95
|
-
} else if (reValue === 0) {
|
|
96
|
-
reValue = '';
|
|
97
|
-
}
|
|
98
|
-
labelEl = <TextComponent $elipsis={false} id={`text-${head.key}-${idx}`} className='multi-elipsis' style={{ display: 'inline', ...head?.align && { textAlign: head.align } }}>{reValue || '-'}</TextComponent>;
|
|
99
|
-
} else if (head?.condition === 'countAdjustment') {
|
|
100
|
-
let reValue:number = 0;
|
|
101
|
-
if (content.quantity !== null && content.quantity !== undefined) {
|
|
102
|
-
reValue = content.quantity - content.qtyOnHand;
|
|
103
|
-
}
|
|
104
|
-
const adjustedLbl:number|string = (reValue > 0) ? '+'+ reValue : reValue;
|
|
105
|
-
labelEl = reValue ? <AdjustedLabel id={`text-${head.key}-${idx}`} className='multi-elipsis' style={{ color: colorCommonQuantity(reValue), textAlign: head?.align || ';eft' }}>{adjustedLbl}</AdjustedLabel> : <></>;
|
|
106
|
-
} else if (head?.condition === 'store') {
|
|
107
|
-
labelEl = (
|
|
108
|
-
<section className="cell-wrapper">
|
|
109
|
-
<StoreContainer>
|
|
110
|
-
<section>
|
|
111
|
-
{
|
|
112
|
-
value.channelImage ? <ImageComponent $mode='store' alt={value.channelName} src={value.channelImage} width='30px' /> : <InitialContainer style={{ fontSize: '10px', width: '30px', height: '30px', backgroundColor: value.channelColor || '#000000' }}>{value.channelInitials}</InitialContainer>
|
|
113
|
-
}
|
|
114
|
-
<div>
|
|
115
|
-
<strong className='multi-elipsis' title={value?.accountName}>{value?.accountName || '-'}</strong>
|
|
116
|
-
<LinkComponent target='_blank' href={`https://app.forstok.com/dashboard/invoices/salesinvoices/${content.invoiceId}`}>INV-{content.invoiceId}</LinkComponent>
|
|
117
|
-
</div>
|
|
118
|
-
</section>
|
|
119
|
-
</StoreContainer>
|
|
120
|
-
</section>
|
|
121
|
-
);
|
|
122
|
-
} else {
|
|
123
|
-
labelEl = <section className="cell-wrapper"><div className='truncate-overflow' {...(height && height !== 'auto') && { style: { maxHeight: height ? (parseInt(height as string) - 34) : 'auto' } }} {...head?.align && { style:{ textAlign: head.align } }}>{_value}</div></section>;
|
|
124
|
-
}
|
|
125
|
-
return labelEl;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export default LabelEditors;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { OnChangeValue } from 'react-select';
|
|
3
|
-
import moment from 'moment';
|
|
4
|
-
import SelectComponent from '../../../select';
|
|
5
|
-
import { unescapeHTML } from '../../../../assets/javascripts/function';
|
|
6
|
-
import type { TOption } from '../../../select/typed';
|
|
7
|
-
import type { TEditorProps } from '../../typed';
|
|
8
|
-
|
|
9
|
-
const SelectBareEditors = ({ head, value, evChange, idx, variantIdx, error, isForceUpdate, setForceUpdate, content }:Omit<TEditorProps, 'evCloseEditor'>) => {
|
|
10
|
-
const [ selectOptions, setSelectOptions ] = useState<TOption[]|null>(null);
|
|
11
|
-
|
|
12
|
-
const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
13
|
-
|
|
14
|
-
const evCustom = useCallback((valueCustom:any) => {
|
|
15
|
-
const keyEl = document.getElementById('cur-key');
|
|
16
|
-
const currentKey = keyEl ? keyEl.innerHTML : '';
|
|
17
|
-
if(currentKey && (currentKey === eckey)) {
|
|
18
|
-
evChange(head, valueCustom, idx, variantIdx);
|
|
19
|
-
}
|
|
20
|
-
}, [eckey, head, idx, variantIdx, evChange])
|
|
21
|
-
|
|
22
|
-
const evChangeSelect = (newValue: OnChangeValue<TOption, boolean>) => {
|
|
23
|
-
const _newValue = newValue as OnChangeValue<TOption, false>;
|
|
24
|
-
const keyEl = document.getElementById('cur-key');
|
|
25
|
-
keyEl && (keyEl.innerHTML = eckey)
|
|
26
|
-
if (head?.condition === 'qtyToReturn') {
|
|
27
|
-
evCustom(_newValue?.value);
|
|
28
|
-
} else {
|
|
29
|
-
evCustom(_newValue);
|
|
30
|
-
}
|
|
31
|
-
setForceUpdate && setForceUpdate(true);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const evCreateSelect = (value: string) => {
|
|
35
|
-
const keyEl = document.getElementById('cur-key');
|
|
36
|
-
keyEl && (keyEl.innerHTML = eckey);
|
|
37
|
-
evCustom(value);
|
|
38
|
-
setForceUpdate && setForceUpdate(true);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const evGenerateOptions = useCallback(() => {
|
|
42
|
-
let options = [];
|
|
43
|
-
if (content?.dataLocations) {
|
|
44
|
-
if (head.key === 'locations-batchId') {
|
|
45
|
-
const optionFilter = content.dataLocations.filter((loc: any) => loc.location === content.locations?.[variantIdx || 0]?.location);
|
|
46
|
-
if (optionFilter.length) {
|
|
47
|
-
options = optionFilter.map((opt: any) => opt.batchId).filter((value: any, index: number, current_value: any) => current_value.indexOf(value) === index).map((opt: any) => ({ value: opt, label: opt }));
|
|
48
|
-
}
|
|
49
|
-
} else if (head.key === 'locations-expiryDate') {
|
|
50
|
-
const optionFilter = content.dataLocations.filter((loc: any) => ((loc.location === content.locations?.[variantIdx || 0]?.location) && (loc.batchId === content.locations?.[variantIdx || 0]?.batchId.value))) ;
|
|
51
|
-
if (optionFilter.length) {
|
|
52
|
-
options = optionFilter.map((opt: any) => {
|
|
53
|
-
return ({
|
|
54
|
-
value: opt.expiryDate,
|
|
55
|
-
label: moment(opt.expiryDate, 'YYYY-MM-DD HH:mm:ss ZZ').format('D MMM YYYY, hh:mm A')
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return options;
|
|
62
|
-
}, [content, head, variantIdx])
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
if(!selectOptions) {
|
|
66
|
-
const masterCategoryEl = document.getElementById('master-categories');
|
|
67
|
-
let _newOptions = [];
|
|
68
|
-
if(head?.condition === 'qtyToReturn') {
|
|
69
|
-
const maxValue = content.qtyOrdered - content.qtyReturned;
|
|
70
|
-
for(let i = 0; i <= maxValue; i++) {
|
|
71
|
-
_newOptions.push({ value: i, label: i });
|
|
72
|
-
}
|
|
73
|
-
} else if (head?.schema) {
|
|
74
|
-
_newOptions = head.schema === 'master_category' ? (masterCategoryEl?.innerHTML !== '' ? JSON.parse(unescapeHTML(masterCategoryEl?.innerHTML)) : []) : [];
|
|
75
|
-
} else if (evGenerateOptions().length) {
|
|
76
|
-
_newOptions = evGenerateOptions();
|
|
77
|
-
} else {
|
|
78
|
-
_newOptions = head.options || [];
|
|
79
|
-
}
|
|
80
|
-
setSelectOptions(_newOptions);
|
|
81
|
-
}
|
|
82
|
-
}, [content, evGenerateOptions, head, selectOptions])
|
|
83
|
-
|
|
84
|
-
useEffect(() => {
|
|
85
|
-
if(isForceUpdate) {
|
|
86
|
-
const _newOptions = evGenerateOptions();
|
|
87
|
-
if (_newOptions.length) {
|
|
88
|
-
setSelectOptions(_newOptions);
|
|
89
|
-
}
|
|
90
|
-
setForceUpdate && setForceUpdate(false);
|
|
91
|
-
}
|
|
92
|
-
}, [content, evGenerateOptions, head, isForceUpdate, setForceUpdate, variantIdx])
|
|
93
|
-
|
|
94
|
-
const selectValue: TOption = head?.condition === 'qtyToReturn' ? { value: value, label: value } : head.typeData === 'Boolean' ?
|
|
95
|
-
(head.options?.filter(opt => opt.value === value).length ? head.options.filter(opt => opt.value === value)[0] : value) :
|
|
96
|
-
(value ? (typeof value == "string" ? { value: value, label: value }: value ) : {});
|
|
97
|
-
const qaId = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
98
|
-
|
|
99
|
-
return (
|
|
100
|
-
(head?.condition === 'adjustLocation' && !content.locations[variantIdx || 0]?.location) ? null : <div className='master-editor'><SelectComponent {...(head.key === 'category') && { isCreateable: true }} options={selectOptions} defaultValue={selectValue} mode='small-table' name={head.fieldType+'_'+head.key} evCreate={evCreateSelect} evChange={evChangeSelect} isForceUpdate={isForceUpdate} setForceUpdate={setForceUpdate} data-qa-id={`mt-select-${qaId}`} {...error && { isError: true, 'data-tip':error, 'data-place': 'top', 'data-type': 'error' }} placeholder={`Select ${head.name}`} /></div>
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export default SelectBareEditors;
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { OnChangeValue } from 'react-select';
|
|
3
|
-
import TextComponent from '../../../text';
|
|
4
|
-
import ErrorComponent from '../../../error';
|
|
5
|
-
import SelectComponent from '../../../select';
|
|
6
|
-
import { unescapeHTML } from '../../../../assets/javascripts/function';
|
|
7
|
-
import type { TMouseEvent } from '../../../../typeds/base.typed';
|
|
8
|
-
import type { TOption } from '../../../select/typed';
|
|
9
|
-
import type { TEditorProps } from '../../typed';
|
|
10
|
-
|
|
11
|
-
const SelectEditors = ({ head, value, height, evChange, idx, variantIdx, error, evCloseEditor }: TEditorProps) => {
|
|
12
|
-
const [isEditing, setEdit] = useState<boolean>(false)
|
|
13
|
-
const [selectOptions, setSelectOptions] = useState<TOption[] | null>(null);
|
|
14
|
-
const [valueFormState, setValueFormState] = useState<TOption | string>((value !== null || value !== undefined) ? value : '');
|
|
15
|
-
const [isForceUpdate, setForceUpdate] = useState<boolean>(false);
|
|
16
|
-
const [isFirstLoadEditor, setFirstLoad] = useState<boolean>(true);
|
|
17
|
-
|
|
18
|
-
const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
19
|
-
|
|
20
|
-
const evCustom = useCallback((valueFormState: TOption | string) => {
|
|
21
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
22
|
-
const currentKey = keyEl ? keyEl.innerHTML : '';
|
|
23
|
-
if (currentKey && (currentKey === eckey)) {
|
|
24
|
-
evChange(head, valueFormState, idx, variantIdx);
|
|
25
|
-
evCloseEditor && evCloseEditor(() => { setEdit(false) });
|
|
26
|
-
}
|
|
27
|
-
}, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (!isFirstLoadEditor) {
|
|
31
|
-
evCustom(valueFormState);
|
|
32
|
-
} else if (isForceUpdate) {
|
|
33
|
-
evCustom(valueFormState);
|
|
34
|
-
} else {
|
|
35
|
-
setFirstLoad(false);
|
|
36
|
-
}
|
|
37
|
-
}, [valueFormState, evCustom, isFirstLoadEditor, isForceUpdate])
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
const docBody = document.body as HTMLBodyElement;
|
|
41
|
-
const evClick = (e: Event) => {
|
|
42
|
-
if (!isEditing) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
const target = e.target as HTMLBodyElement;
|
|
46
|
-
const idTest = target.dataset.id || '';
|
|
47
|
-
if (idTest && /^react-select/.test(idTest)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
else if (!target.closest('.master-editor ._refSelectContainer')) {
|
|
51
|
-
setValueFormState(valueFormState);
|
|
52
|
-
evCloseEditor(() => { setEdit(false) });
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
docBody.addEventListener('click', evClick);
|
|
57
|
-
return () => {
|
|
58
|
-
docBody.removeEventListener('click', evClick);
|
|
59
|
-
}
|
|
60
|
-
}, [valueFormState, isEditing, evCloseEditor])
|
|
61
|
-
|
|
62
|
-
const evClick: TMouseEvent = e => {
|
|
63
|
-
e.preventDefault();
|
|
64
|
-
const target = e.target as HTMLElement;
|
|
65
|
-
if (target.closest('.cell-disabled')) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
69
|
-
keyEl && (keyEl.innerHTML = eckey);
|
|
70
|
-
setEdit(!isEditing);
|
|
71
|
-
const cellEl = target.closest('.cell') as HTMLDivElement;
|
|
72
|
-
!isEditing ? (cellEl && (cellEl.classList.add('cell-editing'))) : (cellEl && (cellEl.classList.remove('cell-editing')));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const evChangeSelect = (newValue: OnChangeValue<TOption, boolean>) => {
|
|
76
|
-
const _newValue = newValue as OnChangeValue<TOption, false>;
|
|
77
|
-
_newValue?.value && setValueFormState(_newValue.value);
|
|
78
|
-
setForceUpdate(true);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const evCreateSelect = (value: string) => {
|
|
82
|
-
setValueFormState(value);
|
|
83
|
-
setForceUpdate(true);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (!selectOptions) {
|
|
88
|
-
const masterCategoryEl = document.getElementById('master-categories') as HTMLDivElement;
|
|
89
|
-
const _newOptions = (head?.schema && head.schema === 'master_category') ?
|
|
90
|
-
(masterCategoryEl.innerHTML !== '' ? JSON.parse(unescapeHTML(masterCategoryEl.innerHTML)) : []) :
|
|
91
|
-
(head.options || []);
|
|
92
|
-
setSelectOptions && setSelectOptions(_newOptions);
|
|
93
|
-
}
|
|
94
|
-
}, [head, selectOptions])
|
|
95
|
-
|
|
96
|
-
const selectValue: TOption = head.typeData === 'Boolean' ?
|
|
97
|
-
(head.options?.filter(opt => opt.value === value).length ? head.options.filter(opt => opt.value === value)[0] : value) :
|
|
98
|
-
(value ? (typeof value == "string" ? { value: value, label: value }: value ) : {});
|
|
99
|
-
const labelValue: string = head.typeData === 'Boolean' ? (head.options?.filter(opt => opt.value === value).length ? head.options.filter(opt => opt.value === value)[0].label : value) : value;
|
|
100
|
-
const qaId = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
101
|
-
|
|
102
|
-
return (
|
|
103
|
-
!isEditing ?
|
|
104
|
-
<section onClick={evClick} className="cell-wrapper">
|
|
105
|
-
{
|
|
106
|
-
head.multiline ?
|
|
107
|
-
<>
|
|
108
|
-
{
|
|
109
|
-
(valueFormState === '' && error) ?
|
|
110
|
-
<TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> :
|
|
111
|
-
<div className='truncate-overflow' data-qa-id={`mt-select-label-${qaId}`} style={{maxHeight: height ? (parseInt(height as string) - 34) : 'auto'}}>{labelValue}</div>
|
|
112
|
-
}
|
|
113
|
-
{error && <ErrorComponent $mode='table'>{error}</ErrorComponent>}
|
|
114
|
-
</>
|
|
115
|
-
:
|
|
116
|
-
<>
|
|
117
|
-
{
|
|
118
|
-
(valueFormState === '' && error) ?
|
|
119
|
-
<TextComponent $color='blue' style={{ fontWeight: 500 }}>+ Add</TextComponent> :
|
|
120
|
-
<div data-qa-id={`mt-select-label-${qaId}`}>{labelValue}</div>
|
|
121
|
-
}
|
|
122
|
-
{error && <ErrorComponent $mode='table'>{error}</ErrorComponent>}
|
|
123
|
-
</>
|
|
124
|
-
}
|
|
125
|
-
</section> :
|
|
126
|
-
<div className='master-editor'>
|
|
127
|
-
<SelectComponent
|
|
128
|
-
options={selectOptions}
|
|
129
|
-
defaultValue={selectValue}
|
|
130
|
-
mode='small-table'
|
|
131
|
-
name={head.fieldType+'_'+head.key}
|
|
132
|
-
evCreate={evCreateSelect}
|
|
133
|
-
evChange={evChangeSelect}
|
|
134
|
-
isForceUpdate={isForceUpdate}
|
|
135
|
-
setForceUpdate={setForceUpdate}
|
|
136
|
-
data-qa-id={`mt-select-${qaId}`}
|
|
137
|
-
{...head.key === 'category' && { isCreateable: true }} />
|
|
138
|
-
</div>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export default SelectEditors
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import SwitchComponent from '../../../switch';
|
|
3
|
-
import type { TEditorProps } from '../../typed';
|
|
4
|
-
|
|
5
|
-
const SwitchEditors = ({ head, value, evChange, idx, variantIdx, evCloseEditor }:Omit<TEditorProps, 'error'>) => {
|
|
6
|
-
const [valueFormState, setValueFormState] = useState<boolean>(value || false);
|
|
7
|
-
const [isFirstLoadEditor, setFirstLoad] = useState<boolean>(true);
|
|
8
|
-
|
|
9
|
-
const nameAlias = `${(head.name).toLowerCase().replaceAll(' ','-')}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
10
|
-
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
const inputSwitchEl = document.getElementById(`${head.fieldType}_${nameAlias}`) as HTMLInputElement;
|
|
13
|
-
inputSwitchEl && (inputSwitchEl.checked = value);
|
|
14
|
-
setValueFormState(value);
|
|
15
|
-
}, [value, head, nameAlias])
|
|
16
|
-
|
|
17
|
-
const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
18
|
-
|
|
19
|
-
const evCustom = useCallback((valueCustom: boolean) => {
|
|
20
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
21
|
-
const currentKey = keyEl ? keyEl.innerHTML : '';
|
|
22
|
-
if (currentKey && (currentKey === eckey)) {
|
|
23
|
-
evChange(head, valueCustom, idx, variantIdx);
|
|
24
|
-
evCloseEditor();
|
|
25
|
-
}
|
|
26
|
-
}, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!isFirstLoadEditor) {
|
|
30
|
-
evCustom(valueFormState);
|
|
31
|
-
} else {
|
|
32
|
-
setFirstLoad(false);
|
|
33
|
-
}
|
|
34
|
-
}, [valueFormState, evCustom, isFirstLoadEditor])
|
|
35
|
-
|
|
36
|
-
const evInput = (currentTarget: HTMLInputElement) => {
|
|
37
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
38
|
-
keyEl && (keyEl.innerHTML = eckey);
|
|
39
|
-
const cellEl = currentTarget.closest('.cell') as HTMLDivElement;
|
|
40
|
-
cellEl && (cellEl.classList.add('cell-editing'));
|
|
41
|
-
const value = currentTarget.checked;
|
|
42
|
-
const isClosed = valueFormState === value;
|
|
43
|
-
setValueFormState(value);
|
|
44
|
-
isClosed && evCloseEditor();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const checkedValue = valueFormState as boolean | undefined;
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div className='master-editor'>
|
|
51
|
-
<SwitchComponent name={head.fieldType+'_'+head.key} id={`${head.fieldType}_${nameAlias}`} aria-label={head.name} value={valueFormState.toString()} defaultChecked={checkedValue} data-qa-id={`mt-checkbox-${nameAlias}`} evChange={e=> { evInput(e.target) }} />
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default SwitchEditors;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { useEffect, useCallback, ReactNode } from 'react';
|
|
2
|
-
import type { TMouseEvent, TObject } from '../../../../typeds/base.typed';
|
|
3
|
-
import type { TOption } from '../../../select/typed';
|
|
4
|
-
import type { TEditorProps } from '../../typed';
|
|
5
|
-
|
|
6
|
-
const TagEditors = ({ head, value, height, evChange, evOpenPopup, idx, variantIdx, resultPopup, setResultPopup, evCloseEditor }:Omit<TEditorProps, 'error'>) => {
|
|
7
|
-
const eckey = `${head.key}-${idx}${(variantIdx !== undefined ? '-'+variantIdx : '')}`;
|
|
8
|
-
|
|
9
|
-
const evCustom = useCallback((result: TObject[string]) => {
|
|
10
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
11
|
-
const currentKey = keyEl ? keyEl.innerHTML : '';
|
|
12
|
-
if (currentKey && (currentKey === eckey)) {
|
|
13
|
-
evChange(head, result, idx, variantIdx);
|
|
14
|
-
evCloseEditor();
|
|
15
|
-
}
|
|
16
|
-
}, [eckey, head, idx, variantIdx, evChange, evCloseEditor])
|
|
17
|
-
|
|
18
|
-
useEffect(()=> {
|
|
19
|
-
if (resultPopup && ('tag' in resultPopup)) {
|
|
20
|
-
setResultPopup && setResultPopup(null);
|
|
21
|
-
evCustom(resultPopup.tag);
|
|
22
|
-
}
|
|
23
|
-
}, [resultPopup, setResultPopup, evCustom])
|
|
24
|
-
|
|
25
|
-
const evClick: TMouseEvent = e => {
|
|
26
|
-
e.preventDefault();
|
|
27
|
-
const target = e.target as HTMLElement;
|
|
28
|
-
if (target.closest('.cell-disabled')) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
const keyEl = document.getElementById('cur-key') as HTMLDivElement;
|
|
32
|
-
keyEl && (keyEl.innerHTML = eckey);
|
|
33
|
-
const cellEl = target.closest('.cell') as HTMLDivElement;
|
|
34
|
-
cellEl && (cellEl.classList.add('cell-editing'));
|
|
35
|
-
evOpenPopup && evOpenPopup(e, 'cell-wrapper');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<section
|
|
40
|
-
className="cell-wrapper"
|
|
41
|
-
onClick={evClick}
|
|
42
|
-
data-popup='table-tag'
|
|
43
|
-
data-detail={JSON.stringify({ title: head.name, value: value })}>
|
|
44
|
-
<div className='truncate-overflow' style={{maxHeight: height ? (parseInt(height as string) - 34) : 'auto'}}>{value && value.map((val: TOption, idx: number) => <span key ={idx}>{(val as unknown as ReactNode)}</span>)}</div>
|
|
45
|
-
</section>
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default TagEditors;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { TEditorProps } from '../../typed';
|
|
2
|
-
|
|
3
|
-
const TextareaEditors = ({ value, height }:Omit<TEditorProps, 'evChange' | 'evCloseEditor' | 'error'>) => {
|
|
4
|
-
return <section className="cell-wrapper"><div className='truncate-overflow' {...(height && height !== 'auto') && { style: { maxHeight: height ? (parseInt(height as string) - 34) : 'auto' } }}>{value}</div></section>;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export default TextareaEditors;
|