@acorex/cdk 20.2.0-next.15 → 20.2.0-next.16
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/common/index.d.ts
CHANGED
|
@@ -653,7 +653,7 @@ declare function convertArrayToDataSource<T = unknown>(items: T[], options?: {
|
|
|
653
653
|
key: string;
|
|
654
654
|
pageSize: number;
|
|
655
655
|
}): AXDataSource<T>;
|
|
656
|
-
declare function applyDataSourceQuery<T extends Record<string,
|
|
656
|
+
declare function applyDataSourceQuery<T extends Record<string, unknown>>(items: T[], filter: AXDataSourceFilterOption): T[];
|
|
657
657
|
|
|
658
658
|
interface AXDataListQuery {
|
|
659
659
|
take?: number;
|
|
@@ -1173,18 +1173,34 @@ class AXDataSource {
|
|
|
1173
1173
|
}
|
|
1174
1174
|
}
|
|
1175
1175
|
function convertArrayToDataSource(items, options = { key: 'id', pageSize: 100 }) {
|
|
1176
|
+
// Normalize primitives to objects so consumers (e.g., select/list) can rely on
|
|
1177
|
+
// value and text fields without triggering extra byKey lookups.
|
|
1178
|
+
const normalizedItems = items.map((candidate) => {
|
|
1179
|
+
const isObjectItem = candidate != null && typeof candidate === 'object';
|
|
1180
|
+
if (isObjectItem) {
|
|
1181
|
+
return candidate;
|
|
1182
|
+
}
|
|
1183
|
+
// For primitive values, create an object with both key and text
|
|
1184
|
+
return { [options.key]: candidate, text: String(candidate ?? '') };
|
|
1185
|
+
});
|
|
1176
1186
|
const config = {
|
|
1177
1187
|
key: options.key,
|
|
1178
1188
|
pageSize: options.pageSize,
|
|
1179
1189
|
load: async (e) => {
|
|
1180
|
-
const
|
|
1190
|
+
const itemsForFilter = normalizedItems;
|
|
1191
|
+
const resultNormalized = e.filter
|
|
1192
|
+
? applyDataSourceQuery(itemsForFilter, e.filter)
|
|
1193
|
+
: itemsForFilter;
|
|
1194
|
+
const result = resultNormalized;
|
|
1181
1195
|
return {
|
|
1182
1196
|
items: result.slice(e.skip, e.skip + e.take),
|
|
1183
|
-
total:
|
|
1197
|
+
total: resultNormalized.length,
|
|
1184
1198
|
};
|
|
1185
1199
|
},
|
|
1186
|
-
byKey: async (v) =>
|
|
1187
|
-
|
|
1200
|
+
byKey: async (v) =>
|
|
1201
|
+
// Search in the normalized list (supports primitive and object arrays)
|
|
1202
|
+
normalizedItems.find((record) => {
|
|
1203
|
+
return record[options.key] == v;
|
|
1188
1204
|
}),
|
|
1189
1205
|
};
|
|
1190
1206
|
return new AXDataSource(config);
|