Skip to content

Commit

Permalink
Merge pull request #735 from mobi/dev
Browse files Browse the repository at this point in the history
v1.8.0
  • Loading branch information
grahamhency authored Jan 26, 2021
2 parents b69570f + 1d2ca3f commit 20d017e
Show file tree
Hide file tree
Showing 27 changed files with 1,520 additions and 52 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Goponents

###### Currently `v1.7.1`
###### Currently `v1.8.0`

This project houses a set of UI components for Angular 7+ and designed around the 'Go' design system.

Expand Down
4 changes: 2 additions & 2 deletions projects/go-lib/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ module.exports = function (config) {
reporters: ['dots'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
logLevel: config.LOG_WARN,
autoWatch: true,
browsers: ['Chrome'],
browsers: ['ChromeHeadless'],
singleRun: false
});
};
2 changes: 1 addition & 1 deletion projects/go-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tangoe/goponents",
"version": "1.7.1",
"version": "1.8.0",
"repository": {
"type": "git",
"url": "git+https://github.com/mobi/goponents.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
[typeahead]="typeahead"
[ngClass]="{'go-select--dark': theme === 'dark'}"
[searchable]="searchable"
[typeToSearchText]="typeToSearchText">
[typeToSearchText]="typeToSearchText"
[virtualScroll]="virtualScroll"
(scrollToEnd)="onScrollToEnd()"
(scroll)="onScroll($event)">
<ng-container *ngIf="multiple && showSelectAll">
<ng-template ng-header-tmp>
<button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ContentChild, Input, OnInit, TemplateRef, ViewEncapsulation } from '@angular/core';
import { Component, ContentChild, EventEmitter, Input, OnInit, Output, TemplateRef, ViewEncapsulation } from '@angular/core';
import { FormControl } from '@angular/forms';
import { Subject } from 'rxjs';
import { generateId } from '../../utilities/form.utils';
Expand Down Expand Up @@ -33,6 +33,9 @@ export class GoSelectComponent implements OnInit {
@Input() typeahead?: Subject<string>;
@Input() typeToSearchText: string = 'Type to Search';
@Input() theme: 'light' | 'dark' = 'light';
@Input() virtualScroll: boolean = false;
@Output() scrollToEnd: EventEmitter<any> = new EventEmitter<any>();
@Output() scroll: EventEmitter<{ start: number, end: number }> = new EventEmitter<{ start: number; end: number }>();

@ContentChild('goSelectOption', { static: false }) goSelectOption: TemplateRef<any>;
@ContentChild('goSelectOptionGroup', { static: false }) goSelectOptionGroup: TemplateRef<any>;
Expand All @@ -45,4 +48,14 @@ export class GoSelectComponent implements OnInit {
onSelectAll(): void {
this.control.patchValue(this.items.map((item: any) => this.bindValue ? item[this.bindValue] : item));
}

onScrollToEnd(): void {
if (this.virtualScroll) {
this.scrollToEnd.emit();
}
}

onScroll($event: { start: number; end: number }): void {
this.scroll.emit($event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,6 @@ describe('GoTableComponent', () => {
});
});

describe('afterViewInit', () => {
afterEach(() => {
component.selectAllControl.setValue(false);
});

it('should select all rows if preselected', () => {
component.tableConfig.preselected = true;
component.ngAfterViewInit();
expect(component.selectAllControl.value).toBe(true);
});
});

describe('setPageByPageNumber', () => {
beforeEach(() => {
component.localTableConfig.totalCount = 135;
Expand Down Expand Up @@ -399,8 +387,12 @@ describe('GoTableComponent', () => {
});

it('should set selectAllIndeterminate to false if selectAll toggled off', () => {
component.ngOnInit();

component.selectAllControl.setValue(false);

component.ngOnDestroy();

expect(component.selectAllIndeterminate).toBe(false);
});

Expand All @@ -414,14 +406,22 @@ describe('GoTableComponent', () => {
});

it('should reset targetedRows if toggling selectAll on', () => {
component.ngOnInit();

component.selectAllControl.setValue(true);

component.ngOnDestroy();

expect(component.targetedRows).toEqual([]);
});

it('should reset targetedRows if toggling selectAll off', () => {
component.ngOnInit();

component.selectAllControl.setValue(false);

component.ngOnDestroy();

expect(component.targetedRows).toEqual([]);
});

Expand All @@ -433,8 +433,12 @@ describe('GoTableComponent', () => {
};
spyOn(component.selectAllEvent, 'emit');

component.ngOnInit();

component.selectAllControl.setValue(false);

component.ngOnDestroy();

expect(component.selectAllEvent.emit).toHaveBeenCalledWith(selectionEventData);
});
});
Expand Down Expand Up @@ -946,11 +950,14 @@ describe('GoTableComponent', () => {
component.tableConfig.selectBy = 'id';

component.renderTable();
component.ngOnInit();

expect(component.rowSelectForm.value['selection_1']).toBe(false);

component.selectAllControl.setValue(true);

component.ngOnDestroy();

expect(component.rowSelectForm.value['selection_1']).toBe(true);
});
});
Expand Down Expand Up @@ -1100,6 +1107,16 @@ describe('GoTableComponent', () => {
component.tableConfig.tableData = fakeTableData;
});

afterEach(() => {
component.selectAllControl.setValue(false);
});

it('should select all rows if preselected', () => {
component.tableConfig.preselected = true;
component.ngAfterViewInit();
expect(component.selectAllControl.value).toBe(true);
});

it('performs a search if datamode is client and table is searchable', () => {
component.tableConfig.searchConfig.searchTerm = 'koala';
component.tableConfig.searchConfig.searchable = true;
Expand Down
55 changes: 28 additions & 27 deletions projects/go-lib/src/lib/components/go-table/go-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ import {
Output,
QueryList,
SimpleChanges,
TemplateRef,
ViewChild
TemplateRef
} from '@angular/core';
import {
FormBuilder,
FormControl,
FormGroup
} from '@angular/forms';
import { Subject } from 'rxjs';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, takeUntil } from 'rxjs/operators';

import { GoConfigService } from '../../go-config.service';
Expand Down Expand Up @@ -125,6 +124,7 @@ export class GoTableComponent implements OnInit, OnChanges, OnDestroy, AfterView
this.setupSearch();
this.setupPageSizes();
this.setupConfigService();
this.setupSelectAllControlSub();
}
}

