Skip to content

Commit

Permalink
fix more refmap collecting issues;
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Apr 8, 2020
1 parent ccb2149 commit 2818afc
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages-premium
7 changes: 5 additions & 2 deletions packages/core/src/common/DayTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface DayTableSeg extends Seg {
}

export interface DayTableCell {
key: string // probably just the serialized date, but could be other metadata if this col is specific to another entity
date: DateMarker
extraHookProps?: object
extraDataAttrs?: object
Expand Down Expand Up @@ -70,9 +71,11 @@ export default class DayTableModel {
return rows
}

private buildCell(row, col) {
private buildCell(row, col): DayTableCell {
let date = this.daySeries.dates[row * this.colCnt + col]
return {
date: this.daySeries.dates[row * this.colCnt + col]
key: date.toISOString(),
date
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/util/RefMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export default class RefMap<RefType> {

// TODO: check callers that don't care about order. should use getAll instead
// NOTE: this method has become less valuable now that we are encouraged to map order by some other index
// TODO: provide ONE array-export function, buildArray, which fails on non-numeric indexes. caller can manipulate and "collect"
collect(
startIndex?: number,
endIndex?: number,
Expand Down
6 changes: 3 additions & 3 deletions packages/daygrid/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ export default class Table extends DateComponent<TableProps, TableState> {
prepareHits() {
this.rowPositions = new PositionCache(
this.rootEl,
this.rowRefs.collect().map((rowObj) => rowObj.cellElRefs.currentMap[0]), // first cell el in each row
this.rowRefs.collect().map((rowObj) => rowObj.getCellEls()[0]), // first cell el in each row. TODO: not optimal
false,
true // vertical
)

this.colPositions = new PositionCache(
this.rootEl,
this.rowRefs.currentMap[0].cellElRefs.collect(), // cell els in first row
this.rowRefs.currentMap[0].getCellEls(), // cell els in first row
true, // horizontal
false
)
Expand Down Expand Up @@ -263,7 +263,7 @@ export default class Table extends DateComponent<TableProps, TableState> {


private getCellEl(row, col) {
return this.rowRefs.currentMap[row].cellElRefs.currentMap[col]
return this.rowRefs.currentMap[row].getCellEls()[col] // TODO: not optimal
}


Expand Down
9 changes: 7 additions & 2 deletions packages/daygrid/src/TableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
import TableSeg from './TableSeg'


export interface TableCellProps extends TableCellModel {
export interface TableCellProps {
date: DateMarker
extraHookProps?: object
extraDataAttrs?: object
extraClassNames?: string[]
elRef?: Ref<HTMLTableCellElement>
innerElRef?: Ref<HTMLDivElement>
bgContent: ComponentChildren
Expand All @@ -42,7 +46,8 @@ export interface TableCellProps extends TableCellModel {
segIsHidden: { [instanceId: string]: boolean } // for more-popover. TODO: rename to be about selected instances
}

export interface TableCellModel { // combine with DayTableCell?
export interface TableCellModel { // TODO: move somewhere else. combine with DayTableCell?
key: string
date: DateMarker
extraHookProps?: object
extraDataAttrs?: object
Expand Down
28 changes: 19 additions & 9 deletions packages/daygrid/src/TableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ interface TableRowState {

export default class TableRow extends DateComponent<TableRowProps, TableRowState> {

public cellElRefs = new RefMap<HTMLTableCellElement>()
private cellElRefs = new RefMap<HTMLTableCellElement>()
private cellInnerElRefs = new RefMap<HTMLElement>()
private cellContentElRefs = new RefMap<HTMLDivElement>()
private segHarnessRefs = new RefMap<HTMLDivElement>()
Expand Down Expand Up @@ -121,8 +121,9 @@ export default class TableRow extends DateComponent<TableRowProps, TableRowState

return (
<TableCell
elRef={this.cellElRefs.createRef(col)}
innerElRef={this.cellInnerElRefs.createRef(col) /* rename */}
key={cell.key}
elRef={this.cellElRefs.createRef(cell.key)}
innerElRef={this.cellInnerElRefs.createRef(cell.key) /* rename prop */}
date={cell.date}
showDayNumber={props.showDayNumbers || showWeekNumber /* for spacing, we need to force day-numbers if week numbers */}
showWeekNumber={showWeekNumber}
Expand All @@ -139,7 +140,7 @@ export default class TableRow extends DateComponent<TableRowProps, TableRowState
allFgSegs={finalSegsByCol[col]}
segIsHidden={segIsHidden}
fgPaddingBottom={paddingBottoms[col]}
fgContentElRef={this.cellContentElRefs.createRef(col)}
fgContentElRef={this.cellContentElRefs.createRef(cell.key)}
fgContent={[
<Fragment>{normalFgNodes}</Fragment>, // Fragment scopes the keys
<Fragment>{mirrorFgNodes}</Fragment>
Expand Down Expand Up @@ -327,11 +328,13 @@ export default class TableRow extends DateComponent<TableRowProps, TableRowState


updateSizing(isExternalSizingChange) {
if (this.props.clientWidth !== null) { // positioning ready?
let { props, cellInnerElRefs, cellContentElRefs } = this

if (props.clientWidth !== null) { // positioning ready?

if (isExternalSizingChange) {
let cellInnerEls = this.cellInnerElRefs.collect()
let cellContentEls = this.cellContentElRefs.collect()
let cellInnerEls = props.cells.map((cell) => cellInnerElRefs.currentMap[cell.key])
let cellContentEls = props.cells.map((cell) => cellContentElRefs.currentMap[cell.key])

if (cellContentEls.length) {
let originEl = this.base as HTMLElement // BAD
Expand All @@ -353,7 +356,7 @@ export default class TableRow extends DateComponent<TableRowProps, TableRowState
}
}

let limitByContentHeight = this.props.dayMaxEvents === true || this.props.dayMaxEventRows === true
let limitByContentHeight = props.dayMaxEvents === true || props.dayMaxEventRows === true

this.setState({
segHeights: this.computeSegHeights(),
Expand All @@ -371,10 +374,17 @@ export default class TableRow extends DateComponent<TableRowProps, TableRowState


computeMaxContentHeight() {
let contentEl = this.cellContentElRefs.currentMap[0]
let contentEl = this.cellContentElRefs.currentMap[this.props.cells[0].key]
return contentEl.getBoundingClientRect().height
}


public getCellEls() {
let elMap = this.cellElRefs.currentMap

return this.props.cells.map((cell) => elMap[cell.key])
}

}

TableRow.addStateEquality({
Expand Down
52 changes: 23 additions & 29 deletions packages/timegrid/src/TimeColsContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,28 @@ export default class TimeColsContent extends BaseComponent<TimeColsContentProps>
{props.axis &&
<td class='fc-timegrid-axis' />
}
{props.cells.map((cell, i) => {
let key = cell.date.toISOString()
return (
<TimeCol
key={key}
elRef={this.cellElRefs.createRef(key)}
date={cell.date}
dateProfile={props.dateProfile}
nowDate={props.nowDate}
todayRange={props.todayRange}
extraHookProps={cell.extraHookProps}
extraDataAttrs={cell.extraDataAttrs}
extraClassNames={cell.extraClassNames}
fgEventSegs={fgEventSegsByRow[i]}
bgEventSegs={bgEventSegsByRow[i]}
businessHourSegs={businessHourSegsByRow[i]}
nowIndicatorSegs={nowIndicatorSegsByRow[i]}
dateSelectionSegs={dateSelectionSegsByRow[i]}
eventDrag={eventDragByRow[i]}
eventResize={eventResizeByRow[i]}
slatCoords={props.slatCoords}
eventSelection={props.eventSelection}
/>
)
})}
{props.cells.map((cell, i) => (
<TimeCol
key={cell.key}
elRef={this.cellElRefs.createRef(cell.key)}
date={cell.date}
dateProfile={props.dateProfile}
nowDate={props.nowDate}
todayRange={props.todayRange}
extraHookProps={cell.extraHookProps}
extraDataAttrs={cell.extraDataAttrs}
extraClassNames={cell.extraClassNames}
fgEventSegs={fgEventSegsByRow[i]}
bgEventSegs={bgEventSegsByRow[i]}
businessHourSegs={businessHourSegsByRow[i]}
nowIndicatorSegs={nowIndicatorSegsByRow[i]}
dateSelectionSegs={dateSelectionSegsByRow[i]}
eventDrag={eventDragByRow[i]}
eventResize={eventResizeByRow[i]}
slatCoords={props.slatCoords}
eventSelection={props.eventSelection}
/>
))}
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -155,8 +152,5 @@ export default class TimeColsContent extends BaseComponent<TimeColsContentProps>


function collectCellEls(elMap: { [key: string]: HTMLElement }, cells: TableCellModel[]) {
return cells.map((cell) => {
let key = cell.date.toISOString() // store in the cell! bad to keep recomputing
return elMap[key]
})
return cells.map((cell) => elMap[cell.key])
}

0 comments on commit 2818afc

Please sign in to comment.