Skip to content
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

refactor: update components to enforce required inputs #357

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/common/breadcrumb/breadcrumb.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Breadcrumb, BreadcrumbService } from './breadcrumb.service';
imports: [NgFor, NgIf, RouterLink]
})
export class BreadcrumbComponent {
@Input()
@Input({ required: true })
set homeBreadcrumb(hb: Breadcrumb) {
this._homeBreadcrumb = hb;
this.homeBreadcrumbChanged$.next(hb);
Expand Down
18 changes: 13 additions & 5 deletions src/app/common/loading-overlay/loading-overlay.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ import { NotificationComponent } from '../notification/notification.component';
imports: [NgIf, NotificationComponent, LoadingSpinnerComponent]
})
export class LoadingOverlayComponent {
@Input() message = 'Loading...';
@Input() isLoading = false;
@Input() isError = false;
@Input() errorMessage = '';
@Input()
message = 'Loading...';

@Output() readonly retry = new EventEmitter();
@Input()
isLoading = false;

@Input()
isError = false;

@Input()
errorMessage = '';

@Output()
readonly retry = new EventEmitter();

handleRetry() {
this.retry.emit(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ import { NgSelectModule } from '@ng-select/ng-select';
imports: [NgSelectModule, FormsModule]
})
export class MultiSelectInputComponent implements ControlValueAccessor {
@Input() placeholder = '';
@ViewChild(NgModel) model?: NgModel;

@Input() readonly = false;
@Input()
placeholder = '';

@ViewChild(NgModel) model?: NgModel;
@Input()
readonly = false;

autocompleteOpen = false;

Expand Down
17 changes: 12 additions & 5 deletions src/app/common/notification/notification.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import { Component, ContentChild, Input, TemplateRef } from '@angular/core';
imports: [NgIf, NgTemplateOutlet]
})
export class NotificationComponent {
@Input() notificationType: 'info' | 'success' | 'warning' | 'danger' = 'info';
@Input() message = '';
@Input() showActions = false;
@Input() small = false;

@ContentChild('notificationActions', { static: true }) actionTemplate: TemplateRef<any> | null =
null;

@Input()
notificationType: 'info' | 'success' | 'warning' | 'danger' = 'info';

@Input()
message = '';

@Input()
showActions = false;

@Input()
small = false;
}
11 changes: 8 additions & 3 deletions src/app/common/search-input/search-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ import { debounceTime } from 'rxjs/operators';
imports: [FormsModule, NgIf]
})
export class SearchInputComponent {
@Input() placeholder = 'Search...';
@Output() readonly applySearch: EventEmitter<string> = new EventEmitter();
@Input() search = '';
@Input()
placeholder = 'Search...';

@Input()
search = '';

@Output()
readonly applySearch: EventEmitter<string> = new EventEmitter();

/**
* If true, searches will be made on `input` events, otherwise searches will be made on `keyup` events
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/table/asy-table-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class AsyTableDataSource<T> extends DataSource<T> {

constructor(
private loadPageFunc: LoadPageFunction<T>,
public storageKey: string | null = null,
public storageKey?: string,
initialSort: SortChange = {} as SortChange,
initialSearch = '',
initialFilter: any = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ColumnChooserComponent implements OnInit {
_defaultColumns: ColumnDefinition[] = [];

@Input()
storageKey: string | null;
storageKey?: string;

@Input()
sortingDisabled = false;
Expand Down
2 changes: 1 addition & 1 deletion src/app/common/table/filter/asy-filter.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AsyFilterDirective {

filters = new Map<string, any>();

@Input()
@Input({ required: true })
dataSource: AsyTableDataSource<any>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ export class AsyHeaderListFilterComponent extends AsyAbstractHeaderFilterCompone

matchAll = false;

@Input() showSearch = false;
@Input()
showSearch = false;

@Input() showMatch = false;
@Input()
showMatch = false;

@Input()
buildFilterFunc?: BuildFilterFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
})
export class AsySkeletonRowsComponent {
_rows: Array<number> = [];
@Input()

@Input({ required: true })
set rows(numRows: number) {
this._rows = Array(numRows).fill(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ export class AsySortHeaderComponent implements AsySortable, OnDestroy, OnInit {
* ID of this sort header. If used within the context of a CdkColumnDef, this will default to
* the column's name.
*/
@Input('asy-sort-header') id: string;
@Input('asy-sort-header')
id: string;

/** Overrides the sort start value of the containing AsySort for this AsySortable. */
@Input() start: SortDir;
@Input()
start: SortDir;

@Input() sortable = true;
@Input()
sortable = true;

private destroyRef = inject(DestroyRef);
private changeDetectorRef = inject(ChangeDetectorRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class ListCacheEntriesComponent implements OnDestroy, OnInit {

dataSource = new AsyTableDataSource<CacheEntry>(
(request) => this.loadData(request.pagingOptions, request.search, request.filter),
null,
undefined,
{
sortField: 'ts',
sortDir: SortDirection.desc
Expand Down
10 changes: 7 additions & 3 deletions src/app/core/audit/audit-object.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { AuditObjectTypes } from './audit.classes';
imports: [JsonPipe]
})
export class DefaultAuditObjectComponent {
@Input() auditObject: any = {};
@Input()
auditObject: any = {};
}
AuditObjectTypes.registerType('default', DefaultAuditObjectComponent);

Expand Down Expand Up @@ -57,8 +58,11 @@ AuditObjectTypes.registerType('export', ExportAuditObjectComponent);
export class AuditObjectComponent implements OnInit {
@ViewChild('content', { read: ViewContainerRef, static: true }) content?: ViewContainerRef;

@Input() auditObject: any = {};
@Input() auditType = '';
@Input()
auditObject: any = {};

@Input()
auditType = '';

ngOnInit() {
if (!AuditObjectTypes.objects.hasOwnProperty(this.auditType)) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/auth/directives/has-every-role.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class HasEveryRoleDirective implements OnInit {
private sessionService = inject(SessionService);
private authorizationService = inject(AuthorizationService);

@Input()
@Input({ required: true })
set hasEveryRole(roles: Array<string | Role>) {
this.roles = roles;
this.updateNgIf();
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/auth/directives/has-role.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class HasRoleDirective implements OnInit {
private sessionService = inject(SessionService);
private authorizationService = inject(AuthorizationService);

@Input()
@Input({ required: true })
set hasRole(role: string | Role) {
this.role = role;
this.updateNgIf();
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/auth/directives/has-some-roles.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class HasSomeRolesDirective implements OnInit {
private sessionService = inject(SessionService);
private authorizationService = inject(AuthorizationService);

@Input()
@Input({ required: true })
set hasSomeRoles(roles: Array<string | Role>) {
this.roles = roles;
this.updateNgIf();
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/help/help-topic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class HelpTopicComponent {

helpTopics = getHelpTopicsMap();

@Input()
@Input({ required: true })
set key(key: string) {
if (this.componentRef) {
this.componentRef.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class HasSomeTeamRolesDirective implements OnInit {
private authorizationService = inject(AuthorizationService);
private teamAuthorizationService = inject(TeamAuthorizationService);

@Input()
@Input({ required: true })
set hasSomeTeamRoles(team: Pick<Team, '_id'>) {
this.team = team;
this.updateNgIf();
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/teams/directives/has-team-role.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class HasTeamRoleDirective implements OnInit {
private authorizationService = inject(AuthorizationService);
private teamAuthorizationService = inject(TeamAuthorizationService);

@Input()
@Input({ required: true })
set hasTeamRole(team: Pick<Team, '_id'>) {
this.team = team;
this.updateNgIf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ListTeamMembersComponent implements OnChanges, OnDestroy, OnInit {
@ViewChild(AsyFilterDirective)
filter: AsyFilterDirective;

@Input()
@Input({ required: true })
team!: Team;

isUserAdmin = false;
Expand All @@ -111,7 +111,7 @@ export class ListTeamMembersComponent implements OnChanges, OnDestroy, OnInit {

dataSource = new AsyTableDataSource<TeamMember>(
(request) => this.loadData(request.pagingOptions, request.search, request.filter),
null,
undefined,
{
sortField: 'name',
sortDir: SortDirection.asc
Expand All @@ -127,9 +127,6 @@ export class ListTeamMembersComponent implements OnChanges, OnDestroy, OnInit {
private alertService = inject(SystemAlertService);

ngOnInit() {
if (!this.team) {
throw new TypeError(`'Team' is required`);
}
this.alertService.clearAllAlerts();

this.sessionService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import { TeamsService } from '../../teams.service';
]
})
export class GeneralDetailsComponent implements OnInit {
@Input()
team?: Team;
@Input({ required: true })
team!: Team;

_team: Team;

Expand Down
4 changes: 2 additions & 2 deletions src/app/core/teams/view-team/view-team.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import { TeamsService } from '../teams.service';
export class ViewTeamComponent {
topics = getTeamTopics();

@Input()
team?: Team;
@Input({ required: true })
team!: Team;

private destroyRef = inject(DestroyRef);
private dialogService = inject(DialogService);
Expand Down
Loading