diff --git a/client/src/components/Grid/configs/types.ts b/client/src/components/Grid/configs/types.ts index 7954aaa72d31..d9d574c589c8 100644 --- a/client/src/components/Grid/configs/types.ts +++ b/client/src/components/Grid/configs/types.ts @@ -8,7 +8,7 @@ interface Action { handler: (router: Router) => void; } -type Field = FieldKey | FieldOperations; +export type FieldArray = Array; interface FieldKey { key: string; @@ -25,14 +25,14 @@ interface OperationHandlerMessage { status: string; } -type OperationHandlerReturn = OperationHandlerMessage | void; +type OperationHandlerReturn = Promise | void; /** * Exported Type declarations */ export interface Config { actions?: Array; - fields: Array; + fields: FieldArray; filtering: Filtering; getData: (offset: number, limit: number, search: string, sort_by: string, sort_desc: boolean) => Promise; plural: string; @@ -45,6 +45,7 @@ export interface Config { export interface FieldOperations { key: string; title: string; + condition?: (data: RowData) => boolean; operations: Array; width?: number; } @@ -55,7 +56,7 @@ export type RowData = Record; export interface Operation { title: string; - icon: string; + icon: any; condition?: (data: RowData) => boolean; handler: (data: RowData, router: Router) => OperationHandlerReturn; } diff --git a/client/src/components/Grid/configs/visualizations.ts b/client/src/components/Grid/configs/visualizations.ts index d039b0de985c..911681c45d66 100644 --- a/client/src/components/Grid/configs/visualizations.ts +++ b/client/src/components/Grid/configs/visualizations.ts @@ -8,7 +8,7 @@ import Filtering, { contains, equals, expandNameTag, toBool, type ValidFilter } import { withPrefix } from "@/utils/redirect"; import { errorMessageAsString, rethrowSimple } from "@/utils/simple-error"; -import { type Config } from "./types"; +import { type Config, type FieldArray } from "./types"; /** * Api endpoint handlers @@ -61,12 +61,12 @@ const actions = [ /** * Declare columns to be displayed */ -const fields = [ +const fields: FieldArray = [ { title: "Title", key: "title", type: "operations", - width: "40%", + width: 40, condition: (data: VisualizationEntry) => !data.deleted, operations: [ { @@ -141,7 +141,7 @@ const fields = [ { title: "Restore", icon: faTrashRestore, - condition: (data: VisualizationEntry) => data.deleted, + condition: (data: VisualizationEntry) => !!data.deleted, handler: async (data: VisualizationEntry) => { try { await axios.put(withPrefix(`/api/visualizations/${data.id}`), { deleted: false });