@alihbuzaid/ember-ui
Version:
Fleetbase UI provides all the interface components, helpers, services and utilities for building a Fleetbase extension into the Console.
69 lines (52 loc) • 1.73 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, computed, get } from '@ember/object';
export default class AsideItemScrollerComponent extends Component {
items = [];
selected;
constructor() {
super(...arguments);
if (typeof this.args.onInit === 'function') {
this.args.onInit(this);
}
}
onCreate() {
const { onCreate } = this.args;
if (typeof onCreate === 'function') {
onCreate(this);
}
}
get itemsGroupByTitleLetter() {
const { titleKey, items } = this.args;
const grouped = {};
for (let i = 0; i < items.length; i++) {
const item = items.objectAt(i);
const title = get(item, titleKey);
const firstLetter = title[0];
if (!title || !firstLetter) {
continue;
}
if (!grouped[firstLetter]) {
grouped[firstLetter] = [];
}
grouped[firstLetter].pushObject(item);
}
return grouped;
}
get powerSelectGrouped() {
const grouped = [];
for (let groupName in this.itemsGroupByTitleLetter) {
grouped.pushObject({
groupName,
options: this.itemsGroupByTitleLetter[groupName],
});
}
return grouped;
}
get resource() {
return this.args.resource ?? 'item';
}
get title() {
return this.args.title ?? 'Directory';
}
}