-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: feat(table): enhancements for table action system #182
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c8c17c
feat(table): adds support for handling table actions that are loaded …
schoenj d2107f1
feat(table): adds support for svg icons in table actions
schoenj 7836f62
refactor(table): unifies table action icon
schoenj e0e41a7
feat(table): adds support for routerLink for table actions
schoenj 45edb90
test(table): adds test for icon/svgIcon support for table actions
schoenj c3783a5
test(table): tests for routerlink table actions
schoenj ddbef58
refactor(table): refactores table action caching and removes obsolete…
schoenj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { IPsTableAction, PsTableAction } from '../../src/models'; | ||
|
||
export abstract class PsTableActionStoreBase<T> { | ||
abstract get(declaration: IPsTableAction<T>): PsTableAction<T>; | ||
} | ||
|
||
export class PsTableActionStore<T> extends PsTableActionStoreBase<T> { | ||
private readonly _store = new WeakMap<IPsTableAction<T>, PsTableAction<T>>(); | ||
|
||
/** | ||
* Gets the existing PsTableAction object by the declaration (IPsTableAction<T>) from the store or creates a new one. | ||
* | ||
* Because actions can have observables as children, we cannot create for each declaration the coresponding PsTableAction<T> at the beginning. | ||
* This forces us to create the PsTableAction<T> dynamicly. But we do not want to execute the same observables multiple times, so we cache them. | ||
* Otherwise the observable would be executed for each row. | ||
* | ||
* @param declaration Action declaration information | ||
* @returns Existing or new PsTableAction | ||
*/ | ||
public get(declaration: IPsTableAction<T>): PsTableAction<T> { | ||
if (!this._store.has(declaration)) { | ||
const action = new PsTableAction<T>(declaration, this); | ||
this._store.set(declaration, action); | ||
} | ||
|
||
return this._store.get(declaration); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,40 @@ | |
<mat-menu #menu> | ||
<ng-template matMenuContent> | ||
<ng-container *ngFor="let action of actions"> | ||
<button | ||
*ngIf="!action.children; else branch" | ||
mat-menu-item | ||
[disabled]="action.isDisabledFn && action.isDisabledFn(items)" | ||
(click)="action.actionFn(items)" | ||
> | ||
<mat-icon [style.color]="action.iconColor">{{ action.icon }}</mat-icon> | ||
{{ action.label }} | ||
</button> | ||
<ng-container *ngIf="action.isLoading || !action.hasChildren; else branch"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the changes here could have a substantial performance impact. all that s ifs and templates are the reason for the current performance problems. with this we have even more of them. |
||
<a | ||
*ngIf="action.routerLink && scope === psTableActionScopes.row; else actionButton" | ||
mat-menu-item | ||
[disabled]="action.isLoading || (action.isDisabledFn && action.isDisabledFn(items))" | ||
[routerLink]="action.routerLink(items[0])" | ||
[queryParams]="(action.routerLinkQueryParams && action.routerLinkQueryParams(items[0])) || undefined" | ||
> | ||
<ng-container [ngTemplateOutlet]="actionIcon" [ngTemplateOutletContext]="{ $implicit: action }"></ng-container> | ||
{{ action.label }} | ||
</a> | ||
<ng-template #actionButton> | ||
<button | ||
*ngIf="action.isLoading || !action.hasChildren; else branch" | ||
mat-menu-item | ||
[disabled]="action.isLoading || (action.isDisabledFn && action.isDisabledFn(items))" | ||
(click)="action.actionFn && action.actionFn(items)" | ||
> | ||
<ng-container [ngTemplateOutlet]="actionIcon" [ngTemplateOutletContext]="{ $implicit: action }"></ng-container> | ||
{{ action.label }} | ||
</button> | ||
</ng-template> | ||
</ng-container> | ||
<ng-template #branch> | ||
<button mat-menu-item [matMenuTriggerFor]="innerPanel.menu"> | ||
<mat-icon [style.color]="action.iconColor">{{ action.icon }}</mat-icon> | ||
<ng-container [ngTemplateOutlet]="actionIcon" [ngTemplateOutletContext]="{ $implicit: action }"></ng-container> | ||
{{ action.label }} | ||
</button> | ||
<ps-table-actions #innerPanel [actions]="action.children | psTableActionsToRender: items" [items]="items"></ps-table-actions> | ||
<ps-table-actions | ||
#innerPanel | ||
[actions]="action.children$ | async | psTableActionsToRender: items" | ||
[items]="items" | ||
[scope]="scope" | ||
></ps-table-actions> | ||
</ng-template> | ||
</ng-container> | ||
<!-- ng-content is deprecated here, as it doesn't work correctly, if it contains a mat-menu-item with a child met-menu --> | ||
|
@@ -34,3 +53,11 @@ | |
</button> | ||
</ng-template> | ||
</mat-menu> | ||
|
||
<ng-template #actionIcon let-action> | ||
<mat-icon *ngIf="!action.isLoading && !action.isSvgIcon" [style.color]="action.iconColor">{{ action.icon }}</mat-icon> | ||
<mat-icon *ngIf="!action.isLoading && action.isSvgIcon" [style.color]="action.iconColor" [svgIcon]="action.icon"></mat-icon> | ||
<mat-icon *ngIf="action.isLoading"> | ||
<mat-spinner mode="indeterminate" diameter="24"></mat-spinner> | ||
</mat-icon> | ||
</ng-template> |
37 changes: 33 additions & 4 deletions
37
projects/components/table/src/subcomponents/table-actions.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,51 @@ | ||
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, Output, ViewChild } from '@angular/core'; | ||
import { MatMenu } from '@angular/material/menu'; | ||
import { IPsTableIntlTexts } from '@prosoft/components/core'; | ||
import { IPsTableAction } from '../models'; | ||
import { merge, Subscription } from 'rxjs'; | ||
import { tap } from 'rxjs/operators'; | ||
|
||
import { PsTableAction, PsTableActionScope } from '../models'; | ||
|
||
@Component({ | ||
selector: 'ps-table-actions', | ||
templateUrl: './table-actions.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class PsTableActionsComponent { | ||
@Input() public actions: IPsTableAction<unknown>[]; | ||
export class PsTableActionsComponent implements OnDestroy { | ||
@Input() | ||
public get actions(): PsTableAction<unknown>[] { | ||
return this._actions; | ||
} | ||
public set actions(value: PsTableAction<unknown>[]) { | ||
this._actions = value || []; | ||
this._subscription?.unsubscribe(); | ||
const observables = this.actions?.filter((x) => x.isObservable).map((x) => x.children$); | ||
|
||
if (observables) { | ||
this._subscription = merge(observables) | ||
.pipe(tap(() => this.cd.markForCheck())) | ||
.subscribe(); | ||
} | ||
} | ||
private _actions: PsTableAction<unknown>[]; | ||
@Input() public items: unknown[]; | ||
@Input() public refreshable: boolean; | ||
@Input() public settingsEnabled: boolean; | ||
@Input() public intl: IPsTableIntlTexts; | ||
@Input() public scope: PsTableActionScope; | ||
|
||
public psTableActionScopes = PsTableActionScope; | ||
|
||
@Output() public refreshData = new EventEmitter<void>(); | ||
@Output() public showSettings = new EventEmitter<void>(); | ||
|
||
@ViewChild('menu', { static: true }) menu: MatMenu; | ||
|
||
private _subscription: Subscription = Subscription.EMPTY; | ||
|
||
constructor(private cd: ChangeDetectorRef) {} | ||
|
||
public ngOnDestroy(): void { | ||
this._subscription?.unsubscribe(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a fan of this, this increases complexity and code size quite a bit