aio-table 13.0.0 → 14.0.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/filter.css +100 -63
- package/index.css +11 -31
- package/index.d.ts +144 -97
- package/index.js +418 -441
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
-
import { createContext, createRef, Fragment, useContext, useEffect, useRef, useState } from "react";
|
|
12
|
-
import AIOInput, { AICheckbox, AIFormInput, AINumber, AIRadio, AISelect, AIText, AITime
|
|
11
|
+
import { createContext, createRef, Fragment, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
12
|
+
import AIOInput, { AICheckbox, AIFormInput, AINumber, AIRadio, AISelect, AIText, AITime } from "aio-input";
|
|
13
13
|
import * as UT from 'aio-utils';
|
|
14
14
|
import usePopup from "aio-popup";
|
|
15
15
|
import AIODate from "aio-date";
|
|
@@ -21,45 +21,74 @@ const AIOTable = (props) => {
|
|
|
21
21
|
const popup = usePopup();
|
|
22
22
|
const fileClass = new UT.FileClass();
|
|
23
23
|
let [searchValue, setSearchValue] = useState('');
|
|
24
|
-
const [searchColumns, setSearchColumns] = useState([]);
|
|
25
|
-
const [excelColumns, setExcelColumns] = useState([]);
|
|
26
|
-
const [filterColumns, setFilterColumns] = useState([]);
|
|
27
|
-
const [toggleColumns, setToggleColumns] = useState([]);
|
|
28
|
-
const filterColumnsRef = useRef(filterColumns);
|
|
29
|
-
filterColumnsRef.current = filterColumns;
|
|
30
|
-
const rowsIndexDicRef = useRef({});
|
|
31
|
-
const setRowsIndexDic = (rowsIndexDic) => rowsIndexDicRef.current = rowsIndexDic;
|
|
32
|
-
const getRowsIndexDic = () => rowsIndexDicRef.current;
|
|
33
24
|
const propsRef = useRef(props);
|
|
34
25
|
propsRef.current = props;
|
|
35
26
|
const pagingHook = usePaging({ rows: props.value, paging: props.paging, onChange: props.onChangePaging });
|
|
36
|
-
const getColumnOption = (key, cellDetails) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
27
|
+
// const getColumnOption: I_getColumnOption<any> = (key, cellDetails) => {
|
|
28
|
+
// if (key === 'id') { return cellDetails.column.id }
|
|
29
|
+
// const columnValue = cellDetails.column[key]
|
|
30
|
+
// if (columnValue !== undefined) {
|
|
31
|
+
// const { getValue = {} } = props
|
|
32
|
+
// if (getValue[columnValue]) { return getValue[columnValue](cellDetails) }
|
|
33
|
+
// return cellDetails.column[key]
|
|
34
|
+
// }
|
|
35
|
+
// const { columnOption } = props;
|
|
36
|
+
// const fn = (columnOption || {})[key] || (() => { })
|
|
37
|
+
// const res = fn(cellDetails);
|
|
38
|
+
// if (res !== undefined) { return res }
|
|
39
|
+
// if (key === 'value') {
|
|
40
|
+
// return cellDetails.row[cellDetails.column.id]
|
|
41
|
+
// }
|
|
42
|
+
// const defaults: { [key in keyof I_table_column<any>]?: any } = { show: true, title: '', justify: false, titleAttrs: {} }
|
|
43
|
+
// return defaults[key]
|
|
44
|
+
// }
|
|
45
|
+
const tableHook = useTable(() => propsRef.current, () => props.paging);
|
|
46
|
+
const getColumn = (col) => {
|
|
47
|
+
const { columnOption = {} } = props;
|
|
48
|
+
const column = Object.assign({}, col);
|
|
49
|
+
for (let prop in columnOption) {
|
|
50
|
+
if (prop !== 'value') {
|
|
51
|
+
const fn = columnOption[prop];
|
|
52
|
+
if (fn) {
|
|
53
|
+
const res = fn({ column, row: undefined, rowIndex: 0 });
|
|
54
|
+
if (res !== undefined) {
|
|
55
|
+
column[prop] = res;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
|
-
return cellDetails.column[key];
|
|
47
|
-
}
|
|
48
|
-
const { columnOption } = props;
|
|
49
|
-
const fn = (columnOption || {})[key] || (() => { });
|
|
50
|
-
const res = fn(cellDetails);
|
|
51
|
-
if (res !== undefined) {
|
|
52
|
-
return res;
|
|
53
59
|
}
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
const res = Object.assign(Object.assign({}, column), col);
|
|
61
|
+
if (!res.value) {
|
|
62
|
+
res.value = `row.${column.id}`;
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
const getColumns = () => {
|
|
67
|
+
let { columns = [] } = props;
|
|
68
|
+
let searchColumns = [], excelColumns = [], filterColumns = [], toggleColumns = [];
|
|
69
|
+
let updatedColumns = columns.map((col, i) => {
|
|
70
|
+
const column = getColumn(col);
|
|
71
|
+
const { filter, search, excel, toggle, id, show = true } = column;
|
|
72
|
+
if (id === undefined) {
|
|
73
|
+
console.error(`aio-table error => missing column id in props.columns[${i}]`);
|
|
74
|
+
}
|
|
75
|
+
const fixedColumn = Object.assign(Object.assign({}, column), { show });
|
|
76
|
+
if (search) {
|
|
77
|
+
searchColumns.push(fixedColumn);
|
|
78
|
+
}
|
|
79
|
+
if (excel) {
|
|
80
|
+
excelColumns.push(fixedColumn);
|
|
81
|
+
}
|
|
82
|
+
if (filter) {
|
|
83
|
+
filterColumns.push(fixedColumn);
|
|
84
|
+
}
|
|
85
|
+
if (toggle) {
|
|
86
|
+
toggleColumns.push(fixedColumn);
|
|
87
|
+
}
|
|
88
|
+
return fixedColumn;
|
|
89
|
+
});
|
|
90
|
+
return { columns: updatedColumns, searchColumns, excelColumns, filterColumns, toggleColumns };
|
|
59
91
|
};
|
|
60
|
-
const tableHook = useTable(() => propsRef.current, () => props.paging, getColumnOption);
|
|
61
|
-
const getIconRef = useRef(new UT.GetSvg());
|
|
62
|
-
const getIcon = getIconRef.current.getIcon;
|
|
63
92
|
const DragColumns = UT.useDrag((dragIndex, dropIndex, reOrder) => {
|
|
64
93
|
const newColumns = reOrder(props.columns || [], dragIndex, dropIndex);
|
|
65
94
|
if (props.onChangeColumns) {
|
|
@@ -71,11 +100,9 @@ const AIOTable = (props) => {
|
|
|
71
100
|
return sort.getValue;
|
|
72
101
|
}
|
|
73
102
|
return (row) => {
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
const cellValue = tableHook.getCellValue(cellDetail, value);
|
|
78
|
-
if (type === 'date') {
|
|
103
|
+
const { type = 'text' } = column;
|
|
104
|
+
const cellValue = tableHook.getCellValue({ row, column, rowIndex: 0 });
|
|
105
|
+
if (type === 'date' || type === 'jalaliDate') {
|
|
79
106
|
const DATE = new AIODate();
|
|
80
107
|
try {
|
|
81
108
|
return DATE.getTime(cellValue);
|
|
@@ -91,15 +118,14 @@ const AIOTable = (props) => {
|
|
|
91
118
|
let sorts = [];
|
|
92
119
|
for (let i = 0; i < columns.length; i++) {
|
|
93
120
|
const column = columns[i];
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
const sortValue = getColumnOption('sort', cellDetail);
|
|
121
|
+
const columnId = column.id;
|
|
122
|
+
const sortValue = column.sort;
|
|
97
123
|
const sort = sortValue === true ? { sortId: columnId } : sortValue;
|
|
98
124
|
if (!sort) {
|
|
99
125
|
continue;
|
|
100
126
|
}
|
|
101
127
|
let { active = false, dir = 'dec', sortId } = sort;
|
|
102
|
-
let sortItem = { dir, title: sort.title ||
|
|
128
|
+
let sortItem = { dir, title: sort.title || column.title, sortId, active, getValue: getGetValue(sort, column) };
|
|
103
129
|
sorts.push(sortItem);
|
|
104
130
|
}
|
|
105
131
|
return sorts;
|
|
@@ -111,41 +137,7 @@ const AIOTable = (props) => {
|
|
|
111
137
|
onChangeRows: props.onChange,
|
|
112
138
|
onChangeSort: props.onChangeSort,
|
|
113
139
|
});
|
|
114
|
-
function getColumns() {
|
|
115
|
-
let { columns = [] } = props;
|
|
116
|
-
let searchColumns = [], excelColumns = [], filterColumns = [], toggleColumns = [];
|
|
117
|
-
let updatedColumns = columns.map((column, i) => {
|
|
118
|
-
const cellDetail = tableHook.getCellDetail({ column });
|
|
119
|
-
const filter = getColumnOption('filter', cellDetail);
|
|
120
|
-
const search = getColumnOption('search', cellDetail);
|
|
121
|
-
const excel = getColumnOption('excel', cellDetail);
|
|
122
|
-
const toggle = getColumnOption('toggle', cellDetail);
|
|
123
|
-
const id = getColumnOption('id', cellDetail);
|
|
124
|
-
if (id === undefined) {
|
|
125
|
-
console.error(`aio-table error => missing column id in props.columns[${i}]`);
|
|
126
|
-
}
|
|
127
|
-
if (search) {
|
|
128
|
-
searchColumns.push(column);
|
|
129
|
-
}
|
|
130
|
-
if (excel) {
|
|
131
|
-
excelColumns.push(column);
|
|
132
|
-
}
|
|
133
|
-
if (filter) {
|
|
134
|
-
filterColumns.push(column);
|
|
135
|
-
}
|
|
136
|
-
if (toggle) {
|
|
137
|
-
toggleColumns.push(column);
|
|
138
|
-
}
|
|
139
|
-
return column;
|
|
140
|
-
});
|
|
141
|
-
setSearchColumns(searchColumns);
|
|
142
|
-
setExcelColumns(excelColumns);
|
|
143
|
-
setFilterColumns(filterColumns);
|
|
144
|
-
setToggleColumns(toggleColumns);
|
|
145
|
-
return updatedColumns;
|
|
146
|
-
}
|
|
147
140
|
useEffect(() => {
|
|
148
|
-
const columns = getColumns();
|
|
149
141
|
sortHook.setSorts(getSorts(columns));
|
|
150
142
|
}, []);
|
|
151
143
|
useEffect(() => {
|
|
@@ -153,28 +145,6 @@ const AIOTable = (props) => {
|
|
|
153
145
|
pagingHook.changePaging(props.paging);
|
|
154
146
|
}
|
|
155
147
|
}, [JSON.stringify(props.paging)]);
|
|
156
|
-
function add() {
|
|
157
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
-
if (!props.onAdd) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const res = yield props.onAdd();
|
|
162
|
-
if (res && props.onChange) {
|
|
163
|
-
props.onChange([res, ...props.value]);
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
function remove(row, index) {
|
|
168
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
-
if (!props.onRemove) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
const res = yield props.onRemove({ row, rowIndex: index });
|
|
173
|
-
if (res === true && props.onChange) {
|
|
174
|
-
props.onChange(props.value.filter((o) => o._id !== row._id));
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
148
|
function exportToExcel() {
|
|
179
149
|
let list = [];
|
|
180
150
|
if (typeof props.excel === 'function') {
|
|
@@ -182,16 +152,12 @@ const AIOTable = (props) => {
|
|
|
182
152
|
}
|
|
183
153
|
else {
|
|
184
154
|
for (let rowIndex = 0; rowIndex < props.value.length; rowIndex++) {
|
|
185
|
-
const isFirst = rowIndex === 0;
|
|
186
|
-
const isLast = rowIndex === props.value.length - 1;
|
|
187
155
|
let row = props.value[rowIndex], json = {};
|
|
188
156
|
for (let j = 0; j < excelColumns.length; j++) {
|
|
189
157
|
const column = excelColumns[j];
|
|
190
|
-
const
|
|
191
|
-
const excel = getColumnOption('excel', cellDetail);
|
|
158
|
+
const { excel, title } = column;
|
|
192
159
|
let key = '';
|
|
193
160
|
if (excel === true) {
|
|
194
|
-
const title = getColumnOption('title', cellDetail);
|
|
195
161
|
if (typeof title === 'string') {
|
|
196
162
|
key = title;
|
|
197
163
|
}
|
|
@@ -205,8 +171,7 @@ const AIOTable = (props) => {
|
|
|
205
171
|
else {
|
|
206
172
|
continue;
|
|
207
173
|
}
|
|
208
|
-
|
|
209
|
-
json[key] = tableHook.getCellValue(cellDetail, value, '');
|
|
174
|
+
json[key] = tableHook.getCellValue({ row, rowIndex, column });
|
|
210
175
|
}
|
|
211
176
|
list.push(json);
|
|
212
177
|
}
|
|
@@ -220,15 +185,11 @@ const AIOTable = (props) => {
|
|
|
220
185
|
if (!searchColumns.length || !searchValue) {
|
|
221
186
|
return rows;
|
|
222
187
|
}
|
|
223
|
-
|
|
224
|
-
return UT.Search(rows, searchValue, (row) => {
|
|
225
|
-
const { isFirst, isLast, rowIndex } = rowsIndexDic[(row)._id];
|
|
188
|
+
return UT.Search(rows, searchValue, (row, rowIndex) => {
|
|
226
189
|
let str = '';
|
|
227
190
|
for (let i = 0; i < searchColumns.length; i++) {
|
|
228
191
|
let column = searchColumns[i];
|
|
229
|
-
|
|
230
|
-
const value = getColumnOption('value', cellDetail);
|
|
231
|
-
let cellValue = tableHook.getCellValue(cellDetail, value, '');
|
|
192
|
+
let cellValue = tableHook.getCellValue({ row, rowIndex, column });
|
|
232
193
|
if (cellValue) {
|
|
233
194
|
str += cellValue + ' ';
|
|
234
195
|
}
|
|
@@ -238,11 +199,6 @@ const AIOTable = (props) => {
|
|
|
238
199
|
}
|
|
239
200
|
function getRows() {
|
|
240
201
|
const rows = props.value;
|
|
241
|
-
const rowsIndexDic = {};
|
|
242
|
-
for (let i = 0; i < props.value.length; i++) {
|
|
243
|
-
rowsIndexDic[props.value[i]._id] = { rowIndex: i, isFirst: i === 0, isLast: i === rows.length - 1 };
|
|
244
|
-
}
|
|
245
|
-
setRowsIndexDic(rowsIndexDic);
|
|
246
202
|
let searchedRows = getSearchedRows(rows);
|
|
247
203
|
let sortedRows = sortHook.getSortedRows(searchedRows);
|
|
248
204
|
let pagedRows = pagingHook.getPagedRows(sortedRows);
|
|
@@ -256,50 +212,70 @@ const AIOTable = (props) => {
|
|
|
256
212
|
props.onSearch(searchValue);
|
|
257
213
|
}
|
|
258
214
|
}
|
|
215
|
+
const { columns, searchColumns, excelColumns, filterColumns, toggleColumns } = useMemo(() => getColumns(), [props.columns]);
|
|
259
216
|
let ROWS = getRows();
|
|
260
217
|
const context = {
|
|
261
218
|
rootProps: props, excelColumns, filterColumns, tableHook, sortHook, ROWS, toggleColumns, pagingHook,
|
|
262
|
-
|
|
219
|
+
search, exportToExcel, DragColumns, popup, columns
|
|
263
220
|
};
|
|
264
221
|
return (_jsxs(Provider, { value: context, children: [_jsx(AIOTableComponent, Object.assign({}, props)), popup.render()] }));
|
|
265
222
|
};
|
|
266
223
|
export default AIOTable;
|
|
267
224
|
const AIOTableComponent = (props) => {
|
|
268
225
|
const { pagingHook, rootProps } = useProvider();
|
|
269
|
-
const {
|
|
226
|
+
const { filter } = rootProps;
|
|
270
227
|
let [dom] = useState(createRef());
|
|
271
|
-
const { gap = [
|
|
228
|
+
const { gap = [] } = props;
|
|
272
229
|
let attrs = UT.AddToAttrs(props.attrs, { className: ['aio-table', props.className], style: Object.assign({ gap: gap[1] }, props.style), attrs: { ref: dom } });
|
|
273
230
|
const filterHook = useFilter();
|
|
274
|
-
return (_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, { filterHook: filterHook }),
|
|
231
|
+
return (_jsxs("div", Object.assign({}, attrs, { children: [_jsx(TableToolbar, { filterHook: filterHook }), !!filter && filterHook.renderTags(), _jsxs("div", { className: 'aio-table-unit aio-table-scroll', style: { gap: gap[1] }, children: [_jsx(TableHeader, {}), _jsx(TableRows, {})] }), pagingHook.render()] })));
|
|
275
232
|
};
|
|
276
233
|
const TableRows = () => {
|
|
277
234
|
let { ROWS, rootProps } = useProvider();
|
|
278
|
-
let {
|
|
279
|
-
const { before: rowBefore = () => null, after: rowAfter = () => null, template: rowTemplate, } = rowOption;
|
|
235
|
+
let { rowBefore = () => null, rowAfter = () => null, rowTemplate, rowsTemplate, placeholder = 'there is not any items' } = rootProps;
|
|
280
236
|
let rows = ROWS.pagedRows || [];
|
|
281
237
|
let content;
|
|
282
238
|
if (rowsTemplate) {
|
|
283
239
|
content = rowsTemplate(rows);
|
|
284
240
|
}
|
|
285
241
|
else if (rows.length) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
242
|
+
if (rootProps.onSwap) {
|
|
243
|
+
content = (_jsx(UT.DragAndDrop, { data: rows, getId: (o) => {
|
|
244
|
+
let { id = 'ailr' + Math.round(Math.random() * 10000000) } = o;
|
|
245
|
+
o._id = o._id === undefined ? id : o._id;
|
|
246
|
+
return o._id;
|
|
247
|
+
}, getContent: (o, { index, id }) => {
|
|
248
|
+
o._id = o._id === undefined ? id : o._id;
|
|
249
|
+
const rowDetail = { row: o, rowIndex: index };
|
|
250
|
+
let Row;
|
|
251
|
+
if (rowTemplate) {
|
|
252
|
+
Row = rowTemplate(rowDetail);
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
Row = _jsx(TableRow, { rowDetail: rowDetail }, o._id);
|
|
256
|
+
}
|
|
257
|
+
return (_jsxs(Fragment, { children: [rowBefore(rowDetail), Row, rowAfter(rowDetail)] }, o._id));
|
|
258
|
+
}, onChange: (newRows) => {
|
|
259
|
+
if (rootProps.onChange) {
|
|
260
|
+
rootProps.onChange(newRows);
|
|
261
|
+
}
|
|
262
|
+
} }));
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
content = rows.map((o, i) => {
|
|
266
|
+
let { id = 'ailr' + Math.round(Math.random() * 10000000) } = o;
|
|
267
|
+
o._id = o._id === undefined ? id : o._id;
|
|
268
|
+
const rowDetail = { row: o, rowIndex: i };
|
|
269
|
+
let Row;
|
|
270
|
+
if (rowTemplate) {
|
|
271
|
+
Row = rowTemplate(rowDetail);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
Row = _jsx(TableRow, { rowDetail: rowDetail }, o._id);
|
|
275
|
+
}
|
|
276
|
+
return (_jsxs(Fragment, { children: [rowBefore(rowDetail), Row, rowAfter(rowDetail)] }, o._id));
|
|
277
|
+
});
|
|
278
|
+
}
|
|
303
279
|
}
|
|
304
280
|
else if (placeholder) {
|
|
305
281
|
content = _jsx("div", { style: { width: '100%', textAlign: 'center', padding: 12, boxSizing: 'border-box' }, children: placeholder });
|
|
@@ -307,253 +283,291 @@ const TableRows = () => {
|
|
|
307
283
|
else {
|
|
308
284
|
return null;
|
|
309
285
|
}
|
|
310
|
-
const { gap = [
|
|
286
|
+
const { gap = [] } = rootProps;
|
|
311
287
|
return _jsx("div", { className: 'aio-table-rows', style: { gap: gap[1] }, children: content });
|
|
312
288
|
};
|
|
313
289
|
const TableToolbar = ({ filterHook }) => {
|
|
314
|
-
let {
|
|
315
|
-
let { toolbarAttrs, toolbar,
|
|
290
|
+
let { exportToExcel, search, rootProps, excelColumns, toggleColumns, sortHook, columns } = useProvider();
|
|
291
|
+
let { toolbarAttrs, toolbar, onSearch, value, onChangeColumns, fa, filter, inlineSort } = rootProps;
|
|
316
292
|
const columnsRef = useRef(columns);
|
|
317
293
|
columnsRef.current = columns;
|
|
318
294
|
toolbarAttrs = UT.AddToAttrs(toolbarAttrs, { className: 'aio-table-toolbar' });
|
|
319
|
-
if (!
|
|
295
|
+
if (!toolbar && !onSearch && !sortHook.sorts.length && !excelColumns.length && !toggleColumns.length && !filter) {
|
|
320
296
|
return null;
|
|
321
297
|
}
|
|
322
298
|
function getAddText() {
|
|
323
299
|
let { addText } = rootProps;
|
|
324
300
|
if (!rootProps.addText) {
|
|
325
|
-
return getIcon('mdiPlusThick', 0.8);
|
|
301
|
+
return new UT.GetSvg('em').getIcon('mdiPlusThick', 0.8);
|
|
326
302
|
}
|
|
327
303
|
return typeof addText === 'function' ? addText(value) : addText;
|
|
328
304
|
}
|
|
329
|
-
|
|
330
|
-
const columns = columnsRef.current || [];
|
|
331
|
-
const column = columns.find((o) => o.id === columnId);
|
|
332
|
-
return getColumnOption(key, tableHook.getCellDetail({ column }));
|
|
333
|
-
};
|
|
334
|
-
return (_jsxs("div", Object.assign({}, toolbarAttrs, { children: [toolbar && _jsx("div", { className: 'aio-table-toolbar-content', children: typeof toolbar === 'function' ? toolbar() : toolbar }), (!!formFilter || !!columnsFilter) && filterHook.renderButton({ className: 'aio-table-toolbar-button' }), !!onSearch && _jsx(AIOInput, { type: 'text', className: 'aio-table-search', onChange: (value) => search(value), after: getIcon('mdiMagnify', 0.7) }), !!sortHook.sorts.length && sortHook.renderSortButton({ className: 'aio-table-toolbar-button aio-table-sort-button' }), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button aio-table-excel-button', onClick: () => exportToExcel(), children: getIcon('mdiFileExcel', 0.8) }), !!toggleColumns.length &&
|
|
305
|
+
return (_jsxs("div", Object.assign({}, toolbarAttrs, { children: [toolbar && _jsx("div", { className: 'aio-table-toolbar-content', children: typeof toolbar === 'function' ? toolbar() : toolbar }), !!filter && filterHook.renderButton(), !!onSearch && _jsx(AIOInput, { type: 'text', className: 'aio-table-search', onChange: (value) => search(value), after: new UT.GetSvg('em').getIcon('mdiMagnify', 0.7) }), !!sortHook.sorts.length && !inlineSort && sortHook.renderSortButton({ className: 'aio-table-toolbar-button aio-table-sort-button' }), !!excelColumns.length && _jsx("div", { className: 'aio-table-toolbar-button aio-table-excel-button', onClick: () => exportToExcel(), children: new UT.GetSvg('em').getIcon('mdiFileExcel', 0.8) }), !!toggleColumns.length &&
|
|
335
306
|
_jsx(AISelect, { popover: {
|
|
336
307
|
header: { title: fa ? 'نمایش ستون ها' : 'Show Columns', onClose: false },
|
|
337
308
|
headerAttrs: { className: 'aio-table-dropdown-header' },
|
|
338
309
|
limitTo: '.aio-table'
|
|
339
|
-
}, className: 'aio-table-toolbar-button aio-table-toggle-button', text: getIcon('mdiEye', 0.8), justify: true, hideTags: true, options: toggleColumns.map((o) => (Object.assign(
|
|
340
|
-
text: (column) =>
|
|
341
|
-
checked: (column) =>
|
|
310
|
+
}, className: 'aio-table-toolbar-button aio-table-toggle-button', text: new UT.GetSvg('em').getIcon('mdiEye', 0.8), justify: true, hideTags: true, options: toggleColumns.map((o) => (Object.assign({}, o))), caret: false, option: {
|
|
311
|
+
text: (column) => column.title,
|
|
312
|
+
checked: (column) => !!column.show,
|
|
342
313
|
onClick: (column) => {
|
|
314
|
+
console.log(toggleColumns);
|
|
343
315
|
if (!onChangeColumns) {
|
|
344
316
|
return;
|
|
345
317
|
}
|
|
346
318
|
const columns = columnsRef.current || [];
|
|
347
|
-
|
|
319
|
+
const newColumns = columns.map((o) => column.id === o.id ? Object.assign(Object.assign({}, o), { show: !o.show }) : o);
|
|
320
|
+
onChangeColumns(newColumns);
|
|
348
321
|
},
|
|
322
|
+
show: () => true,
|
|
323
|
+
justify: () => false,
|
|
349
324
|
close: () => false
|
|
350
|
-
} })
|
|
325
|
+
} })] })));
|
|
351
326
|
};
|
|
352
327
|
const TableHeader = () => {
|
|
353
|
-
let { rootProps,
|
|
354
|
-
let { headerAttrs,
|
|
328
|
+
let { rootProps, columns } = useProvider();
|
|
329
|
+
let { headerAttrs, gap = [] } = rootProps;
|
|
355
330
|
headerAttrs = UT.AddToAttrs(headerAttrs, { className: 'aio-table-header', style: { gap: gap[0] } });
|
|
356
331
|
let Titles = columns.map((column, i) => {
|
|
357
|
-
const columnId =
|
|
332
|
+
const columnId = column.id;
|
|
358
333
|
return _jsx(TableTitle, { column: column, isLast: i === columns.length - 1, colIndex: i }, columnId);
|
|
359
334
|
});
|
|
360
|
-
|
|
361
|
-
return _jsxs("div", Object.assign({}, headerAttrs, { children: [Titles, RemoveTitle] }));
|
|
335
|
+
return _jsx("div", Object.assign({}, headerAttrs, { children: Titles }));
|
|
362
336
|
};
|
|
363
337
|
const TableTitle = (p) => {
|
|
364
338
|
const { column, colIndex } = p;
|
|
365
|
-
let { tableHook, DragColumns,
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
339
|
+
let { tableHook, DragColumns, sortHook, rootProps } = useProvider();
|
|
340
|
+
const { show = true, title } = column;
|
|
341
|
+
if (!show) {
|
|
368
342
|
return null;
|
|
369
343
|
}
|
|
370
|
-
const title = getColumnOption('title', cellDetails);
|
|
371
344
|
const attrs = Object.assign(Object.assign(Object.assign({}, tableHook.getTitleAttrs(column)), DragColumns.getDragAttrs(colIndex)), DragColumns.getDropAttrs(colIndex));
|
|
372
|
-
return
|
|
345
|
+
return (_jsxs("div", Object.assign({}, attrs, { children: [title, !!rootProps.inlineSort && sortHook.renderSortArrow(sortHook.getSortByColumn(column), true)] })));
|
|
373
346
|
};
|
|
374
347
|
const TableRow = (props) => {
|
|
375
348
|
const { rowDetail } = props;
|
|
376
349
|
const { row, rowIndex } = rowDetail;
|
|
377
350
|
const rowId = row._id;
|
|
378
|
-
let {
|
|
379
|
-
const { columns = [] } = rootProps;
|
|
380
|
-
const isOdd = rowIndex % 2 === 0;
|
|
351
|
+
let { rootProps, tableHook, columns } = useProvider();
|
|
381
352
|
function getCells() {
|
|
382
353
|
return columns.map((column) => {
|
|
383
|
-
|
|
354
|
+
const { show = true } = column;
|
|
355
|
+
if (!show) {
|
|
384
356
|
return null;
|
|
385
357
|
}
|
|
386
|
-
const
|
|
387
|
-
const columnId = getColumnOption('id', cellDetail);
|
|
358
|
+
const columnId = column.id;
|
|
388
359
|
const key = rowId + ' ' + columnId;
|
|
389
|
-
|
|
390
|
-
const cellValue = tableHook.getCellValue(cellDetail, value);
|
|
391
|
-
return (_jsx(TableCell, { cellDetail: cellDetail, cellValue: cellValue, isOdd: isOdd }, key));
|
|
360
|
+
return (_jsx(TableCell, { row: row, rowIndex: rowIndex, column: column }, key));
|
|
392
361
|
});
|
|
393
362
|
}
|
|
394
|
-
|
|
395
|
-
return (_jsx(_Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getRowAttrs(props.rowDetail, isOdd), { children: [getCells(), onRemove ? _jsx("button", { className: 'aio-table-remove', onClick: () => remove(row, rowIndex), children: getIcon('mdiClose', 0.8) }) : null] }), rowId) }));
|
|
363
|
+
return (_jsx("div", Object.assign({}, tableHook.getRowAttrs({ row, rowIndex }), { children: getCells() }), rowId));
|
|
396
364
|
};
|
|
397
365
|
const TableCell = (props) => {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const { tableHook
|
|
401
|
-
const {
|
|
402
|
-
|
|
403
|
-
if (type === '
|
|
404
|
-
cellValue =
|
|
366
|
+
var _a, _b;
|
|
367
|
+
let { row, column, rowIndex } = props;
|
|
368
|
+
const { tableHook } = useProvider();
|
|
369
|
+
const { type = 'text', id } = column;
|
|
370
|
+
let cellValue = tableHook.getCellValue({ row, rowIndex, column });
|
|
371
|
+
if (type === 'date') {
|
|
372
|
+
cellValue = new AIODate().toObject(cellValue);
|
|
373
|
+
}
|
|
374
|
+
else if (type === 'jalaliDate') {
|
|
375
|
+
cellValue = new AIODate().toObject(cellValue, true);
|
|
405
376
|
}
|
|
406
|
-
const before = getColumnOption('before', cellDetail);
|
|
407
|
-
const after = getColumnOption('after', cellDetail);
|
|
408
|
-
const subtext = getColumnOption('subtext', cellDetail);
|
|
409
377
|
const rowId = row._id;
|
|
410
|
-
const colId =
|
|
378
|
+
const colId = id;
|
|
411
379
|
const getTemplateValue = () => {
|
|
412
|
-
|
|
413
|
-
if (typeof column.template === 'function') {
|
|
414
|
-
return column.template(cellDetail);
|
|
415
|
-
}
|
|
416
|
-
if (typeof column.template === 'string' && getValue[column.template]) {
|
|
417
|
-
return getValue[column.template](cellDetail);
|
|
418
|
-
}
|
|
419
|
-
if ((columnOption || {}).template) {
|
|
420
|
-
return columnOption.template(cellDetail);
|
|
421
|
-
}
|
|
422
|
-
const pattern = getColumnOption('pattern', cellDetail);
|
|
423
|
-
if (pattern && cellValue) {
|
|
380
|
+
if (column.type === 'date') {
|
|
424
381
|
try {
|
|
425
|
-
|
|
426
|
-
return new AIODate().getDateByPattern(cellValue, pattern);
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
return pattern.replace('{value}', cellValue);
|
|
430
|
-
}
|
|
382
|
+
cellValue = new AIODate().toObject(cellValue);
|
|
431
383
|
}
|
|
432
384
|
catch (_a) { }
|
|
433
385
|
}
|
|
386
|
+
else if (column.type === 'jalaliDate') {
|
|
387
|
+
try {
|
|
388
|
+
cellValue = new AIODate().toObject(cellValue, true);
|
|
389
|
+
}
|
|
390
|
+
catch (_b) { }
|
|
391
|
+
}
|
|
392
|
+
const cellTemplateValue = tableHook.getCellTemplateValue({ row, column, rowIndex, key: 'template' });
|
|
393
|
+
if (cellTemplateValue !== undefined) {
|
|
394
|
+
return cellTemplateValue;
|
|
395
|
+
}
|
|
396
|
+
return tableHook.getCellPatternValue({ row, column, rowIndex });
|
|
434
397
|
};
|
|
435
398
|
const templateValue = getTemplateValue();
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
const
|
|
399
|
+
const before = tableHook.getCellTemplateValue({ row, column, rowIndex, key: 'before' });
|
|
400
|
+
const after = tableHook.getCellTemplateValue({ row, column, rowIndex, key: 'after' });
|
|
401
|
+
const subtext = tableHook.getCellTemplateValue({ row, column, rowIndex, key: 'subtext' });
|
|
439
402
|
let content;
|
|
403
|
+
if (column.template) {
|
|
404
|
+
content = tableHook.getCellTemplateValue({ row, column, rowIndex, key: 'template' });
|
|
405
|
+
}
|
|
406
|
+
else if (column.pattern) {
|
|
407
|
+
content = tableHook.getCellPatternValue({ row, column, rowIndex });
|
|
408
|
+
}
|
|
440
409
|
if (templateValue !== undefined) {
|
|
441
410
|
content = templateValue;
|
|
442
411
|
}
|
|
412
|
+
else if (column.type === 'number') {
|
|
413
|
+
content = UT.SplitNumber(cellValue);
|
|
414
|
+
}
|
|
443
415
|
else {
|
|
444
416
|
content = cellValue;
|
|
445
417
|
}
|
|
446
|
-
|
|
418
|
+
content = content !== undefined && content !== null && content !== '' ? _jsxs(_Fragment, { children: [(_a = column.prefix) !== null && _a !== void 0 ? _a : null, content, (_b = column.affix) !== null && _b !== void 0 ? _b : null] }) : content;
|
|
419
|
+
return (_jsx(Fragment, { children: _jsxs("div", Object.assign({}, tableHook.getCellAttrs({ row, column, rowIndex }), { children: [before !== undefined && _jsx("div", { className: "aio-table-cell-before", children: before }), _jsx("div", { className: `aio-table-cell-value${subtext !== undefined ? ' has-subtext' : ''}`, "data-subtext": subtext, children: content }), after !== undefined && _jsx("div", { className: "aio-table-cell-after", children: after })] })) }, rowId + ' ' + colId));
|
|
447
420
|
};
|
|
448
|
-
const useTable = (getProps, getPaging
|
|
449
|
-
const
|
|
450
|
-
const { onSwap, onChange, value: rows } = getProps();
|
|
451
|
-
const newRows = reOrder(rows, dragIndex, dropIndex);
|
|
452
|
-
const from = rows[dragIndex];
|
|
453
|
-
const to = rows[dropIndex];
|
|
454
|
-
if (typeof onSwap === 'function') {
|
|
455
|
-
onSwap(newRows, from, to);
|
|
456
|
-
}
|
|
457
|
-
else if (onChange) {
|
|
458
|
-
onChange(newRows);
|
|
459
|
-
}
|
|
460
|
-
}, 'aio-table-row');
|
|
461
|
-
const getCellValue = (cellDetail, cellValue, def) => {
|
|
462
|
-
const { getValue = {} } = getProps();
|
|
421
|
+
const useTable = (getProps, getPaging) => {
|
|
422
|
+
const fixIndexByPaging = (rowIndex) => {
|
|
463
423
|
const paging = getPaging();
|
|
464
424
|
if (paging) {
|
|
465
425
|
let { number, size } = paging;
|
|
466
|
-
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
}
|
|
476
|
-
else if (cellValue.indexOf('row.') !== -1) {
|
|
426
|
+
return rowIndex + ((number - 1) * size);
|
|
427
|
+
}
|
|
428
|
+
return rowIndex;
|
|
429
|
+
};
|
|
430
|
+
const getCellValue = (p) => {
|
|
431
|
+
let { row, column, rowIndex } = p;
|
|
432
|
+
if (typeof column.value === 'string') {
|
|
433
|
+
let result = column.value;
|
|
434
|
+
if (result.indexOf('row.') !== -1) {
|
|
477
435
|
try {
|
|
478
|
-
eval(`result = ${
|
|
479
|
-
}
|
|
480
|
-
catch (_a) {
|
|
481
|
-
result = '';
|
|
436
|
+
eval(`result = ${result}`);
|
|
482
437
|
}
|
|
438
|
+
catch (_a) { }
|
|
483
439
|
}
|
|
484
|
-
return result
|
|
440
|
+
return result;
|
|
485
441
|
}
|
|
486
|
-
if (
|
|
487
|
-
return
|
|
442
|
+
if (typeof column.value === 'function') {
|
|
443
|
+
return column.value({ row, rowIndex, column });
|
|
488
444
|
}
|
|
489
|
-
if (
|
|
490
|
-
|
|
445
|
+
if (typeof column.value === 'undefined') {
|
|
446
|
+
const { columnOption } = getProps();
|
|
447
|
+
if (columnOption === null || columnOption === void 0 ? void 0 : columnOption.value) {
|
|
448
|
+
return columnOption.value({ row, column, rowIndex: fixIndexByPaging(rowIndex) });
|
|
449
|
+
}
|
|
491
450
|
}
|
|
492
|
-
return cellValue === undefined ? def : cellValue;
|
|
493
451
|
};
|
|
494
|
-
|
|
452
|
+
const getTemplateParam = (p) => {
|
|
453
|
+
const value = getCellValue(p);
|
|
454
|
+
let dateObject = { year: 0, month: 0, day: 0, hour: 0, minute: 0, second: 0 };
|
|
455
|
+
if (p.column.type === 'date') {
|
|
456
|
+
try {
|
|
457
|
+
dateObject = new AIODate().toObject(value);
|
|
458
|
+
}
|
|
459
|
+
catch (_a) { }
|
|
460
|
+
}
|
|
461
|
+
else if (p.column.type === 'jalaliDate') {
|
|
462
|
+
try {
|
|
463
|
+
dateObject = new AIODate().toObject(value, true);
|
|
464
|
+
}
|
|
465
|
+
catch (_b) { }
|
|
466
|
+
}
|
|
467
|
+
const rowIndex = fixIndexByPaging(p.rowIndex);
|
|
468
|
+
const change = (newRow) => changeCell(p.row, newRow);
|
|
469
|
+
return { value, dateObject, rowIndex, row: p.row, column: p.column, change };
|
|
470
|
+
};
|
|
471
|
+
const getCellTemplateValue = (p) => {
|
|
472
|
+
let { row, rowIndex, column, key } = p;
|
|
473
|
+
const { templates } = getProps();
|
|
474
|
+
if (!column[key]) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const templateParam = getTemplateParam({ row, column, rowIndex });
|
|
478
|
+
if (typeof column[key] === 'function') {
|
|
479
|
+
const fn = column[key];
|
|
480
|
+
return fn(templateParam);
|
|
481
|
+
}
|
|
482
|
+
if (typeof column[key] === 'string') {
|
|
483
|
+
if (templates && templates[column[key]]) {
|
|
484
|
+
const fn = templates[column[key]];
|
|
485
|
+
return fn(templateParam);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
return column[key];
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
const getCellPatternValue = (p) => {
|
|
493
|
+
let { row, rowIndex, column } = p;
|
|
494
|
+
const cellValue = getCellValue({ row, column, rowIndex });
|
|
495
|
+
const { pattern } = column;
|
|
496
|
+
if (pattern && cellValue !== undefined) {
|
|
497
|
+
try {
|
|
498
|
+
if (column.type === 'date') {
|
|
499
|
+
return new AIODate().getDateByPattern(cellValue, pattern);
|
|
500
|
+
}
|
|
501
|
+
else if (column.type === 'jalaliDate') {
|
|
502
|
+
return new AIODate().getDateByPattern(cellValue, pattern, true);
|
|
503
|
+
}
|
|
504
|
+
else {
|
|
505
|
+
return pattern.replace('{value}', cellValue);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
catch (_a) { }
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
function changeCell(row, newRow) {
|
|
495
512
|
if (newRow) { }
|
|
496
513
|
const { onChange, value: propsValue } = getProps();
|
|
497
514
|
if (!onChange) {
|
|
498
515
|
return;
|
|
499
516
|
}
|
|
500
|
-
const rowId =
|
|
517
|
+
const rowId = row._id;
|
|
501
518
|
onChange(propsValue.map((o) => o._id !== rowId ? o : newRow));
|
|
502
519
|
}
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
const
|
|
506
|
-
const
|
|
507
|
-
const
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
const { column } = cellDetail;
|
|
512
|
-
const attrs = getCellValue(cellDetail, column.attrs, {});
|
|
513
|
-
const justify = getColumnOption('justify', cellDetail);
|
|
514
|
-
const width = getColumnOption('width', cellDetail);
|
|
515
|
-
const minWidth = getColumnOption('minWidth', cellDetail);
|
|
520
|
+
const getCellAttrs = (p) => {
|
|
521
|
+
const { row, rowIndex, column } = p;
|
|
522
|
+
const { cellAttrs } = getProps();
|
|
523
|
+
const cellValue = getCellValue({ row, column, rowIndex });
|
|
524
|
+
const propsCellAttrs = cellAttrs ? cellAttrs({ row, rowIndex: fixIndexByPaging(rowIndex), column, value: cellValue }) : {};
|
|
525
|
+
const columnCellAttrs = column.cellAttrs ? column.cellAttrs({ row, rowIndex: fixIndexByPaging(rowIndex), column, value: cellValue }) : {};
|
|
526
|
+
const attrs = Object.assign(Object.assign({}, propsCellAttrs), columnCellAttrs);
|
|
527
|
+
const { justify, width, minWidth } = column;
|
|
516
528
|
const className = `aio-table-cell` + (justify ? ` aio-table-cell-justify` : '');
|
|
517
529
|
let isNumber = false;
|
|
518
530
|
try {
|
|
519
|
-
if (
|
|
531
|
+
if (typeof cellValue === 'number' || column.type === 'number') {
|
|
532
|
+
isNumber = true;
|
|
533
|
+
}
|
|
534
|
+
else if (typeof cellValue === 'string' && !isNaN(+cellValue)) {
|
|
520
535
|
isNumber = true;
|
|
521
536
|
}
|
|
522
537
|
}
|
|
523
538
|
catch (_a) { }
|
|
524
539
|
const style = { width, minWidth, flex: width ? undefined : 1, direction: isNumber ? 'ltr' : undefined };
|
|
525
|
-
|
|
526
|
-
style.background = isOdd ? striped[0] : striped[1];
|
|
527
|
-
}
|
|
528
|
-
return UT.AddToAttrs(attrs, { className: [className, isOdd ? 'aio-table-cell-odd' : 'aio-table-cell-even'], style, attrs: { title: typeof cellValue === 'string' ? cellValue : undefined } });
|
|
540
|
+
return UT.AddToAttrs(attrs, { className: [className, rowIndex % 2 === 0 ? 'aio-table-cell-odd' : 'aio-table-cell-even'], style, attrs: { title: typeof cellValue === 'string' ? cellValue : undefined } });
|
|
529
541
|
};
|
|
530
542
|
const getTitleAttrs = (column) => {
|
|
531
|
-
const
|
|
532
|
-
const
|
|
533
|
-
const
|
|
534
|
-
const
|
|
535
|
-
const
|
|
543
|
+
const { justify, width, minWidth, title } = column;
|
|
544
|
+
const { titleAttrs } = getProps();
|
|
545
|
+
const propsTitleAttrs = titleAttrs ? titleAttrs(column) : {};
|
|
546
|
+
const columnTitleAttrs = column.titleAttrs ? column.titleAttrs(column) : {};
|
|
547
|
+
const attrs = Object.assign(Object.assign({}, propsTitleAttrs), columnTitleAttrs);
|
|
536
548
|
const className = `aio-table-title` + (justify ? ` aio-table-title-justify` : '');
|
|
537
549
|
const style = { width, minWidth, flex: width ? undefined : 1 };
|
|
538
|
-
const title = getColumnOption('title', cellDetail);
|
|
539
550
|
return UT.AddToAttrs(attrs, { className, style, attrs: { title: typeof title === 'string' ? title : undefined } });
|
|
540
551
|
};
|
|
541
|
-
const getRowAttrs = (
|
|
542
|
-
const {
|
|
543
|
-
const {
|
|
544
|
-
const attrs = rowAttrs ? rowAttrs(
|
|
545
|
-
let obj = UT.AddToAttrs(attrs, { className: ['aio-table-row',
|
|
552
|
+
const getRowAttrs = (p) => {
|
|
553
|
+
const { row, rowIndex } = p;
|
|
554
|
+
const { onSwap, gap = [], rowAttrs } = getProps();
|
|
555
|
+
const attrs = rowAttrs ? rowAttrs({ row, rowIndex }) : {};
|
|
556
|
+
let obj = UT.AddToAttrs(attrs, { className: ['aio-table-row', rowIndex % 2 === 0 ? 'aio-table-row-odd' : 'aio-table-row-even'], style: { gap: gap[0] } });
|
|
546
557
|
if (onSwap) {
|
|
547
|
-
obj = Object.assign(
|
|
558
|
+
obj = Object.assign({}, obj);
|
|
548
559
|
}
|
|
549
560
|
return obj;
|
|
550
561
|
};
|
|
551
|
-
return { getCellValue, getCellAttrs, getTitleAttrs, getRowAttrs, changeCell
|
|
562
|
+
return { getCellValue, getCellTemplateValue, getCellPatternValue, getCellAttrs, getTitleAttrs, getRowAttrs, changeCell };
|
|
552
563
|
};
|
|
553
564
|
export const useSort = (p) => {
|
|
554
565
|
let [sorts, setSorts] = useState(p.sorts);
|
|
555
|
-
const getIconRef = useRef(new UT.GetSvg().getIcon);
|
|
556
566
|
const isInitSortExecutedRef = useRef(false);
|
|
567
|
+
const getActiveSorts = (sorts) => {
|
|
568
|
+
let activeSorts = (sorts || []).filter((sort) => sort.active !== false);
|
|
569
|
+
return activeSorts.map((o) => ({ getValue: o.getValue, dir: o.dir }));
|
|
570
|
+
};
|
|
557
571
|
const getSortedRows = (rows) => {
|
|
558
572
|
if (isInitSortExecutedRef.current) {
|
|
559
573
|
return rows;
|
|
@@ -561,44 +575,17 @@ export const useSort = (p) => {
|
|
|
561
575
|
if (p.onChangeSort) {
|
|
562
576
|
return rows;
|
|
563
577
|
}
|
|
564
|
-
let activeSorts = sorts
|
|
578
|
+
let activeSorts = getActiveSorts(sorts);
|
|
565
579
|
if (!activeSorts.length || !rows.length) {
|
|
566
580
|
return rows;
|
|
567
581
|
}
|
|
568
582
|
isInitSortExecutedRef.current = true;
|
|
569
|
-
let sortedRows =
|
|
583
|
+
let sortedRows = UT.SortArray(rows, activeSorts);
|
|
570
584
|
if (p.onChangeRows) {
|
|
571
585
|
p.onChangeRows(sortedRows);
|
|
572
586
|
}
|
|
573
587
|
return sortedRows;
|
|
574
588
|
};
|
|
575
|
-
const sortRows = (rows, sorts) => {
|
|
576
|
-
if (!rows) {
|
|
577
|
-
return [];
|
|
578
|
-
}
|
|
579
|
-
if (!sorts || !sorts.length) {
|
|
580
|
-
return rows;
|
|
581
|
-
}
|
|
582
|
-
return rows.sort((a, b) => {
|
|
583
|
-
for (let i = 0; i < sorts.length; i++) {
|
|
584
|
-
let { dir, getValue } = sorts[i];
|
|
585
|
-
if (!getValue) {
|
|
586
|
-
return 0;
|
|
587
|
-
}
|
|
588
|
-
let aValue = getValue(a), bValue = getValue(b);
|
|
589
|
-
if (aValue < bValue) {
|
|
590
|
-
return -1 * (dir === 'dec' ? -1 : 1);
|
|
591
|
-
}
|
|
592
|
-
if (aValue > bValue) {
|
|
593
|
-
return 1 * (dir === 'dec' ? -1 : 1);
|
|
594
|
-
}
|
|
595
|
-
if (i === sorts.length - 1) {
|
|
596
|
-
return 0;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
return 0;
|
|
600
|
-
});
|
|
601
|
-
};
|
|
602
589
|
const changeSort = (sortId, changeObject) => {
|
|
603
590
|
let newSorts = sorts.map((sort) => {
|
|
604
591
|
if (sort.sortId === sortId) {
|
|
@@ -618,21 +605,56 @@ export const useSort = (p) => {
|
|
|
618
605
|
}
|
|
619
606
|
else {
|
|
620
607
|
setSorts(sorts);
|
|
621
|
-
|
|
608
|
+
const activeSorts = getActiveSorts(sorts);
|
|
622
609
|
if (activeSorts.length && !!p.onChangeRows) {
|
|
623
|
-
p.onChangeRows(
|
|
610
|
+
p.onChangeRows(UT.SortArray(p.rows, activeSorts));
|
|
624
611
|
}
|
|
625
612
|
}
|
|
626
613
|
});
|
|
627
|
-
const renderSortArrow = (option) => {
|
|
628
|
-
|
|
614
|
+
const renderSortArrow = (option, inline) => {
|
|
615
|
+
if (option === false) {
|
|
616
|
+
return null;
|
|
617
|
+
}
|
|
618
|
+
let { dir = 'dec', sortId, active } = option;
|
|
619
|
+
let path = dir === 'dec' ? 'mdiArrowDown' : 'mdiArrowUp';
|
|
620
|
+
if (inline && !active) {
|
|
621
|
+
path = 'mdiSortVariantOff';
|
|
622
|
+
}
|
|
629
623
|
return (_jsx("div", { className: 'aio-sort-arrow', onClick: (e) => {
|
|
630
624
|
e.stopPropagation();
|
|
631
625
|
if (!sortId) {
|
|
632
626
|
return;
|
|
633
627
|
}
|
|
634
|
-
|
|
635
|
-
|
|
628
|
+
let newActive = active, newDir = dir;
|
|
629
|
+
if (inline) {
|
|
630
|
+
if (active) {
|
|
631
|
+
if (dir === 'inc') {
|
|
632
|
+
newDir = 'dec';
|
|
633
|
+
newActive = true;
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
newActive = false;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
newDir = 'inc';
|
|
641
|
+
newActive = true;
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
else {
|
|
645
|
+
newDir = dir === 'dec' ? 'inc' : 'dec';
|
|
646
|
+
}
|
|
647
|
+
changeSort(sortId, { dir: newDir, active: newActive });
|
|
648
|
+
}, children: new UT.GetSvg('em').getIcon(path, 0.8) }));
|
|
649
|
+
};
|
|
650
|
+
const getSortByColumn = (column) => {
|
|
651
|
+
const sort = column.sort;
|
|
652
|
+
if (!sort) {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
const sortId = sort === true ? column.id : (sort.sortId === undefined ? column.id : sort.sortId);
|
|
656
|
+
const res = sorts.find((o) => o.sortId === sortId);
|
|
657
|
+
return res === undefined ? false : res;
|
|
636
658
|
};
|
|
637
659
|
const renderSortButton = (attrs, limitTo) => {
|
|
638
660
|
if (!sorts.length) {
|
|
@@ -647,11 +669,11 @@ export const useSort = (p) => {
|
|
|
647
669
|
header: { title: p.fa ? 'مرتب سازی' : 'Sort', onClose: false },
|
|
648
670
|
headerAttrs: { className: 'aio-sort-header' },
|
|
649
671
|
limitTo: limitTo || '.aio-table'
|
|
650
|
-
}, attrs: Attrs, text:
|
|
672
|
+
}, attrs: Attrs, text: new UT.GetSvg('em').getIcon('mdiSort', 0.7), onSwap: (newSorts) => changeSorts(newSorts) }, 'sortbutton'));
|
|
651
673
|
};
|
|
652
|
-
return { sorts, setSorts, renderSortButton, getSortedRows, changeSort, changeSorts };
|
|
674
|
+
return { sorts, setSorts, renderSortButton, getSortedRows, changeSort, changeSorts, renderSortArrow, getSortByColumn };
|
|
653
675
|
};
|
|
654
|
-
|
|
676
|
+
const usePaging = (p) => {
|
|
655
677
|
const timeoutRef = useRef(undefined);
|
|
656
678
|
const startRef = useRef(undefined);
|
|
657
679
|
const endRef = useRef(undefined);
|
|
@@ -754,8 +776,8 @@ const FilterContextProvider = (props) => _jsx(FilterContext.Provider, { value: p
|
|
|
754
776
|
const useFilterContext = () => useContext(FilterContext);
|
|
755
777
|
const useFilter = () => {
|
|
756
778
|
const { rootProps } = useProvider();
|
|
757
|
-
const {
|
|
758
|
-
const {
|
|
779
|
+
const { filter } = rootProps;
|
|
780
|
+
const { onChange } = filter || {};
|
|
759
781
|
const trans = (key) => {
|
|
760
782
|
const { fa } = rootProps;
|
|
761
783
|
const dic = {
|
|
@@ -788,39 +810,34 @@ const useFilter = () => {
|
|
|
788
810
|
};
|
|
789
811
|
const popup = usePopup({ rtl: !!rootProps.fa });
|
|
790
812
|
const filterDataHook = useFilterData(popup, trans);
|
|
791
|
-
const type = columnsFilter ? 'columns' : 'form';
|
|
792
|
-
const form = useForm({
|
|
793
|
-
initData: value, onChange, getLayout: () => ({
|
|
794
|
-
v: items.map((o) => ({
|
|
795
|
-
input: Object.assign(Object.assign({}, o), { deSelect: true })
|
|
796
|
-
}))
|
|
797
|
-
})
|
|
798
|
-
});
|
|
799
813
|
const renderButton = (attrs) => {
|
|
800
|
-
return (_jsxs(FilterContextProvider, { value: { trans, popup, filterDataHook,
|
|
814
|
+
return (_jsxs(FilterContextProvider, { value: { trans, popup, filterDataHook, rootProps }, children: [_jsx(FilterButton, { attrs: attrs }), popup.render()] }));
|
|
801
815
|
};
|
|
802
816
|
const renderTags = () => {
|
|
803
|
-
return (_jsxs(FilterContextProvider, { value: { trans, popup, filterDataHook,
|
|
817
|
+
return (_jsxs(FilterContextProvider, { value: { trans, popup, filterDataHook, rootProps }, children: [_jsx(FilterColumnsTags, { filterItems: filterDataHook.getData(), remove: true }), popup.render()] }));
|
|
804
818
|
};
|
|
805
819
|
return { renderButton, renderTags };
|
|
806
820
|
};
|
|
807
821
|
const FilterButton = ({ attrs }) => {
|
|
808
|
-
const { popup, trans } = useFilterContext();
|
|
822
|
+
const { popup, trans, rootProps } = useFilterContext();
|
|
823
|
+
const { filter = {} } = rootProps;
|
|
824
|
+
const { modalAttrs } = filter;
|
|
809
825
|
const openModal = () => {
|
|
810
826
|
popup.addModal({
|
|
811
827
|
header: { title: trans('filters') },
|
|
812
828
|
position: 'fullscreen', body: _jsx(FilterModal, {}),
|
|
813
|
-
backdropAttrs: { className: 'aio-filter-modal aio-filter-modal-size' }
|
|
829
|
+
backdropAttrs: { className: 'aio-table-filter-modal aio-table-filter-modal-size' },
|
|
830
|
+
modalAttrs
|
|
814
831
|
});
|
|
815
832
|
};
|
|
816
|
-
const Attrs = UT.AddToAttrs(attrs, { className: 'aio-
|
|
817
|
-
return (_jsx("button", Object.assign({}, Attrs, { children: new UT.GetSvg().getIcon('mdiFilter', 0.7) })));
|
|
833
|
+
const Attrs = UT.AddToAttrs(attrs, { className: 'aio-table-toolbar-button', attrs: { onClick: openModal } });
|
|
834
|
+
return (_jsx("button", Object.assign({}, Attrs, { children: new UT.GetSvg('em').getIcon('mdiFilter', 0.7) })));
|
|
818
835
|
};
|
|
819
|
-
const FilterColumnsTags = ({ filterItems, remove
|
|
836
|
+
const FilterColumnsTags = ({ filterItems, remove }) => {
|
|
820
837
|
const { filterDataHook } = useFilterContext();
|
|
821
838
|
const { filterColumns } = useProvider();
|
|
822
839
|
const getTags = () => {
|
|
823
|
-
var _a, _b
|
|
840
|
+
var _a, _b;
|
|
824
841
|
const res = [];
|
|
825
842
|
for (let i = 0; i < filterItems.length; i++) {
|
|
826
843
|
const filterItem = filterItems[i];
|
|
@@ -846,9 +863,9 @@ const FilterColumnsTags = ({ filterItems, remove, wrap }) => {
|
|
|
846
863
|
const option = options.find((o) => o.value === value);
|
|
847
864
|
valuePresent = (option === null || option === void 0 ? void 0 : option.text) || '';
|
|
848
865
|
}
|
|
849
|
-
else if (type === 'date') {
|
|
866
|
+
else if (type === 'date' || type === 'jalaliDate') {
|
|
850
867
|
const dateUnit = ((_b = column.filterInput) === null || _b === void 0 ? void 0 : _b.dateUnit) || { year: true, month: true, day: true };
|
|
851
|
-
const jalali =
|
|
868
|
+
const jalali = column.type === 'jalaliDate';
|
|
852
869
|
if (dateUnit === 'month') {
|
|
853
870
|
valuePresent = new AIODate().getDateByPattern(value, '{year}/{month}', jalali);
|
|
854
871
|
}
|
|
@@ -875,88 +892,65 @@ const FilterColumnsTags = ({ filterItems, remove, wrap }) => {
|
|
|
875
892
|
if (!filterItems.length) {
|
|
876
893
|
return null;
|
|
877
894
|
}
|
|
878
|
-
return (_jsx("div", { className: "aio-filter-tags", children: getTags() }));
|
|
879
|
-
};
|
|
880
|
-
const FilterFormTags = () => {
|
|
881
|
-
const { form } = useFilterContext();
|
|
882
|
-
return (_jsx(_Fragment, { children: form.renderTags }));
|
|
895
|
+
return (_jsx("div", { className: "aio-table-filter-tags", children: getTags() }));
|
|
883
896
|
};
|
|
884
897
|
const FilterTag = ({ filterItem, valuePresent, column, onRemove }) => {
|
|
885
898
|
var _a;
|
|
886
899
|
const { trans } = useFilterContext();
|
|
887
900
|
const { operator } = filterItem;
|
|
888
|
-
return (_jsxs("div", { className: "aio-filter-tag", onClick: onRemove, children: [_jsx("div", { className: "aio-filter-tag-column", children: ((_a = column.filterInput) === null || _a === void 0 ? void 0 : _a.label) || column.title || '' }), !!operator && _jsx("div", { className: "aio-filter-tag-operator", children: trans(operator) }), _jsx("div", { className: "aio-filter-tag-value", children: valuePresent }), !!onRemove && new UT.GetSvg().getIcon('mdiClose', 0.6)] }));
|
|
901
|
+
return (_jsxs("div", { className: "aio-table-filter-tag", onClick: onRemove, children: [_jsx("div", { className: "aio-table-filter-tag-column", children: ((_a = column.filterInput) === null || _a === void 0 ? void 0 : _a.label) || column.title || '' }), !!operator && _jsx("div", { className: "aio-table-filter-tag-operator", children: trans(operator) }), _jsx("div", { className: "aio-table-filter-tag-value", children: valuePresent }), !!onRemove && new UT.GetSvg('em').getIcon('mdiClose', 0.6)] }));
|
|
889
902
|
};
|
|
890
903
|
const SaveConfirm = ({ onSubmit }) => {
|
|
891
904
|
const { popup, filterDataHook, trans } = useFilterContext();
|
|
892
|
-
const [name, setName] = useState(
|
|
893
|
-
|
|
894
|
-
const filtered = filterDataHook.getSaves().filter((collection) => {
|
|
895
|
-
if (!collection.name) {
|
|
896
|
-
return false;
|
|
897
|
-
}
|
|
898
|
-
if (!text) {
|
|
899
|
-
return true;
|
|
900
|
-
}
|
|
901
|
-
return collection.name.indexOf(text) !== -1;
|
|
902
|
-
});
|
|
903
|
-
const res = filtered.map((collection) => ({ text: collection.name, value: collection.name }));
|
|
904
|
-
return res;
|
|
905
|
-
});
|
|
906
|
-
return (_jsxs("div", { className: "aio-filter-save-modal", children: [_jsx(AIFormInput, { label: trans('inter filter name'), input: (_jsx(SuggestionInput, { value: name, onChange: (newName) => setName(newName), getOptions: getOptions })) }), _jsxs("div", { className: "aio-filter-save-modal-footer", children: [_jsx("button", { className: "aio-filter-button aio-filter-active-button", disabled: !name, onClick: () => onSubmit(name), children: trans(name === filterDataHook.activeName ? 'edit' : 'save') }), _jsx("button", { className: "aio-filter-button", onClick: () => popup.removeModal(), children: trans('cansel') })] })] }));
|
|
905
|
+
const [name, setName] = useState('');
|
|
906
|
+
return (_jsxs("div", { className: "aio-table-filter-save-modal", children: [_jsx(AIFormInput, { label: trans('inter filter name'), input: (_jsx(AIText, { options: filterDataHook.getSaves(), option: { text: (o) => o.name, value: (o) => o.name, onClick: (o) => setName(o) }, onChange: (newName, option) => setName(option ? option.text : newName) })) }), _jsxs("div", { className: "aio-table-filter-save-modal-footer", children: [_jsx("button", { className: "aio-table-filter-button aio-table-filter-active-button", disabled: !name, onClick: () => onSubmit(name), children: trans(name === filterDataHook.activeName ? 'edit' : 'save') }), _jsx("button", { className: "aio-table-filter-button", onClick: () => popup.removeModal(), children: trans('cansel') })] })] }));
|
|
907
907
|
};
|
|
908
|
-
const
|
|
908
|
+
const FilterSaveds = () => {
|
|
909
909
|
const { trans, filterDataHook } = useFilterContext();
|
|
910
910
|
const saves = filterDataHook.getSaves();
|
|
911
911
|
if (!saves.length) {
|
|
912
|
-
return (_jsx("div", { className: "
|
|
912
|
+
return (_jsx("div", { className: "aio-table-saved-filters-empty", children: trans('saved empty') }));
|
|
913
913
|
}
|
|
914
|
-
return (_jsx("div", { className: "
|
|
914
|
+
return (_jsx("div", { className: "aio-table-saved-filters", children: saves.map((o) => _jsx(FilterSaved, { item: o }, o.name)) }));
|
|
915
915
|
};
|
|
916
|
-
const
|
|
916
|
+
const FilterSaved = ({ item }) => {
|
|
917
917
|
const { rootProps } = useProvider();
|
|
918
|
-
const { trans, filterDataHook
|
|
918
|
+
const { trans, filterDataHook } = useFilterContext();
|
|
919
919
|
const { fa } = rootProps;
|
|
920
920
|
if (!item.name) {
|
|
921
921
|
return null;
|
|
922
922
|
}
|
|
923
|
-
const header_layout = () => _jsxs("div", { className: "
|
|
924
|
-
const name_layout = () => _jsx("div", { className: "
|
|
923
|
+
const header_layout = () => _jsxs("div", { className: "aio-table-saved-filter-header", children: [" ", name_layout(), " ", remove_layout(), " ", activate_layout()] });
|
|
924
|
+
const name_layout = () => _jsx("div", { className: "aio-table-saved-filter-name", children: item.name });
|
|
925
925
|
const remove_layout = () => {
|
|
926
|
-
const attrs = { className: "
|
|
926
|
+
const attrs = { className: "aio-table-filter-remove-button", onClick: () => filterDataHook.removeSave(item), style: { [fa ? 'right' : 'left']: -4 } };
|
|
927
927
|
return (_jsx("div", Object.assign({}, attrs, { children: _jsx(FilterRemoveIcon, {}) })));
|
|
928
928
|
};
|
|
929
929
|
const activate_layout = () => {
|
|
930
|
-
return (_jsxs("div", { className: "aio-filter-
|
|
930
|
+
return (_jsxs("div", { className: "aio-table-filter-button", onClick: () => filterDataHook.activeSave(item), children: [_jsx(FilterActiveIcon, {}), " ", trans('activate')] }));
|
|
931
931
|
};
|
|
932
932
|
const body_layout = () => {
|
|
933
|
-
|
|
934
|
-
return _jsx("div", { className: "af-collection-body", children: _jsx(FilterColumnsTags, { filterItems: item.data.filter((o) => o.value !== undefined && o.value !== '') }) });
|
|
935
|
-
}
|
|
936
|
-
else {
|
|
937
|
-
return _jsx("div", { className: "af-collection-body", children: _jsx(FilterFormTags, {}) });
|
|
938
|
-
}
|
|
933
|
+
return _jsx("div", { className: "aio-table-saved-filter-body", children: _jsx(FilterColumnsTags, { filterItems: item.data.filter((o) => o.value !== undefined && o.value !== '') }) });
|
|
939
934
|
};
|
|
940
|
-
return (_jsxs("div", { className: "
|
|
935
|
+
return (_jsxs("div", { className: "aio-table-saved-filter", children: [header_layout(), " ", body_layout()] }));
|
|
941
936
|
};
|
|
942
937
|
const FilterModal = () => {
|
|
943
938
|
const { rootProps } = useProvider();
|
|
944
939
|
const { trans } = useFilterContext();
|
|
945
|
-
const { fa,
|
|
946
|
-
const { getSavedItems } =
|
|
940
|
+
const { fa, filter } = rootProps;
|
|
941
|
+
const { getSavedItems } = filter || {};
|
|
947
942
|
const collections_layout = () => {
|
|
948
|
-
return (_jsxs("div", { className: "aio-filter-panel", children: [_jsx("div", { className: "aio-filter-panel-header", children: _jsx("div", { className: "aio-filter-panel-label", children: trans('saved filters') }) }), _jsx(
|
|
943
|
+
return (_jsxs("div", { className: "aio-table-filter-panel", children: [_jsx("div", { className: "aio-table-filter-panel-header", children: _jsx("div", { className: "aio-table-filter-panel-label", children: trans('saved filters') }) }), _jsx(FilterSaveds, {})] }));
|
|
949
944
|
};
|
|
950
|
-
return (_jsxs("div", { className: `aio-filter-body aio-filter-body-${fa ? 'rtl' : 'ltr'}`, children: [_jsx(CurrentFilters, {}), !!
|
|
945
|
+
return (_jsxs("div", { className: `aio-table-filter-body aio-table-filter-body-${fa ? 'rtl' : 'ltr'}`, children: [_jsx(CurrentFilters, {}), !!getSavedItems && collections_layout()] }));
|
|
951
946
|
};
|
|
952
947
|
const CurrentFilters = () => {
|
|
953
948
|
const { rootProps } = useProvider();
|
|
954
|
-
const { filterDataHook, trans
|
|
955
|
-
const {
|
|
956
|
-
const canSave = (!!
|
|
949
|
+
const { filterDataHook, trans } = useFilterContext();
|
|
950
|
+
const { filter } = rootProps;
|
|
951
|
+
const canSave = (!!filter && !!filter.setSavedItems);
|
|
957
952
|
const data = filterDataHook.getData();
|
|
958
|
-
return (_jsxs("div", { className: "aio-filter-panel", children: [_jsxs("div", { className: "aio-filter-panel-header", children: [_jsx("div", { className: "aio-filter-panel-label", children: trans('current filters') }),
|
|
959
|
-
_jsx("div", { className: "af-current-filters", children: data.map((columnsFilterItem) => _jsx(CurrentFilter, { filterItem: columnsFilterItem }, columnsFilterItem.id)) }), !!formFilter && form.renderLayout] }));
|
|
953
|
+
return (_jsxs("div", { className: "aio-table-filter-panel", children: [_jsxs("div", { className: "aio-table-filter-panel-header", children: [_jsx("div", { className: "aio-table-filter-panel-label", children: trans('current filters') }), _jsxs("button", { className: "aio-table-filter-button", onClick: filterDataHook.addColumnsFilterItem, children: [_jsx(FilterAddIcon, {}), " ", trans('add')] }), !!canSave && !!data.length && _jsxs("button", { className: "aio-table-filter-button", onClick: filterDataHook.save, children: [_jsx(FilterSaveIcon, {}), " ", trans('save')] })] }), _jsx("div", { className: "aio-table-current-filters", children: data.map((columnsFilterItem) => _jsx(CurrentFilter, { filterItem: columnsFilterItem }, columnsFilterItem.id)) })] }));
|
|
960
954
|
};
|
|
961
955
|
const CurrentFilter = ({ filterItem }) => {
|
|
962
956
|
const { operator, columnId, value } = filterItem;
|
|
@@ -978,6 +972,7 @@ const CurrentFilter = ({ filterItem }) => {
|
|
|
978
972
|
text: { contain: true, notContain: true, equal: true, notEqual: true },
|
|
979
973
|
number: { less: true, more: true, lessequal: true, moreequal: true, equal: true, notEqual: true },
|
|
980
974
|
date: { less: true, more: true, lessequal: true, moreequal: true, equal: true, notEqual: true },
|
|
975
|
+
jalaliDate: { less: true, more: true, lessequal: true, moreequal: true, equal: true, notEqual: true },
|
|
981
976
|
select: { equal: true, notEqual: true },
|
|
982
977
|
multiSelect: { contain: true, notContain: true },
|
|
983
978
|
checkbox: {}
|
|
@@ -995,12 +990,13 @@ const CurrentFilter = ({ filterItem }) => {
|
|
|
995
990
|
filterDataHook.changeColumnsFilterItem({ filterItem: filterItem, key: 'value', value: newValue, column });
|
|
996
991
|
};
|
|
997
992
|
const getValueInput = () => {
|
|
993
|
+
var _a, _b;
|
|
998
994
|
if (!column) {
|
|
999
995
|
return null;
|
|
1000
996
|
}
|
|
1001
|
-
|
|
997
|
+
const type = ((_a = column.filterInput) === null || _a === void 0 ? void 0 : _a.type) || column.type || 'text';
|
|
1002
998
|
if (type === 'select') {
|
|
1003
|
-
return (_jsx(AISelect, Object.assign({}, column.filterInput, { value: value, onChange: (value) => changeValue(value), deSelect: true })));
|
|
999
|
+
return (_jsx(AISelect, Object.assign({}, column.filterInput, { value: value, onChange: (value) => changeValue(value), deSelect: true, popover: Object.assign({ fitHorizontal: true }, (_b = column.filterInput) === null || _b === void 0 ? void 0 : _b.popover) })));
|
|
1004
1000
|
}
|
|
1005
1001
|
if (type === 'multiSelect') {
|
|
1006
1002
|
return (_jsx(AIRadio, Object.assign({ multiple: true }, column.filterInput, { value: value, onChange: (value) => changeValue(value), deSelect: true })));
|
|
@@ -1014,16 +1010,15 @@ const CurrentFilter = ({ filterItem }) => {
|
|
|
1014
1010
|
if (type === 'number') {
|
|
1015
1011
|
return _jsx(AINumber, Object.assign({}, column.filterInput, { value: value, onChange: (value) => changeValue(value), deSelect: true, inputAttrs: { style: { letterSpacing: 4 } }, justify: true }));
|
|
1016
1012
|
}
|
|
1017
|
-
if (type === 'date') {
|
|
1018
|
-
return _jsx(TimeInput, Object.assign({}, column.filterInput, { filterItem: filterItem, onChange: (value) => changeValue(value), column: column }));
|
|
1013
|
+
if (type === 'date' || type === 'jalaliDate') {
|
|
1014
|
+
return _jsx(TimeInput, Object.assign({}, column.filterInput, { filterItem: filterItem, onChange: (value) => changeValue(value), column: column, jalali: type === 'jalaliDate' }));
|
|
1019
1015
|
}
|
|
1020
1016
|
};
|
|
1021
|
-
return (_jsx(_Fragment, { children: _jsxs("div", { className: "aio-filter-row", children: [!!column &&
|
|
1022
|
-
_jsx(AISelect, {
|
|
1023
|
-
_jsx(AISelect, { className: 'aio-filter-operator-select', options: operators, value: operator, option: { text: (operator) => trans(operator), value: (operator) => operator }, onChange: (operator) => filterDataHook.changeColumnsFilterItem({ filterItem: filterItem, key: 'operator', value: operator, column }), popover: { fitHorizontal: true } }), getValueInput(), _jsx("div", { className: "aio-
|
|
1017
|
+
return (_jsx(_Fragment, { children: _jsxs("div", { className: "aio-table-filter-row", children: [!!column &&
|
|
1018
|
+
_jsx(AISelect, { className: 'msf', options: filterColumns.map((o) => ({ text: o.title, value: o.id })), value: columnId, onChange: (columnId) => filterDataHook.changeColumnsFilterItem({ filterItem: filterItem, key: 'columnId', value: columnId, column }), popover: { fitHorizontal: true } }), !!column && !!operators.length &&
|
|
1019
|
+
_jsx(AISelect, { className: 'aio-table-filter-operator-select', options: operators, value: operator, option: { text: (operator) => trans(operator), value: (operator) => operator }, onChange: (operator) => filterDataHook.changeColumnsFilterItem({ filterItem: filterItem, key: 'operator', value: operator, column }), popover: { fitHorizontal: true } }), getValueInput(), _jsx("div", { className: "aio-table-filter-remove-button", onClick: () => filterDataHook.removeFilterItem(filterItem), children: _jsx(FilterRemoveIcon, {}) })] }) }));
|
|
1024
1020
|
};
|
|
1025
|
-
const TimeInput = ({ filterItem, onChange, column }) => {
|
|
1026
|
-
var _a;
|
|
1021
|
+
const TimeInput = ({ filterItem, onChange, column, jalali }) => {
|
|
1027
1022
|
const [unit] = useState(getUnit);
|
|
1028
1023
|
function getUnit() {
|
|
1029
1024
|
const { dateUnit = 'day' } = column.filterInput || {};
|
|
@@ -1040,42 +1035,40 @@ const TimeInput = ({ filterItem, onChange, column }) => {
|
|
|
1040
1035
|
return res;
|
|
1041
1036
|
}
|
|
1042
1037
|
const DATE = new AIODate();
|
|
1043
|
-
const jalali = column.jalali || ((_a = column.filterInput) === null || _a === void 0 ? void 0 : _a.jalali);
|
|
1044
1038
|
return (_jsx(AITime, { jalali: jalali, timeUnit: unit, value: filterItem.value, deSelect: true, onChange: (value) => onChange(value ? DATE.getTime(value) : undefined) }));
|
|
1045
1039
|
};
|
|
1046
|
-
const FilterSaveIcon = () => new UT.GetSvg().getIcon('mdiSaveContent', 0.8);
|
|
1047
|
-
const FilterRemoveIcon = () => new UT.GetSvg().getIcon('mdiClose', 0.6);
|
|
1048
|
-
const FilterActiveIcon = () => new UT.GetSvg().getIcon('mdiCheckBold', 0.6);
|
|
1049
|
-
const FilterAddIcon = () => new UT.GetSvg().getIcon('mdiPlusThick', 0.7);
|
|
1040
|
+
const FilterSaveIcon = () => new UT.GetSvg('em').getIcon('mdiSaveContent', 0.8);
|
|
1041
|
+
const FilterRemoveIcon = () => new UT.GetSvg('em').getIcon('mdiClose', 0.6);
|
|
1042
|
+
const FilterActiveIcon = () => new UT.GetSvg('em').getIcon('mdiCheckBold', 0.6);
|
|
1043
|
+
const FilterAddIcon = () => new UT.GetSvg('em').getIcon('mdiPlusThick', 0.7);
|
|
1050
1044
|
const useFilterData = (popup, trans) => {
|
|
1051
1045
|
const [activeName, setActiveName] = useState();
|
|
1052
1046
|
const { filterColumns, rootProps } = useProvider();
|
|
1053
|
-
const {
|
|
1047
|
+
const { filter = {} } = rootProps;
|
|
1054
1048
|
const [saves, setSaves] = useState([]);
|
|
1055
1049
|
const savesRef = useRef(saves);
|
|
1056
1050
|
savesRef.current = saves;
|
|
1057
1051
|
const getSaves = () => savesRef.current;
|
|
1058
1052
|
const [data, setData] = useState(getInitialData);
|
|
1059
1053
|
function getInitialData() {
|
|
1060
|
-
if (
|
|
1061
|
-
|
|
1054
|
+
if (filter.cache) {
|
|
1055
|
+
const storage = new UT.Storage(filter.cache);
|
|
1056
|
+
const data = storage.load('columnsFilterData', filter.items || []);
|
|
1057
|
+
if (filter.onChange) {
|
|
1058
|
+
filter.onChange(data);
|
|
1059
|
+
}
|
|
1060
|
+
return data;
|
|
1062
1061
|
}
|
|
1063
|
-
|
|
1064
|
-
return
|
|
1062
|
+
else {
|
|
1063
|
+
return filter.items || [];
|
|
1065
1064
|
}
|
|
1066
1065
|
}
|
|
1067
1066
|
const getData = () => dataRef.current;
|
|
1068
1067
|
const dataRef = useRef(data);
|
|
1069
1068
|
dataRef.current = data;
|
|
1070
1069
|
const changeData = (newData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1071
|
-
if (
|
|
1072
|
-
const res = yield
|
|
1073
|
-
if (res === false) {
|
|
1074
|
-
return false;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
if (formFilter && formFilter.onChange) {
|
|
1078
|
-
const res = yield formFilter.onChange(newData);
|
|
1070
|
+
if (filter.onChange) {
|
|
1071
|
+
const res = yield filter.onChange(newData);
|
|
1079
1072
|
if (res === false) {
|
|
1080
1073
|
return false;
|
|
1081
1074
|
}
|
|
@@ -1084,7 +1077,7 @@ const useFilterData = (popup, trans) => {
|
|
|
1084
1077
|
return true;
|
|
1085
1078
|
});
|
|
1086
1079
|
const changeSaves = (newSaves) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1087
|
-
const { setSavedItems } =
|
|
1080
|
+
const { setSavedItems } = filter;
|
|
1088
1081
|
if (!setSavedItems) {
|
|
1089
1082
|
return false;
|
|
1090
1083
|
}
|
|
@@ -1118,7 +1111,7 @@ const useFilterData = (popup, trans) => {
|
|
|
1118
1111
|
popup.removeModal();
|
|
1119
1112
|
}
|
|
1120
1113
|
}) })),
|
|
1121
|
-
backdropAttrs: { className: 'aio-filter-modal' }
|
|
1114
|
+
backdropAttrs: { className: 'aio-table-filter-modal' }
|
|
1122
1115
|
});
|
|
1123
1116
|
};
|
|
1124
1117
|
const removeSave = (saveItem) => {
|
|
@@ -1127,37 +1120,21 @@ const useFilterData = (popup, trans) => {
|
|
|
1127
1120
|
text: trans('remove confirm'),
|
|
1128
1121
|
submitText: trans('remove'),
|
|
1129
1122
|
canselText: trans('cansel'),
|
|
1130
|
-
backdropAttrs: { className: 'aio-filter-modal' },
|
|
1131
|
-
submitAttrs: { className: 'aio-filter-button aio-filter-active-button' },
|
|
1132
|
-
canselAttrs: { className: 'aio-filter-button' },
|
|
1123
|
+
backdropAttrs: { className: 'aio-table-filter-modal' },
|
|
1124
|
+
submitAttrs: { className: 'aio-table-filter-button aio-table-filter-active-button' },
|
|
1125
|
+
canselAttrs: { className: 'aio-table-filter-button' },
|
|
1133
1126
|
onSubmit: () => __awaiter(void 0, void 0, void 0, function* () { return yield changeSaves(savesRef.current.filter((o) => o.name !== saveItem.name)); })
|
|
1134
1127
|
});
|
|
1135
1128
|
};
|
|
1136
|
-
const activeSave = (saveItem) => {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
submitAttrs: { className: 'aio-filter-button aio-filter-active-button' },
|
|
1144
|
-
canselAttrs: { className: 'aio-filter-button' },
|
|
1145
|
-
onSubmit: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1146
|
-
const { onChange } = columnsFilter || formFilter || {};
|
|
1147
|
-
if (!onChange) {
|
|
1148
|
-
return false;
|
|
1149
|
-
}
|
|
1150
|
-
const res = yield changeData(saveItem.data);
|
|
1151
|
-
if (res) {
|
|
1152
|
-
setActiveName(saveItem.name);
|
|
1153
|
-
popup.removeModal('savedItems');
|
|
1154
|
-
}
|
|
1155
|
-
return !!res;
|
|
1156
|
-
})
|
|
1157
|
-
});
|
|
1158
|
-
};
|
|
1129
|
+
const activeSave = (saveItem) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1130
|
+
const { onChange } = filter;
|
|
1131
|
+
if (!onChange) {
|
|
1132
|
+
return false;
|
|
1133
|
+
}
|
|
1134
|
+
changeData(saveItem.data);
|
|
1135
|
+
});
|
|
1159
1136
|
const fetchSaves = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1160
|
-
const { getSavedItems } =
|
|
1137
|
+
const { getSavedItems } = filter;
|
|
1161
1138
|
if (!getSavedItems) {
|
|
1162
1139
|
return;
|
|
1163
1140
|
}
|
|
@@ -1175,7 +1152,7 @@ const useFilterData = (popup, trans) => {
|
|
|
1175
1152
|
value = options[0].value;
|
|
1176
1153
|
}
|
|
1177
1154
|
const operatorDic = {
|
|
1178
|
-
text: 'contain', number: 'equal', date: 'equal', select: 'equal', multiSelect: 'contain', checkbox: false
|
|
1155
|
+
text: 'contain', number: 'equal', date: 'equal', jalaliDate: 'equal', select: 'equal', multiSelect: 'contain', checkbox: false
|
|
1179
1156
|
};
|
|
1180
1157
|
const operator = column ? (operatorDic[type] === false ? undefined : operatorDic[type]) : undefined;
|
|
1181
1158
|
return { value, operator, columnId: column === null || column === void 0 ? void 0 : column.id, id: 'a' + UT.GetRandomNumber(10000000, 99999999) };
|