Skip to content
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

feat(events): add event search #20

Merged
merged 12 commits into from
Dec 29, 2023
2 changes: 2 additions & 0 deletions api-contracts/openapi/components/schemas/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ EventOrderByField:
$ref: "./event.yaml#/EventOrderByField"
EventOrderByDirection:
$ref: "./event.yaml#/EventOrderByDirection"
EventSearch:
$ref: "./event.yaml#/EventSearch"
EventKeyList:
$ref: "./event.yaml#/EventKeyList"
EventKey:
Expand Down
3 changes: 3 additions & 0 deletions api-contracts/openapi/components/schemas/event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ EventOrderByDirection:
enum:
- asc
- desc

EventSearch:
type: string
6 changes: 6 additions & 0 deletions api-contracts/openapi/paths/event/event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ withTenant:
type: array
items:
$ref: "../../components/schemas/_index.yaml#/EventKey"
- description: The search query to filter for
in: query
name: search
required: false
schema:
$ref: "../../components/schemas/_index.yaml#/EventSearch"
- description: What to order by
in: query
name: orderByField
Expand Down
4 changes: 4 additions & 0 deletions api/v1/server/handlers/events/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (t *EventService) EventList(ctx echo.Context, request gen.EventListRequestO
Offset: &offset,
}

if request.Params.Search != nil {
listOpts.Search = request.Params.Search
}

if request.Params.Keys != nil {
listOpts.Keys = *request.Params.Keys
}
Expand Down
107 changes: 60 additions & 47 deletions api/v1/server/oas/gen/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from '@/components/ui/button';
import { DataTableViewOptions } from './data-table-view-options';

import { DataTableFacetedFilter } from './data-table-faceted-filter';
import { Input } from '@/components/ui/input.tsx';

