Skip to content
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

index: Add dropdown for picking release #35

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
928 changes: 925 additions & 3 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.0",
"react-select": "^5.8.0",
"supports-color": "^9.4.0",
"tailwindcss": "^3.3.3"
},
Expand Down
15 changes: 14 additions & 1 deletion site/src/app/AppBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import {
VerifiedIcon,
} from '@primer/octicons-react';

import { useState } from 'react';
import { NormalisedApp, Organization } from '../schema';
import VSCodeButton from './VSCodeButton';
import TagList from './TagList';
import ReleasesDropDownList from './ReleasesDropDownList'
import VSCodeQueryParams from './VSCodeQueryParams';

interface Props {
app: NormalisedApp;
Expand All @@ -37,6 +40,9 @@ function Avatar({ app }: { app: NormalisedApp }) {
}

function AppBlock({ app, setShowingAppId }: Props): JSX.Element {

const [queryParams, setQueryParams] = useState(new VSCodeQueryParams(app));

return (
<li className="flex w-full max-w-5xl flex-col gap-3 border border-gray-300 bg-white p-3 lg:w-2/3">
<div className="flex gap-3">
Expand Down Expand Up @@ -89,7 +95,14 @@ function AppBlock({ app, setShowingAppId }: Props): JSX.Element {
</Markdown>

<div className="flex flex-wrap items-center gap-2">
<VSCodeButton app={app} />
<ReleasesDropDownList app={app}
onReleaseChosen={(branch) => {
const newQueryParams = new VSCodeQueryParams(app);
newQueryParams.branch = branch;
setQueryParams(newQueryParams);
}}/>

<VSCodeButton queryParams={queryParams} />

<button
className="button bg-[#768692] text-white"
Expand Down
4 changes: 2 additions & 2 deletions site/src/app/InstructionsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Step = ({ children }: PropsWithChildren) => (
);

function InstructionsDialog({ app, close }: Props): JSX.Element {
const latestRelease = app.releases.at(-1);
const latestRelease = app.releases.at(0)?.tag ?? app.defaultBranch;

return (
<div className="flex flex-col">
Expand All @@ -44,7 +44,7 @@ function InstructionsDialog({ app, close }: Props): JSX.Element {

<CodeBlock
text={`west init -m "${app.repo}" --mr ${
latestRelease?.tag ?? '<latest tag>'
latestRelease ?? '<latest tag>'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the changed assignment above latestRelease will always be defined, so the ?? '<latest tag>' could be removed here. But it is also ok if you want to keep it as an additional safety measure.

}`}
/>
</Step>
Expand Down
31 changes: 31 additions & 0 deletions site/src/app/ReleasesDropDownList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import { NormalisedApp } from '../schema';
import Select from 'react-select';

interface Props {
app: NormalisedApp;
onReleaseChosen: (tag: string) => void;
};

function ReleasesDropDownList({ app, onReleaseChosen }: Props): JSX.Element {
const releases = [{ label: app.defaultBranch, value: app.defaultBranch }, ...app.releases.map((release) => ({ label: release.tag, value: release.tag ?? '' })),];

return (
<div className="font-thin max-w-[20%] min-w-[15%]">
<Select
instanceId={`${app.id}-release-select`}
defaultValue={releases[0]}
options={releases}
menuPlacement="auto"
onChange={(option) => { onReleaseChosen(option ? option.value : ""); }}
hideSelectedOptions={true}
/>
</div>
)
}

export default ReleasesDropDownList;
15 changes: 4 additions & 11 deletions site/src/app/VSCodeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@
*/

import Image from 'next/image';
import { NormalisedApp } from '../schema';
import VSCodeQueryParams from './VSCodeQueryParams';

interface Props {
app: NormalisedApp;
queryParams: VSCodeQueryParams;
}

function VSCodeButton({ app }: Props): JSX.Element {
const params = new URLSearchParams({
app: app.name,
branch: app.defaultBranch,
manifest: app.manifest ?? '',
repo: app.repo,
});

function VSCodeButton({ queryParams }: Props): JSX.Element {
return (
<a
href={`vscode://nordic-semiconductor.nrf-connect-extension-pack/get-application?${params.toString()}`}
href={`vscode://nordic-semiconductor.nrf-connect-extension-pack/get-application?${queryParams.toString()}`}
title="Open in nRF Connect for VS Code"
className="button bg-[#0032A0] text-white"
>
Expand Down
32 changes: 32 additions & 0 deletions site/src/app/VSCodeQueryParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import { NormalisedApp } from '../schema';


class VSCodeQueryParams{
app: string;
branch: string;
manifest: string;
repo: string;

constructor(app: NormalisedApp) {
this.app = app.name;
this.branch = app.defaultBranch;
this.manifest = app.manifest ?? "";
this.repo = app.repo;
}

toString(): string {
return new URLSearchParams({
app: this.app,
branch: this.branch,
manifest: this.manifest,
repo: this.repo,
}).toString();
}
};

export default VSCodeQueryParams;
Loading