Skip to content

Commit

Permalink
refactor: replace PortForwardRow by ForwardConfig (podman-desktop…
Browse files Browse the repository at this point in the history
…#9857)

* refactor: replace port forward row

Signed-off-by: axel7083 <[email protected]>

* fix: remove mapping

Signed-off-by: axel7083 <[email protected]>

* fix: tests

Signed-off-by: axel7083 <[email protected]>

---------

Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 authored Nov 13, 2024
1 parent ead5e63 commit b6902f7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
),
);
Expand All @@ -31,7 +30,7 @@ async function deletePortForward(): Promise<void> {
}
async function openExternal(): Promise<void> {
return window.openExternal(`http://localhost:${object.mapping.localPort}`);
return window.openExternal(`http://localhost:${object.forward.localPort}`);
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<script lang="ts">
import { get } from 'svelte/store';
import type { PortForwardRow } from '/@/lib/kubernetes-port-forward/port-forward-row';
import { handleNavigation } from '/@/navigation';
import { podsInfos } from '/@/stores/pods';
import { WorkloadKind } from '/@api/kubernetes-port-forward-model';
import { type ForwardConfig, WorkloadKind } from '/@api/kubernetes-port-forward-model';
import { NavigationPage } from '/@api/navigation-page';
import type { PodInfo } from '../../../../main/src/plugin/api/pod-info';
interface Props {
object: PortForwardRow;
object: ForwardConfig;
}
let { object }: Props = $props();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,53 @@
import { faEthernet } from '@fortawesome/free-solid-svg-icons';
import { EmptyScreen, NavPage, Table, TableColumn, TableRow, TableSimpleColumn } from '@podman-desktop/ui-svelte';
import type { PortForwardRow } from '/@/lib/kubernetes-port-forward/port-forward-row';
import PortForwardActions from '/@/lib/kubernetes-port-forward/PortForwardActions.svelte';
import PortForwardIcon from '/@/lib/kubernetes-port-forward/PortForwardIcon.svelte';
import { kubernetesCurrentContextPortForwards } from '/@/stores/kubernetes-contexts-state';
import type { ForwardConfig } from '/@api/kubernetes-port-forward-model';
import PodNameColumn from './PortForwardNameColumn.svelte';
const columns = [
new TableColumn<PortForwardRow>('Status', {
new TableColumn<ForwardConfig>('Status', {
align: 'center',
width: '70px',
renderer: PortForwardIcon,
}),
new TableColumn<PortForwardRow>('Name', {
new TableColumn<ForwardConfig>('Name', {
align: 'left',
renderer: PodNameColumn,
}),
new TableColumn<PortForwardRow, string>('Type', {
new TableColumn<ForwardConfig, string>('Type', {
align: 'left',
renderer: TableSimpleColumn,
renderMapping: config => config.kind,
}),
new TableColumn<PortForwardRow, string>('Local Port', {
new TableColumn<ForwardConfig, string>('Local Port', {
align: 'left',
renderer: TableSimpleColumn,
renderMapping: config => String(config.mapping.localPort),
renderMapping: config => String(config.forward.localPort),
}),
new TableColumn<PortForwardRow, string>('Remote Port', {
new TableColumn<ForwardConfig, string>('Remote Port', {
align: 'left',
renderer: TableSimpleColumn,
renderMapping: config => String(config.mapping.remotePort),
renderMapping: config => String(config.forward.remotePort),
}),
new TableColumn<PortForwardRow>('Actions', {
new TableColumn<ForwardConfig>('Actions', {
align: 'right',
renderer: PortForwardActions,
}),
];
const row = new TableRow<PortForwardRow>({});
let portForwardRows: PortForwardRow[] = $derived.by(() => {
return $kubernetesCurrentContextPortForwards.map(config => ({
...config,
mapping: config.forward,
}));
});
const row = new TableRow<ForwardConfig>({});
</script>

<NavPage searchEnabled={false} title="Port forwarding">
<div class="flex min-w-full h-full" slot="content">
{#if $kubernetesCurrentContextPortForwards.length > 0}
<Table
kind="port"
data={portForwardRows}
data={$kubernetesCurrentContextPortForwards}
columns={columns}
row={row}
defaultSortColumn="Name">
Expand Down

This file was deleted.

0 comments on commit b6902f7

Please sign in to comment.