@ram_28/kf-ai-sdk 1.0.5 → 1.0.8
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/api/index.d.ts +1 -1
- package/dist/api/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/index.d.ts +3 -4
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/types.d.ts +84 -127
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
- package/dist/components/hooks/useFilter/useFilter.d.ts +1 -1
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/index.d.ts +1 -1
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/types.d.ts +6 -49
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +5 -35
- package/dist/components/hooks/useTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useTable/useTable.d.ts +0 -5
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/index.cjs +13 -13
- package/dist/index.mjs +2395 -2865
- package/dist/types/common.d.ts +35 -26
- package/dist/types/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/sdk/api/index.ts +7 -3
- package/sdk/components/hooks/useFilter/index.ts +19 -31
- package/sdk/components/hooks/useFilter/types.ts +157 -138
- package/sdk/components/hooks/useFilter/useFilter.ts +259 -414
- package/sdk/components/hooks/useKanban/index.ts +0 -1
- package/sdk/components/hooks/useKanban/types.ts +8 -71
- package/sdk/components/hooks/useKanban/useKanban.ts +14 -77
- package/sdk/components/hooks/useTable/types.ts +7 -63
- package/sdk/components/hooks/useTable/useTable.ts +13 -122
- package/sdk/types/common.ts +42 -26
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +0 -33
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +0 -1
- package/dist/components/hooks/useFilter/validation.utils.d.ts +0 -38
- package/dist/components/hooks/useFilter/validation.utils.d.ts.map +0 -1
- package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +0 -298
- package/sdk/components/hooks/useFilter/validation.utils.ts +0 -401
|
@@ -4,12 +4,8 @@
|
|
|
4
4
|
// Core TypeScript interfaces for the kanban board functionality
|
|
5
5
|
// Following patterns from useTable and useForm
|
|
6
6
|
|
|
7
|
-
import type {
|
|
8
|
-
|
|
9
|
-
ValidationError,
|
|
10
|
-
FieldDefinition,
|
|
11
|
-
} from "../useFilter";
|
|
12
|
-
import type { LogicalOperator } from "../../../types/common";
|
|
7
|
+
import type { Condition, ConditionGroup, UseFilterReturn } from "../useFilter";
|
|
8
|
+
import type { ConditionGroupOperator } from "../../../types/common";
|
|
13
9
|
|
|
14
10
|
// ============================================================
|
|
15
11
|
// CORE DATA STRUCTURES
|
|
@@ -199,15 +195,12 @@ export interface UseKanbanOptions<T> {
|
|
|
199
195
|
/** Enable search functionality */
|
|
200
196
|
enableSearch?: boolean;
|
|
201
197
|
|
|
202
|
-
/** Field definitions for card validation */
|
|
203
|
-
cardFieldDefinitions?: Record<keyof T, FieldDefinition>;
|
|
204
|
-
|
|
205
198
|
/** Initial state */
|
|
206
199
|
initialState?: {
|
|
207
200
|
/** Initial filter conditions */
|
|
208
|
-
filters?:
|
|
209
|
-
/** Initial filter operator */
|
|
210
|
-
filterOperator?:
|
|
201
|
+
filters?: Array<Condition | ConditionGroup>;
|
|
202
|
+
/** Initial filter operator for combining filter conditions */
|
|
203
|
+
filterOperator?: ConditionGroupOperator;
|
|
211
204
|
/** Initial search query */
|
|
212
205
|
search?: string;
|
|
213
206
|
/** Initial column order */
|
|
@@ -230,7 +223,6 @@ export interface UseKanbanOptions<T> {
|
|
|
230
223
|
onCardDelete?: (cardId: string) => void;
|
|
231
224
|
onSuccess?: (data: any) => void;
|
|
232
225
|
onError?: (error: Error) => void;
|
|
233
|
-
onFilterError?: (errors: ValidationError[]) => void;
|
|
234
226
|
}
|
|
235
227
|
|
|
236
228
|
// ============================================================
|
|
@@ -272,60 +264,6 @@ export interface SearchOperations {
|
|
|
272
264
|
clear: () => void;
|
|
273
265
|
}
|
|
274
266
|
|
|
275
|
-
/**
|
|
276
|
-
* Filter functionality interface (reusing from useFilter)
|
|
277
|
-
*/
|
|
278
|
-
export interface FilterOperations {
|
|
279
|
-
/** Current filter conditions */
|
|
280
|
-
conditions: FilterConditionWithId[];
|
|
281
|
-
/** Logical operator for combining conditions */
|
|
282
|
-
logicalOperator: LogicalOperator;
|
|
283
|
-
/** Whether all conditions are valid */
|
|
284
|
-
isValid: boolean;
|
|
285
|
-
/** Current validation errors */
|
|
286
|
-
validationErrors: ValidationError[];
|
|
287
|
-
/** Whether there are any conditions */
|
|
288
|
-
hasConditions: boolean;
|
|
289
|
-
|
|
290
|
-
/** Add a new filter condition */
|
|
291
|
-
addCondition: (
|
|
292
|
-
condition: Omit<FilterConditionWithId, "id" | "isValid">
|
|
293
|
-
) => string;
|
|
294
|
-
/** Update an existing condition */
|
|
295
|
-
updateCondition: (
|
|
296
|
-
id: string,
|
|
297
|
-
updates: Partial<FilterConditionWithId>
|
|
298
|
-
) => boolean;
|
|
299
|
-
/** Remove a condition */
|
|
300
|
-
removeCondition: (id: string) => boolean;
|
|
301
|
-
/** Clear all conditions */
|
|
302
|
-
clearConditions: () => void;
|
|
303
|
-
/** Get a specific condition */
|
|
304
|
-
getCondition: (id: string) => FilterConditionWithId | undefined;
|
|
305
|
-
|
|
306
|
-
/** Set logical operator */
|
|
307
|
-
setLogicalOperator: (operator: LogicalOperator) => void;
|
|
308
|
-
|
|
309
|
-
/** Bulk operations */
|
|
310
|
-
setConditions: (conditions: FilterConditionWithId[]) => void;
|
|
311
|
-
replaceCondition: (
|
|
312
|
-
id: string,
|
|
313
|
-
newCondition: Omit<FilterConditionWithId, "id" | "isValid">
|
|
314
|
-
) => boolean;
|
|
315
|
-
|
|
316
|
-
/** Validation */
|
|
317
|
-
validateCondition: (condition: Partial<FilterConditionWithId>) => any;
|
|
318
|
-
validateAllConditions: () => any;
|
|
319
|
-
|
|
320
|
-
/** State management */
|
|
321
|
-
exportState: () => any;
|
|
322
|
-
importState: (state: any) => void;
|
|
323
|
-
resetToInitial: () => void;
|
|
324
|
-
|
|
325
|
-
/** Utilities */
|
|
326
|
-
getConditionCount: () => number;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
267
|
/**
|
|
330
268
|
* Main return interface for useKanban hook
|
|
331
269
|
* Follows useTable pattern with flat access
|
|
@@ -392,11 +330,11 @@ export interface UseKanbanReturn<T> {
|
|
|
392
330
|
clearSearch: () => void;
|
|
393
331
|
|
|
394
332
|
// ============================================================
|
|
395
|
-
// FILTER (
|
|
333
|
+
// FILTER (Simplified chainable API)
|
|
396
334
|
// ============================================================
|
|
397
335
|
|
|
398
336
|
/** Filter functionality */
|
|
399
|
-
filter:
|
|
337
|
+
filter: UseFilterReturn;
|
|
400
338
|
|
|
401
339
|
// ============================================================
|
|
402
340
|
// DRAG DROP (Flat Access)
|
|
@@ -491,7 +429,7 @@ export interface MoveCardRequest {
|
|
|
491
429
|
*/
|
|
492
430
|
export interface ReorderRequest {
|
|
493
431
|
itemIds: string[];
|
|
494
|
-
containerId?: string;
|
|
432
|
+
containerId?: string;
|
|
495
433
|
}
|
|
496
434
|
|
|
497
435
|
/**
|
|
@@ -537,7 +475,6 @@ export interface CardValidationContext<T> {
|
|
|
537
475
|
card: Partial<KanbanCard<T>>;
|
|
538
476
|
column?: KanbanColumn<T>;
|
|
539
477
|
allColumns: KanbanColumn<T>[];
|
|
540
|
-
fieldDefinitions?: Record<keyof T, FieldDefinition>;
|
|
541
478
|
}
|
|
542
479
|
|
|
543
480
|
/**
|
|
@@ -28,19 +28,17 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
28
28
|
cardSource,
|
|
29
29
|
source,
|
|
30
30
|
enableDragDrop = true,
|
|
31
|
-
cardFieldDefinitions,
|
|
32
31
|
initialState,
|
|
33
32
|
onCardMove,
|
|
34
33
|
onCardCreate,
|
|
35
34
|
onCardUpdate,
|
|
36
35
|
onCardDelete,
|
|
37
36
|
onError,
|
|
38
|
-
onFilterError,
|
|
39
37
|
} = options;
|
|
40
38
|
|
|
41
39
|
// Use source or cardSource (backwards compatibility)
|
|
42
40
|
const dataSource = source || cardSource;
|
|
43
|
-
|
|
41
|
+
|
|
44
42
|
if (!dataSource) {
|
|
45
43
|
throw new Error('useKanban requires either "source" or "cardSource" parameter');
|
|
46
44
|
}
|
|
@@ -90,12 +88,9 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
90
88
|
// FILTER INTEGRATION
|
|
91
89
|
// ============================================================
|
|
92
90
|
|
|
93
|
-
const
|
|
91
|
+
const filter = useFilter({
|
|
94
92
|
initialConditions: initialState?.filters,
|
|
95
|
-
|
|
96
|
-
fieldDefinitions: cardFieldDefinitions,
|
|
97
|
-
validateOnChange: true,
|
|
98
|
-
onValidationError: onFilterError,
|
|
93
|
+
initialOperator: initialState?.filterOperator || "And",
|
|
99
94
|
});
|
|
100
95
|
|
|
101
96
|
// Helper to generate API options for a specific column
|
|
@@ -109,7 +104,7 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
109
104
|
RHSType: "Constant"
|
|
110
105
|
};
|
|
111
106
|
|
|
112
|
-
const basePayload =
|
|
107
|
+
const basePayload = filter.payload;
|
|
113
108
|
let combinedPayload: any;
|
|
114
109
|
|
|
115
110
|
if (!basePayload) {
|
|
@@ -156,9 +151,9 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
156
151
|
if (search.query) {
|
|
157
152
|
opts.Search = search.query;
|
|
158
153
|
}
|
|
159
|
-
|
|
154
|
+
|
|
160
155
|
return opts;
|
|
161
|
-
}, [
|
|
156
|
+
}, [filter.payload, columnPagination, sorting, search.query]);
|
|
162
157
|
|
|
163
158
|
// ============================================================
|
|
164
159
|
// COLUMN QUERY GENERATION
|
|
@@ -190,21 +185,13 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
190
185
|
await Promise.all(columnQueries.map(q => q.refetch()));
|
|
191
186
|
};
|
|
192
187
|
|
|
193
|
-
// Get total card count (Global count, or sum of columns? Usually global might differ if filters applied)
|
|
194
|
-
// For simplicity, we can fetch global count but restricted by filters?
|
|
195
|
-
// Actually, standard Kanban usually doesn't show "Total Cards" unless it's per column.
|
|
196
|
-
// We will keep the global count query for now but it might be slightly inaccurate if we want "Total Visible".
|
|
197
|
-
// Let's rely on summing up column counts for "Total Visible" and keep this for "Total Database"?
|
|
198
|
-
// Or just query with base filters?
|
|
199
|
-
// Let's keep existing logic but apply ONLY base filters + search.
|
|
200
|
-
|
|
201
188
|
const cardApiOptions = useMemo((): ListOptions => {
|
|
202
189
|
// This is for the GLOBAL count (ignoring column split)
|
|
203
190
|
const opts: ListOptions = {};
|
|
204
191
|
if (search.query) opts.Search = search.query;
|
|
205
|
-
if (
|
|
192
|
+
if (filter.payload) opts.Filter = filter.payload;
|
|
206
193
|
return opts;
|
|
207
|
-
}, [search.query,
|
|
194
|
+
}, [search.query, filter.payload]);
|
|
208
195
|
|
|
209
196
|
const {
|
|
210
197
|
data: countData,
|
|
@@ -232,11 +219,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
232
219
|
|
|
233
220
|
const createCardMutation = useMutation({
|
|
234
221
|
mutationFn: async (card: Partial<KanbanCard<T>> & { columnId: string }) => {
|
|
235
|
-
// We need to fetch the current count or max position to append correclty if not provided
|
|
236
|
-
// Simplification: just send position=999999 or let backend handle it?
|
|
237
|
-
// Since we want optimistic UI, we should calculate it.
|
|
238
|
-
// But calculating it from partial data (paginated) is risky.
|
|
239
|
-
// Let's rely on backend or default to top/bottom logic.
|
|
240
222
|
const position = card.position ?? 999999;
|
|
241
223
|
const response = await api<KanbanCard<T>>(dataSource).create({ ...card, position });
|
|
242
224
|
return response._id;
|
|
@@ -251,7 +233,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
251
233
|
const previousCards = queryClient.getQueryData<ListResponse<KanbanCard<T>>>(queryKey);
|
|
252
234
|
|
|
253
235
|
if (previousCards) {
|
|
254
|
-
// Determine position
|
|
255
236
|
const currentCards = previousCards.Data;
|
|
256
237
|
const position = newCardVariables.position ?? currentCards.length;
|
|
257
238
|
|
|
@@ -273,7 +254,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
273
254
|
return { previousCards, queryKey };
|
|
274
255
|
},
|
|
275
256
|
onSuccess: async (cardId, _variables, context) => {
|
|
276
|
-
// Refetch the specific column
|
|
277
257
|
if (context?.queryKey) {
|
|
278
258
|
await queryClient.invalidateQueries({ queryKey: context.queryKey });
|
|
279
259
|
}
|
|
@@ -301,22 +281,10 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
301
281
|
return { id, updates };
|
|
302
282
|
},
|
|
303
283
|
onMutate: async () => {
|
|
304
|
-
// We don't know the columnId easily without passing it.
|
|
305
|
-
// We can try to finding it in all column queries
|
|
306
|
-
// For now, simpler to just invalidate everything on success/error
|
|
307
|
-
// OR pass columnId in updates if available.
|
|
308
|
-
// If we want optimistic updates, we need to iterate all queries.
|
|
309
|
-
|
|
310
|
-
// Strategy: Invalidate all columns. Optimistic update is hard without knowing columnId.
|
|
311
|
-
// If the user passes columnId in updates, we can optimize.
|
|
312
|
-
|
|
313
284
|
await queryClient.cancelQueries({ queryKey: ["kanban-cards", dataSource] });
|
|
314
285
|
return {};
|
|
315
286
|
},
|
|
316
287
|
onSuccess: async (result) => {
|
|
317
|
-
// Find the card to trigger callback
|
|
318
|
-
// Since we don't have a single list, this is harder.
|
|
319
|
-
// We can skip finding it for now or iterate queries.
|
|
320
288
|
onCardUpdateRef.current?.({ _id: result.id, ...result.updates } as any);
|
|
321
289
|
},
|
|
322
290
|
onError: (error, _variables, _context) => {
|
|
@@ -334,8 +302,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
334
302
|
},
|
|
335
303
|
onMutate: async () => {
|
|
336
304
|
await queryClient.cancelQueries({ queryKey: ["kanban-cards", dataSource] });
|
|
337
|
-
// Optimistic delete: Iterate all column queries and remove?
|
|
338
|
-
// For now, simple invalidation
|
|
339
305
|
return {};
|
|
340
306
|
},
|
|
341
307
|
onSuccess: async (id) => {
|
|
@@ -356,7 +322,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
356
322
|
return { cardId, fromColumnId, toColumnId, position };
|
|
357
323
|
},
|
|
358
324
|
onMutate: async ({ cardId, fromColumnId, toColumnId, position }) => {
|
|
359
|
-
// Cancel queries for only the affected columns
|
|
360
325
|
const fromOpts = getColumnApiOptions(fromColumnId);
|
|
361
326
|
const toOpts = getColumnApiOptions(toColumnId);
|
|
362
327
|
const fromQueryKey = ["kanban-cards", dataSource, fromColumnId, fromOpts];
|
|
@@ -365,23 +330,18 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
365
330
|
await queryClient.cancelQueries({ queryKey: fromQueryKey });
|
|
366
331
|
await queryClient.cancelQueries({ queryKey: toQueryKey });
|
|
367
332
|
|
|
368
|
-
// Get current data for both columns
|
|
369
333
|
const previousFromData = queryClient.getQueryData<ListResponse<KanbanCard<T>>>(fromQueryKey);
|
|
370
334
|
const previousToData = queryClient.getQueryData<ListResponse<KanbanCard<T>>>(toQueryKey);
|
|
371
335
|
|
|
372
|
-
// Optimistic update: move card between columns
|
|
373
336
|
if (previousFromData && previousToData) {
|
|
374
|
-
// Find the card in the source column
|
|
375
337
|
const cardToMove = previousFromData.Data.find(c => c._id === cardId);
|
|
376
338
|
|
|
377
339
|
if (cardToMove) {
|
|
378
|
-
// Remove card from source column
|
|
379
340
|
const newFromData = {
|
|
380
341
|
...previousFromData,
|
|
381
342
|
Data: previousFromData.Data.filter(c => c._id !== cardId)
|
|
382
343
|
};
|
|
383
344
|
|
|
384
|
-
// Add card to target column with updated columnId
|
|
385
345
|
const movedCard = {
|
|
386
346
|
...cardToMove,
|
|
387
347
|
columnId: toColumnId,
|
|
@@ -394,7 +354,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
394
354
|
Data: [...previousToData.Data, movedCard].sort((a, b) => a.position - b.position)
|
|
395
355
|
};
|
|
396
356
|
|
|
397
|
-
// Update cache optimistically
|
|
398
357
|
queryClient.setQueryData(fromQueryKey, newFromData);
|
|
399
358
|
queryClient.setQueryData(toQueryKey, newToData);
|
|
400
359
|
}
|
|
@@ -417,7 +376,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
417
376
|
);
|
|
418
377
|
},
|
|
419
378
|
onError: (error, _variables, context) => {
|
|
420
|
-
// Rollback optimistic update on error
|
|
421
379
|
if (context?.previousFromData && context?.fromQueryKey) {
|
|
422
380
|
queryClient.setQueryData(context.fromQueryKey, context.previousFromData);
|
|
423
381
|
}
|
|
@@ -427,7 +385,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
427
385
|
onErrorRef.current?.(error as Error);
|
|
428
386
|
},
|
|
429
387
|
onSettled: (_data, _error, variables) => {
|
|
430
|
-
// Invalidate queries to ensure sync with server
|
|
431
388
|
const fromOpts = getColumnApiOptions(variables.fromColumnId);
|
|
432
389
|
const toOpts = getColumnApiOptions(variables.toColumnId);
|
|
433
390
|
queryClient.invalidateQueries({ queryKey: ["kanban-cards", dataSource, variables.fromColumnId, fromOpts] });
|
|
@@ -445,15 +402,12 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
445
402
|
);
|
|
446
403
|
},
|
|
447
404
|
onMutate: async ({ columnId }) => {
|
|
448
|
-
// Optimistic reorder restricted to single column
|
|
449
405
|
const opts = getColumnApiOptions(columnId);
|
|
450
406
|
const queryKey = ["kanban-cards", dataSource, columnId, opts];
|
|
451
407
|
await queryClient.cancelQueries({ queryKey });
|
|
452
|
-
// Can implement optimistic reorder here if we want to parse cardIds
|
|
453
|
-
// But simpler to just invalidate.
|
|
454
408
|
return {};
|
|
455
409
|
},
|
|
456
|
-
onSuccess: () => {},
|
|
410
|
+
onSuccess: () => {},
|
|
457
411
|
onError: (error, _variables, _context) => {
|
|
458
412
|
onErrorRef.current?.(error as Error);
|
|
459
413
|
},
|
|
@@ -474,7 +428,7 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
474
428
|
cardId: card._id,
|
|
475
429
|
fromColumnId,
|
|
476
430
|
toColumnId,
|
|
477
|
-
position: undefined,
|
|
431
|
+
position: undefined,
|
|
478
432
|
});
|
|
479
433
|
} catch (error) {
|
|
480
434
|
// Error already handled in mutation onError
|
|
@@ -484,11 +438,10 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
484
438
|
);
|
|
485
439
|
|
|
486
440
|
// ============================================================
|
|
487
|
-
// COMPUTED VALUES
|
|
441
|
+
// COMPUTED VALUES
|
|
488
442
|
// ============================================================
|
|
489
443
|
|
|
490
444
|
const processedColumns = useMemo(() => {
|
|
491
|
-
// Map column configs to KanbanColumn structure using query results
|
|
492
445
|
return columnConfigs
|
|
493
446
|
.sort((a, b) => a.position - b.position)
|
|
494
447
|
.map((config, index) => {
|
|
@@ -502,7 +455,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
502
455
|
color: config.color,
|
|
503
456
|
limit: config.limit,
|
|
504
457
|
cards: cards.sort((a, b) => a.position - b.position),
|
|
505
|
-
// We can expose loading/error state per column here if needed in the future
|
|
506
458
|
_created_at: new Date(),
|
|
507
459
|
_modified_at: new Date(),
|
|
508
460
|
};
|
|
@@ -532,9 +484,7 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
532
484
|
"aria-grabbed": enableDragDrop && dragDropManager.draggedCard?._id === card._id,
|
|
533
485
|
onDragStart: (e: any) => {
|
|
534
486
|
if (!enableDragDrop) return;
|
|
535
|
-
// Abstracting the dataTransfer logic
|
|
536
487
|
e.dataTransfer.setData("text/plain", JSON.stringify(card));
|
|
537
|
-
// Use native event if available (ShadCN/Radix sometimes wraps events) or fallback to e
|
|
538
488
|
const nativeEvent = e.nativeEvent || e;
|
|
539
489
|
dragDropManager.handleDragStart(nativeEvent, card);
|
|
540
490
|
},
|
|
@@ -578,14 +528,6 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
578
528
|
setSearch({ query: "" });
|
|
579
529
|
}, []);
|
|
580
530
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
// ============================================================
|
|
584
|
-
// PROP GETTERS
|
|
585
|
-
// ============================================================
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
531
|
const totalCards = countData?.Count || 0;
|
|
590
532
|
|
|
591
533
|
const isLoading = isLoadingCards || isLoadingCount;
|
|
@@ -658,9 +600,7 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
658
600
|
),
|
|
659
601
|
moveCard: useCallback(
|
|
660
602
|
async (cardId: string, toColumnId: string, position?: number, fromColumnId?: string) => {
|
|
661
|
-
// If fromColumnId is not provided, we need to find it
|
|
662
603
|
if (!fromColumnId) {
|
|
663
|
-
// Find the card in the columns to get its current columnId
|
|
664
604
|
for (const column of processedColumns) {
|
|
665
605
|
const card = column.cards.find(c => c._id === cardId);
|
|
666
606
|
if (card) {
|
|
@@ -688,8 +628,8 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
688
628
|
setSearchQuery,
|
|
689
629
|
clearSearch,
|
|
690
630
|
|
|
691
|
-
// Filter (
|
|
692
|
-
filter
|
|
631
|
+
// Filter (Simplified chainable API)
|
|
632
|
+
filter,
|
|
693
633
|
|
|
694
634
|
// Drag Drop (Flat Access)
|
|
695
635
|
isDragging: enableDragDrop ? dragDropManager.isDragging : false,
|
|
@@ -702,13 +642,10 @@ export function useKanban<T extends Record<string, any> = Record<string, any>>(
|
|
|
702
642
|
handleDrop: enableDragDrop ? dragDropManager.handleDrop : () => {},
|
|
703
643
|
handleDragEnd: enableDragDrop ? dragDropManager.handleDragEnd : () => {},
|
|
704
644
|
handleKeyDown: enableDragDrop ? dragDropManager.handleKeyDown : () => {},
|
|
705
|
-
|
|
706
|
-
// Prop Getters
|
|
645
|
+
|
|
707
646
|
// Prop Getters
|
|
708
647
|
getCardProps: enableDragDrop ? getCardProps : (_card: any) => ({} as any),
|
|
709
648
|
getColumnProps: enableDragDrop ? getColumnProps : (_columnId: string) => ({} as any),
|
|
710
|
-
|
|
711
|
-
|
|
712
649
|
|
|
713
650
|
// Load More (Per Column)
|
|
714
651
|
loadMore: useCallback((columnId: string) => {
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type { ListResponse,
|
|
2
|
-
import type {
|
|
3
|
-
FilterConditionWithId,
|
|
4
|
-
TypedFilterConditionInput,
|
|
5
|
-
ValidationError,
|
|
6
|
-
FieldDefinition,
|
|
7
|
-
} from "../useFilter";
|
|
1
|
+
import type { ListResponse, ConditionGroupOperator } from "../../../types/common";
|
|
2
|
+
import type { Condition, ConditionGroup, UseFilterReturn } from "../useFilter";
|
|
8
3
|
|
|
9
4
|
// ============================================================
|
|
10
5
|
// TYPE DEFINITIONS
|
|
@@ -34,28 +29,23 @@ export interface UseTableOptions<T> {
|
|
|
34
29
|
enableFiltering?: boolean;
|
|
35
30
|
/** Enable pagination */
|
|
36
31
|
enablePagination?: boolean;
|
|
37
|
-
/** Field definitions for filter validation */
|
|
38
|
-
fieldDefinitions?: Record<keyof T, FieldDefinition>;
|
|
39
32
|
/** Initial state */
|
|
40
33
|
initialState?: {
|
|
41
34
|
pagination?: {
|
|
42
|
-
pageNo: number;
|
|
35
|
+
pageNo: number;
|
|
43
36
|
pageSize: number;
|
|
44
37
|
};
|
|
45
38
|
sorting?: {
|
|
46
39
|
field: keyof T;
|
|
47
40
|
direction: "asc" | "desc";
|
|
48
41
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
filterOperator?: LogicalOperator;
|
|
42
|
+
filters?: Array<Condition | ConditionGroup>;
|
|
43
|
+
filterOperator?: ConditionGroupOperator;
|
|
52
44
|
};
|
|
53
45
|
/** Error callback */
|
|
54
46
|
onError?: (error: Error) => void;
|
|
55
47
|
/** Success callback */
|
|
56
48
|
onSuccess?: (data: T[]) => void;
|
|
57
|
-
/** Filter error callback */
|
|
58
|
-
onFilterError?: (errors: ValidationError[]) => void;
|
|
59
49
|
}
|
|
60
50
|
|
|
61
51
|
export interface UseTableReturn<T> {
|
|
@@ -86,54 +76,8 @@ export interface UseTableReturn<T> {
|
|
|
86
76
|
set: (field: keyof T, direction: "asc" | "desc") => void;
|
|
87
77
|
};
|
|
88
78
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
value: string;
|
|
92
|
-
setValue: (value: string) => void;
|
|
93
|
-
clear: () => void;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Advanced Filtering (Filter Conditions) - Type-safe: lhsField constrained to keyof T
|
|
97
|
-
filter: {
|
|
98
|
-
// State
|
|
99
|
-
conditions: FilterConditionWithId[];
|
|
100
|
-
logicalOperator: LogicalOperator;
|
|
101
|
-
isValid: boolean;
|
|
102
|
-
validationErrors: ValidationError[];
|
|
103
|
-
hasConditions: boolean;
|
|
104
|
-
|
|
105
|
-
// Condition Management (type-safe)
|
|
106
|
-
addCondition: (condition: TypedFilterConditionInput<T>) => string;
|
|
107
|
-
updateCondition: (
|
|
108
|
-
id: string,
|
|
109
|
-
updates: Partial<TypedFilterConditionInput<T>>
|
|
110
|
-
) => boolean;
|
|
111
|
-
removeCondition: (id: string) => boolean;
|
|
112
|
-
clearConditions: () => void;
|
|
113
|
-
getCondition: (id: string) => FilterConditionWithId | undefined;
|
|
114
|
-
|
|
115
|
-
// Logical Operator
|
|
116
|
-
setLogicalOperator: (operator: LogicalOperator) => void;
|
|
117
|
-
|
|
118
|
-
// Bulk Operations
|
|
119
|
-
setConditions: (conditions: FilterConditionWithId[]) => void;
|
|
120
|
-
replaceCondition: (
|
|
121
|
-
id: string,
|
|
122
|
-
newCondition: TypedFilterConditionInput<T>
|
|
123
|
-
) => boolean;
|
|
124
|
-
|
|
125
|
-
// Validation
|
|
126
|
-
validateCondition: (condition: Partial<FilterConditionWithId>) => any;
|
|
127
|
-
validateAllConditions: () => any;
|
|
128
|
-
|
|
129
|
-
// State Management
|
|
130
|
-
exportState: () => any;
|
|
131
|
-
importState: (state: any) => void;
|
|
132
|
-
resetToInitial: () => void;
|
|
133
|
-
|
|
134
|
-
// Utilities
|
|
135
|
-
getConditionCount: () => number;
|
|
136
|
-
};
|
|
79
|
+
// Filter (Simplified chainable API)
|
|
80
|
+
filter: UseFilterReturn;
|
|
137
81
|
|
|
138
82
|
// Pagination (Flat Access)
|
|
139
83
|
pagination: {
|