-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix table filter issue and put it on the table header
- Loading branch information
1 parent
27cd7a3
commit 6274ebf
Showing
5 changed files
with
170 additions
and
105 deletions.
There are no files selected for viewing
129 changes: 72 additions & 57 deletions
129
apps/analytics/app/_components/analytics/EventsTable/Columns.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,84 @@ | ||
"use client"; | ||
|
||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { type Dispatch, type SetStateAction } from "react"; | ||
import { DataTableColumnHeader } from "~/components/DataTable/column-header"; | ||
import { MetadataDialog } from "~/components/MetadataDialog"; | ||
import type { Event } from "~/db/getEvents"; | ||
import { type EventType } from "./EventsTable"; | ||
import { StackTraceDialog } from "./StackTraceDialog"; | ||
import TableFilter from "./TableFilter"; | ||
|
||
export const columns: ColumnDef<Event>[] = [ | ||
{ | ||
accessorKey: "type", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Event" /> | ||
), | ||
}, | ||
{ | ||
accessorKey: "timestamp", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Timestamp" /> | ||
), | ||
cell: ({ row }) => { | ||
return ( | ||
<div className="break-all">{row.original.timestamp.toUTCString()}</div> | ||
); | ||
export const getColumns = ( | ||
eventTypes: EventType[], | ||
setEventTypes: Dispatch<SetStateAction<EventType[]>> | ||
) => { | ||
const columns: ColumnDef<Event>[] = [ | ||
{ | ||
accessorKey: "type", | ||
header: ({ column }) => ( | ||
<div className="flex space-x-4"> | ||
<TableFilter eventTypes={eventTypes} setEventTypes={setEventTypes} /> | ||
<DataTableColumnHeader column={column} /> | ||
</div> | ||
), | ||
}, | ||
}, | ||
{ | ||
accessorKey: "installationId", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Installation Id" /> | ||
), | ||
cell: ({ row }) => { | ||
return <div className="break-all">{row.original.installationId}</div>; | ||
{ | ||
accessorKey: "timestamp", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Timestamp" /> | ||
), | ||
cell: ({ row }) => { | ||
return ( | ||
<div className="break-all"> | ||
{row.original.timestamp.toUTCString()} | ||
</div> | ||
); | ||
}, | ||
}, | ||
}, | ||
{ | ||
accessorKey: "name", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Name" /> | ||
), | ||
}, | ||
{ | ||
accessorKey: "message", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Message" /> | ||
), | ||
}, | ||
{ | ||
accessorKey: "stack", | ||
header: "", | ||
cell: ({ row }) => | ||
row.original.stack && ( | ||
<div className="min-w-max"> | ||
<StackTraceDialog error={row.original} /> | ||
</div> | ||
{ | ||
accessorKey: "installationId", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Installation Id" /> | ||
), | ||
cell: ({ row }) => { | ||
return <div className="break-all">{row.original.installationId}</div>; | ||
}, | ||
}, | ||
{ | ||
accessorKey: "name", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Name" /> | ||
), | ||
}, | ||
{ | ||
accessorKey: "message", | ||
header: ({ column }) => ( | ||
<DataTableColumnHeader column={column} title="Message" /> | ||
), | ||
}, | ||
{ | ||
accessorKey: "metadata", | ||
header: "", | ||
cell: ({ row }) => { | ||
return ( | ||
<div className="min-w-max"> | ||
<MetadataDialog event={row.original} /> | ||
</div> | ||
); | ||
}, | ||
}, | ||
]; | ||
{ | ||
accessorKey: "stack", | ||
header: "", | ||
cell: ({ row }) => | ||
row.original.stack && ( | ||
<div className="min-w-max"> | ||
<StackTraceDialog error={row.original} /> | ||
</div> | ||
), | ||
}, | ||
{ | ||
accessorKey: "metadata", | ||
header: "", | ||
cell: ({ row }) => { | ||
return ( | ||
<div className="min-w-max"> | ||
<MetadataDialog event={row.original} /> | ||
</div> | ||
); | ||
}, | ||
}, | ||
]; | ||
|
||
return columns; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"use client"; | ||
|
||
import React, { useState } from "react"; | ||
|
||
const eventTypes = [ | ||
"AppSetup", | ||
"ProtocolInstalled", | ||
"InterviewStarted", | ||
"InterviewCompleted", | ||
"DataExported", | ||
"Error", | ||
]; | ||
|
||
const DropdownMenu = () => { | ||
const [selectedOptions, setSelectedOptions] = useState( | ||
eventTypes.map((eventType) => ({ text: eventType, isSelected: true })) | ||
); | ||
|
||
const toggleOption = (option: string) => { | ||
setSelectedOptions((prevOptions) => | ||
prevOptions.map((prevOption) => | ||
prevOption.text === option | ||
? { ...prevOption, isSelected: !prevOption.isSelected } | ||
: prevOption | ||
) | ||
); | ||
}; | ||
|
||
const toggleAllOptions = (isSelected: boolean) => { | ||
setSelectedOptions((prevOptions) => | ||
prevOptions.map((prevOption) => ({ ...prevOption, isSelected })) | ||
); | ||
}; | ||
|
||
const isAllSelected = selectedOptions.every((option) => option.isSelected); | ||
|
||
return ( | ||
<div className="border-2 p-4"> | ||
<label className="text-sm flex items-center gap-3 pl-2 transition-colors hover:bg-muted p-1 rounded-md"> | ||
<input | ||
type="checkbox" | ||
checked={isAllSelected} | ||
onChange={() => toggleAllOptions(!isAllSelected)} | ||
/> | ||
All | ||
</label> | ||
{selectedOptions.map((option) => ( | ||
<label | ||
className="text-sm flex items-center gap-3 pl-2 transition-colors hover:bg-muted p-1 rounded-md" | ||
key={option.text} | ||
> | ||
<input | ||
type="checkbox" | ||
checked={option.isSelected} | ||
onChange={() => toggleOption(option.text)} | ||
/> | ||
{option.text} | ||
</label> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DropdownMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters