UNPKG

@mskcc/carbon-react

Version:

Carbon react components for the MSKCC DSM

53 lines (47 loc) 1.6 kB
/** * MSKCC 2021, 2024 */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var sorting = require('./sorting.js'); var normalize = require('../tools/normalize.js'); /** * Helper to derive the next state from the given props and the * prevState. Potential future-facing API hook for React v17. * * Currently, it's being used as a way to normalize the incoming data that we * are receiving for rows */ const getDerivedStateFromProps = (props, prevState) => { const { rowIds, rowsById, cellsById } = normalize["default"](props.rows, props.headers, prevState); const state = { rowIds, rowsById, cellsById, sortDirection: prevState.sortDirection || sorting.initialSortState, sortHeaderKey: prevState.sortHeaderKey || null, // Copy over rowIds so the reference doesn't mutate the stored // `initialRowOrder` initialRowOrder: rowIds.slice(), filterInputValue: prevState.filterInputValue || null, // Optional state field to indicate whether a consumer should show a // batch actions menu shouldShowBatchActions: prevState.shouldShowBatchActions || false }; if (prevState.sortDirection && prevState.sortHeaderKey) { const { rowIds } = sorting.getSortedState(props, state, prevState.sortHeaderKey, prevState.sortDirection); state.rowIds = rowIds; } state.isExpandedAll = state.rowIds.every(id => { return state.rowsById[id].isExpanded === true; }); return state; }; var getDerivedStateFromProps$1 = getDerivedStateFromProps; exports["default"] = getDerivedStateFromProps$1;