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

add pagination for workflows #1109

Merged
merged 8 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api-contracts/openapi/paths/workflow/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ withTenant:
format: uuid
minLength: 36
maxLength: 36
- description: The number to skip
in: query
name: offset
required: false
schema:
type: integer
format: int
default: 0
- description: The number to limit by
in: query
name: limit
required: false
schema:
type: integer
format: int
default: 50
- description: Search by name
in: query
name: name
required: false
schema:
type: string
responses:
"200":
content:
Expand Down
22 changes: 20 additions & 2 deletions api/v1/server/handlers/workflows/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,30 @@ import (
func (t *WorkflowService) WorkflowList(ctx echo.Context, request gen.WorkflowListRequestObject) (gen.WorkflowListResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)

limit := 50
offset := 0
if request.Params.Limit == nil {
request.Params.Limit = new(int)
*request.Params.Limit = 50
}

if request.Params.Offset == nil {
request.Params.Offset = new(int)
*request.Params.Offset = 0
}

if request.Params.Name == nil {
request.Params.Name = new(string)

}

name := *request.Params.Name

limit := *request.Params.Limit
offset := *request.Params.Offset

listOpts := &repository.ListWorkflowsOpts{
Limit: &limit,
Offset: &offset,
Name: &name,
}

listResp, err := t.config.APIRepository.Workflow().ListWorkflows(tenant.ID, listOpts)
Expand Down
113 changes: 75 additions & 38 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 @@ -19,20 +19,27 @@ import { Label } from '@radix-ui/react-label';
interface DataTablePaginationProps<TData> {
table: Table<TData>;
onSetPageSize?: (pageSize: number) => void;
showSelectedRows?: boolean;
}

export function DataTablePagination<TData>({
table,
onSetPageSize,
showSelectedRows = true,
}: DataTablePaginationProps<TData>) {
const pagination = table.getState().pagination;

return (
<div className="flex items-center justify-between px-2">
<div className="flex-1 text-sm text-gray-600 dark:text-gray-400">
{table.getFilteredSelectedRowModel().rows.length} of{' '}
{table.getFilteredRowModel().rows.length} row(s) selected.
{showSelectedRows && (
<div>
{table.getFilteredSelectedRowModel().rows.length} of{' '}
{table.getFilteredRowModel().rows.length} row(s) selected.
</div>
)}
</div>

<div className="flex items-center space-x-6 lg:space-x-8">
<div className="flex items-center space-x-2">
<Label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface DataTableProps<TData extends IDGetter, TValue> {
setColumnFilters?: OnChangeFn<ColumnFiltersState>;
pagination?: PaginationState;
setPagination?: OnChangeFn<PaginationState>;
showSelectedRows?: boolean;
pageCount?: number;
onSetPageSize?: (pageSize: number) => void;
showColumnToggle?: boolean;
Expand Down Expand Up @@ -99,6 +100,7 @@ export function DataTable<TData extends IDGetter, TValue>({
setPagination,
pageCount,
onSetPageSize,
showSelectedRows = true,
showColumnToggle,
columnVisibility,
setColumnVisibility,
Expand Down Expand Up @@ -259,7 +261,11 @@ export function DataTable<TData extends IDGetter, TValue>({
{!card ? getTable() : getCards()}
</div>
{pagination && (
<DataTablePagination table={table} onSetPageSize={onSetPageSize} />
<DataTablePagination
table={table}
onSetPageSize={onSetPageSize}
showSelectedRows={showSelectedRows}
/>
)}
</div>
);
Expand Down
22 changes: 21 additions & 1 deletion frontend/app/src/lib/api/generated/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,10 +1116,30 @@ export class Api<SecurityDataType = unknown> extends HttpClient<SecurityDataType
* @request GET:/api/v1/tenants/{tenant}/workflows
* @secure
*/
workflowList = (tenant: string, params: RequestParams = {}) =>
workflowList = (
tenant: string,
query?: {
/**
* The number to skip
* @format int
* @default 0
*/
offset?: number;
/**
* The number to limit by
* @format int
* @default 50
*/
limit?: number;
/** Search by name */
name?: string;
},
params: RequestParams = {},
) =>
this.request<WorkflowList, APIErrors>({
path: `/api/v1/tenants/${tenant}/workflows`,
method: 'GET',
query: query,
secure: true,
format: 'json',
...params,
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/src/lib/api/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ListEventQuery = Parameters<typeof api.eventList>[1];
type ListRateLimitsQuery = Parameters<typeof api.rateLimitList>[1];
type ListLogLineQuery = Parameters<typeof api.logLineList>[1];
type ListWorkflowRunsQuery = Parameters<typeof api.workflowRunList>[1];
type ListWorkflowsQuery = Parameters<typeof api.workflowList>[1];
export type ListCloudLogsQuery = Parameters<typeof cloudApi.logList>[1];
export type GetCloudMetricsQuery = Parameters<typeof cloudApi.metricsCpuGet>[1];
type WorkflowRunMetrics = Parameters<typeof api.workflowRunGetMetrics>[1];
Expand Down Expand Up @@ -159,9 +160,9 @@ export const queries = createQueryKeyStore({
}),
},
workflows: {
list: (tenant: string) => ({
list: (tenant: string, query?: ListWorkflowsQuery) => ({
queryKey: ['workflow:list', tenant],
queryFn: async () => (await api.workflowList(tenant)).data,
queryFn: async () => (await api.workflowList(tenant, query)).data,
}),
get: (workflow: string) => ({
queryKey: ['workflow:get', workflow],
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/pages/main/events/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function EventsTable() {
isLoading: workflowKeysIsLoading,
error: workflowKeysError,
} = useQuery({
...queries.workflows.list(tenant.metadata.id),
...queries.workflows.list(tenant.metadata.id, { limit: 200 }),
});

const workflowKeyFilters = useMemo((): FilterOption[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function CronsTable() {
};

const { data: workflowKeys } = useQuery({
...queries.workflows.list(tenant.metadata.id),
...queries.workflows.list(tenant.metadata.id, { limit: 200 }),
});

const workflowKeyFilters = useMemo((): FilterOption[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function ScheduledRunsTable({
isLoading: workflowKeysIsLoading,
error: workflowKeysError,
} = useQuery({
...queries.workflows.list(tenant.metadata.id),
...queries.workflows.list(tenant.metadata.id, { limit: 200 }),
});

const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export function WorkflowRunsTable({
isLoading: workflowKeysIsLoading,
error: workflowKeysError,
} = useQuery({
...queries.workflows.list(tenant.metadata.id),
...queries.workflows.list(tenant.metadata.id, { limit: 200 }),
});

const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function TriggerWorkflowForm({
});

const { data: workflowKeys, isFetched } = useQuery({
...queries.workflows.list(tenant.metadata.id),
...queries.workflows.list(tenant.metadata.id, { limit: 200 }),
});

const workflow = useMemo(() => {
Expand Down
Loading
Loading