Skip to content

Commit

Permalink
feat: Add find/delete methods for columns in Widget instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-coster committed Jul 2, 2021
1 parent 2d87d1e commit 3bd307c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lib/entities/BravoWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { DataFavroWidget } from '$types/FavroWidgetTypes.js';
import { BravoEntity } from '$lib/BravoEntity.js';
import { selectRandom } from '$lib/utility.js';
import { BravoColumn } from './BravoColumn.js';
import { ArrayMatchFunction } from '$/types/Utility.js';

export type OptionWidgetColor = typeof BravoWidget['colors'][number];

export class BravoWidget extends BravoEntity<DataFavroWidget> {
/** TODO: Move to cache! */
private _columns?: BravoColumn[];

get widgetCommonId() {
Expand All @@ -27,13 +29,21 @@ export class BravoWidget extends BravoEntity<DataFavroWidget> {
return this._data.editRole;
}

async getColumns() {
async listColumns() {
if (!this._columns) {
this._columns = await this._client.listColumns(this.widgetCommonId);
}
return [...this._columns];
}

async findColumn(matchFunction: ArrayMatchFunction<BravoColumn>) {
return await this._client.findColumn(this.widgetCommonId, matchFunction);
}

async deleteColumnById(columnId: string) {
return await this.findColumn((col) => col.columnId == columnId);
}

async delete() {
if (!this.deleted) {
await this._client.deleteWidgetById(this.widgetCommonId);
Expand Down

0 comments on commit 3bd307c

Please sign in to comment.