Skip to content

Commit 943282f

Browse files
committed
feat(lit-wes workflow type and version fields): changed the input feild in lit-wes to dropdown
re elixir-cloud-aai#180
1 parent 0257a87 commit 943282f

File tree

4 files changed

+158
-18
lines changed

4 files changed

+158
-18
lines changed

Diff for: packages/ecc-client-lit-ga4gh-wes/src/API/Workflow/wesGet.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,31 @@ const fetchWorkflow = async (baseURL: string, id: string) => {
6868
}
6969
};
7070

71+
/**
72+
* Create a workflow run
73+
* @param {string} baseURL - Base URL for fetching workflows
74+
*/
75+
const fetchWorkflowType = async (baseURL: string) => {
76+
const url = `${baseURL}/service-info`;
77+
try {
78+
const response = await fetch(url);
79+
if (!response) {
80+
return {
81+
isError: true,
82+
breakpoint: "fetchWorkflowtype",
83+
error: "No response from server",
84+
};
85+
}
86+
return await response.json();
87+
} catch (error) {
88+
return {
89+
isError: true,
90+
breakpoint: "fetchworkflowtype",
91+
error,
92+
};
93+
}
94+
};
95+
7196
/**
7297
*This mathod cancel a specific workflow
7398
* @param id ID of the workflow to be deleted
@@ -121,4 +146,4 @@ const postWorkflow = async (baseURL: string, data: any) => {
121146
}
122147
};
123148

124-
export { fetchWorkflows, fetchWorkflow, cancelWorkflow, postWorkflow };
149+
export { fetchWorkflows, fetchWorkflow, fetchWorkflowType, cancelWorkflow, postWorkflow };

Diff for: packages/ecc-client-lit-ga4gh-wes/src/components/wes-create-run/wes-create-run.ts

+77-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { html, LitElement } from "lit";
2-
import { property, state } from "lit/decorators.js";
3-
import { postWorkflow } from "../../API/Workflow/wesGet.js";
2+
import { customElement, property, state } from "lit/decorators.js";
3+
import { postWorkflow, fetchWorkflowType } from "../../API/Workflow/wesGet.js";
44
import "@elixir-cloud/design";
55

66
// TODO: import the interface from the design package
7-
export interface Field {
7+
interface Field {
88
key: string;
99
label: string;
1010
type?:
@@ -21,14 +21,16 @@ export interface Field {
2121
| "array"
2222
| "switch"
2323
| "file"
24-
| "group";
24+
| "group"
25+
| "select";
2526
fieldOptions?: {
2627
required?: boolean;
2728
default?: string | boolean;
2829
multiple?: boolean;
2930
accept?: string;
3031
returnIfEmpty?: string;
3132
tooltip?: string;
33+
options?: Array<{ label: string; value: string }>;
3234
};
3335
arrayOptions?: {
3436
defaultInstances?: number;
@@ -42,15 +44,8 @@ export interface Field {
4244
children?: Array<Field>;
4345
}
4446

45-
/**
46-
* @summary This component is used to create task runs using WES API.
47-
* @since 1.0.0
48-
*
49-
* @property {string} baseURL - Base URL
50-
*
51-
*/
52-
53-
export default class ECCClientGa4ghWesCreateRuns extends LitElement {
47+
@customElement("ecc-client-lit-ga4gh-wes-create-run")
48+
export class WESCreateRun extends LitElement {
5449
@state() private form: FormData = new FormData();
5550
@property({ type: String }) private baseURL =
5651
"https://prowes.rahtiapp.fi/ga4gh/wes/v1";
@@ -69,21 +64,23 @@ export default class ECCClientGa4ghWesCreateRuns extends LitElement {
6964
{
7065
key: "workflow_type",
7166
label: "Type",
72-
type: "text",
67+
type: "select",
7368
fieldOptions: {
7469
required: true,
7570
tooltip:
7671
"The type of workflow language and must be CWL or WDL currently.",
72+
options: [],
7773
},
7874
},
7975
{
8076
key: "workflow_type_version",
8177
label: "Type version",
82-
type: "text",
78+
type: "select",
8379
fieldOptions: {
8480
required: true,
8581
tooltip:
8682
"The version of the workflow language submitted and must be one supported by this WES instance.",
83+
options: [],
8784
},
8885
},
8986
{
@@ -136,6 +133,71 @@ export default class ECCClientGa4ghWesCreateRuns extends LitElement {
136133
},
137134
];
138135

136+
connectedCallback() {
137+
super.connectedCallback?.();
138+
this._updateWorkflowType();
139+
}
140+
141+
private async _updateWorkflowType() {
142+
const data = await fetchWorkflowType(this.baseURL);
143+
const workflowTypes = data.workflow_type_versions;
144+
145+
const eccUtilsDesignForm = this.shadowRoot?.querySelector(
146+
"ecc-utils-design-form"
147+
) as any;
148+
149+
if (eccUtilsDesignForm) {
150+
const workflowTypeKey = "workflow_type";
151+
const workflowTypeVersionKey = "workflow_type_version";
152+
153+
// Find the dropdown field for workflow_type in this.fields
154+
const workflowTypeDropdown = this.fields.find(
155+
(field) => field.key === workflowTypeKey
156+
);
157+
158+
// Find the dropdown field for workflow_type_version in this.fields
159+
const workflowTypeVersionDropdown = this.fields.find(
160+
(field) => field.key === workflowTypeVersionKey
161+
);
162+
163+
// Check if the dropdown fields exist and have fieldOptions
164+
if (
165+
workflowTypeDropdown &&
166+
workflowTypeDropdown.fieldOptions &&
167+
workflowTypeVersionDropdown &&
168+
workflowTypeVersionDropdown.fieldOptions
169+
) {
170+
// Update the options of the workflow_type dropdown
171+
workflowTypeDropdown.fieldOptions.options = Object.keys(
172+
workflowTypes
173+
).map((type: string) => ({
174+
label: type,
175+
value: type,
176+
}));
177+
178+
// Manually trigger a re-render or update of the form
179+
eccUtilsDesignForm.requestUpdate();
180+
// Add an event listener to workflow_type dropdown change
181+
const formData = eccUtilsDesignForm.getFormData();
182+
const selectedWorkflowType = formData[workflowTypeKey];
183+
184+
// Check if fieldOptions is defined
185+
if (workflowTypeVersionDropdown.fieldOptions) {
186+
// Update the options of the workflow_type_version dropdown based on the selected workflow_type
187+
workflowTypeVersionDropdown.fieldOptions.options =
188+
workflowTypes[selectedWorkflowType] || [];
189+
190+
eccUtilsDesignForm.requestUpdate();
191+
}
192+
}
193+
} else {
194+
console.error({
195+
message: "ecc-utils-design-form not found",
196+
breakPoint: "WESCreateRun.updateDropdown",
197+
});
198+
}
199+
}
200+
139201
async submitForm(form: any) {
140202
Object.keys(form).forEach((key) => {
141203
this.form.append(key, form[key]);

Diff for: packages/ecc-utils-design/src/components/form/form.styles.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ const styles = css`
1212
margin-top: 0.5rem;
1313
margin-bottom: 0.5rem;
1414
}
15+
form sl-dropdown {
16+
margin-top: 0.5rem;
17+
margin-bottom: 0.5rem;
18+
}
1519
form sl-switch {
1620
margin-top: 0.5rem;
1721
margin-bottom: 0.5rem;

Diff for: packages/ecc-utils-design/src/components/form/form.ts

+51-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { html, LitElement, TemplateResult } from "lit";
22
import { property, state } from "lit/decorators.js";
3+
import "@shoelace-style/shoelace/dist/components/dropdown/dropdown.js";
4+
import "@shoelace-style/shoelace/dist/components/menu/menu.js";
5+
import "@shoelace-style/shoelace/dist/components/menu-item/menu-item.js";
36
import "@shoelace-style/shoelace/dist/components/input/input.js";
47
import "@shoelace-style/shoelace/dist/components/button/button.js";
58
import "@shoelace-style/shoelace/dist/components/switch/switch.js";
@@ -12,7 +15,7 @@ import getShoelaceStyles from "../../styles/shoelace.styles.js";
1215
import { hostStyles } from "../../styles/host.styles.js";
1316
import formStyles from "./form.styles.js";
1417

15-
export interface Field {
18+
interface Field {
1619
key: string;
1720
label: string;
1821
type?:
@@ -29,14 +32,16 @@ export interface Field {
2932
| "array"
3033
| "switch"
3134
| "file"
32-
| "group";
35+
| "group"
36+
| "select";
3337
fieldOptions?: {
3438
required?: boolean;
3539
default?: string | boolean;
3640
multiple?: boolean;
3741
accept?: string;
3842
returnIfEmpty?: string;
3943
tooltip?: string;
44+
options?: Array<{ label: string; value: string }>;
4045
};
4146
arrayOptions?: {
4247
defaultInstances?: number;
@@ -201,6 +206,46 @@ export default class EccUtilsDesignForm extends LitElement {
201206
`;
202207
}
203208

209+
if (field.type === "select" && field.fieldOptions?.options) {
210+
if (!_.get(this.form, path) && !this.hasUpdated) {
211+
_.set(
212+
this.form,
213+
path,
214+
field.fieldOptions?.default ||
215+
field.fieldOptions?.options[0]?.value ||
216+
""
217+
);
218+
}
219+
220+
return html`
221+
<sl-dropdown>
222+
<sl-button slot="trigger" caret>${field.label}</sl-button>
223+
<sl-menu>
224+
${field.fieldOptions?.options.map(
225+
(option) => html`
226+
<sl-menu-item
227+
value="${option.value}"
228+
?selected="${option.value === _.get(this.form, path)}"
229+
?required="${field.fieldOptions?.required ? "*" : ""}"
230+
@click="${(e: Event) => {
231+
const { value } = e.target as HTMLSelectElement;
232+
if (!value) {
233+
_.unset(this.form, path);
234+
} else {
235+
_.set(this.form, path, value);
236+
}
237+
this.requestUpdate();
238+
}}"
239+
>
240+
${option.label}
241+
</sl-menu-item>
242+
`
243+
)}
244+
</sl-menu>
245+
</sl-dropdown>
246+
`;
247+
}
248+
204249
if (!_.get(this.form, path)) {
205250
if (field.fieldOptions?.default && !this.hasUpdated) {
206251
_.set(this.form, path, field.fieldOptions.default);
@@ -486,6 +531,10 @@ export default class EccUtilsDesignForm extends LitElement {
486531
`;
487532
}
488533

534+
public getFormData(): object {
535+
return this.form;
536+
}
537+
489538
public loading() {
490539
this.formState = "loading";
491540
}

0 commit comments

Comments
 (0)