Skip to content

Commit

Permalink
getting templates from cli
Browse files Browse the repository at this point in the history
Signed-off-by: msivasubramaniaan <[email protected]>
  • Loading branch information
msivasubramaniaan authored and datho7561 committed Sep 25, 2023
1 parent a16099e commit 06a8bfa
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 34 deletions.
3 changes: 1 addition & 2 deletions src/serverlessFunction/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface FunctionContent {
image?: string;
imageDigest?: string;
builder?: string;
invoke?: string;
invocation?: { format?: string };
}

Expand Down Expand Up @@ -71,8 +72,6 @@ export interface ClusterVersion {
];
}



export interface InvokeFunction {
instance: string;
id: string;
Expand Down
3 changes: 3 additions & 0 deletions src/webview/common/propertyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface HelmChartHomePageProps extends React.AnchorHTMLAttributes<HTMLA
}

export interface CreateFunctionPageProps extends DefaultProps {
basicTemplates: string[],
onCreateSubmit: (name: string, language: string, template: string, location: Uri, image: string) => void;
}

Expand All @@ -63,6 +64,8 @@ export interface InvokeFunctionPageProps extends DefaultProps {
uri: Uri;
instance: string;
invokeURL: string;
template: string;
basicTemplates: string[];
onInvokeSubmit: (name: string, instance: string, id: string, path: string, contentType: string, format: string, source: string,
type: string, data: string, file: string, enableUrl: boolean, invokeURL: string) => void;
}
Expand Down
13 changes: 2 additions & 11 deletions src/webview/serverless-function/app/createFunction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
helpText?: string
},
images: string[],
baseTemplates: string[],
templates: string[],
language: string,
template: string,
Expand All @@ -53,7 +52,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
helpText: 'Image name should be in the form of \'[registry]/[namespace]/[name]:[tag]\''
},
images: [],
baseTemplates: [],
templates: [],
language: '',
template: '',
Expand All @@ -62,7 +60,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
showLoadScreen: false
}
VSCodeMessage.postMessage({
action: 'getTemplates'
action: 'selectFolder'
});
}

Expand Down Expand Up @@ -100,13 +98,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
wsFolderItems: message.data.wsFolderItems
});
}
} else if (message.data.action === 'getTemplates') {
this.setState({
baseTemplates: message.data.basicTemplates
});
VSCodeMessage.postMessage({
action: 'selectFolder'
});
}
});
}
Expand Down Expand Up @@ -139,7 +130,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
handleDropDownChange = (_event: any, value: string, isLang = false): void => {
if (isLang) {
this.setState({
templates: this.state.baseTemplates[this.convert(value)]
templates: this.props.basicTemplates[this.convert(value)]
});
this.setState({
language: value,
Expand Down
6 changes: 5 additions & 1 deletion src/webview/serverless-function/app/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ button {
text-transform: none;
}

.MuiIconButton-root.Mui-disabled > .MuiSvgIcon-root {
color: var(--vscode-titleBar-inactiveForeground) !important;
}

.MuiButton-root.Mui-disabled {
-webkit-text-fill-color: white !important;
}
Expand Down Expand Up @@ -171,7 +175,7 @@ button {
}

.Mui-disabled {
-webkit-text-fill-color: var(--vscode-button-foreground) !important;
-webkit-text-fill-color: var(--vscode-titleBar-inactiveForeground) !important;
}

.Mui-active {
Expand Down
25 changes: 20 additions & 5 deletions src/webview/serverless-function/app/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
id: any,
folderURI: Uri,
instance: string,
invokeURL: string
invokeURL: string,
runtime: string,
basicTemplates: string[],
template: string
}> {

constructor(props: DefaultProps | Readonly<DefaultProps>) {
Expand All @@ -27,7 +30,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
id: undefined,
folderURI: undefined,
instance: '',
invokeURL: ''
invokeURL: '',
runtime: '',
basicTemplates: [],
template: ''
}
}

Expand All @@ -40,7 +46,15 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
id: message.data.id,
folderURI: message.data.uri,
instance: message.data.instance,
invokeURL: message.data.url
invokeURL: message.data.url,
runtime: message.data.runtime,
template: message.data.template,
basicTemplates: message.data.basicTemplates
})
} else if (message.data.action === 'create') {
this.setState({
invoke: false,
basicTemplates: message.data.basicTemplates
})
}
});
Expand Down Expand Up @@ -80,9 +94,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
return (
this.state.invoke ?
<InvokeFunction instance={this.state.instance} uri={this.state.folderURI} name={this.state.name}
invokeURL={this.state.invokeURL} id={this.state.id} onInvokeSubmit={this.handleInvokeSubmit} />
invokeURL={this.state.invokeURL} id={this.state.id}
template={this.state.template} basicTemplates={this.state.basicTemplates} onInvokeSubmit={this.handleInvokeSubmit} />
:
<CreateFunction onCreateSubmit={this.handleCreateSubmit} />
<CreateFunction onCreateSubmit={this.handleCreateSubmit} basicTemplates={this.state.basicTemplates} />
)
}
}
6 changes: 3 additions & 3 deletions src/webview/serverless-function/app/invokeFunction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
contentType: 'text/plain',
source: '/boson/fn',
type: 'boson.fn',
format: 'HTTP',
format: props.template?.length > 0 ? props.template : 'http',
input: 'Hello World',
inputFilePath: '',
mode: 'text',
Expand Down Expand Up @@ -206,7 +206,6 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
'video/3gpp2',
'application/x-7z-compressed',
];
const templates = ['HTTP', 'Cloud Events'];
return (
<div className='mainContainer margin'>
<div className='title'>
Expand Down Expand Up @@ -319,8 +318,9 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
</Button>
<Autocomplete
defaultValue={format}
disabled={this.props.template !== undefined}
id='format-dropdown'
options={templates}
options={this.props.basicTemplates}
onChange={(e, v) => this.handleDropDownChange(e, v)}
PaperComponent={({ children }) => (
<Paper sx={{
Expand Down
30 changes: 18 additions & 12 deletions src/webview/serverless-function/serverlessFunctionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
panel.dispose();
break;
}
case 'getTemplates': {
const templates = await Functions.getInstance().getTemplates();
await panel?.webview.postMessage({
action: eventName,
basicTemplates: templates
});
break;
}
default:
break;
}
Expand Down Expand Up @@ -163,25 +155,39 @@ export default class ServerlessFunctionViewLoader {
panel.reveal(vscode.ViewColumn.One);
return null;
}
const templates = await Functions.getInstance().getTemplates();
if (invoke) {
const panel = await this.createView(title);
const getEnvFuncId = crypto.randomUUID();
ServerlessFunctionViewLoader.invokePanelMap.set(title, panel);
const yamlContent = await Utils.getFuncYamlContent(folderURI.fsPath);
let template: string, runtime: string, basicTemplates: string[] = ['cloudevent', 'http'];
if (yamlContent) {
template = yamlContent.invoke;
runtime = yamlContent.runtime;
basicTemplates = template ? templates[runtime] : basicTemplates;
}
void panel.webview.postMessage({
action: 'invoke',
instance: status,
name: title.substring(0, title.indexOf('-')).trim(),
id: getEnvFuncId,
uri: folderURI,
runtime,
template,
basicTemplates,
url
});
return panel;
} else if (!invoke) {
return await this.createView(title);
const panel = await this.createView(title);
void panel.webview.postMessage({
action: 'create',
basicTemplates: templates
});
return panel;
}

return this.createView(title);

return null;
}

private static async createView(
Expand Down

0 comments on commit 06a8bfa

Please sign in to comment.