Skip to content

Better looking version strings in the Dashboard #15252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/dashboard/src/components/SelectIDEComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { IDEOption, IDEOptions } from "@gitpod/gitpod-protocol/lib/ide-protocol";
import { IDEOption, IDEOptions, makeIdeVersionHumanReadable } from "@gitpod/gitpod-protocol";
import { useCallback, useEffect, useState } from "react";
import { getGitpodService } from "../service/service";
import { DropDown2, DropDown2Element } from "./DropDown2";
Expand Down Expand Up @@ -149,7 +149,7 @@ function IdeOptionElementInDropDown(p: IdeOptionElementProps): JSX.Element {
{version && (
<>
<div className="mx-1">&middot;</div>
<div>{version}</div>
<div>{makeIdeVersionHumanReadable(version)}</div>
</>
)}
{label && (
Expand Down
9 changes: 7 additions & 2 deletions components/dashboard/src/user-settings/SelectIDE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Tooltip from "../components/Tooltip";
import { getGitpodService } from "../service/service";
import { UserContext } from "../user-context";
import CheckBox from "../components/CheckBox";
import { User } from "@gitpod/gitpod-protocol";
import { User, makeIdeVersionHumanReadable } from "@gitpod/gitpod-protocol";
import PillLabel from "../components/PillLabel";

export type IDEChangedTrackLocation = "workspace_list" | "workspace_start" | "preferences";
Expand Down Expand Up @@ -94,7 +94,12 @@ export default function SelectIDE(props: SelectIDEProps) {
const selected = defaultIde === id;
const version = useLatestVersion ? option.latestImageVersion : option.imageVersion;
const onSelect = () => actuallySetDefaultIde(id);
return renderIdeOption(option, selected, version, onSelect);
return renderIdeOption(
option,
selected,
makeIdeVersionHumanReadable(version),
onSelect,
);
})}
</div>
{ideOptions.options[defaultIde]?.notes && (
Expand Down
26 changes: 26 additions & 0 deletions components/gitpod-protocol/src/ide-protocol.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License-AGPL.txt in the project root for license information.
*/

import { suite, test } from "mocha-typescript";
import * as chai from "chai";
import { makeIdeVersionHumanReadable } from ".";

const expect = chai.expect;

@suite
class TestIdeProtocol {
@test public testSuffixedIdeVersion() {
const versionString = "v1.74.0-insider";

expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0 Insider");
}
@test public testUnsuffixedIdeVersion() {
const versionString = "v1.74.0";

expect(makeIdeVersionHumanReadable(versionString)).to.deep.equal("v1.74.0");
}
}
module.exports = new TestIdeProtocol(); // Only to circumvent no usage warning :-/
24 changes: 24 additions & 0 deletions components/gitpod-protocol/src/ide-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,27 @@ export interface IDEOption {
*/
latestImageVersion?: string;
}

/**
* Takes a version string of the form `X.Y.Z-<pre-release-tag>` and returns a human-readable version string
* where the pre-release tag is capitalized and separated from the version number by a space.
*
* @example
* makeIdeVersionHumanReadable("1.74.0-insider") // returns "1.74.0 Insider"
*
* @param [versionString] - The version string to convert to human-readable format
* @returns A human-readable version string, or `undefined` if `versionString` is falsy
*/
export const makeIdeVersionHumanReadable = (versionString?: string): string | undefined => {
if (!versionString) {
return undefined;
}

let [version, pre] = versionString.split("-");
if (pre) {
// Capitalize the string, so that 1.74.0-insider becomes 1.74.0 Insider
pre = pre[0].toUpperCase() + pre.slice(1);
}

return [version, pre].join(" ").trim();
};
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from "./snapshot-url";
export * from "./oss-allowlist";
export * from "./installation-admin-protocol";
export * from "./webhook-event";
export * from "./ide-protocol";