MCPcopy Index your code
hub / github.com/tinyplex/tinybase / writeGroupRow

Function writeGroupRow

src/queries/index.ts:551–607  ·  view source on GitHub ↗
(
              leaf: [IdMap2<Cell>, IdSet, Id, Row],
              changedGroupedSelectedCells: IdMap<[Cell]>,
              selectedRowId: Id,
              forceRemove?: 1,
            )

Source from the content-addressed store, hash-verified

549 const tree = mapNew<Cell, any>();
550
551 const writeGroupRow = (
552 leaf: [IdMap2<Cell>, IdSet, Id, Row],
553 changedGroupedSelectedCells: IdMap<[Cell]>,
554 selectedRowId: Id,
555 forceRemove?: 1,
556 ) =>
557 ifNotUndefined(
558 leaf,
559 ([selectedCells, selectedRowIds, groupRowId, groupRow]) => {
560 mapForEach(
561 changedGroupedSelectedCells,
562 (selectedCellId, [newCell]) => {
563 const selectedCell = mapEnsure(
564 selectedCells,
565 selectedCellId,
566 mapNew,
567 );
568 const oldLeafCell = mapGet(selectedCell, selectedRowId);
569 const newLeafCell = forceRemove ? undefined : newCell;
570 if (oldLeafCell !== newLeafCell) {
571 const oldNewSet = setNew([[oldLeafCell, newLeafCell]]);
572 const oldLength = collSize(selectedCell);
573 mapSet(selectedCell, selectedRowId, newLeafCell);
574 collForEach(
575 mapGet(groupedSelectedCellIds, selectedCellId),
576 ([groupedCellId, aggregators]) => {
577 const aggregateValue = getAggregateValue(
578 groupRow[groupedCellId],
579 oldLength,
580 selectedCell as IdMap<Cell>,
581 oldNewSet as Set<ChangedCell>,
582 aggregators,
583 );
584 groupRow[groupedCellId] = (
585 isUndefined(getCellOrValueType(aggregateValue))
586 ? undefined
587 : aggregateValue
588 ) as Cell;
589 },
590 );
591 }
592 },
593 );
594 if (
595 collIsEmpty(selectedRowIds) ||
596 !arrayEvery(havings, (having) =>
597 having((cellId) => groupRow[cellId] as any),
598 )
599 ) {
600 resultStore.delRow(queryId, groupRowId);
601 } else if (isUndefined(groupRowId)) {
602 leaf[2] = resultStore.addRow(queryId, groupRow) as Id;
603 } else {
604 resultStore.setRow(queryId, groupRowId, groupRow);
605 }
606 },
607 );
608

Callers 1

setQueryDefinitionImplFunction · 0.70

Calls 15

mapForEachFunction · 0.90
mapEnsureFunction · 0.90
mapGetFunction · 0.90
setNewFunction · 0.90
collSizeFunction · 0.90
mapSetFunction · 0.90
collForEachFunction · 0.90
getAggregateValueFunction · 0.90
isUndefinedFunction · 0.90
getCellOrValueTypeFunction · 0.90
collIsEmptyFunction · 0.90
arrayEveryFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…