Skip to content

Commit

Permalink
Fix typing warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed Nov 16, 2023
1 parent 3039faa commit 8e23476
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
8 changes: 4 additions & 4 deletions client/src/components/Grid/GridElements/GridOperations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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" />
Expand Down
22 changes: 14 additions & 8 deletions client/src/components/Grid/GridList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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>
Expand Down
20 changes: 7 additions & 13 deletions client/src/components/Grid/configs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8e23476

Please sign in to comment.