From b6902f72a01b9ccf9bfc92a68c6d10893cf21ddb Mon Sep 17 00:00:00 2001 From: axel7083 <42176370+axel7083@users.noreply.github.com> Date: Wed, 13 Nov 2024 11:41:15 +0100 Subject: [PATCH] refactor: replace `PortForwardRow` by `ForwardConfig` (#9857) * refactor: replace port forward row Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * fix: remove mapping Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> * fix: tests Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> --------- Signed-off-by: axel7083 <42176370+axel7083@users.noreply.github.com> --- .../PortForwardActions.spec.ts | 12 ++------ .../PortForwardActions.svelte | 9 +++--- .../PortForwardIcon.svelte | 4 +-- .../PortForwardNameColumn.svelte | 5 ++-- .../PortForwardingList.svelte | 29 +++++++------------ .../port-forward-row.ts | 25 ---------------- 6 files changed, 22 insertions(+), 62 deletions(-) delete mode 100644 packages/renderer/src/lib/kubernetes-port-forward/port-forward-row.ts diff --git a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.spec.ts b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.spec.ts index afd080cdcfee0..741d2f9483a0f 100644 --- a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.spec.ts +++ b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.spec.ts @@ -22,7 +22,6 @@ import { fireEvent, render } from '@testing-library/svelte'; import { readable } from 'svelte/store'; import { beforeEach, expect, test, vi } from 'vitest'; -import type { PortForwardRow } from '/@/lib/kubernetes-port-forward/port-forward-row'; import PortForwardActions from '/@/lib/kubernetes-port-forward/PortForwardActions.svelte'; import * as kubeContextStore from '/@/stores/kubernetes-contexts-state'; import { type ForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-model'; @@ -40,11 +39,6 @@ const MOCKED_USER_FORWARD_CONFIG: ForwardConfig = { }, }; -const MOCKED_PORT_FORWARD_ROW: PortForwardRow = { - ...MOCKED_USER_FORWARD_CONFIG, - mapping: MOCKED_USER_FORWARD_CONFIG.forward, -}; - beforeEach(() => { vi.resetAllMocks(); @@ -61,7 +55,7 @@ beforeEach(() => { test('actions should be defined', () => { const { getByTitle } = render(PortForwardActions, { - object: MOCKED_PORT_FORWARD_ROW, + object: MOCKED_USER_FORWARD_CONFIG, }); const openBtn = getByTitle('Open forwarded port'); @@ -73,7 +67,7 @@ test('actions should be defined', () => { test('open should call openExternal', async () => { const { getByTitle } = render(PortForwardActions, { - object: MOCKED_PORT_FORWARD_ROW, + object: MOCKED_USER_FORWARD_CONFIG, }); const openBtn = getByTitle('Open forwarded port'); @@ -84,7 +78,7 @@ test('open should call openExternal', async () => { test('remove should call deleteKubernetesPortForward', async () => { const { getByTitle } = render(PortForwardActions, { - object: MOCKED_PORT_FORWARD_ROW, + object: MOCKED_USER_FORWARD_CONFIG, }); const deleteBtn = getByTitle('Delete forwarded port'); diff --git a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.svelte b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.svelte index fb0df0c796121..d17d0f25e02d3 100644 --- a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.svelte +++ b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardActions.svelte @@ -2,14 +2,13 @@ import { faSquareUpRight, faTrash } from '@fortawesome/free-solid-svg-icons'; import { withConfirmation } from '/@/lib/dialogs/messagebox-utils'; -import type { PortForwardRow } from '/@/lib/kubernetes-port-forward/port-forward-row'; import { kubernetesCurrentContextPortForwards } from '/@/stores/kubernetes-contexts-state'; import { type ForwardConfig } from '/@api/kubernetes-port-forward-model'; import ListItemButtonIcon from '../ui/ListItemButtonIcon.svelte'; interface Props { - object: PortForwardRow; + object: ForwardConfig; } let { object }: Props = $props(); @@ -19,8 +18,8 @@ let userConfigForward: ForwardConfig | undefined = $derived( config.kind === object.kind && config.name === object.name && config.namespace === object.namespace && - config.forward.remotePort === object.mapping.remotePort && - config.forward.localPort === object.mapping.localPort, + config.forward.remotePort === object.forward.remotePort && + config.forward.localPort === object.forward.localPort, ), ); @@ -31,7 +30,7 @@ async function deletePortForward(): Promise { } async function openExternal(): Promise { - return window.openExternal(`http://localhost:${object.mapping.localPort}`); + return window.openExternal(`http://localhost:${object.forward.localPort}`); } diff --git a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardIcon.svelte b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardIcon.svelte index 16128d1429753..96b72cd7481cf 100644 --- a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardIcon.svelte +++ b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardIcon.svelte @@ -3,10 +3,10 @@ import { faEthernet } from '@fortawesome/free-solid-svg-icons'; import { StatusIcon } from '@podman-desktop/ui-svelte'; import Fa from 'svelte-fa'; -import type { PortForwardRow } from '/@/lib/kubernetes-port-forward/port-forward-row'; +import type { ForwardConfig } from '/@api/kubernetes-port-forward-model'; interface Props { - object: PortForwardRow; + object: ForwardConfig; } let { object }: Props = $props(); diff --git a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardNameColumn.svelte b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardNameColumn.svelte index 1a1e2f8fdea0a..306644767e569 100644 --- a/packages/renderer/src/lib/kubernetes-port-forward/PortForwardNameColumn.svelte +++ b/packages/renderer/src/lib/kubernetes-port-forward/PortForwardNameColumn.svelte @@ -1,16 +1,15 @@ @@ -55,7 +48,7 @@ let portForwardRows: PortForwardRow[] = $derived.by(() => { {#if $kubernetesCurrentContextPortForwards.length > 0} diff --git a/packages/renderer/src/lib/kubernetes-port-forward/port-forward-row.ts b/packages/renderer/src/lib/kubernetes-port-forward/port-forward-row.ts deleted file mode 100644 index 586ff7b46b97b..0000000000000 --- a/packages/renderer/src/lib/kubernetes-port-forward/port-forward-row.ts +++ /dev/null @@ -1,25 +0,0 @@ -/********************************************************************** - * Copyright (C) 2024 Red Hat, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ***********************************************************************/ -import type { PortMapping, WorkloadKind } from '/@api/kubernetes-port-forward-model'; - -export interface PortForwardRow { - name: string; - namespace: string; - kind: WorkloadKind; - mapping: PortMapping; -}