-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: complete database panel with filters
- Loading branch information
1 parent
9826128
commit 1641d90
Showing
8 changed files
with
339 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/component/panels/databasePanel/DatabaseTable/NamesRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { CSSProperties } from 'react'; | ||
|
||
const style: CSSProperties = { | ||
whiteSpace: 'pre-line', | ||
textOverflow: 'ellipsis', | ||
}; | ||
|
||
export default function NamesRenderer(props: { names: string[] }) { | ||
return <p style={style}>{props.names.join('\n')}</p>; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/component/panels/databasePanel/DatabaseTable/RangesRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { CSSProperties } from 'react'; | ||
|
||
import { DataBaseRange } from '../../../../data/data1d/database'; | ||
|
||
const style: CSSProperties = { | ||
whiteSpace: 'pre-line', | ||
textOverflow: 'ellipsis', | ||
}; | ||
|
||
export function RangesRenderer(props: { ranges: DataBaseRange[] }) { | ||
return ( | ||
<p style={style}> | ||
{props.ranges | ||
.map((range) => { | ||
return range.signals.map((signal) => signal.delta).join(','); | ||
}) | ||
.join('\n')} | ||
</p> | ||
); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/component/panels/databasePanel/DatabaseTable/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useMemo, memo } from 'react'; | ||
|
||
import { usePreferences } from '../../../context/PreferencesContext'; | ||
import ReactTable from '../../../elements/ReactTable/ReactTable'; | ||
import setCustomColumn from '../../../elements/ReactTable/setCustomColumn'; | ||
import { getValue } from '../../../utility/LocalStorage'; | ||
import NoTableData from '../../extra/placeholder/NoTableData'; | ||
import { databaseDefaultValues } from '../../extra/preferences/defaultValues'; | ||
|
||
import NamesRenderer from './NamesRenderer'; | ||
import { RangesRenderer } from './RangesRenderer'; | ||
|
||
interface DatabaseTableProps { | ||
data: any; | ||
} | ||
|
||
function DatabaseTable({ data }: DatabaseTableProps) { | ||
const preferences = usePreferences(); | ||
const initialColumns = useMemo( | ||
() => [ | ||
{ | ||
index: 1, | ||
Header: '#', | ||
width: '1%', | ||
minWidth: '24px', | ||
Cell: ({ row }) => row.index + 1, | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
const tableColumns = useMemo(() => { | ||
const databasePreferences = getValue( | ||
preferences, | ||
'formatting.panels.database', | ||
databaseDefaultValues, | ||
); | ||
|
||
let cols = [...initialColumns]; | ||
|
||
if (databasePreferences.showNames) { | ||
setCustomColumn(cols, { | ||
index: 2, | ||
columnLabel: 'names', | ||
accessor: (row) => row.names[0], | ||
Cell: ({ row }) => <NamesRenderer names={row?.original.names} />, | ||
}); | ||
} | ||
|
||
if (databasePreferences.showRanges) { | ||
setCustomColumn(cols, { | ||
index: 3, | ||
columnLabel: 'ranges', | ||
Cell: ({ row }) => <RangesRenderer ranges={row?.original.ranges} />, | ||
}); | ||
} | ||
|
||
if (databasePreferences.showSolvent) { | ||
setCustomColumn(cols, { | ||
index: 4, | ||
columnLabel: 'solvent', | ||
Cell: ({ row }) => <RangesRenderer ranges={row?.original.solvent} />, | ||
}); | ||
} | ||
return cols.sort((object1, object2) => object1.index - object2.index); | ||
}, [initialColumns, preferences]); | ||
|
||
return data && data.length > 0 ? ( | ||
<ReactTable data={data} columns={tableColumns} /> | ||
) : ( | ||
<NoTableData /> | ||
); | ||
} | ||
|
||
export default memo(DatabaseTable); |
Oops, something went wrong.