-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat(ui): add filter bars to Errors and Logs tabs #1329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
105 changes: 68 additions & 37 deletions
105
packages/spotlight/src/ui/telemetry/components/events/EventList.tsx
This file contains hidden or 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,55 +1,86 @@ | ||
| import CardList from "@spotlight/ui/telemetry/components/shared/CardList"; | ||
| import { OriginBadge } from "@spotlight/ui/telemetry/components/shared/OriginBadge"; | ||
| import TimeSince from "@spotlight/ui/telemetry/components/shared/TimeSince"; | ||
| import { useState } from "react"; | ||
| import { Link } from "react-router-dom"; | ||
| import { useSentryEvents } from "../../data/useSentryEvents"; | ||
| import useErrorFiltering from "../../hooks/useErrorFiltering"; | ||
| import { isErrorEvent } from "../../utils/sentry"; | ||
| import { truncateId } from "../../utils/text"; | ||
| import EmptyState from "../shared/EmptyState"; | ||
| import ListFilter from "../shared/ListFilter"; | ||
| import PlatformIcon from "../shared/PlatformIcon"; | ||
| import { EventSummary } from "./Event"; | ||
|
|
||
| export default function EventList({ traceId }: { traceId?: string }) { | ||
| const events = useSentryEvents(traceId); | ||
| const [searchQuery, setSearchQuery] = useState(""); | ||
| const [activeFilters, setActiveFilters] = useState<string[]>([]); | ||
|
|
||
| const matchingEvents = events.filter(isErrorEvent); | ||
| const errorEvents = events.filter(isErrorEvent); | ||
| const { ERROR_FILTER_CONFIGS, filteredEvents } = useErrorFiltering(errorEvents, activeFilters, searchQuery); | ||
|
|
||
| return matchingEvents.length !== 0 ? ( | ||
| <CardList> | ||
| {matchingEvents.map(e => { | ||
| return ( | ||
| <Link | ||
| className="hover:bg-primary-900 flex cursor-pointer items-center gap-x-4 px-6 py-2" | ||
| key={e.event_id} | ||
| to={`/telemetry/errors/${e.event_id}/details`} | ||
| > | ||
| <PlatformIcon event={e} className="text-primary-300 rounded-md" /> | ||
| <div className="text-primary-300 flex w-48 flex-col truncate font-mono text-sm"> | ||
| <div className="flex items-center gap-x-2"> | ||
| <div>{truncateId(e.event_id)}</div> | ||
| <OriginBadge sourceType={e.__sourceType} /> | ||
| // Filtering is only exposed on the top-level Errors tab, not inside a trace's error list. | ||
| const showFilter = !traceId && errorEvents.length > 0; | ||
| const matchingEvents = traceId ? errorEvents : filteredEvents; | ||
|
|
||
| const list = | ||
| matchingEvents.length !== 0 ? ( | ||
| <CardList> | ||
| {matchingEvents.map(e => { | ||
| return ( | ||
| <Link | ||
| className="hover:bg-primary-900 flex cursor-pointer items-center gap-x-4 px-6 py-2" | ||
| key={e.event_id} | ||
| to={`/telemetry/errors/${e.event_id}/details`} | ||
| > | ||
| <PlatformIcon event={e} className="text-primary-300 rounded-md" /> | ||
| <div className="text-primary-300 flex w-48 flex-col truncate font-mono text-sm"> | ||
| <div className="flex items-center gap-x-2"> | ||
| <div>{truncateId(e.event_id)}</div> | ||
| <OriginBadge sourceType={e.__sourceType} /> | ||
| </div> | ||
| <span /> | ||
| <TimeSince date={e.timestamp} /> | ||
| </div> | ||
| <div className="flex-1 overflow-hidden"> | ||
| <EventSummary event={e} /> | ||
| </div> | ||
| <span /> | ||
| <TimeSince date={e.timestamp} /> | ||
| </div> | ||
| <div className="flex-1 overflow-hidden"> | ||
| <EventSummary event={e} /> | ||
| </div> | ||
| </Link> | ||
| ); | ||
| })} | ||
| </CardList> | ||
| ) : ( | ||
| <EmptyState | ||
| variant={!traceId ? "full" : "simple"} | ||
| className={!traceId ? "h-full" : undefined} | ||
| title={!traceId ? "No Errors" : undefined} | ||
| description={ | ||
| !traceId | ||
| ? "No errors captured yet. That's either very good news or your SDK isn't set up." | ||
| : "No errors in this trace." | ||
| } | ||
| showDocsLink={!traceId} | ||
| /> | ||
| </Link> | ||
| ); | ||
| })} | ||
| </CardList> | ||
| ) : ( | ||
| <EmptyState | ||
| variant={!traceId ? "full" : "simple"} | ||
| className={!traceId ? "h-full" : undefined} | ||
| title={!traceId ? "No Errors" : undefined} | ||
| description={ | ||
| !traceId | ||
| ? showFilter | ||
| ? "No errors match the current filters." | ||
| : "No errors captured yet. That's either very good news or your SDK isn't set up." | ||
| : "No errors in this trace." | ||
| } | ||
| showDocsLink={!traceId && !showFilter} | ||
| /> | ||
| ); | ||
|
|
||
| if (!showFilter) { | ||
| return list; | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex h-full flex-col overflow-hidden"> | ||
| <ListFilter | ||
| searchQuery={searchQuery} | ||
| setSearchQuery={setSearchQuery} | ||
| activeFilters={activeFilters} | ||
| setActiveFilters={setActiveFilters} | ||
| filterConfigs={ERROR_FILTER_CONFIGS} | ||
| searchPlaceholder="Search by message or exception type..." | ||
| /> | ||
| <div className="flex-1 overflow-auto">{list}</div> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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
134 changes: 134 additions & 0 deletions
134
packages/spotlight/src/ui/telemetry/components/shared/ListFilter.tsx
This file contains hidden or 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,134 @@ | ||
| import { ReactComponent as X } from "@spotlight/ui/assets/cross.svg"; | ||
| import { ReactComponent as Search } from "@spotlight/ui/assets/search.svg"; | ||
|
|
||
| import { Badge } from "@spotlight/ui/ui/badge"; | ||
| import { Button } from "@spotlight/ui/ui/button"; | ||
| import { Input } from "@spotlight/ui/ui/input"; | ||
| import { useCallback, useMemo } from "react"; | ||
| import type { FilterConfigs } from "../../hooks/filterTypes"; | ||
| import { FilterDropdown } from "./FilterDropdown"; | ||
|
|
||
| interface ListFilterProps { | ||
| searchQuery: string; | ||
| setSearchQuery: (query: string) => void; | ||
| activeFilters: string[]; | ||
| setActiveFilters: React.Dispatch<React.SetStateAction<string[]>>; | ||
| filterConfigs: FilterConfigs; | ||
| searchPlaceholder?: string; | ||
| } | ||
|
|
||
| export default function ListFilter({ | ||
| searchQuery, | ||
| setSearchQuery, | ||
| activeFilters, | ||
| setActiveFilters, | ||
| filterConfigs, | ||
| searchPlaceholder = "Search...", | ||
| }: ListFilterProps) { | ||
| const handleFilterChange = useCallback( | ||
| (value: string, checked: boolean, type: "checkbox" | "radio") => { | ||
| if (type === "checkbox") { | ||
| if (checked) { | ||
| setActiveFilters(prev => [...prev, value]); | ||
| } else { | ||
| setActiveFilters(prev => prev.filter(f => f !== value)); | ||
| } | ||
| } else if (type === "radio") { | ||
| if (checked) { | ||
| setActiveFilters([value]); | ||
| } else { | ||
| setActiveFilters([]); | ||
| } | ||
| } | ||
| }, | ||
| [setActiveFilters], | ||
| ); | ||
|
|
||
| const clearAllFilters = useCallback(() => { | ||
| setActiveFilters([]); | ||
| setSearchQuery(""); | ||
| }, [setSearchQuery, setActiveFilters]); | ||
|
|
||
| const visibleFilterConfigs = useMemo( | ||
| () => Object.entries(filterConfigs).filter(([, config]) => config.show), | ||
| [filterConfigs], | ||
| ); | ||
|
|
||
| const labelForValue = useCallback( | ||
| (value: string) => { | ||
| for (const config of Object.values(filterConfigs)) { | ||
| const option = config.options.find(o => o.value === value); | ||
| if (option) return option.label; | ||
| } | ||
| return value; | ||
| }, | ||
| [filterConfigs], | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="p-4"> | ||
| <div className="flex flex-wrap items-center gap-2"> | ||
| <div className="relative min-w-[250px] flex-1"> | ||
| <Search className="absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 transform text-gray-400" /> | ||
| <Input | ||
| type="text" | ||
| placeholder={searchPlaceholder} | ||
| value={searchQuery} | ||
| onChange={e => setSearchQuery(e.target.value)} | ||
| className="border-primary-700 bg-primary-950 w-full pl-9 text-white placeholder:text-gray-400" | ||
| /> | ||
| {searchQuery && ( | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="absolute right-2 top-1/2 h-5 w-5 -translate-y-1/2 transform text-gray-400" | ||
| onClick={() => setSearchQuery("")} | ||
| > | ||
| <X className="h-3 w-3" /> | ||
| </Button> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="flex flex-wrap gap-2"> | ||
| {visibleFilterConfigs.map(([key, config]) => ( | ||
| <FilterDropdown | ||
| key={key} | ||
| icon={config.icon} | ||
| label={config.label} | ||
| options={config.options} | ||
| type={config.type} | ||
| activeFilters={activeFilters} | ||
| onFilterChange={(value, checked) => handleFilterChange(value, checked, config.type)} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
|
|
||
| {activeFilters.length > 0 && ( | ||
| <div className="mt-4 flex flex-wrap gap-2"> | ||
| {activeFilters.map(filter => ( | ||
| <Badge key={filter} className="text-white"> | ||
| {labelForValue(filter)} | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="ml-1 h-4 w-4 text-gray-400 hover:bg-transparent hover:text-white" | ||
| onClick={() => setActiveFilters(prev => prev.filter(f => f !== filter))} | ||
| > | ||
| <X className="h-3 w-3" /> | ||
| </Button> | ||
| </Badge> | ||
| ))} | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="text-xs text-gray-400 hover:bg-transparent hover:text-white" | ||
| onClick={clearAllFilters} | ||
| > | ||
| Clear all | ||
| </Button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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,16 @@ | ||
| import type { ElementType } from "react"; | ||
|
|
||
| export interface FilterOption { | ||
| label: string; | ||
| value: string; | ||
| } | ||
|
|
||
| export interface FilterConfig { | ||
| icon: ElementType; | ||
| label: string; | ||
| options: FilterOption[]; | ||
| show: boolean; | ||
| type: "checkbox" | "radio"; | ||
| } | ||
|
|
||
| export type FilterConfigs = Record<string, FilterConfig>; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.