Skip to content

Commit 991e61f

Browse files
authored
feat: Improve filtering for workflow executions (#14898)
1 parent 66f8bb7 commit 991e61f

File tree

9 files changed

+83
-3
lines changed

9 files changed

+83
-3
lines changed

.changeset/tough-showers-cross.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
"@medusajs/medusa": patch
4+
---
5+
6+
Improved filtering support for workflow executions

integration-tests/modules/__tests__/workflow-engine/admin/workflow-executions.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ medusaIntegrationTestRunner({
120120
transaction_id: expect.any(String),
121121
id: expect.any(String),
122122
state: "invoking",
123+
execution: expect.anything(),
123124
created_at: expect.any(String),
124125
updated_at: expect.any(String),
125126
deleted_at: null,
@@ -178,6 +179,7 @@ medusaIntegrationTestRunner({
178179
),
179180
id: expect.any(String),
180181
state: "invoking",
182+
execution: expect.anything(),
181183
created_at: expect.any(String),
182184
updated_at: expect.any(String),
183185
deleted_at: null,
@@ -189,6 +191,7 @@ medusaIntegrationTestRunner({
189191
),
190192
id: expect.any(String),
191193
state: "invoking",
194+
execution: expect.anything(),
192195
created_at: expect.any(String),
193196
updated_at: expect.any(String),
194197
deleted_at: null,

packages/admin/dashboard/src/routes/workflow-executions/workflow-execution-list/components/workflow-execution-list-table/use-workflow-execution-table-columns.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { StatusCell } from "../../../../../components/table/table-cells/common/s
66
import { TransactionStepState } from "../../../types"
77
import { getTransactionState, getTransactionStateColor } from "../../../utils"
88
import { HttpTypes } from "@medusajs/types"
9+
import {
10+
DateCell,
11+
DateHeader,
12+
} from "../../../../../components/table/table-cells/common/date-cell"
913

1014
const columnHelper =
1115
createColumnHelper<
@@ -20,6 +24,10 @@ export const useWorkflowExecutionTableColumns = (): ColumnDef<
2024

2125
return useMemo(
2226
() => [
27+
columnHelper.accessor("workflow_id", {
28+
header: t("workflowExecutions.workflowIdLabel"),
29+
cell: ({ getValue }) => <Badge size="2xsmall">{getValue()}</Badge>,
30+
}),
2331
columnHelper.accessor("transaction_id", {
2432
header: t("workflowExecutions.transactionIdLabel"),
2533
cell: ({ getValue }) => <Badge size="2xsmall">{getValue()}</Badge>,
@@ -64,6 +72,13 @@ export const useWorkflowExecutionTableColumns = (): ColumnDef<
6472
})
6573
},
6674
}),
75+
columnHelper.accessor("created_at", {
76+
header: () => <DateHeader />,
77+
cell: ({ getValue }) => {
78+
const date = new Date(getValue())
79+
return <DateCell date={date} />
80+
},
81+
}),
6782
],
6883
[t]
6984
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { useTranslation } from "react-i18next"
2+
import { Filter } from "../../../../../components/table/data-table"
3+
import { getTransactionState } from "../../../utils"
4+
import { TransactionState } from "../../../types"
5+
6+
export const useWorkflowExecutionTableFilters = () => {
7+
const { t } = useTranslation()
8+
9+
const filters: Filter[] = [
10+
{
11+
label: t("workflowExecutions.workflowIdLabel"),
12+
key: "workflow_id",
13+
type: "string",
14+
},
15+
{
16+
label: t("fields.status"),
17+
key: "state",
18+
type: "select",
19+
multiple: true,
20+
options: Object.values(TransactionState).map((state) => ({
21+
label: getTransactionState(t, state),
22+
value: state,
23+
})),
24+
},
25+
{ label: t("fields.createdAt"), key: "created_at", type: "date" },
26+
]
27+
28+
return filters
29+
}

packages/admin/dashboard/src/routes/workflow-executions/workflow-execution-list/components/workflow-execution-list-table/use-workflow-execution-table-query.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ export const useWorkflowExecutionTableQuery = ({
88
pageSize?: number
99
prefix?: string
1010
}) => {
11-
const raw = useQueryParams(["q", "offset"], prefix)
11+
const raw = useQueryParams(
12+
["q", "offset", "order", "workflow_id", "state", "created_at"],
13+
prefix
14+
)
1215

13-
const { offset, ...rest } = raw
16+
const { offset, order, workflow_id, state, created_at, ...rest } = raw
1417

1518
const searchParams: HttpTypes.AdminGetWorkflowExecutionsParams = {
1619
limit: pageSize,
1720
offset: offset ? parseInt(offset) : 0,
21+
order: order ? order : "-created_at",
22+
workflow_id: workflow_id?.split(","),
23+
state: state?.split(","),
24+
created_at: created_at ? JSON.parse(created_at) : undefined,
1825
...rest,
1926
}
2027

packages/admin/dashboard/src/routes/workflow-executions/workflow-execution-list/components/workflow-execution-list-table/workflow-execution-list-table.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useWorkflowExecutions } from "../../../../../hooks/api/workflow-executi
66
import { useDataTable } from "../../../../../hooks/use-data-table"
77
import { useWorkflowExecutionTableColumns } from "./use-workflow-execution-table-columns"
88
import { useWorkflowExecutionTableQuery } from "./use-workflow-execution-table-query"
9+
import { useWorkflowExecutionTableFilters } from "./use-workflow-execution-table-filters"
910

1011
const PAGE_SIZE = 20
1112

@@ -25,6 +26,7 @@ export const WorkflowExecutionListTable = () => {
2526
}
2627
)
2728

29+
const filters = useWorkflowExecutionTableFilters()
2830
const columns = useWorkflowExecutionTableColumns()
2931

3032
const { table } = useDataTable({
@@ -54,8 +56,10 @@ export const WorkflowExecutionListTable = () => {
5456
table={table}
5557
columns={columns}
5658
count={count}
59+
filters={filters}
5760
isLoading={isLoading}
5861
pageSize={PAGE_SIZE}
62+
orderBy={[{ key: "created_at", label: t("fields.createdAt") }]}
5963
navigateTo={(row) => `${row.id}`}
6064
search
6165
pagination

packages/core/types/src/http/workflow-execution/admin/queries.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { OperatorMap } from "../../.."
12
import { FindParams } from "../../common"
23

34
export interface AdminGetWorkflowExecutionsParams extends FindParams {
@@ -13,4 +14,12 @@ export interface AdminGetWorkflowExecutionsParams extends FindParams {
1314
* Filter by the ID of the workflow to retrieve workflow executions for a specific workflow.
1415
*/
1516
workflow_id?: string | string[]
17+
/**
18+
* Filter by the state of the workflow execution.
19+
*/
20+
state?: string | string[]
21+
/**
22+
* Filter by the creation date of the workflow execution.
23+
*/
24+
created_at?: OperatorMap<string>
1625
}

packages/medusa/src/api/admin/workflows-executions/query-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const defaultAdminWorkflowExecutionsFields = [
1919
"workflow_id",
2020
"transaction_id",
2121
"state",
22+
"execution",
2223
"created_at",
2324
"updated_at",
2425
"deleted_at",

packages/medusa/src/api/admin/workflows-executions/validators.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { TransactionHandlerType } from "@medusajs/framework/utils"
22
import { z } from "@medusajs/framework/zod"
3-
import { createFindParams, createSelectParams } from "../../utils/validators"
3+
import {
4+
createFindParams,
5+
createOperatorMap,
6+
createSelectParams,
7+
} from "../../utils/validators"
48

59
export type AdminGetWorkflowExecutionDetailsParamsType = z.infer<
610
typeof AdminGetWorkflowExecutionDetailsParams
@@ -19,6 +23,8 @@ export const AdminGetWorkflowExecutionsParams = createFindParams({
1923
q: z.string().optional(),
2024
transaction_id: z.union([z.string(), z.array(z.string())]).optional(),
2125
workflow_id: z.union([z.string(), z.array(z.string())]).optional(),
26+
state: z.union([z.string(), z.array(z.string())]).optional(),
27+
created_at: createOperatorMap().optional(),
2228
})
2329
)
2430

0 commit comments

Comments
 (0)