export interface FilterOption {
label: string;
Expand All @@ -22,26 +23,28 @@ interface DataTableToolbarProps<TData> {
table: Table<TData>;
filters: ToolbarFilters;
actions: JSX.Element[];
setSearch?: (search: string) => void;
search?: string;
}

export function DataTableToolbar<TData>({
table,
filters,
actions,
setSearch,
search,
}: DataTableToolbarProps<TData>) {
const isFiltered = table.getState().columnFilters.length > 0;

return (
<div className="flex items-center justify-between">
<div className="flex flex-1 items-center space-x-2">
{/* <Input
placeholder="Filter tasks..."
value={(table.getColumn("title")?.getFilterValue() as string) ?? ""}
onChange={(event) =>
table.getColumn("title")?.setFilterValue(event.target.value)
}
<Input
placeholder="Search for tasks..."
steebchen marked this conversation as resolved.
Show resolved Hide resolved
value={search}
onChange={(e) => setSearch && setSearch(e.target.value)}
className="h-8 w-[150px] lg:w-[250px]"
/> */}
/>
{filters.map(
(filter) =>
table.getColumn(filter.columnId) && (
Expand Down
14 changes: 12 additions & 2 deletions frontend/app/src/components/molecules/data-table/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ interface DataTableProps<TData extends IDGetter, TValue> {
actions?: JSX.Element[];
sorting?: SortingState;
setSorting?: OnChangeFn<SortingState>;
setSearch?: (search: string) => void;
search?: string;
columnFilters?: ColumnFiltersState;
setColumnFilters?: OnChangeFn<ColumnFiltersState>;
pagination?: PaginationState;
Expand Down Expand Up @@ -76,6 +78,8 @@ export function DataTable<TData extends IDGetter, TValue>({
actions = [],
sorting,
setSorting,
setSearch,
search,
columnFilters,
setColumnFilters,
pagination,
Expand All @@ -90,7 +94,7 @@ export function DataTable<TData extends IDGetter, TValue>({
getRowId,
}: DataTableProps<TData, TValue>) {
const tableData = React.useMemo(
() => (isLoading ? Array(10).fill({}) : data),
() => (isLoading ? Array(10).fill({ metadata: {} }) : data),
[isLoading, data],
);

Expand Down Expand Up @@ -160,7 +164,13 @@ export function DataTable<TData extends IDGetter, TValue>({
return (
<div className="space-y-4">
{filters && filters.length > 0 && (
<DataTableToolbar table={table} filters={filters} actions={actions} />
<DataTableToolbar
table={table}
filters={filters}
actions={actions}
search={search}
setSearch={setSearch}
/>
)}
<div className="rounded-md border">
<Table>
Expand Down
3 changes: 3 additions & 0 deletions frontend/app/src/lib/api/generated/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
EventList,
EventOrderByDirection,
EventOrderByField,
EventSearch,
ReplayEventRequest,
Tenant,
User,
Expand Down Expand Up @@ -165,6 +166,8 @@ export class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType
limit?: number;
/** A list of keys to filter by */
keys?: EventKey[];
/** The search query to filter for */
search?: EventSearch;
/** What to order by */
orderByField?: EventOrderByField;
/** The order direction */
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/lib/api/generated/data-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export enum EventOrderByDirection {
Desc = "desc",
}

export type EventSearch = string;

export interface EventKeyList {
pagination?: PaginationResponse;
rows?: EventKey[];
Expand Down
9 changes: 5 additions & 4 deletions frontend/app/src/pages/main/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function EventsTable() {
}
}, [selectedEvent, searchParams, setSearchParams]);

const [search, setSearch] = useState<string | undefined>(undefined);
const [sorting, setSorting] = useState<SortingState>([]);
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [pagination, setPagination] = useState<PaginationState>({
Expand Down Expand Up @@ -134,6 +135,7 @@ function EventsTable() {
orderByDirection,
offset,
limit: pageSize,
search,
}),
});

Expand Down Expand Up @@ -170,10 +172,6 @@ function EventsTable() {
// }
// }, [listEventsQuery.data?.pagination]);

if (listEventsQuery.isLoading) {
return <Loading />;
}
steebchen marked this conversation as resolved.
Show resolved Hide resolved

const tableColumns = columns({
onRowClick: (row: Event) => {
setSelectedEvent(row);
Expand Down Expand Up @@ -225,6 +223,7 @@ function EventsTable() {
{selectedEvent && <ExpandedEventContent event={selectedEvent} />}
</Dialog>
<DataTable
isLoading={listEventsQuery.isLoading}
columns={tableColumns}
data={listEventsQuery.data?.rows || []}
filters={[
Expand All @@ -237,6 +236,8 @@ function EventsTable() {
actions={actions}
sorting={sorting}
setSorting={setSorting}
search={search}
setSearch={setSearch}
columnFilters={columnFilters}
setColumnFilters={setColumnFilters}
pagination={pagination}
Expand Down
3 changes: 3 additions & 0 deletions internal/repository/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type ListEventOpts struct {
// (optional) number of events to return
Limit *int

// (optional) a search query
Search *string

// (optional) the event that this event is replaying
ReplayedEvent *string `validate:"omitempty,uuid"`

Expand Down
12 changes: 8 additions & 4 deletions internal/repository/prisma/dbsqlc/events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ WHERE

-- name: ListEvents :many
SELECT
sqlc.embed(events),
sqlc.embed(events),
sum(case when runs."status" = 'PENDING' then 1 else 0 end) AS pendingRuns,
sum(case when runs."status" = 'RUNNING' then 1 else 0 end) AS runningRuns,
sum(case when runs."status" = 'SUCCEEDED' then 1 else 0 end) AS succeededRuns,
sum(case when runs."status" = 'FAILED' then 1 else 0 end) AS failedRuns
FROM
"Event" as events
"Event" as events
LEFT JOIN
"WorkflowRunTriggeredBy" as runTriggers ON events."id" = runTriggers."eventId"
LEFT JOIN
Expand All @@ -28,7 +28,11 @@ WHERE
(
sqlc.narg('keys')::text[] IS NULL OR
events."key" = ANY(sqlc.narg('keys')::text[])
)
) AND
(
sqlc.narg('search') IS NULL OR
events."data" = sqlc.narg('search') -- TODO!!
)
GROUP BY
events."id"
ORDER BY
Expand All @@ -50,4 +54,4 @@ WHERE
GROUP BY
event_hour
ORDER BY
event_hour;
event_hour;
Loading
Loading