Skip to content

Commit 06a8bfa

Browse files
msivasubramaniaandatho7561
authored andcommitted
getting templates from cli
Signed-off-by: msivasubramaniaan <msivasub@redhat.com>
1 parent a16099e commit 06a8bfa

File tree

7 files changed

+52
-34
lines changed

7 files changed

+52
-34
lines changed

src/serverlessFunction/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface FunctionContent {
1818
image?: string;
1919
imageDigest?: string;
2020
builder?: string;
21+
invoke?: string;
2122
invocation?: { format?: string };
2223
}
2324

@@ -71,8 +72,6 @@ export interface ClusterVersion {
7172
];
7273
}
7374

74-
75-
7675
export interface InvokeFunction {
7776
instance: string;
7877
id: string;

src/webview/common/propertyTypes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface HelmChartHomePageProps extends React.AnchorHTMLAttributes<HTMLA
5454
}
5555

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

@@ -63,6 +64,8 @@ export interface InvokeFunctionPageProps extends DefaultProps {
6364
uri: Uri;
6465
instance: string;
6566
invokeURL: string;
67+
template: string;
68+
basicTemplates: string[];
6669
onInvokeSubmit: (name: string, instance: string, id: string, path: string, contentType: string, format: string, source: string,
6770
type: string, data: string, file: string, enableUrl: boolean, invokeURL: string) => void;
6871
}

src/webview/serverless-function/app/createFunction.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
3030
helpText?: string
3131
},
3232
images: string[],
33-
baseTemplates: string[],
3433
templates: string[],
3534
language: string,
3635
template: string,
@@ -53,7 +52,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
5352
helpText: 'Image name should be in the form of \'[registry]/[namespace]/[name]:[tag]\''
5453
},
5554
images: [],
56-
baseTemplates: [],
5755
templates: [],
5856
language: '',
5957
template: '',
@@ -62,7 +60,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
6260
showLoadScreen: false
6361
}
6462
VSCodeMessage.postMessage({
65-
action: 'getTemplates'
63+
action: 'selectFolder'
6664
});
6765
}
6866

@@ -100,13 +98,6 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
10098
wsFolderItems: message.data.wsFolderItems
10199
});
102100
}
103-
} else if (message.data.action === 'getTemplates') {
104-
this.setState({
105-
baseTemplates: message.data.basicTemplates
106-
});
107-
VSCodeMessage.postMessage({
108-
action: 'selectFolder'
109-
});
110101
}
111102
});
112103
}
@@ -139,7 +130,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
139130
handleDropDownChange = (_event: any, value: string, isLang = false): void => {
140131
if (isLang) {
141132
this.setState({
142-
templates: this.state.baseTemplates[this.convert(value)]
133+
templates: this.props.basicTemplates[this.convert(value)]
143134
});
144135
this.setState({
145136
language: value,

src/webview/serverless-function/app/home.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ button {
4646
text-transform: none;
4747
}
4848

49+
.MuiIconButton-root.Mui-disabled > .MuiSvgIcon-root {
50+
color: var(--vscode-titleBar-inactiveForeground) !important;
51+
}
52+
4953
.MuiButton-root.Mui-disabled {
5054
-webkit-text-fill-color: white !important;
5155
}
@@ -171,7 +175,7 @@ button {
171175
}
172176

173177
.Mui-disabled {
174-
-webkit-text-fill-color: var(--vscode-button-foreground) !important;
178+
-webkit-text-fill-color: var(--vscode-titleBar-inactiveForeground) !important;
175179
}
176180

177181
.Mui-active {

src/webview/serverless-function/app/home.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
1616
id: any,
1717
folderURI: Uri,
1818
instance: string,
19-
invokeURL: string
19+
invokeURL: string,
20+
runtime: string,
21+
basicTemplates: string[],
22+
template: string
2023
}> {
2124

2225
constructor(props: DefaultProps | Readonly<DefaultProps>) {
@@ -27,7 +30,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
2730
id: undefined,
2831
folderURI: undefined,
2932
instance: '',
30-
invokeURL: ''
33+
invokeURL: '',
34+
runtime: '',
35+
basicTemplates: [],
36+
template: ''
3137
}
3238
}
3339

@@ -40,7 +46,15 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
4046
id: message.data.id,
4147
folderURI: message.data.uri,
4248
instance: message.data.instance,
43-
invokeURL: message.data.url
49+
invokeURL: message.data.url,
50+
runtime: message.data.runtime,
51+
template: message.data.template,
52+
basicTemplates: message.data.basicTemplates
53+
})
54+
} else if (message.data.action === 'create') {
55+
this.setState({
56+
invoke: false,
57+
basicTemplates: message.data.basicTemplates
4458
})
4559
}
4660
});
@@ -80,9 +94,10 @@ export class ServerlessFunction extends React.Component<DefaultProps, {
8094
return (
8195
this.state.invoke ?
8296
<InvokeFunction instance={this.state.instance} uri={this.state.folderURI} name={this.state.name}
83-
invokeURL={this.state.invokeURL} id={this.state.id} onInvokeSubmit={this.handleInvokeSubmit} />
97+
invokeURL={this.state.invokeURL} id={this.state.id}
98+
template={this.state.template} basicTemplates={this.state.basicTemplates} onInvokeSubmit={this.handleInvokeSubmit} />
8499
:
85-
<CreateFunction onCreateSubmit={this.handleCreateSubmit} />
100+
<CreateFunction onCreateSubmit={this.handleCreateSubmit} basicTemplates={this.state.basicTemplates} />
86101
)
87102
}
88103
}

