• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

teableio / teable / 8538004962

03 Apr 2024 11:36AM CUT coverage: 18.233% (-3.3%) from 21.535%
8538004962

Pull #528

github

web-flow
Merge c1a248a6f into 45ee7ebb3
Pull Request #528: feat: Kanban view

575 of 1136 branches covered (50.62%)

29 of 2908 new or added lines in 83 files covered. (1.0%)

5 existing lines in 5 files now uncovered.

6439 of 35315 relevant lines covered (18.23%)

3.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.0
/packages/sdk/src/context/aggregation/GroupPointProvider.tsx
1
import { useQuery, useQueryClient } from '@tanstack/react-query';
1✔
2
import type { IKanbanViewOptions } from '@teable/core';
1✔
3
import { SortFunc, ViewType } from '@teable/core';
1✔
4
import { getGroupPoints } from '@teable/openapi';
1✔
5
import type { FC, ReactNode } from 'react';
1✔
6
import { useCallback, useContext, useEffect, useMemo } from 'react';
1✔
7
import { ReactQueryKeys } from '../../config';
1✔
8
import { useActionTrigger, useIsHydrated, useSearch, useView } from '../../hooks';
1✔
9
import type { PropKeys } from '../action-trigger';
1✔
10
import { AnchorContext } from '../anchor';
1✔
11
import { GroupPointContext } from './GroupPointContext';
1✔
12

1✔
13
interface GroupPointProviderProps {
1✔
14
  children: ReactNode;
1✔
15
}
1✔
16

1✔
17
export const GroupPointProvider: FC<GroupPointProviderProps> = ({ children }) => {
1✔
18
  const isHydrated = useIsHydrated();
×
19
  const { tableId, viewId } = useContext(AnchorContext);
×
20
  const { listener } = useActionTrigger();
×
21
  const queryClient = useQueryClient();
×
22
  const view = useView(viewId);
×
NEW
23
  const { searchQuery } = useSearch();
×
NEW
24
  const { type, group, options } = view || {};
×
NEW
25

×
NEW
26
  const groupBy = useMemo(() => {
×
NEW
27
    if (type === ViewType.Kanban) {
×
NEW
28
      const { stackFieldId } = (options ?? {}) as IKanbanViewOptions;
×
NEW
29
      if (stackFieldId == null) return;
×
NEW
30
      return [{ order: SortFunc.Asc, fieldId: stackFieldId }];
×
NEW
31
    }
×
NEW
32
    return group;
×
NEW
33
  }, [group, options, type]);
×
NEW
34

×
NEW
35
  const query = useMemo(() => {
×
NEW
36
    return {
×
NEW
37
      viewId,
×
NEW
38
      groupBy,
×
NEW
39
      search: searchQuery,
×
NEW
40
    };
×
NEW
41
    // eslint-disable-next-line react-hooks/exhaustive-deps
×
NEW
42
  }, [viewId, JSON.stringify(groupBy), searchQuery]);
×
43

×
44
  const { data: resGroupPoints } = useQuery({
×
45
    queryKey: ReactQueryKeys.groupPoints(tableId as string, query),
×
46
    queryFn: ({ queryKey }) => getGroupPoints(queryKey[1], queryKey[2]),
×
NEW
47
    enabled: Boolean(tableId && isHydrated && groupBy?.length),
×
48
    refetchOnWindowFocus: false,
×
49
    retry: 1,
×
50
  });
×
51

×
52
  const updateGroupPoints = useCallback(
×
53
    () => queryClient.invalidateQueries(ReactQueryKeys.groupPoints(tableId as string, query)),
×
54
    [query, queryClient, tableId]
×
55
  );
×
56

×
57
  useEffect(() => {
×
58
    if (tableId == null) return;
×
59

×
60
    const relevantProps: PropKeys[] = ['addRecord', 'deleteRecord', 'setRecord', 'applyViewFilter'];
×
61

×
62
    listener?.(relevantProps, () => updateGroupPoints(), [tableId, viewId]);
×
63
  }, [listener, tableId, updateGroupPoints, viewId]);
×
64

×
65
  const groupPoints = useMemo(() => resGroupPoints?.data || null, [resGroupPoints]);
×
66

×
67
  return <GroupPointContext.Provider value={groupPoints}>{children}</GroupPointContext.Provider>;
×
68
};
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc