mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 10:14:22 +08:00
* chore: remove react-tracked part 1 * move out table specific state to own store * chore: remove react-tracked part 2 * remove unused type * ensure table is properly updated on changes * remove all filters save in local storage * Tiny fixes * fix sort / filters applying issue + feedback * fix entity links * remove unnecessary style --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { CalculatedColumn } from 'react-data-grid'
|
|
import { ADD_COLUMN_KEY, SELECT_COLUMN_KEY } from '../constants'
|
|
import type { SavedState } from '../types'
|
|
|
|
export function getInitialGridColumns(
|
|
gridColumns: CalculatedColumn<any, any>[],
|
|
savedState?: SavedState
|
|
) {
|
|
let result = gridColumns
|
|
|
|
if (savedState?.gridColumns) {
|
|
result = []
|
|
|
|
// filter utility columns select, add-column
|
|
const stateColumnsFiltered = savedState.gridColumns.filter((x) => x?.name !== '')
|
|
|
|
for (let i = 0; i < stateColumnsFiltered.length; i++) {
|
|
const state = stateColumnsFiltered[i]
|
|
const found = gridColumns.find((y) => y.key === state.key)
|
|
// merge with savedState item props: width
|
|
if (found) result.push({ ...found, width: state.width, frozen: state.frozen })
|
|
}
|
|
|
|
// check for newly created columns
|
|
const newGridColumns = gridColumns.filter((x) => {
|
|
// no existed in stateColumnsFiltered and not utility column
|
|
const found = stateColumnsFiltered.find((state) => state.key === x.key)
|
|
return !found && x.name !== ''
|
|
})
|
|
result = result.concat(newGridColumns)
|
|
|
|
// process utility columns
|
|
const selectColumn = gridColumns.find((x) => x.key === SELECT_COLUMN_KEY)
|
|
if (selectColumn) {
|
|
result = [selectColumn, ...result]
|
|
}
|
|
const addColumn = gridColumns.find((x) => x.key === ADD_COLUMN_KEY)
|
|
if (addColumn) {
|
|
result.push(addColumn)
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|