@fleetbase/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
56 lines (46 loc) • 1.69 kB
JavaScript
import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { isArray } from '@ember/array';
const { assign } = Object;
export default class FilterSelectComponent extends Component {
fetch;
value;
optionLabel;
optionValue;
placeholder;
options = [];
isLoading = false;
constructor() {
super(...arguments);
this.value = this.args.value;
this.options = isArray(this.args.options) ? this.args.options : [];
this.optionLabel = this.args.optionLabel ?? this.args.filterOptionLabel;
this.optionValue = this.args.optionValue ?? this.args.filterOptionValue;
this.placeholder = this.args.placeholder ?? this.args.filterPlaceholder;
if (typeof this.args.filter?.filterFetchOptions === 'string') {
this.fetchOptions(this.args.filter?.filterFetchOptions);
}
}
onChange(selection) {
const { onChange, filter } = this.args;
this.value = selection;
if (typeof onChange === 'function') {
onChange(filter, selection);
}
}
fetchOptions(uri, params = {}) {
const { fetchParams } = this.args;
const queryParams = assign(params, fetchParams ?? {});
this.isLoading = true;
this.fetch
.get(uri, queryParams)
.then((options) => {
this.options = options;
})
.finally(() => {
this.isLoading = false;
});
}
}