Skip to content

Commit

Permalink
Glimmer component for modifying parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
minghay committed Jun 18, 2024
1 parent 22a4518 commit d7119f9
Show file tree
Hide file tree
Showing 4 changed files with 482 additions and 0 deletions.
98 changes: 98 additions & 0 deletions app/components/pipeline/parameters/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import {
extractJobParameters,
extractEventParameters,
getNormalizedParameterGroups
} from 'screwdriver-ui/utils/pipeline/parameters';

export default class PipelineParametersComponent extends Component {
@tracked parameters;

@tracked selectedParameters;

constructor() {
super(...arguments);

const { pipelineParameters, jobParameters } = extractEventParameters(
this.args.event
);

this.parameters = getNormalizedParameterGroups(
pipelineParameters,
this.args.pipeline.parameters,
jobParameters,
extractJobParameters(this.args.jobs),
this.args.job ? this.args.job.name : null
);

this.selectedParameters = {
pipeline: { ...pipelineParameters },
job: { ...jobParameters }
};
}

get title() {
return `${this.args.action} pipeline with parameters`.toUpperCase();
}

@action
toggleParameterGroup(groupName) {
const updatedParameters = [];

this.parameters.forEach(group => {
if (group.paramGroupTitle === groupName) {
updatedParameters.push({ ...group, isOpen: !group.isOpen });
} else {
updatedParameters.push(group);
}
});

this.parameters = updatedParameters;
}

@action
openSelect(powerSelectObject) {
setTimeout(() => {
const container = document.getElementsByClassName('parameters-container');
const scrollFrame = container[0];
const optionsBox = document.getElementById(
`ember-power-select-options-${powerSelectObject.uniqueId}`
);

if (optionsBox === null) {
return;
}

const optionsBoxRect = optionsBox.getBoundingClientRect();
const scrollFrameRect = scrollFrame.getBoundingClientRect();
const hiddenAreaHeight = optionsBoxRect.bottom - scrollFrameRect.bottom;

if (hiddenAreaHeight > 0) {
scrollFrame.scrollBy({ top: hiddenAreaHeight + 10 });
}
}, 100);
}

@action
onInput(parameterGroup, parameter, event) {
this.updateParameter(parameterGroup, parameter, event.target.value);
}

@action
updateParameter(parameterGroup, parameter, value) {
if (parameterGroup) {
const jobParameters = { ...this.selectedParameters.job[parameterGroup] };

jobParameters[parameter.name] = { value };
this.selectedParameters.job[parameterGroup] = jobParameters;
} else {
this.selectedParameters.pipeline[parameter.name] = { value };
}

const { pipeline, job } = this.selectedParameters;

this.args.onUpdateParameters({ ...pipeline, ...job });
}
}
61 changes: 61 additions & 0 deletions app/components/pipeline/parameters/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@use 'screwdriver-colors' as colors;
@use 'variables';

@mixin styles {
.pipeline-parameters {
.parameter-title {
font-size: 1.2rem;
font-weight: variables.$weight-bold;
color: colors.$sd-light-gray;
}

.parameters-container {
max-height: 50vh;
overflow-y: scroll;

.parameter-group {
border-radius: 8px;
border: 1px solid colors.$sd-separator;
margin-top: 1rem;
padding: 0.5rem;

.group-title {
font-size: 1.5rem;
}

.parameter-list {
&.collapsed {
display: none;
}

.parameter {
display: flex;
padding: 0.2rem;

label {
display: flex;
margin-top: auto;
margin-bottom: auto;
padding-right: 0.5rem;
flex-basis: 25%;

svg {
margin-top: auto;
margin-bottom: auto;
padding-left: 0.25rem;
}
}

.dropdown-selection-container {
flex: 1;
}

> input {
flex: 1;
}
}
}
}
}
}
}
42 changes: 42 additions & 0 deletions app/components/pipeline/parameters/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<div class="pipeline-parameters">
<div class="parameter-title">
{{this.title}}
</div>
<div class="parameters-container">
{{#each this.parameters as |parameterGroup|}}
<div class="parameter-group">
<div class="group-title">
<FaIcon @icon={{if parameterGroup.isOpen "minus-square" "plus-square"}} {{on "click" (fn this.toggleParameterGroup parameterGroup.paramGroupTitle)}}></FaIcon>
{{parameterGroup.paramGroupTitle}}
</div>
<div class="parameter-list {{if parameterGroup.isOpen "expanded" "collapsed"}}">
{{#each parameterGroup.parameters as |parameter|}}
<div class="parameter">
<label>
{{parameter.name}}
{{#if parameter.description}}
<FaIcon @icon="question-circle" @title={{parameter.description}}></FaIcon>
{{/if}}
</label>
{{#if (is-array parameter.defaultValues)}}
<div class="dropdown-selection-container">
<Pipeline::Parameters::Selectable
@parameter={{parameter}}
@onOpen={{this.openSelect}}
@onSelectValue={{(fn this.updateParameter parameterGroup.jobName)}}
/>
</div>
{{else}}
<Input
@value={{parameter.value}}
defaultValue={{parameter.value}}
{{on "input" (fn this.onInput parameterGroup.jobName parameter)}}
/>
{{/if}}
</div>
{{/each}}
</div>
</div>
{{/each}}
</div>
</div>
Loading

0 comments on commit d7119f9

Please sign in to comment.