Skip to content

Commit

Permalink
Extended ISingleScoreResult to except column desc directly (#113)
Browse files Browse the repository at this point in the history
### Developer Checklist (Definition of Done)

**Issue**

- [x] All acceptance criteria from the issue are met
- [x] Tested in latest Chrome/Firefox

**UI/UX/Vis**

- [ ] Requires UI/UX/Vis review
  - [ ] Reviewer(s) are notified (_tag assignees_)
  - [ ] Review has occurred (_link to notes_)
  - [ ] Feedback is included in this PR
  - [ ] Reviewer(s) approve of concept and design

**Code**

- [x] Branch is up-to-date with the branch to be merged with, i.e.,
develop
- [x] Code is cleaned up and formatted
- [ ] Unit tests are written (frontend/backend if applicable)
- [ ] Integration tests are written (if applicable)

**PR**

- [x] Descriptive title for this pull request is provided (will be used
for release notes later)
- [x] Reviewer and assignees are defined
- [x] Add type label (e.g., *bug*, *feature*) to this pull request
- [x] Add release label (e.g., `release: minor`) to this PR following
[semver](https://semver.org/)
- [x] The PR is connected to the corresponding issue (via `Closes #...`)
- [x] [Summary of changes](#summary-of-changes) is written


### Summary of changes

- Allows directly passing a desc instead of a builder for scores. This
is useful if you already have a predefined desc that you want to use.

### Screenshots


### Additional notes for the reviewer(s)

-  
Thanks for creating this pull request 🤗
  • Loading branch information
puehringer authored Nov 10, 2023
2 parents 9b4d00a + 6cf7c43 commit 35bab5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/ranking/overrides/DatavisynTaggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export class DatavisynTaggle<T extends DataProvider = LocalDataProvider> 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<unknown>;
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<unknown>)
: (score.desc as IScoreColumnDesc<unknown>);

// 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);

Expand Down
21 changes: 15 additions & 6 deletions src/ranking/score/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IValueColumnDesc<unknown>>;
}
} & (
| {
/**
* The lineup builder object to be used for the score column
*/
builder: ColumnBuilder<IValueColumnDesc<unknown>>;
}
| {
/**
* The lineup column desc to be used for the score column
*/
desc: IValueColumnDesc<unknown>;
}
);

export type IScoreResult = ISingleScoreResult | ISingleScoreResult[];

Expand Down

0 comments on commit 35bab5e

Please sign in to comment.