summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts')
-rw-r--r--polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts156
1 files changed, 124 insertions, 32 deletions
diff --git a/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts b/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts
index 55f7567f94..203318070f 100644
--- a/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts
+++ b/polygerrit-ui/app/elements/admin/gr-plugin-config-array-editor/gr-plugin-config-array-editor.ts
@@ -14,19 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
import '@polymer/iron-input/iron-input';
import '@polymer/paper-toggle-button/paper-toggle-button';
-import '../../../styles/gr-form-styles';
-import '../../../styles/shared-styles';
import '../../shared/gr-button/gr-button';
-import {dom, EventApi} from '@polymer/polymer/lib/legacy/polymer.dom';
-import {PolymerElement} from '@polymer/polymer/polymer-element';
-import {htmlTemplate} from './gr-plugin-config-array-editor_html';
-import {property, customElement} from '@polymer/decorators';
import {
PluginConfigOptionsChangedEventDetail,
ArrayPluginOption,
} from '../gr-repo-plugin-config/gr-repo-plugin-config-types';
+import {formStyles} from '../../../styles/gr-form-styles';
+import {sharedStyles} from '../../../styles/shared-styles';
+import {LitElement, html, css} from 'lit';
+import {customElement, property, state} from 'lit/decorators';
+import {BindValueChangeEvent} from '../../../types/events';
declare global {
interface HTMLElementTagNameMap {
@@ -35,61 +35,153 @@ declare global {
}
@customElement('gr-plugin-config-array-editor')
-export class GrPluginConfigArrayEditor extends PolymerElement {
- static get template() {
- return htmlTemplate;
- }
-
+export class GrPluginConfigArrayEditor extends LitElement {
/**
* Fired when the plugin config option changes.
*
* @event plugin-config-option-changed
*/
- @property({type: String})
- _newValue = '';
+ // private but used in test
+ @state() newValue = '';
// This property is never null, since this component in only about operations
// on pluginOption.
@property({type: Object})
pluginOption!: ArrayPluginOption;
- @property({type: Boolean, reflectToAttribute: true})
+ @property({type: Boolean, reflect: true})
disabled = false;
- _handleAddTap(e: MouseEvent) {
+ static override get styles() {
+ return [
+ sharedStyles,
+ formStyles,
+ css`
+ .wrapper {
+ width: 30em;
+ }
+ .existingItems {
+ background: var(--table-header-background-color);
+ border: 1px solid var(--border-color);
+ border-radius: var(--border-radius);
+ }
+ gr-button {
+ float: right;
+ margin-left: var(--spacing-m);
+ width: 4.5em;
+ }
+ .row {
+ align-items: center;
+ display: flex;
+ justify-content: space-between;
+ padding: var(--spacing-m) 0;
+ width: 100%;
+ }
+ .existingItems .row {
+ padding: var(--spacing-m);
+ }
+ .existingItems .row:not(:first-of-type) {
+ border-top: 1px solid var(--border-color);
+ }
+ input {
+ flex-grow: 1;
+ }
+ .hide {
+ display: none;
+ }
+ .placeholder {
+ color: var(--deemphasized-text-color);
+ padding-top: var(--spacing-m);
+ }
+ `,
+ ];
+ }
+
+ override render() {
+ return html`
+ <div class="wrapper gr-form-styles">
+ ${this.renderPluginOptions()}
+ <div class="row ${this.disabled ? 'hide' : ''}">
+ <iron-input
+ .bindValue=${this.newValue}
+ @bind-value-changed=${this.handleBindValueChangedNewValue}
+ >
+ <input
+ id="input"
+ @keydown=${this.handleInputKeydown}
+ ?disabled=${this.disabled}
+ />
+ </iron-input>
+ <gr-button
+ id="addButton"
+ ?disabled=${!this.newValue.length}
+ link
+ @click=${this.handleAddTap}
+ >Add</gr-button
+ >
+ </div>
+ </div>
+ `;
+ }
+
+ private renderPluginOptions() {
+ if (!this.pluginOption?.info?.values?.length) {
+ return html`<div class="row placeholder">None configured.</div>`;
+ }
+
+ return html`
+ <div class="existingItems">
+ ${this.pluginOption.info.values.map(item =>
+ this.renderPluginOptionValue(item)
+ )}
+ </div>
+ `;
+ }
+
+ private renderPluginOptionValue(item: string) {
+ return html`
+ <div class="row">
+ <span>${item}</span>
+ <gr-button
+ link
+ ?disabled=${this.disabled}
+ @click=${() => this.handleDelete(item)}
+ >Delete</gr-button
+ >
+ </div>
+ `;
+ }
+
+ private handleAddTap(e: MouseEvent) {
e.preventDefault();
- this._handleAdd();
+ this.handleAdd();
}
- _handleInputKeydown(e: KeyboardEvent) {
+ private handleInputKeydown(e: KeyboardEvent) {
// Enter.
if (e.keyCode === 13) {
e.preventDefault();
- this._handleAdd();
+ this.handleAdd();
}
}
- _handleAdd() {
- if (!this._newValue.length) {
+ private handleAdd() {
+ if (!this.newValue.length) {
return;
}
- this._dispatchChanged(
- this.pluginOption.info.values.concat([this._newValue])
- );
- this._newValue = '';
+ this.dispatchChanged(this.pluginOption.info.values.concat([this.newValue]));
+ this.newValue = '';
}
- _handleDelete(e: MouseEvent) {
- const value = ((dom(e) as EventApi).localTarget as HTMLElement).dataset[
- 'item'
- ];
- this._dispatchChanged(
+ private handleDelete(value: string) {
+ this.dispatchChanged(
this.pluginOption.info.values.filter(str => str !== value)
);
}
- _dispatchChanged(values: string[]) {
+ // private but used in test
+ dispatchChanged(values: string[]) {
const {_key, info} = this.pluginOption;
const detail: PluginConfigOptionsChangedEventDetail = {
_key,
@@ -101,7 +193,7 @@ export class GrPluginConfigArrayEditor extends PolymerElement {
);
}
- _computeShowInputRow(disabled: boolean) {
- return disabled ? 'hide' : '';
+ private handleBindValueChangedNewValue(e: BindValueChangeEvent) {
+ this.newValue = e.detail.value;
}
}