Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static getDataState(data, { groupBy }, lastState) {
let initial = { flatData: data }
lastState = lastState || initial
if (lastState.data !== data || lastState.groupBy !== groupBy) {
if (!groupBy) return initial
let keys = []
let groups = groupBySortedKeys(groupBy, data, keys)
let sequentialData = []
let flatData = []
keys.forEach(group => {
let items = groups[group]
let groupItem = { __isGroup: true, group }
sequentialData = [...sequentialData, ...items]
flatData = [...flatData, groupItem, ...items]
}, [])
return {
groups,
groupBy,
flatData,
sequentialData,
sortedKeys: keys,