Skip to content
Merged
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
60 changes: 59 additions & 1 deletion src/components/Drawer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h, React } from '../runtime';
import { styles } from '../styles';
import { defaultChannelVersion, helmInstallCommand } from '../catalog';
import { IconImg, resolveIconSrc } from '../icons';
import type { CatalogEntry } from '../types';
import type { CatalogEntry, Prerequisite } from '../types';

function humanizeKey(key: string): string {
return key
Expand Down Expand Up @@ -53,6 +53,62 @@ function renderCapabilityValue(key: string, value: unknown): any {
);
}

function prerequisiteHelmCommand(pre: Prerequisite): string {
const helm = pre.helm!;
const release = pre.name;
const lines = [`helm install ${release} ${helm.oci} \\`];
if (helm.version) lines.push(` --version ${helm.version} \\`);
lines.push(` -n ${helm.namespace}${helm.createNamespace ? ' --create-namespace' : ''}`);
for (const [k, v] of Object.entries(helm.defaultValues ?? {})) {
lines[lines.length - 1] += ' \\';
lines.push(` --set ${k}=${v}`);
}
return lines.join('\n');
}

function renderPrerequisite(pre: Prerequisite, key: number): any {
return h(
'div',
{ key, style: styles.prereqCard },
h(
'div',
{ style: styles.prereqHead },
h('span', { style: styles.prereqName }, pre.name),
pre.installUrl
? h(
'a',
{
href: pre.installUrl,
target: '_blank',
rel: 'noopener noreferrer',
style: styles.prereqLink,
},
'Docs ↗',
)
: null,
),
pre.description ? h('div', { style: styles.prereqDesc }, pre.description) : null,
pre.helm
? h(
'details',
null,
h('summary', { style: styles.prereqSummary }, 'Install command'),
h('pre', { style: { ...styles.codeBlock, marginTop: '0.5rem' } }, prerequisiteHelmCommand(pre)),
)
: null,
);
}

function renderPrerequisites(prerequisites: Prerequisite[] | undefined): any {
if (!prerequisites || !prerequisites.length) return null;
return h(
'div',
{ style: styles.section },
h('h3', { style: styles.sectionTitle }, 'Prerequisites'),
h('div', { style: styles.prereqList }, ...prerequisites.map(renderPrerequisite)),
);
}

function renderCapabilities(caps: Record<string, unknown>): any {
const entries = Object.entries(caps);
if (!entries.length) return null;
Expand Down Expand Up @@ -247,6 +303,8 @@ export function Drawer(props: { entry: CatalogEntry; pluginName: string; onClose
)
: null,

isGated ? null : renderPrerequisites(entry.install?.prerequisites),

h(
'div',
{ style: styles.section },
Expand Down
40 changes: 40 additions & 0 deletions src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,44 @@ export const styles = {
whiteSpace: 'pre' as const,
overflowX: 'auto' as const,
},
prereqList: {
display: 'flex',
flexDirection: 'column' as const,
gap: '0.5rem',
} as const,
prereqCard: {
border: '1px solid #e5e7eb',
borderRadius: 8,
padding: '0.625rem 0.75rem',
background: '#f9fafb',
} as const,
prereqHead: {
display: 'flex',
alignItems: 'baseline',
justifyContent: 'space-between',
gap: '0.5rem',
} as const,
prereqName: {
fontWeight: 600,
color: '#111827',
fontSize: '0.875rem',
} as const,
prereqDesc: {
color: '#374151',
fontSize: '0.8125rem',
marginTop: '0.2rem',
} as const,
prereqLink: {
fontSize: '0.75rem',
color: '#2563eb',
textDecoration: 'none',
whiteSpace: 'nowrap' as const,
} as const,
prereqSummary: {
cursor: 'pointer',
fontSize: '0.75rem',
color: '#2563eb',
marginTop: '0.5rem',
userSelect: 'none' as const,
} as const,
};
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

export type ExtensionType = 'plugin' | 'provider' | string;

export interface Prerequisite {
name: string;
description?: string;
installUrl?: string;
helm?: {
oci: string;
version?: string;
namespace: string;
createNamespace?: boolean;
defaultValues?: Record<string, string>;
};
}

export interface CatalogEntry {
name: string;
type: ExtensionType;
Expand All @@ -24,6 +37,7 @@ export interface CatalogEntry {
};
install?: {
helm?: { namespace?: string; releaseName?: string };
prerequisites?: Prerequisite[];
};
plugin?: {
contributes?: { backend?: boolean; ui?: boolean; cli?: boolean };
Expand Down
Loading