From dd435933cc5bcfd082c72fbdc1351eb9d649de20 Mon Sep 17 00:00:00 2001 From: Faust1 Date: Wed, 20 Mar 2024 16:29:28 +0100 Subject: [PATCH] fix: table with less data --- .../components/table.component.ts | 36 +++++++----- .../partitions/components/table.component.ts | 36 +++++++----- src/app/results/components/table.component.ts | 32 +++++----- .../sessions/components/table.component.ts | 58 +++++++++---------- src/app/tasks/components/table.component.ts | 34 ++++++----- 5 files changed, 108 insertions(+), 88 deletions(-) diff --git a/src/app/applications/components/table.component.ts b/src/app/applications/components/table.component.ts index 1fa10ca30..bf73b37f9 100644 --- a/src/app/applications/components/table.component.ts +++ b/src/app/applications/components/table.component.ts @@ -131,21 +131,27 @@ export class ApplicationsTableComponent implements OnInit, AfterViewInit { } @Input({ required: true }) set data(entries: ApplicationRaw[]) { - entries.forEach((entry, index) => { - const application = this._data[index]; - if (application && application.raw.name === entry.name && application.raw.version === entry.version) { - this._data[index].value$?.next(entry); - } else { - const lineData: ApplicationData = { - raw: entry, - queryTasksParams: this.createTasksByStatusQueryParams(entry.name, entry.version), - filters: this.countTasksByStatusFilters(entry.name, entry.version), - value$: new Subject() - }; - this._data.splice(index, 1, lineData); - } - }); - this.dataSource.data = this._data; + if (entries.length !== 0) { + this._data = this.data.filter(d => entries.find(entry => entry.name === d.raw.namespace && entry.version === d.raw.version)); + entries.forEach((entry, index) => { + const application = this._data[index]; + if (application && application.raw.name === entry.name && application.raw.version === entry.version) { + this._data[index].value$?.next(entry); + } else { + const lineData: ApplicationData = { + raw: entry, + queryTasksParams: this.createTasksByStatusQueryParams(entry.name, entry.version), + filters: this.countTasksByStatusFilters(entry.name, entry.version), + value$: new Subject() + }; + this._data.splice(index, 1, lineData); + } + }); + this.dataSource.data = this._data; + } else { + this._data = []; + this.dataSource.data = this._data; + } } @Output() optionsChange = new EventEmitter(); diff --git a/src/app/partitions/components/table.component.ts b/src/app/partitions/components/table.component.ts index e21c1c885..08e232d43 100644 --- a/src/app/partitions/components/table.component.ts +++ b/src/app/partitions/components/table.component.ts @@ -83,21 +83,27 @@ export class PartitionsTableComponent implements OnInit, AfterViewInit { } @Input({ required: true }) set data(entries: PartitionRaw[]) { - entries.forEach((entry, index) => { - const partition = this._data[index]; - if (partition && partition.raw.id === entry.id) { - this._data[index].value$?.next(entry); - } else { - const lineData: PartitionData = { - raw: entry, - queryTasksParams: this.createTasksByStatusQueryParams(entry.id), - filters: this.countTasksByStatusFilters(entry.id), - value$: new Subject() - }; - this._data.splice(index, 1, lineData); - } - }); - this.dataSource.data = this._data; + if (entries.length !== 0) { + this._data = this.data.filter(d => entries.find(entry => entry.id === d.raw.id)); + entries.forEach((entry, index) => { + const partition = this._data[index]; + if (partition && partition.raw.id === entry.id) { + this._data[index].value$?.next(entry); + } else { + const lineData: PartitionData = { + raw: entry, + queryTasksParams: this.createTasksByStatusQueryParams(entry.id), + filters: this.countTasksByStatusFilters(entry.id), + value$: new Subject() + }; + this._data.splice(index, 1, lineData); + } + }); + this.dataSource.data = this._data; + } else { + this._data = []; + this.dataSource.data = this._data; + } } @Output() optionsChange = new EventEmitter(); diff --git a/src/app/results/components/table.component.ts b/src/app/results/components/table.component.ts index 865c0aa1d..b15bb7a90 100644 --- a/src/app/results/components/table.component.ts +++ b/src/app/results/components/table.component.ts @@ -71,19 +71,25 @@ export class ResultsTableComponent implements AfterViewInit { private _data: ResultData[] = []; @Input({required: true}) set data(entries: ResultRaw[]) { - entries.forEach((entry, index) => { - const result = this._data[index]; - if (result && result.raw.resultId === entry.resultId) { - this._data[index].value$?.next(entry); - } else { - const lineData: ResultData = { - raw: entry, - value$: new Subject(), - }; - this._data.splice(index, 1, lineData); - } - }); - this.dataSource.data = this._data; + if (entries.length !== 0) { + this._data = this.data.filter(d => entries.find(entry => entry.resultId === d.raw.resultId)); + entries.forEach((entry, index) => { + const result = this._data[index]; + if (result && result.raw.resultId === entry.resultId) { + this._data[index].value$?.next(entry); + } else { + const lineData: ResultData = { + raw: entry, + value$: new Subject(), + }; + this._data.splice(index, 1, lineData); + } + }); + this.dataSource.data = this._data; + } else { + this._data = []; + this.dataSource.data = this._data; + } } get data(): ResultData[] { diff --git a/src/app/sessions/components/table.component.ts b/src/app/sessions/components/table.component.ts index a17bd7b73..3767e8212 100644 --- a/src/app/sessions/components/table.component.ts +++ b/src/app/sessions/components/table.component.ts @@ -187,38 +187,34 @@ export class ApplicationsTableComponent implements OnInit, AfterViewInit { }); this.data$.subscribe(entries => { - entries.forEach((entry, index) => { - const session = this._data[index]; - if (session && session.raw.sessionId === entry.sessionId) { - session.raw = entry; - this._data.splice(index, 1, session); - this._data[index].value$.next(entry); - } else { - const queryParams = new Map, Params>(); - queryParams.set('sessionId', { '0-root-1-0': entry.sessionId }); - const session: SessionData = { - raw: entry, - queryParams, - queryTasksParams: this.createTasksByStatusQueryParams(entry.sessionId), - resultsQueryParams: {...this.createResultsQueryParams(entry.sessionId)}, - filters: this.countTasksByStatusFilters(entry.sessionId), - value$: new Subject(), - }; - this._data.splice(index, 1, session); - } - }); - this.dataSource.data = this._data; - }); - } - - hasDifference(first: SessionRaw, second: SessionRaw): boolean{ - const keys = Object.keys(first); - for(const key of keys) { - if (JSON.stringify(first[key as keyof SessionRaw]) !== JSON.stringify(second[key as keyof SessionRaw])) { - return true; + if (entries.length !== 0) { + this._data = this.data.filter(d => entries.find(entry => entry.sessionId === d.raw.sessionId)); + entries.forEach((entry, index) => { + const session = this._data[index]; + if (session && session.raw.sessionId === entry.sessionId) { + session.raw = entry; + this._data.splice(index, 1, session); + this._data[index].value$.next(entry); + } else { + const queryParams = new Map, Params>(); + queryParams.set('sessionId', { '0-root-1-0': entry.sessionId }); + const session: SessionData = { + raw: entry, + queryParams, + queryTasksParams: this.createTasksByStatusQueryParams(entry.sessionId), + resultsQueryParams: {...this.createResultsQueryParams(entry.sessionId)}, + filters: this.countTasksByStatusFilters(entry.sessionId), + value$: new Subject(), + }; + this._data.splice(index, 1, session); + } + }); + this.dataSource.data = this._data; + } else { + this._data = []; + this.dataSource.data = this._data; } - } - return false; + }); } getIcon(name: string): string { diff --git a/src/app/tasks/components/table.component.ts b/src/app/tasks/components/table.component.ts index 61df19090..f9dc5dbd2 100644 --- a/src/app/tasks/components/table.component.ts +++ b/src/app/tasks/components/table.component.ts @@ -98,20 +98,26 @@ export class TasksTableComponent implements AfterViewInit { } @Input({required: true}) set data(entries: TaskSummary[]) { - entries.forEach((entry, index) => { - const task = this._data[index]; - if (task && task.raw.id === entry.id) { - this._data[index].value$?.next(entry); - } else { - const lineData: TaskData = { - raw: entry, - resultsQueryParams: this.createResultsQueryParams(entry.id), - value$: new Subject(), - }; - this._data.splice(index, 1, lineData); - } - }); - this.dataSource.data = this._data; + if (entries.length !== 0) { + this._data = this.data.filter(d => entries.find(entry => entry.id === d.raw.id)); + entries.forEach((entry, index) => { + const task = this._data[index]; + if (task && task.raw.id === entry.id) { + this._data[index].value$?.next(entry); + } else { + const lineData: TaskData = { + raw: entry, + resultsQueryParams: this.createResultsQueryParams(entry.id), + value$: new Subject(), + }; + this._data.splice(index, 1, lineData); + } + }); + this.dataSource.data = this._data; + } else { + this._data = []; + this.dataSource.data = this._data; + } } get columnKeys() {