Expand Down Expand Up @@ -164,10 +164,6 @@ export class GoTableComponent implements OnInit, OnChanges, OnDestroy, AfterView
this.handleSort();
this.setPage(this.localTableConfig.pageConfig.offset);
this.setSearchTerm();

if (this.localTableConfig.selectable) {
this.setupSelectAllControlSub();
}
}

this.showTable = Boolean(this.tableConfig);
Expand Down Expand Up @@ -546,34 +542,39 @@ export class GoTableComponent implements OnInit, OnChanges, OnDestroy, AfterView
private setupRowSelectFormControlsSubs(): void {
this.getDisplayData().forEach((row: any) => {
this.rowSelectForm.get(`selection_${row[this.localTableConfig.selectBy]}`)
.valueChanges.pipe(takeUntil(this.pageChange$))
.valueChanges.pipe(
takeUntil(this.pageChange$),
takeUntil(this.destroy$)
)
.subscribe((value: boolean) => {
this.selectionChange(value, row);
});
});
}

private setupSelectAllControlSub(): void {
this.selectAllControl.valueChanges
.pipe(
distinctUntilChanged(),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.targetedRows = [];
this.updateRowSelectForm();

if (!this.selectAllControl.value) {
this.selectAllIndeterminate = false;
if (this.tableConfig.selectable) {
this.selectAllControl.valueChanges
.pipe(
distinctUntilChanged(),
takeUntil(this.destroy$)
)
.subscribe(() => {
this.targetedRows = [];
this.updateRowSelectForm();

if (!this.selectAllControl.value) {
this.selectAllIndeterminate = false;
}

this.selectAllEvent.emit({
deselectedRows: this.selectAllControl.value ? this.targetedRows : [],
selectionMode: this.determineSelectionMode(),
selectedRows: !this.selectAllControl.value ? this.targetedRows : []
});
}

this.selectAllEvent.emit({
deselectedRows: this.selectAllControl.value ? this.targetedRows : [],
selectionMode: this.determineSelectionMode(),
selectedRows: !this.selectAllControl.value ? this.targetedRows : []
});
}
);
)
}
}

private updateRowSelectForm(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface GoTimeFormat {
hours: string;
minutes: string;
ampm: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<div class="go-time--wrapper">
<div
class="go-time"
[ngClass]="{
'go-time--above': displayAbove,
'go-time--right': displayFromRight,
'go-time--append-to-content': appendToContent
}"
>
<div class="go-time-column">
<go-icon-button
buttonIcon="keyboard_arrow_up"
(click)="increaseHour()"
></go-icon-button>
<input
#hourInput
class="go-form__input hour-minute-input"
placeholder="HH"
[(ngModel)]="hour"
(keypress)="validateInput($event, '^([0-1]|[0][0-9]|[1][0-2])$')"
/>
<go-icon-button
buttonIcon="keyboard_arrow_down"
(click)="decreaseHour()"
></go-icon-button>
</div>
<!-- Colon -->
<div class="go-time-column colon-content">
<span>:</span>
</div>
<div class="go-time-column">
<go-icon-button
buttonIcon="keyboard_arrow_up"
(click)="increaseMinute()"
></go-icon-button>
<input
class="go-form__input hour-minute-input"
placeholder="MM"
[(ngModel)]="minute"
(keypress)="validateInput($event, '^([0-5]?[0-9])$')"
[ngClass]="{ 'go-form__input--error': inputMinuteError }"
/>
<go-icon-button
buttonIcon="keyboard_arrow_down"
(click)="decreaseMinute()"
></go-icon-button>
</div>
<!-- AM / PM Button -->
<div class="go-time-column go-time-format">
<go-button buttonVariant="secondary" (click)="changeFormat()">
{{ format ? 'AM' : 'PM' }}
</go-button>
</div>
<!-- Action Button Group -->
<div>
<ul class="go-button-group go-time-action">
<li class="go-button-group__item">
<go-button class="go-time-button" buttonVariant="secondary" (handleClick)="clear()">
Clear
</go-button>
</li>
<li class="go-button-group__item">
<go-button class="go-time-button" buttonVariant="primary" (handleClick)="apply()">
Apply
</go-button>
</li>
</ul>
</div>
</div>
</div>
Loading

0 comments on commit 20d017e

Please sign in to comment.