Skip to content

Commit 6c955c5

Browse files
committed
Better looking version strings in the Dashboard
1 parent 0e2ec6c commit 6c955c5

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

components/dashboard/src/user-settings/SelectIDE.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Tooltip from "../components/Tooltip";
1212
import { getGitpodService } from "../service/service";
1313
import { UserContext } from "../user-context";
1414
import CheckBox from "../components/CheckBox";
15-
import { User } from "@gitpod/gitpod-protocol";
15+
import { User, makeIdeVersionHumanReadable } from "@gitpod/gitpod-protocol";
1616
import PillLabel from "../components/PillLabel";
1717

1818
export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
@@ -94,7 +94,12 @@ export default function SelectIDE(props: SelectIDEProps) {
9494
const selected = defaultIde === id;
9595
const version = useLatestVersion ? option.latestImageVersion : option.imageVersion;
9696
const onSelect = () => actuallySetDefaultIde(id);
97-
return renderIdeOption(option, selected, version, onSelect);
97+
return renderIdeOption(
98+
option,
99+
selected,
100+
makeIdeVersionHumanReadable(version),
101+
onSelect,
102+
);
98103
})}
99104
</div>
100105
{ideOptions.options[defaultIde]?.notes && (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { suite, test } from "mocha-typescript";
8+
import * as chai from "chai";
9+
import { makeIdeVersionHumanReadable } from ".";
10+
11+
const expect = chai.expect;
12+
13+
@suite
14+
class TestIdeProtocol {
15+
@test public testSuffixedIdeVersion() {
16+
const versionString = "v1.74.0-insider";
17+
18+
expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0 Insider");
19+
}
20+
@test public testUnsuffixedIdeVersion() {
21+
const versionString = "v1.74.0";
22+
23+
expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0");
24+
}
25+
}
26+
module.exports = new TestIdeProtocol(); // Only to circumvent no usage warning :-/

components/gitpod-protocol/src/ide-protocol.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,27 @@ export interface IDEOption {
145145
*/
146146
latestImageVersion?: string;
147147
}
148+
149+
/**
150+
* Takes a version string of the form `X.Y.Z-<pre-release-tag>` and returns a human-readable version string
151+
* where the pre-release tag is capitalized and separated from the version number by a space.
152+
*
153+
* @example
154+
* makeIdeVersionHumanReadable("1.74.0-insider") // returns "1.74.0 Insider"
155+
*
156+
* @param [versionString] - The version string to convert to human-readable format
157+
* @returns A human-readable version string, or `undefined` if `versionString` is falsy
158+
*/
159+
export const makeIdeVersionHumanReadable = (versionString?: string): string | undefined => {
160+
if (!versionString) {
161+
return undefined;
162+
}
163+
164+
let [version, pre] = versionString.split("-");
165+
if (pre) {
166+
// Capitalize the string, so that 1.74.0-insider becomes 1.74.0 Insider
167+
pre = pre[0].toUpperCase() + pre.slice(1);
168+
}
169+
170+
return [version, pre].join(" ").trim();
171+
};

components/gitpod-protocol/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export * from "./snapshot-url";
2020
export * from "./oss-allowlist";
2121
export * from "./installation-admin-protocol";
2222
export * from "./webhook-event";
23+
export * from "./ide-protocol";

0 commit comments

Comments
 (0)