Skip to content

Commit

Permalink
Merge pull request #2 from platforma-open/vadim.piven/table_display_fix
Browse files Browse the repository at this point in the history
Table display fix
  • Loading branch information
vadimpiven authored Oct 9, 2024
2 parents 13194e3 + 7e7664a commit 27303a7
Show file tree
Hide file tree
Showing 19 changed files with 1,442 additions and 1,280 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @platforma-open/milaboratories.clonotype-browser

## 1.2.0

### Minor Changes

- Fixed table display

### Patch Changes

- Updated dependencies
- @platforma-open/milaboratories.clonotype-browser.workflow@1.2.0
- @platforma-open/milaboratories.clonotype-browser.model@1.2.0
- @platforma-open/milaboratories.clonotype-browser.ui@1.2.0

## 1.1.0

### Minor Changes
Expand Down
6 changes: 6 additions & 0 deletions model/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @platforma-open/milaboratories.clonotype-browser.model

## 1.2.0

### Minor Changes

- Fixed table display

## 1.1.0

### Minor Changes
Expand Down
5 changes: 2 additions & 3 deletions model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platforma-open/milaboratories.clonotype-browser.model",
"version": "1.1.0",
"version": "1.2.0",
"description": "Block model",
"type": "module",
"main": "dist/index.cjs",
Expand All @@ -10,8 +10,7 @@
"build": "tsup && vite build && block-tools build-model"
},
"dependencies": {
"@platforma-sdk/model": "catalog:",
"zod": "catalog:"
"@platforma-sdk/model": "catalog:"
},
"devDependencies": {
"@platforma-sdk/block-tools": "catalog:",
Expand Down
150 changes: 64 additions & 86 deletions model/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import {
AxisId,
AxisSpec,
BlockModel,
InferHrefType,
Option,
PColumn,
PObject,
PObjectSpec,
PlDataTableState,
Ref,
TreeNodeAccessor,
type InferOutputsType,
type InferHrefType,
type PlDataTableState,
type PColumnSpec,
type ValueType,
isPColumn,
isPColumnSpec,
type InferOutputsType
mapJoinEntry
} from '@platforma-sdk/model';

function getClonotypeColumnBlockId(spec: PObjectSpec): string | undefined {
if (!isPColumnSpec(spec)) return undefined;
export function getClonotypeColumnBlockId(spec: PColumnSpec): string | undefined {
if (
spec.axesSpec.length !== 3 ||
spec.axesSpec[0].name !== 'pl7.app/sampleId' ||
Expand All @@ -27,91 +21,75 @@ function getClonotypeColumnBlockId(spec: PObjectSpec): string | undefined {
return spec.axesSpec[2]?.domain?.['pl7.app/blockId'];
}

export type UiState = { inputBlockId?: string; tableState?: PlDataTableState };

export function axisMatch(query: AxisId, spec: AxisSpec): boolean {
if (spec.name !== query.name || spec.type !== query.type) return false;
if (query.domain === undefined) return true;
for (const [domainKey, domainValue] of Object.entries(query.domain))
if (spec.domain?.[domainKey] !== domainValue) return false;
return true;
}

export const platforma = BlockModel.create<{}, UiState>('Heavy')
export type UiState = {
inputBlockId?: string;
tableState: PlDataTableState;
};

export const model = BlockModel.create<{}, UiState>('Heavy')
.initialArgs({})

.sections([{ type: 'link', href: '/', label: 'Browser' }])
.output('inputOptions', (ctx) => {
const potentialBlocks = new Set<string>();
for (const e of ctx.resultPool.getSpecsFromResultPool().entries) {
const blockId = getClonotypeColumnBlockId(e.obj);
if (blockId === undefined) continue;
potentialBlocks.add(blockId);
}
const collection = ctx.resultPool.getSpecs();
if (collection === undefined || !collection.isComplete) return undefined;

const potentialBlocks = collection.entries
.map(({ obj }) => obj)
.filter(isPColumnSpec)
.map(getClonotypeColumnBlockId)
.filter((blockId): blockId is string => !!blockId)
.reduce((potentialBlocks, blockId) => {
potentialBlocks.add(blockId);
return potentialBlocks;
}, new Set<string>());

return [...potentialBlocks].map((blockId) => ({
blockId,
label: ctx.getBlockLabel(blockId)
}));
})

.output('sampleLabels', (ctx) => {
const blockId = ctx.uiState?.inputBlockId;
if (blockId === undefined) return undefined;

let sampleAxisId: AxisId | undefined = undefined;
for (const e of ctx.resultPool.getSpecsFromResultPool().entries) {
if (!isPColumnSpec(e.obj)) return undefined;
if (getClonotypeColumnBlockId(e.obj) !== blockId) continue;
sampleAxisId = e.obj.axesSpec[0];
break;
.output('pFrame', (ctx) => {
const collection = ctx.resultPool.getData();
if (collection === undefined || !collection.isComplete) return undefined;

const valueTypes = ['Int', 'Long', 'Float', 'Double', 'String', 'Bytes'] as ValueType[];
const columns = collection.entries
.map(({ obj }) => obj)
.filter(isPColumn)
.filter((column) => valueTypes.find((valueType) => valueType === column.spec.valueType));

try {
return ctx.createPFrame(columns);
} catch (err) {
return undefined;
}

if (sampleAxisId === undefined) return undefined;

const sampleLabelsObj = ctx.resultPool.getDataFromResultPool().entries.find((f) => {
const spec = f.obj.spec;
if (!isPColumnSpec(spec)) return false;
if (spec.name !== 'pl7.app/label' || spec.axesSpec.length !== 1) return false;
const axisSpec = spec.axesSpec[0];
return axisMatch(sampleAxisId, axisSpec);
});
if (sampleLabelsObj === undefined) return undefined;

return Object.entries(sampleLabelsObj.obj.data.getDataAsJson<Record<string, string>>()).map(
(e) => ({ text: e[1], value: JSON.parse(e[0])[0] as string })
);
})

.output('table', (ctx) => {
const blockId = ctx.uiState?.inputBlockId;
if (blockId === undefined) return undefined;

const columns = new Set<string>();
for (const e of ctx.resultPool.getSpecsFromResultPool().entries) {
if (getClonotypeColumnBlockId(e.obj) !== blockId) continue;
columns.add(`${e.ref.blockId}:${e.ref.name}`);
}

const data: PColumn<TreeNodeAccessor>[] = [];
for (const e of ctx.resultPool.getDataFromResultPool().entries) {
const refId = `${e.ref.blockId}:${e.ref.name}`;
if (!columns.delete(refId)) continue;
data.push(e.obj as PColumn<TreeNodeAccessor>);
.output('pTable', (ctx) => {
const join = ctx.uiState?.tableState.pTableParams?.join;
if (!join) return undefined;

const collection = ctx.resultPool.getData();
if (!collection || !collection.isComplete) return undefined;

const columns = collection.entries.map(({ obj }) => obj).filter(isPColumn);
if (columns.length === 0) return undefined;

try {
return ctx.createPTable({
src: mapJoinEntry(join, (idAndSpec) => {
const column = columns.find((column) => column.id === idAndSpec.columnId);
if (!column) throw Error(`column '${column}' not ready`);
return column;
}),
filters: ctx.uiState.tableState.pTableParams?.filters ?? [],
sorting: ctx.uiState.tableState.pTableParams?.sorting ?? []
});
} catch (err) {
return undefined;
}
if (columns.size !== 0) return undefined;
return ctx.createPTable({
src: { type: 'full', entries: data.map((o) => ({ type: 'column', column: o })) },
filters: ctx.uiState?.tableState?.pTableParams?.filters ?? [],
sorting: ctx.uiState?.tableState?.pTableParams?.sorting ?? []
});
})

.sections((ctx) => {
return [{ type: 'link', href: '/', label: 'Browser' }];
})

.done();

export type BlockOutputs = InferOutputsType<typeof platforma>;
export type Href = InferHrefType<typeof platforma>;
export type BlockOutputs = InferOutputsType<typeof model>;

export type NavigationHref = InferHrefType<typeof model>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platforma-open/milaboratories.clonotype-browser",
"version": "1.1.0",
"version": "1.2.0",
"scripts": {
"pretty": "prettier --write \"./**/*.{js,jsx,mjs,cjs,ts,tsx,json,vue}\"",
"build": "rm -rf ./block-pack && block-tools pack",
Expand Down
Loading

0 comments on commit 27303a7

Please sign in to comment.