From 6cf7c43c80474e2fc66fb96fd44bbf28fcd1b2f1 Mon Sep 17 00:00:00 2001 From: Thomas Schachinger Date: Thu, 9 Nov 2023 10:23:49 +0100 Subject: [PATCH] extended ISingleScoreResult to except column desc directly --- src/ranking/overrides/DatavisynTaggle.tsx | 9 ++++++--- src/ranking/score/interfaces.ts | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/ranking/overrides/DatavisynTaggle.tsx b/src/ranking/overrides/DatavisynTaggle.tsx index dd7107d07..c9710b9eb 100644 --- a/src/ranking/overrides/DatavisynTaggle.tsx +++ b/src/ranking/overrides/DatavisynTaggle.tsx @@ -43,12 +43,15 @@ export class DatavisynTaggle extends throw new Error('No ranking found'); } - return castArray(desc).map(({ data, builder }) => { - const colDesc = builder.build(data.map((d) => ({ [(builder as any).desc.column]: d }))) as IScoreColumnDesc; + return castArray(desc).map((score) => { + const colDesc = + 'builder' in score + ? (score.builder.build(score.data.map((d) => ({ [(score.builder as any).desc.column]: d }))) as IScoreColumnDesc) + : (score.desc as IScoreColumnDesc); // Patch the accessor and add the scoreData directly in the column + colDesc.scoreData = score.data; colDesc.accessor = (row, descRef) => descRef.scoreData[row.i]; - colDesc.scoreData = data; const col = this.data.create(colDesc); diff --git a/src/ranking/score/interfaces.ts b/src/ranking/score/interfaces.ts index efec1e565..547112d8f 100644 --- a/src/ranking/score/interfaces.ts +++ b/src/ranking/score/interfaces.ts @@ -3,16 +3,25 @@ import { ColumnBuilder, IValueColumnDesc, IDataRow } from 'lineupjs'; /** * A single score result */ -export interface ISingleScoreResult { +export type ISingleScoreResult = { /** * The data to be used for the score column */ data: unknown[]; - /** - * The lineup builder object to be used for the score column - */ - builder: ColumnBuilder>; -} +} & ( + | { + /** + * The lineup builder object to be used for the score column + */ + builder: ColumnBuilder>; + } + | { + /** + * The lineup column desc to be used for the score column + */ + desc: IValueColumnDesc; + } +); export type IScoreResult = ISingleScoreResult | ISingleScoreResult[];