All files / src/form/select WorkspaceSelect.ts

51.42% Statements 36/70
100% Branches 2/2
40% Functions 2/5
51.42% Lines 36/70

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 7192x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x 92x                 92x                                       92x 92x 92x 92x 92x 92x 92x 92x               92x 92x 92x  
import { css, html, TemplateResult } from 'lit';
import { Select, SelectOption } from './Select';
import { property } from 'lit/decorators.js';
import { getScrollParent } from '../../utils';
 
export interface WorkspaceOption extends SelectOption {
  name: string;
  id: string;
  type: string;
}
 
export class WorkspaceSelect extends Select<WorkspaceOption> {
  static get styles() {
    return css`
      ${super.styles}
 
      :host {
        border: 0px solid blue;
      }
    `;
  }
 
  @property({ type: String })
  endpoint = '/api/internal/orgs.json';

  @property({ type: String })
  nameKey = 'name';

  @property({ type: String })
  valueKey = 'id';

  @property({ type: String })
  placeholder: string = 'Choose Workspace';

  @property({ type: Boolean })
  sorted: boolean = true;

  @property({ type: Object })
  workspace: WorkspaceOption;

  constructor() {
    super();
    this.shouldExclude = (option: WorkspaceOption) => {
      const selected = this.values[0];
      return option.id === selected?.id;
    };

    this.searchable = true;
  }

  public firstUpdated(changed: Map<string, any>) {
    super.firstUpdated(changed);
    this.allowAnchor = !!getScrollParent(this);
  }
 
  public prepareOptionsDefault(options: WorkspaceOption[]): WorkspaceOption[] {
    options.forEach((option) => {
      option.type = 'workspace';
    });
    return options;
  }

  public renderOptionDefault(option: WorkspaceOption): TemplateResult {
    if (!option) {
      return html``;
    }

    return html`<temba-user name=${option.name} showname></temba-user>`;
  }
}