Skip to content

Commit e5089ba

Browse files
committed
Responsive PortsView
1 parent f8921da commit e5089ba

File tree

8 files changed

+220
-76
lines changed

8 files changed

+220
-76
lines changed

Diff for: extensions/gitpod-shared/portsview/src/App.svelte

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<script lang="ts">
55
import { vscode } from "./utils/vscodeApi";
66
import PortTable from "./porttable/PortTable.svelte";
7+
import PortList from "./porttable/PortList.svelte";
78
import type { GitpodPortObject } from "./protocol/gitpod";
89
910
let ports: GitpodPortObject[] = [];
@@ -14,8 +15,22 @@
1415
}
1516
});
1617
vscode.postMessage({ command: "queryPortData" });
18+
19+
let innerWidth = 0;
1720
</script>
1821

22+
<svelte:window bind:innerWidth />
23+
1924
<main>
20-
<PortTable {ports} />
25+
{#if innerWidth > 500}
26+
<PortTable {ports} />
27+
{:else}
28+
<PortList {ports} />
29+
{/if}
2130
</main>
31+
32+
<style>
33+
:global(body) {
34+
padding: 10px;
35+
}
36+
</style>

Diff for: extensions/gitpod-shared/portsview/src/components/HoverOptions.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
.opts {
5050
display: inline-flex;
5151
flex: none;
52-
padding-left: 4px;
5352
box-sizing: border-box;
5453
align-content: center;
54+
align-items: center;
5555
}
5656
.hide {
5757
display: none;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!-----------------------------------------------------------------------------------------------
2+
Copyright (c) Gitpod. All rights reserved.
3+
------------------------------------------------------------------------------------------------>
4+
<script lang="ts">
5+
import { createEventDispatcher } from "svelte";
6+
import HoverOptions from "../components/HoverOptions.svelte";
7+
import type { HoverOption } from "../protocol/components";
8+
import type { GitpodPortObject, PortCommand } from "../protocol/gitpod";
9+
import { commandIconMap, getCommands, getNLSTitle } from "../utils/commands";
10+
11+
export let port: GitpodPortObject;
12+
export let alwaysShow: boolean = false;
13+
14+
const copyOpt: HoverOption = {
15+
icon: "copy",
16+
title: "Copy URL",
17+
command: "urlCopy",
18+
};
19+
20+
function getHoverOption(port?: GitpodPortObject) {
21+
if (port == null) {
22+
return [];
23+
}
24+
const opts: HoverOption[] = getCommands(port).map((e) => ({
25+
icon: commandIconMap[e],
26+
title: getNLSTitle(e),
27+
command: e,
28+
}));
29+
opts.unshift(copyOpt);
30+
return opts;
31+
}
32+
33+
$: hoverOpts = getHoverOption(port);
34+
const dispatch = createEventDispatcher<{
35+
command: PortCommand;
36+
}>();
37+
function onHoverCommand(command: string) {
38+
dispatch("command", command as PortCommand);
39+
}
40+
</script>
41+
42+
<HoverOptions
43+
alwaysShow={alwaysShow}
44+
options={hoverOpts}
45+
on:command={(e) => {
46+
onHoverCommand(e.detail);
47+
}}
48+
>
49+
<slot />
50+
</HoverOptions>

Diff for: extensions/gitpod-shared/portsview/src/porttable/PortInfo.svelte

-2
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@
3434
<style>
3535
.container {
3636
display: flex;
37-
width: 100%;
3837
}
3938
span {
4039
display: inline-block;
4140
}
4241
.title {
43-
flex: none;
4442
min-width: 0;
4543
overflow: hidden;
4644
text-overflow: ellipsis;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!-----------------------------------------------------------------------------------------------
2+
Copyright (c) Gitpod. All rights reserved.
3+
------------------------------------------------------------------------------------------------>
4+
<script lang="ts">
5+
import PortInfo from "./PortInfo.svelte";
6+
import PortStatus from "./PortStatus.svelte";
7+
import { vscode } from "../utils/vscodeApi";
8+
import type { GitpodPortObject, PortCommand } from "../protocol/gitpod";
9+
import PortHoverActions from "./PortHoverActions.svelte";
10+
11+
function postData(command: string, port: GitpodPortObject) {
12+
vscode.postMessage({
13+
port,
14+
command: command as PortCommand,
15+
});
16+
}
17+
18+
export let ports: GitpodPortObject[] = [];
19+
</script>
20+
21+
<main>
22+
<div class="container">
23+
{#each ports as port, i (port.status.localPort)}
24+
<PortHoverActions
25+
{port}
26+
on:command={(e) => {
27+
postData(e.detail, port);
28+
}}
29+
>
30+
<div class="line" title={port.info.tooltip}>
31+
<div class="status">
32+
<PortStatus port={port} />
33+
</div>
34+
<div class="info">
35+
<PortInfo {port} />
36+
</div>
37+
<div class="desc">
38+
<span title={port.info.description}>{port.info.description}</span>
39+
</div>
40+
</div>
41+
</PortHoverActions>
42+
{/each}
43+
</div>
44+
</main>
45+
46+
<style>
47+
.container {
48+
padding: 0 5px;
49+
font-size: 13px;
50+
}
51+
.line {
52+
display: flex;
53+
width: 100%;
54+
padding: 4px 0;
55+
gap: 0.5rem;
56+
}
57+
.desc, .line {
58+
overflow: hidden;
59+
text-overflow: ellipsis;
60+
white-space: nowrap;
61+
}
62+
.desc {
63+
color: var(--vscode-disabledForeground)
64+
}
65+
</style>

Diff for: extensions/gitpod-shared/portsview/src/porttable/PortLocalAddress.svelte

+5-33
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,14 @@
33
------------------------------------------------------------------------------------------------>
44
<script lang="ts">
55
import { createEventDispatcher } from "svelte";
6-
import HoverOptions from "../components/HoverOptions.svelte";
7-
import type { HoverOption } from "../protocol/components";
86
import type { GitpodPortObject, PortCommand } from "../protocol/gitpod";
9-
import { commandIconMap, getCommands, getNLSTitle } from "../utils/commands";
7+
import PortHoverActions from "./PortHoverActions.svelte";
108
119
export let port: GitpodPortObject;
1210
13-
const copyOpt: HoverOption = {
14-
icon: "copy",
15-
title: "Copy URL",
16-
command: "urlCopy",
17-
};
18-
19-
function getHoverOption(port?: GitpodPortObject) {
20-
if (port == null) {
21-
return [];
22-
}
23-
const opts: HoverOption[] = getCommands(port).map((e) => ({
24-
icon: commandIconMap[e],
25-
title: getNLSTitle(e),
26-
command: e,
27-
}));
28-
opts.unshift(copyOpt);
29-
return opts;
30-
}
31-
32-
$: hoverOpts = getHoverOption(port);
3311
const dispatch = createEventDispatcher<{
3412
command: { command: PortCommand; port: GitpodPortObject };
3513
}>();
36-
function onHoverCommand(command: string) {
37-
dispatch("command", { command: command as PortCommand, port });
38-
}
3914
function openAddr(e: Event) {
4015
e.preventDefault();
4116
if (port.status.exposed.url) {
@@ -44,23 +19,20 @@
4419
}
4520
</script>
4621

47-
<HoverOptions
22+
<PortHoverActions
23+
{port}
4824
alwaysShow
49-
options={hoverOpts}
50-
on:command={(e) => {
51-
onHoverCommand(e.detail);
52-
}}
25+
on:command={(e) => { console.log(e); dispatch("command", { command: e.detail, port}) }}
5326
>
5427
<a on:click={(e) => { openAddr(e) }} href={port.status.exposed.url}>{port.status.exposed.url}</a>
55-
</HoverOptions>
28+
</PortHoverActions>
5629

5730
<style>
5831
a {
5932
color: var(--vscode-foreground);
6033
overflow: hidden;
6134
text-overflow: ellipsis;
6235
white-space: nowrap;
63-
display: inline-block;
6436
}
6537
a:focus {
6638
outline: none;

Diff for: extensions/gitpod-shared/portsview/src/porttable/PortStatus.svelte

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
<script lang="ts">
55
import type { IconStatus } from "../protocol/gitpod";
66
7-
export let status: IconStatus = "NotServed";
7+
import type { GitpodPortObject } from "../protocol/gitpod";
8+
9+
export let port: GitpodPortObject;
810
911
const fillArr: IconStatus[] = ["Detecting", "Served"];
1012
13+
$: status = port?.info.iconStatus ?? "NotServed";
14+
1115
$: circleFill = fillArr.includes(status);
1216
</script>
1317

1418
<main>
15-
<div class="container">
19+
<div class="container" title={port.info.description}>
1620
{#if status === "ExposureFailed"}
1721
<i class="codicon codicon-warning ExposureFailed" />
1822
{:else if circleFill}

0 commit comments

Comments
 (0)