Skip to content

Commit

Permalink
Add additional types to config initialization, expect type specific i…
Browse files Browse the repository at this point in the history
…con props
  • Loading branch information
guerler committed Nov 16, 2023
1 parent cb41ce3 commit 3585aeb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
4 changes: 2 additions & 2 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useRouter } from "vue-router/composables";
import { timeout } from "@/utils/timeout";
import { Config, FieldKeyHandler, Operation, RowData } from "./configs/types";
import { Config, FieldHandler, Operation, RowData } from "./configs/types";
import GridLink from "./GridElements/GridLink.vue";
import GridOperations from "./GridElements/GridOperations.vue";
Expand Down Expand Up @@ -129,7 +129,7 @@ function onSort(sortKey: string) {
/**
* Process tag inputs
*/
async function onTagInput(data: RowData, tags: Array<string>, tagsHandler: FieldKeyHandler) {
async function onTagInput(data: RowData, tags: Array<string>, tagsHandler: FieldHandler) {
await tagsHandler({ ...data, tags: tags });
data.tags = tags;
}
Expand Down
57 changes: 28 additions & 29 deletions client/src/components/Grid/configs/types.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
import { IconProp } from "@fortawesome/fontawesome-svg-core";
import type Router from "vue-router";

import Filtering from "@/utils/filtering";

interface Action {
export interface Action {
title: string;
icon?: string;
icon?: IconProp;
handler: (router: Router) => void;
}

export type FieldArray = Array<FieldKey | FieldOperations>;

interface FieldKey {
key: string;
disabled?: boolean;
type: string;
handler?: FieldKeyHandler;
}

// TODO: Apply strict literals
// type FieldType = "date" | "operations" | "sharing" | "tags" | "text" | undefined;
export type ActionArray = Array<Action>;

interface OperationHandlerMessage {
message: string;
status: string;
}

type OperationHandlerReturn = Promise<OperationHandlerMessage> | void;

/**
* Exported Type declarations
*/
export interface Config {
actions?: Array<Action>;
actions?: ActionArray;
fields: FieldArray;
filtering: Filtering<any>;
getData: (offset: number, limit: number, search: string, sort_by: string, sort_desc: boolean) => Promise<any>;
Expand All @@ -42,21 +23,39 @@ export interface Config {
title: string;
}

export type FieldArray = Array<FieldKey | FieldOperations>;

interface FieldKey {
key: string;
title: string;
disabled?: boolean;
type: string;
handler?: (data: RowData) => void;
}

export type FieldHandler = (data: RowData) => void;

export interface FieldOperations {
key: string;
title: string;
type: string;
condition?: (data: RowData) => boolean;
operations: Array<Operation>;
width?: number;
}

export type FieldKeyHandler = (data: RowData) => void;

export type RowData = Record<string, unknown>;

export interface Operation {
title: string;
icon: any;
icon: IconProp;
condition?: (data: RowData) => boolean;
handler: (data: RowData, router: Router) => OperationHandlerReturn;
}

interface OperationHandlerMessage {
message: string;
status: string;
}

type OperationHandlerReturn = Promise<OperationHandlerMessage> | void;

export type RowData = Record<string, unknown>;
8 changes: 4 additions & 4 deletions client/src/components/Grid/configs/visualizations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { faCopy, faEdit, faEye, faShareAlt, faTrash, faTrashRestore } from "@fortawesome/free-solid-svg-icons";
import { faCopy, faEdit, faEye, faPlus, faShareAlt, faTrash, faTrashRestore } from "@fortawesome/free-solid-svg-icons";
import axios from "axios";
import type Router from "vue-router";

Expand All @@ -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, type FieldArray } from "./types";
import type { ActionArray, Config, FieldArray } from "./types";

/**
* Api endpoint handlers
Expand Down Expand Up @@ -48,10 +48,10 @@ async function getData(offset: number, limit: number, search: string, sort_by: s
/**
* Actions are grid-wide operations
*/
const actions = [
const actions: ActionArray = [
{
title: "Create",
icon: "plus",
icon: faPlus,
handler: (router: Router) => {
router.push(`/visualizations`);
},
Expand Down

0 comments on commit 3585aeb

Please sign in to comment.