ESLint: Fix warnings.

This commit is contained in:
baldo 2022-08-25 22:15:59 +02:00
parent 2e72d42d22
commit 1a0fcbdd6f
5 changed files with 27 additions and 21 deletions

View file

@ -21,7 +21,7 @@ function toggleExpansion() {
title="Hilfe" title="Hilfe"
/> />
<p v-if="expanded" class="help-text"> <p v-if="expanded" class="help-text">
{{ text }} {{ props.text }}
</p> </p>
</template> </template>

View file

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useConfigStore } from "@/stores/config"; import { useConfigStore } from "@/stores/config";
import { useNodeStore } from "@/stores/node"; import { useNodeStore } from "@/stores/node";
import { computed, nextTick, onMounted, ref } from "vue"; import { nextTick, onMounted, ref } from "vue";
import CONSTRAINTS from "@/shared/validation/constraints"; import CONSTRAINTS from "@/shared/validation/constraints";
import ActionButton from "@/components/form/ActionButton.vue"; import ActionButton from "@/components/form/ActionButton.vue";
import type { import type {

View file

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import ButtonGroup from "@/components/form/ButtonGroup.vue"; import ButtonGroup from "@/components/form/ButtonGroup.vue";
import type { Hostname, StoredNode } from "@/types"; import type { StoredNode } from "@/types";
import { ButtonSize, ComponentAlignment, ComponentVariant } from "@/types"; import { ButtonSize, ComponentAlignment, ComponentVariant } from "@/types";
import { useConfigStore } from "@/stores/config"; import { useConfigStore } from "@/stores/config";
import { computed } from "vue"; import { computed } from "vue";

View file

@ -3,12 +3,14 @@ import {
isMap, isMap,
isNodesFilter, isNodesFilter,
isString, isString,
isUndefined,
MonitoringState, MonitoringState,
NODES_FILTER_FIELDS, NODES_FILTER_FIELDS,
type NodesFilter, type NodesFilter,
OnlineState, OnlineState,
type SearchTerm, type SearchTerm,
type UnixTimestampMilliseconds, type UnixTimestampMilliseconds,
type ValueOf,
} from "@/types"; } from "@/types";
import { computed, nextTick, onMounted, ref, watch } from "vue"; import { computed, nextTick, onMounted, ref, watch } from "vue";
import { useConfigStore } from "@/stores/config"; import { useConfigStore } from "@/stores/config";
@ -20,7 +22,10 @@ interface Props {
const SEARCH_THROTTLE_DELAY_MS = 500; const SEARCH_THROTTLE_DELAY_MS = 500;
const FILTER_LABELS: Record<string, string | Map<string | boolean, any>> = { const FILTER_LABELS: Record<
string,
string | Map<ValueOf<NodesFilter>, string>
> = {
hasKey: new Map([ hasKey: new Map([
[true, "Mit VPN-Schlüssel"], [true, "Mit VPN-Schlüssel"],
[false, "Ohne VPN-Schlüssel"], [false, "Ohne VPN-Schlüssel"],
@ -54,7 +59,7 @@ const configStore = useConfigStore();
type Filter = { type Filter = {
field: string; field: string;
value: any; value: ValueOf<NodesFilter>;
}; };
const selectedFilters = ref<Filter[]>([]); const selectedFilters = ref<Filter[]>([]);
@ -153,17 +158,15 @@ function removeSelectedFilter(filter: Filter): void {
} }
function updateSelectedFilters() { function updateSelectedFilters() {
const filter = props.filter as Record<string, any>; const filter = props.filter;
selectedFilters.value = []; selectedFilters.value = [];
for (const field of Object.keys(NODES_FILTER_FIELDS)) { for (const [field, value] of Object.entries(filter)) {
if (Object.prototype.hasOwnProperty.call(filter, field)) {
addSelectedFilter({ addSelectedFilter({
field, field,
value: filter[field], value,
}); });
} }
} }
}
watch(props, updateSelectedFilters); watch(props, updateSelectedFilters);
onMounted(updateSelectedFilters); onMounted(updateSelectedFilters);
@ -178,7 +181,8 @@ function renderFilter(filter: Filter): string {
return `${label}: ${filter.value}`; return `${label}: ${filter.value}`;
} }
if (!label.has(filter.value)) { const filterValue = label.get(filter.value);
if (isUndefined(filterValue)) {
throw new Error( throw new Error(
`Filter ${filter.field} has no translation for value: ${ `Filter ${filter.field} has no translation for value: ${
filter.value filter.value
@ -186,7 +190,7 @@ function renderFilter(filter: Filter): string {
); );
} }
return label.get(filter.value); return filterValue;
} }
function setFocus(focus: boolean): void { function setFocus(focus: boolean): void {
@ -202,7 +206,7 @@ function showSuggestedFilters(expanded: boolean): void {
} }
function buildNodesFilter(): NodesFilter { function buildNodesFilter(): NodesFilter {
const nodesFilter: Record<string, any> = {}; const nodesFilter: Record<string, ValueOf<NodesFilter>> = {};
for (const filter of selectedFilters.value) { for (const filter of selectedFilters.value) {
nodesFilter[filter.field] = filter.value; nodesFilter[filter.field] = filter.value;
} }

View file

@ -1,10 +1,10 @@
<script lang="ts"> <script lang="ts">
import { type Component, defineComponent, type PropType } from "vue"; import { type Component, defineComponent, type PropType } from "vue";
import { type EnumValue, SortDirection } from "@/types"; import { type ValueOf, SortDirection } from "@/types";
type Props<SortField> = { type Props<SortField> = {
field: PropType<EnumValue<SortField>>; field: PropType<ValueOf<SortField>>;
currentField: PropType<EnumValue<SortField>>; currentField: PropType<ValueOf<SortField>>;
currentDirection: PropType<SortDirection>; currentDirection: PropType<SortDirection>;
}; };
@ -12,8 +12,8 @@ type SortTH<SortField> = Component<Props<SortField>>;
function defineGenericComponent<SortField>(): SortTH<SortField> { function defineGenericComponent<SortField>(): SortTH<SortField> {
const props: Props<SortField> = { const props: Props<SortField> = {
field: null as unknown as PropType<EnumValue<SortField>>, field: null as unknown as PropType<ValueOf<SortField>>,
currentField: null as unknown as PropType<EnumValue<SortField>>, currentField: null as unknown as PropType<ValueOf<SortField>>,
currentDirection: null as unknown as PropType<SortDirection>, currentDirection: null as unknown as PropType<SortDirection>,
}; };
return defineComponent({ return defineComponent({
@ -30,6 +30,7 @@ function defineGenericComponent<SortField>(): SortTH<SortField> {
}, },
}, },
emits: { emits: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
sort: (field: SortField, direction: SortDirection) => true, sort: (field: SortField, direction: SortDirection) => true,
}, },
methods: { methods: {
@ -48,6 +49,7 @@ function defineGenericComponent<SortField>(): SortTH<SortField> {
const component = defineGenericComponent<unknown>(); const component = defineGenericComponent<unknown>();
// eslint-disable-next-line no-redeclare
export function SortTH<SortField>(): SortTH<SortField> { export function SortTH<SortField>(): SortTH<SortField> {
return component as SortTH<SortField>; return component as SortTH<SortField>;
} }