refactor(keyword-highlighting): remove duplication after rebase
This commit is contained in:
@@ -19,6 +19,9 @@ import {
|
||||
SortDirection,
|
||||
} from '@angular/material/sort';
|
||||
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { SkTextDirective } from '../../../custom-directives/sk-text.directive';
|
||||
export interface BaseColumn<T> {
|
||||
@@ -43,7 +46,15 @@ export type GenericColumn<T> = AccessorColumn<T> | DisplayColumn<T>;
|
||||
@Component({
|
||||
selector: 'app-data-table',
|
||||
standalone: true,
|
||||
imports: [MatTableModule, NgTemplateOutlet, MatSortModule, SkTextDirective],
|
||||
imports: [
|
||||
MatTableModule,
|
||||
NgTemplateOutlet,
|
||||
MatSortModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
MatTooltipModule,
|
||||
SkTextDirective,
|
||||
],
|
||||
templateUrl: './data-table.component.html',
|
||||
styleUrl: './data-table.component.scss',
|
||||
})
|
||||
@@ -54,6 +65,7 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
|
||||
detailTemplate = input<TemplateRef<any> | null>(null);
|
||||
expandedElement = signal<T | null>(null);
|
||||
canExpand = input<((row: T) => boolean) | null>(null);
|
||||
|
||||
maxHeight = input<string | null>(null);
|
||||
containerOverflow = computed(() => (this.maxHeight() ? 'auto' : 'visible'));
|
||||
@@ -78,7 +90,12 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
|
||||
handleSortChange = output<Sort>();
|
||||
|
||||
displayedColumns = computed(() => this.columns().map((col) => col.id));
|
||||
readonly expandColumnId = 'expand';
|
||||
|
||||
displayedColumns = computed(() => {
|
||||
const ids = this.columns().map((col) => col.id);
|
||||
return this.detailTemplate() ? [this.expandColumnId, ...ids] : ids;
|
||||
});
|
||||
dataSource = new MatTableDataSource<T>([]);
|
||||
|
||||
sort = viewChild.required(MatSort);
|
||||
@@ -160,8 +177,13 @@ export class DataTableComponent<T> implements AfterViewInit {
|
||||
}
|
||||
}
|
||||
|
||||
isExpandable(row: T): boolean {
|
||||
if (!this.detailTemplate()) return false;
|
||||
return this.canExpand()?.(row) ?? true;
|
||||
}
|
||||
|
||||
toggleRow(row: T): void {
|
||||
if (!this.detailTemplate()) return;
|
||||
if (!this.isExpandable(row)) return;
|
||||
this.expandedElement.update((current) => (current === row ? null : row));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user