(sourceItems: T[], groupKey: string)
| 149 | |
| 150 | // Start a new column whenever the row key wraps |
| 151 | function buildInferredColumns (sourceItems: T[], groupKey: string) { |
| 152 | const columns: PivotColumn<C>[] = [] |
| 153 | const groupItems: C[] = [] |
| 154 | |
| 155 | let currentCells: (C | null)[] = Array(rowKeys.length).fill(null) |
| 156 | let currentItems: C[] = [] |
| 157 | let columnIndex = 0 |
| 158 | let lastRowIndex = -1 |
| 159 | |
| 160 | for (const item of sourceItems) { |
| 161 | const rowKey = getPropertyFromItem(item, itemRow) |
| 162 | const rowIndex = rowIndexByKey.get(rowKey) |
| 163 | |
| 164 | if (rowIndex === undefined) continue |
| 165 | |
| 166 | if (rowIndex <= lastRowIndex) { |
| 167 | columns.push({ key: String(columnIndex), cells: currentCells, items: currentItems }) |
| 168 | columnIndex++ |
| 169 | currentCells = Array(rowKeys.length).fill(null) |
| 170 | currentItems = [] |
| 171 | } |
| 172 | |
| 173 | const cell = makeCell(item, rowKey, columnIndex, groupKey) |
| 174 | currentCells[rowIndex] = cell |
| 175 | currentItems.push(cell) |
| 176 | groupItems.push(cell) |
| 177 | lastRowIndex = rowIndex |
| 178 | } |
| 179 | |
| 180 | if (currentCells.some(c => c !== null)) { |
| 181 | columns.push({ key: String(columnIndex), cells: currentCells, items: currentItems }) |
| 182 | } |
| 183 | |
| 184 | return { columns, groupItems } |
| 185 | } |
| 186 | |
| 187 | for (const [groupKey, { label, items: sourceItems }] of groupMap) { |
| 188 | const { columns, groupItems } = explicit |
no test coverage detected
searching dependent graphs…