src/webview/serverless-function/app/invokeFunction.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
3333
contentType: 'text/plain',
3434
source: '/boson/fn',
3535
type: 'boson.fn',
36-
format: 'HTTP',
36+
format: props.template?.length > 0 ? props.template : 'http',
3737
input: 'Hello World',
3838
inputFilePath: '',
3939
mode: 'text',
@@ -206,7 +206,6 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
206206
'video/3gpp2',
207207
'application/x-7z-compressed',
208208
];
209-
const templates = ['HTTP', 'Cloud Events'];
210209
return (
211210
<div className='mainContainer margin'>
212211
<div className='title'>
@@ -319,8 +318,9 @@ export class InvokeFunction extends React.Component<InvokeFunctionPageProps, {
319318
</Button>
320319
<Autocomplete
321320
defaultValue={format}
321+
disabled={this.props.template !== undefined}
322322
id='format-dropdown'
323-
options={templates}
323+
options={this.props.basicTemplates}
324324
onChange={(e, v) => this.handleDropDownChange(e, v)}
325325
PaperComponent={({ children }) => (
326326
<Paper sx={{

src/webview/serverless-function/serverlessFunctionLoader.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,6 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
121121
panel.dispose();
122122
break;
123123
}
124-
case 'getTemplates': {
125-
const templates = await Functions.getInstance().getTemplates();
126-
await panel?.webview.postMessage({
127-
action: eventName,
128-
basicTemplates: templates
129-
});
130-
break;
131-
}
132124
default:
133125
break;
134126
}
@@ -163,25 +155,39 @@ export default class ServerlessFunctionViewLoader {
163155
panel.reveal(vscode.ViewColumn.One);
164156
return null;
165157
}
158+
const templates = await Functions.getInstance().getTemplates();
166159
if (invoke) {
167160
const panel = await this.createView(title);
168161
const getEnvFuncId = crypto.randomUUID();
169162
ServerlessFunctionViewLoader.invokePanelMap.set(title, panel);
163+
const yamlContent = await Utils.getFuncYamlContent(folderURI.fsPath);
164+
let template: string, runtime: string, basicTemplates: string[] = ['cloudevent', 'http'];
165+
if (yamlContent) {
166+
template = yamlContent.invoke;
167+
runtime = yamlContent.runtime;
168+
basicTemplates = template ? templates[runtime] : basicTemplates;
169+
}
170170
void panel.webview.postMessage({
171171
action: 'invoke',
172172
instance: status,
173173
name: title.substring(0, title.indexOf('-')).trim(),
174174
id: getEnvFuncId,
175175
uri: folderURI,
176+
runtime,
177+
template,
178+
basicTemplates,
176179
url
177180
});
178181
return panel;
179182
} else if (!invoke) {
180-
return await this.createView(title);
183+
const panel = await this.createView(title);
184+
void panel.webview.postMessage({
185+
action: 'create',
186+
basicTemplates: templates
187+
});
188+
return panel;
181189
}
182-
183-
return this.createView(title);
184-
190+
return null;
185191
}
186192

187193
private static async createView(

0 commit comments

Comments
 (0)