Skip to content

Commit

Permalink
Add additional header row with letters
Browse files Browse the repository at this point in the history
  • Loading branch information
guergana committed Jun 22, 2024
1 parent c0f4d26 commit b690119
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/components/Editors/Table/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import LightTooltip from '../../Parts/Tooltips/Light'
import * as helpers from '../../../helpers'
import * as types from '../../../types'
import { createGroups } from './groups'

// TODO: remove colors hard-coding
// TODO: use proper InovuaDatagrid types
Expand Down Expand Up @@ -30,8 +31,11 @@ export function createColumns(
},
}

// Using groups to add the headers with the letters of the alphabet
const groups = createGroups(schema.fields.length)

const dataColumns = []
for (const field of schema.fields) {
for (const [index, field] of schema.fields.entries()) {
// TODO: fix this on ther server side -- schema should not have hidden fields
// Otherwise the _rowNumber and _rowValid are displayed on the table
if (field.name === '_rowNumber' || field.name === '_rowValid') continue
Expand All @@ -46,6 +50,7 @@ export function createColumns(
name: field.name,
header,
type: ['integer', 'number'].includes(field.type) ? 'number' : 'string',
group: groups[index].name,
headerProps:
field.name in errorIndex.label
? { style: { color: 'white', background: 'red' } }
Expand Down
23 changes: 23 additions & 0 deletions client/components/Editors/Table/groups.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface Group {
name: string
header: string
}

export function createGroups(letterAmount: number): Array<Group> {
// Generate an array with letters from the latin alphabet
const alpha = Array.from(Array(letterAmount)).map((e, i) => i + 65)

Check failure on line 8 in client/components/Editors/Table/groups.tsx

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'e' is declared but its value is never read.

Check failure on line 8 in client/components/Editors/Table/groups.tsx

View workflow job for this annotation

GitHub Actions / test (macos-latest)

'e' is declared but its value is never read.
const alphabet = alpha.map((x) => String.fromCharCode(x))

const groups: Array<Group> = []

alphabet.forEach((letter) => {
const letterEntry = {
name: letter,
header: letter,
headerStyle: { textAlign: 'center' },
}
groups.push(letterEntry)
})

return groups
}
4 changes: 4 additions & 0 deletions client/components/Editors/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import InovuaDatagrid from '@inovua/reactdatagrid-community'
import { TypeDataGridProps } from '@inovua/reactdatagrid-community/types'
import { TypeComputedProps } from '@inovua/reactdatagrid-community/types'
import { createColumns } from './columns'
import { createGroups } from './groups'
import * as settings from './settings'
import * as types from '../../../types'
import debounce from 'lodash/debounce'
Expand All @@ -30,6 +31,8 @@ export default function TableEditor(props: TableEditorProps) {

const [rowHeight] = React.useState(40)

const groups = createGroups(columns.length - 1)

React.useEffect(() => {
const debouncedHandleResize = debounce(function handleResize() {
resizeTable()
Expand Down Expand Up @@ -59,6 +62,7 @@ export default function TableEditor(props: TableEditorProps) {
dataSource={source}
columns={columns}
pagination={true}
groups={groups}
loadingText={<Typography>Loading...</Typography>}
renderLoadMask={LoadMask}
defaultActiveCell={settings.DEFAULT_ACTIVE_CELL}
Expand Down

0 comments on commit b690119

Please sign in to comment.