@seafile/sdoc-editor 1.0.64 → 1.0.65
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.
|
@@ -72,116 +72,119 @@ function SeaTableTable(_ref) {
|
|
|
72
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
73
73
|
}, [column_width]);
|
|
74
74
|
(0, _react.useEffect)(() => {
|
|
75
|
-
|
|
76
|
-
table_id
|
|
77
|
-
} = element;
|
|
78
|
-
const table = editor.getTableById(table_id);
|
|
79
|
-
if (!tableInfoRef.current) {
|
|
80
|
-
tableInfoRef.current = {};
|
|
81
|
-
}
|
|
82
|
-
if (!tableInfoRef.current[table_id]) {
|
|
83
|
-
tableInfoRef.current[table_id] = {
|
|
84
|
-
formulaRows: editor.getTableFormulaResults(table, table.rows),
|
|
85
|
-
idRowMap: table.rows.reduce((result, item) => {
|
|
86
|
-
result[item._id] = item;
|
|
87
|
-
return result;
|
|
88
|
-
}, {})
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// filter rows
|
|
93
|
-
let validRecords = table.rows;
|
|
94
|
-
const {
|
|
95
|
-
idRowMap,
|
|
96
|
-
formulaRows
|
|
97
|
-
} = tableInfoRef.current[table_id];
|
|
98
|
-
if (element.filters && Array.isArray(element.filters) && element.filters.length > 0) {
|
|
99
|
-
const {
|
|
100
|
-
filter_conjunction,
|
|
101
|
-
filters
|
|
102
|
-
} = element;
|
|
103
|
-
const {
|
|
104
|
-
username,
|
|
105
|
-
userId,
|
|
106
|
-
userDepartmentIdsMap
|
|
107
|
-
} = window.seafile || window.seafileConfig;
|
|
108
|
-
const optionalParams = {
|
|
109
|
-
formulaRows,
|
|
110
|
-
username,
|
|
111
|
-
userId,
|
|
112
|
-
userDepartmentIdsMap
|
|
113
|
-
};
|
|
114
|
-
const {
|
|
115
|
-
row_ids
|
|
116
|
-
} = (0, _dtableUtils.getFilteredRowsWithoutFormulaCalculation)(filter_conjunction, filters, validRecords, table, optionalParams);
|
|
117
|
-
validRecords = row_ids.map(rowId => {
|
|
118
|
-
const row = idRowMap[rowId];
|
|
119
|
-
return row;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// sort rows
|
|
124
|
-
if (element.sorts && Array.isArray(element.sorts) && element.sorts.length > 0) {
|
|
75
|
+
async function initTableData() {
|
|
125
76
|
const {
|
|
126
|
-
|
|
77
|
+
table_id
|
|
127
78
|
} = element;
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const shownRecords = readOnly ? validRecords.slice(0, 200) : validRecords.slice(0, 10);
|
|
142
|
-
setIsShowTipMessage(isShowTipMessage);
|
|
143
|
-
setRecords(validRecords);
|
|
144
|
-
setShownRecords(shownRecords);
|
|
79
|
+
const table = await editor.getTableById(table_id);
|
|
80
|
+
if (!tableInfoRef.current) {
|
|
81
|
+
tableInfoRef.current = {};
|
|
82
|
+
}
|
|
83
|
+
if (!tableInfoRef.current[table_id]) {
|
|
84
|
+
tableInfoRef.current[table_id] = {
|
|
85
|
+
formulaRows: editor.getTableFormulaResults(table, table.rows),
|
|
86
|
+
idRowMap: table.rows.reduce((result, item) => {
|
|
87
|
+
result[item._id] = item;
|
|
88
|
+
return result;
|
|
89
|
+
}, {})
|
|
90
|
+
};
|
|
91
|
+
}
|
|
145
92
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (element.shown_column_keys && Array.isArray(element.shown_column_keys) && element.shown_column_keys.length > 0) {
|
|
93
|
+
// filter rows
|
|
94
|
+
let validRecords = table.rows;
|
|
149
95
|
const {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// formatted columns
|
|
155
|
-
validColumns = validColumns.map(column => {
|
|
156
|
-
const {
|
|
157
|
-
type
|
|
158
|
-
} = column;
|
|
159
|
-
if (type === _dtableUtils.CellType.LINK) {
|
|
96
|
+
idRowMap,
|
|
97
|
+
formulaRows
|
|
98
|
+
} = tableInfoRef.current[table_id];
|
|
99
|
+
if (element.filters && Array.isArray(element.filters) && element.filters.length > 0) {
|
|
160
100
|
const {
|
|
161
|
-
|
|
162
|
-
|
|
101
|
+
filter_conjunction,
|
|
102
|
+
filters
|
|
103
|
+
} = element;
|
|
163
104
|
const {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} =
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
105
|
+
username,
|
|
106
|
+
userId,
|
|
107
|
+
userDepartmentIdsMap
|
|
108
|
+
} = window.seafile || window.seafileConfig;
|
|
109
|
+
const optionalParams = {
|
|
110
|
+
formulaRows,
|
|
111
|
+
username,
|
|
112
|
+
userId,
|
|
113
|
+
userDepartmentIdsMap
|
|
172
114
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
115
|
+
const {
|
|
116
|
+
row_ids
|
|
117
|
+
} = (0, _dtableUtils.getFilteredRowsWithoutFormulaCalculation)(filter_conjunction, filters, validRecords, table, optionalParams);
|
|
118
|
+
validRecords = row_ids.map(rowId => {
|
|
119
|
+
const row = idRowMap[rowId];
|
|
120
|
+
return row;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// sort rows
|
|
125
|
+
if (element.sorts && Array.isArray(element.sorts) && element.sorts.length > 0) {
|
|
126
|
+
const {
|
|
127
|
+
sorts
|
|
128
|
+
} = element;
|
|
129
|
+
const value = {
|
|
130
|
+
collaborators: editor.collaborators
|
|
179
131
|
};
|
|
132
|
+
const row_ids = (0, _dtableUtils.sortTableRows)(sorts, validRecords, table.columns, {
|
|
133
|
+
formulaRows,
|
|
134
|
+
value
|
|
135
|
+
});
|
|
136
|
+
validRecords = row_ids.map(rowId => {
|
|
137
|
+
const row = idRowMap[rowId];
|
|
138
|
+
return row;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
const isShowTipMessage = readOnly ? validRecords.length > 200 : validRecords.length > 10;
|
|
142
|
+
const shownRecords = readOnly ? validRecords.slice(0, 200) : validRecords.slice(0, 10);
|
|
143
|
+
setIsShowTipMessage(isShowTipMessage);
|
|
144
|
+
setRecords(validRecords);
|
|
145
|
+
setShownRecords(shownRecords);
|
|
146
|
+
|
|
147
|
+
// filter columns
|
|
148
|
+
let validColumns = table.columns;
|
|
149
|
+
if (element.shown_column_keys && Array.isArray(element.shown_column_keys) && element.shown_column_keys.length > 0) {
|
|
150
|
+
const {
|
|
151
|
+
shown_column_keys
|
|
152
|
+
} = element;
|
|
153
|
+
validColumns = table.columns.filter(item => shown_column_keys.includes(item.key));
|
|
180
154
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
155
|
+
// formatted columns
|
|
156
|
+
validColumns = validColumns.map(column => {
|
|
157
|
+
const {
|
|
158
|
+
type
|
|
159
|
+
} = column;
|
|
160
|
+
if (type === _dtableUtils.CellType.LINK) {
|
|
161
|
+
const {
|
|
162
|
+
data
|
|
163
|
+
} = column;
|
|
164
|
+
const {
|
|
165
|
+
display_column_key,
|
|
166
|
+
array_type,
|
|
167
|
+
array_data
|
|
168
|
+
} = data;
|
|
169
|
+
const display_column = {
|
|
170
|
+
key: display_column_key || '0000',
|
|
171
|
+
type: array_type || _dtableUtils.CellType.TEXT,
|
|
172
|
+
data: array_data || null
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
...column,
|
|
176
|
+
data: {
|
|
177
|
+
...data,
|
|
178
|
+
display_column
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return column;
|
|
183
|
+
});
|
|
184
|
+
setColumns(validColumns);
|
|
185
|
+
setIsLoading(false);
|
|
186
|
+
}
|
|
187
|
+
initTableData();
|
|
185
188
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
186
189
|
}, [element, readOnly]);
|
|
187
190
|
const handleScroll = (0, _react.useCallback)(e => {
|