({
surveyId,
data,
hasMore = false,
isLoading = false,
onLoadMore,
className,
})
| 37 | } |
| 38 | |
| 39 | export const SurveyEventTable: React.FC<SurveyEventTableProps> = ({ |
| 40 | surveyId, |
| 41 | data, |
| 42 | hasMore = false, |
| 43 | isLoading = false, |
| 44 | onLoadMore, |
| 45 | className, |
| 46 | }) => { |
| 47 | const { t } = useTranslation(); |
| 48 | const workspaceId = useCurrentWorkspaceId(); |
| 49 | const filters = useInsightsStore((state) => |
| 50 | state.currentFilters.filter((f): f is NonNullable<typeof f> => !!f) |
| 51 | ); |
| 52 | const dateRange = useInsightsStore((state) => state.currentDateRange); |
| 53 | const [isDownloading, setIsDownloading] = useState(false); |
| 54 | const [downloadedCount, setDownloadedCount] = useState(0); |
| 55 | const trpcUtils = trpc.useUtils(); |
| 56 | const [hiddenColumnIds = [], setHiddenColumnIds] = useLocalStorageState< |
| 57 | string[] |
| 58 | >(`tianji-survey-table-hidden-columns-${surveyId}`, { |
| 59 | defaultValue: [], |
| 60 | }); |
| 61 | const [columnOrder = [], setColumnOrder] = useLocalStorageState<string[]>( |
| 62 | `tianji-survey-table-column-order-${surveyId}`, |
| 63 | { |
| 64 | defaultValue: [], |
| 65 | } |
| 66 | ); |
| 67 | const [allowWrap = true, setAllowWrap] = useLocalStorageState<boolean>( |
| 68 | `tianji-survey-table-allow-wrap-${surveyId}`, |
| 69 | { |
| 70 | defaultValue: false, |
| 71 | } |
| 72 | ); |
| 73 | |
| 74 | const { data: survey } = trpc.survey.get.useQuery( |
| 75 | { workspaceId, surveyId }, |
| 76 | { enabled: Boolean(surveyId) } |
| 77 | ); |
| 78 | |
| 79 | const surveyFields = useMemo(() => { |
| 80 | if (!survey?.payload) return []; |
| 81 | const payload = survey.payload as { |
| 82 | items: Array<{ label: string; name: string; type: string }>; |
| 83 | }; |
| 84 | return payload.items || []; |
| 85 | }, [survey]); |
| 86 | |
| 87 | const allColumns = useMemo<ColumnDef<EventData>[]>(() => { |
| 88 | const baseColumns: ColumnDef<EventData>[] = [ |
| 89 | { |
| 90 | id: 'createdAt', |
| 91 | accessorKey: 'createdAt', |
| 92 | header: t('Time'), |
| 93 | size: 180, |
| 94 | cell: ({ row }) => { |
| 95 | const eventDate = dayjs(row.original.createdAt); |
| 96 | return eventDate.isValid() |
nothing calls this directly
no test coverage detected