From 999a978553685894afca9685c38dbc9c5c101022 Mon Sep 17 00:00:00 2001 From: amvanbaren Date: Mon, 2 Dec 2024 16:03:43 +0200 Subject: [PATCH] Add engines to Works With section --- webui/src/extension-registry-types.ts | 2 +- .../extension-detail-overview.tsx | 63 +++++++++++++++---- webui/src/utils.ts | 19 ++++++ 3 files changed, 71 insertions(+), 13 deletions(-) diff --git a/webui/src/extension-registry-types.ts b/webui/src/extension-registry-types.ts index 569125632..45fecbe0b 100644 --- a/webui/src/extension-registry-types.ts +++ b/webui/src/extension-registry-types.ts @@ -91,7 +91,7 @@ export interface Extension { description?: string; // key: engine, value: version constraint - engines?: string[]; + engines?: Record; categories?: string[]; tags?: string[]; license?: string; diff --git a/webui/src/pages/extension-detail/extension-detail-overview.tsx b/webui/src/pages/extension-detail/extension-detail-overview.tsx index 17b952e04..4ebf8f59d 100644 --- a/webui/src/pages/extension-detail/extension-detail-overview.tsx +++ b/webui/src/pages/extension-detail/extension-detail-overview.tsx @@ -8,15 +8,15 @@ * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ -import React, { FunctionComponent, ReactNode, useContext, useEffect, useState, useRef } from 'react'; -import { Box, Theme, Typography, Button, Link, NativeSelect, SxProps, styled } from '@mui/material'; +import React, { FunctionComponent, ReactNode, useContext, useEffect, useState, useRef, useMemo } from 'react'; +import { Box, Theme, Typography, Button, Link, NativeSelect, SxProps, styled, Grid, Stack } from '@mui/material'; import { Link as RouteLink, useNavigate, useParams } from 'react-router-dom'; import HomeIcon from '@mui/icons-material/Home'; import GitHubIcon from '@mui/icons-material/GitHub'; import BugReportIcon from '@mui/icons-material/BugReport'; import QuestionAnswerIcon from '@mui/icons-material/QuestionAnswer'; import { MainContext } from '../../context'; -import { addQuery, createRoute, getTargetPlatformDisplayName } from '../../utils'; +import { addQuery, createRoute, getTargetPlatformDisplayName, getEngineDisplayName } from '../../utils'; import { DelayedLoadIndicator } from '../../components/delayed-load-indicator'; import { SanitizedMarkdown } from '../../components/sanitized-markdown'; import { Timestamp } from '../../components/timestamp'; @@ -24,7 +24,6 @@ import { Extension, ExtensionReference, VERSION_ALIASES } from '../../extension- import { ExtensionListRoutes } from '../extension-list/extension-list-container'; import { ExtensionDetailRoutes } from './extension-detail'; import { ExtensionDetailDownloadsMenu } from './extension-detail-downloads-menu'; -import { UrlString } from '../..'; export const ExtensionDetailOverview: FunctionComponent = props => { @@ -35,6 +34,50 @@ export const ExtensionDetailOverview: FunctionComponent(new AbortController()); + const worksWithEngines = useMemo(() => { + const engines = props.extension.engines; + if (engines == null) { + return null; + } + + const data = Object.keys(engines) + .map((engine) => ({ + key: engine, + name: getEngineDisplayName(engine), + version: engines[engine] + })) + .filter((d) => d.name != null); + + return (<> + + + { + data.map((d) => {d.name}:) + } + + + + + { + data.map((d) => {d.version}) + } + + + ); + }, [props.extension.engines]); + + const worksWithTargetPlatforms = useMemo(() => { + return ( + Target Platforms:{' '} + { + Object.keys(props.extension.downloads).map((targetPlatform, index) => { + const displayName = getTargetPlatformDisplayName(targetPlatform); + return displayName ? {index > 0 ? ', ' : ''}{displayName} : null; + }) + } + ); + }, [props.extension.downloads]); + useEffect(() => { updateReadme(); return () => { @@ -163,13 +206,6 @@ export const ExtensionDetailOverview: FunctionComponent; }; - const renderWorksWithList = (downloads: { [targetPlatform: string]: UrlString }): ReactNode => { - return Object.keys(downloads).map((targetPlatform, index) => { - const displayName = getTargetPlatformDisplayName(targetPlatform); - return displayName ? {index > 0 ? ', ' : ''}{displayName} : null; - }); - }; - const renderResourceLink = (label: string, resourceLink: SxProps, href?: string): ReactNode => { if (!href || !(href.startsWith('http') || href.startsWith('mailto'))) { return ''; @@ -294,7 +330,10 @@ export const ExtensionDetailOverview: FunctionComponent Works With - {renderWorksWithList(extension.downloads)} + + {worksWithEngines} + {worksWithTargetPlatforms} + : null diff --git a/webui/src/utils.ts b/webui/src/utils.ts index c952c9c6a..b8c9fd9f1 100644 --- a/webui/src/utils.ts +++ b/webui/src/utils.ts @@ -198,3 +198,22 @@ export function getTargetPlatformDisplayName(targetPlatform: string): string { return targetPlatformDisplayNames.get(targetPlatform) ?? ''; } + +export function getEngineDisplayName(engine: string): string { + const engineDisplayNames = new Map([ + ['vscode', 'VS Code'], + ['node', 'Node.js'], + ['npm', 'npm'], + ['pnpm', 'pnpm'], + ['yarn', 'Yarn'], + ['vsce', 'vsce'], + ['sqlops', 'SQL Operation Studio'], + ['azdata', 'Azure Data Studio'], + ['theiaPlugin', 'Theia Plugin'], + ['opensumi', 'OpenSumi'], + ['nadako.vshaxe', 'nadako.vshaxe'], + ['hbenl.vscode-test-explorer', 'hbenl.vscode-test-explorer'], + ]); + + return engineDisplayNames.get(engine) ?? ''; +} \ No newline at end of file