From 8e23476a7032f363c29e2db7f2919fbcb39ca157 Mon Sep 17 00:00:00 2001
From: guerler <aysam.guerler@gmail.com>
Date: Thu, 16 Nov 2023 22:02:07 +0300
Subject: [PATCH] Fix typing warnings

---
 .../Grid/GridElements/GridOperations.vue      |  8 +++----
 client/src/components/Grid/GridList.vue       | 22 ++++++++++++-------
 client/src/components/Grid/configs/types.ts   | 20 ++++++-----------
 3 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/client/src/components/Grid/GridElements/GridOperations.vue b/client/src/components/Grid/GridElements/GridOperations.vue
index cae8c013eece..d135109286fc 100644
--- a/client/src/components/Grid/GridElements/GridOperations.vue
+++ b/client/src/components/Grid/GridElements/GridOperations.vue
@@ -3,13 +3,13 @@ import { library } from "@fortawesome/fontawesome-svg-core";
 import { faCaretDown } from "@fortawesome/free-solid-svg-icons";
 import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
 
-import type { FieldOperations, Operation, RowData } from "@/components/Grid/configs/types";
+import type { Operation, RowData } from "@/components/Grid/configs/types";
 
 library.add(faCaretDown);
 
 interface Props {
     rowData: RowData;
-    operations: FieldOperations;
+    operations: Array<Operation>;
 }
 
 const props = defineProps<Props>();
@@ -37,10 +37,10 @@ function hasCondition(conditionHandler: (rowData: RowData) => Boolean) {
             <FontAwesomeIcon icon="caret-down" class="fa-lg" />
             <span class="font-weight-bold">{{ rowData.title }}</span>
         </button>
-        <div class="dropdown-menu" aria-labelledby="dataset-dropdown">
+        <div v-if="operations" class="dropdown-menu" aria-labelledby="dataset-dropdown">
             <span v-for="(operation, operationIndex) in operations" :key="operationIndex">
                 <button
-                    v-if="hasCondition(operation.condition)"
+                    v-if="operation && operation.condition && hasCondition(operation.condition)"
                     class="dropdown-item"
                     @click.prevent="emit('execute', operation)">
                     <icon :icon="operation.icon" />
diff --git a/client/src/components/Grid/GridList.vue b/client/src/components/Grid/GridList.vue
index 77c3789aedd8..d43c9716f2d9 100644
--- a/client/src/components/Grid/GridList.vue
+++ b/client/src/components/Grid/GridList.vue
@@ -129,11 +129,17 @@ function onSort(sortKey: string) {
 /**
  * Process tag inputs
  */
-async function onTagInput(data: RowData, tags: Array<string>, tagsHandler: FieldHandler) {
-    await tagsHandler({ ...data, tags: tags });
-    data.tags = tags;
+function onTagInput(data: RowData, tags: Array<string>, tagsHandler?: FieldHandler) {
+    if (tagsHandler) {
+        tagsHandler({ ...data, tags: tags });
+        data.tags = tags;
+    }
+}
+function onFilter(filter?: string) {
+    if (filter) {
+        applyFilter(filter, true);
+    }
 }
-
 /**
  * Initialize grid data
  */
@@ -233,19 +239,19 @@ watch(operationMessage, () => {
                     <GridLink
                         v-else-if="fieldEntry.type == 'link'"
                         :text="rowData[fieldEntry.key]"
-                        @click="fieldEntry.handler(rowData, router)" />
+                        @click="fieldEntry.handler && fieldEntry.handler(rowData, router)" />
                     <SharingIndicators
                         v-else-if="fieldEntry.type == 'sharing'"
                         :object="rowData"
-                        @filter="(filter) => applyFilter(filter, true)" />
+                        @filter="onFilter($event)" />
                     <UtcDate v-else-if="fieldEntry.type == 'date'" :date="rowData[fieldEntry.key]" mode="elapsed" />
                     <StatelessTags
                         v-else-if="fieldEntry.type == 'tags'"
                         clickable
                         :value="rowData[fieldEntry.key]"
                         :disabled="fieldEntry.disabled"
-                        @input="(tags) => onTagInput(rowData, tags, fieldEntry.handler)"
-                        @tag-click="(t) => applyFilter('tag', t, true)" />
+                        @input="onTagInput(rowData, $event, fieldEntry.handler)"
+                        @tag-click="applyFilter('tag', $event, true)" />
                     <span v-else v-localize> Data not available. </span>
                 </td>
             </tr>
diff --git a/client/src/components/Grid/configs/types.ts b/client/src/components/Grid/configs/types.ts
index 9cafc448bd98..80e357fa1b5e 100644
--- a/client/src/components/Grid/configs/types.ts
+++ b/client/src/components/Grid/configs/types.ts
@@ -23,27 +23,21 @@ export interface Config {
     title: string;
 }
 
-export type FieldArray = Array<FieldKey | FieldOperations>;
+export type FieldArray = Array<FieldEntry>;
 
-interface FieldKey {
+export interface FieldEntry {
     key: string;
     title: string;
+    condition?: (data: RowData) => boolean;
     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>;
+    operations?: Array<Operation>;
+    handler?: FieldHandler;
     width?: number;
 }
 
+export type FieldHandler = (data: RowData, router?: Router) => void;
+
 export interface Operation {
     title: string;
     icon: IconDefinition;