mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
change export file name to include name of table and a timestamp, and add title props to table views to make this work
This commit is contained in:
@@ -14,7 +14,7 @@ export const CrossSearchExportMenuItem = ({ handleClose }: { handleClose: () =>
|
|||||||
const token = useUser().token
|
const token = useUser().token
|
||||||
const fetchOptions = token ? { headers: { Authorization: `Bearer ${token}` } } : {}
|
const fetchOptions = token ? { headers: { Authorization: `Bearer ${token}` } } : {}
|
||||||
|
|
||||||
const filename = `cross_search${currentDateAsString()}.csv`
|
const filename = `cross_search-${currentDateAsString()}.csv`
|
||||||
|
|
||||||
const fetchCSVFile = async () => {
|
const fetchCSVFile = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const StagingView = <T extends MRT_RowData>() => {
|
|||||||
<SelectingTable<Reference, T>
|
<SelectingTable<Reference, T>
|
||||||
buttonText="Add existing reference"
|
buttonText="Add existing reference"
|
||||||
data={data}
|
data={data}
|
||||||
|
title="References"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={referenceTableColumns}
|
columns={referenceTableColumns}
|
||||||
idFieldName="rid"
|
idFieldName="rid"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export const SelectingTable = <T extends MRT_RowData, ParentType extends object>
|
|||||||
buttonText,
|
buttonText,
|
||||||
data,
|
data,
|
||||||
columns,
|
columns,
|
||||||
|
title,
|
||||||
editingAction,
|
editingAction,
|
||||||
tableRowAction,
|
tableRowAction,
|
||||||
fieldName,
|
fieldName,
|
||||||
@@ -26,6 +27,7 @@ export const SelectingTable = <T extends MRT_RowData, ParentType extends object>
|
|||||||
buttonText: string
|
buttonText: string
|
||||||
data: T[] | undefined
|
data: T[] | undefined
|
||||||
columns: MRT_ColumnDef<T>[]
|
columns: MRT_ColumnDef<T>[]
|
||||||
|
title: string
|
||||||
editingAction?: (object: T) => void
|
editingAction?: (object: T) => void
|
||||||
tableRowAction?: (row: T) => void
|
tableRowAction?: (row: T) => void
|
||||||
fieldName: keyof ParentType
|
fieldName: keyof ParentType
|
||||||
@@ -74,6 +76,7 @@ export const SelectingTable = <T extends MRT_RowData, ParentType extends object>
|
|||||||
<TableView<T>
|
<TableView<T>
|
||||||
data={filteredData}
|
data={filteredData}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
title={title}
|
||||||
isFetching={false}
|
isFetching={false}
|
||||||
visibleColumns={visibleColumns}
|
visibleColumns={visibleColumns}
|
||||||
selectorFn={editingAction ?? defaultEditingAction}
|
selectorFn={editingAction ?? defaultEditingAction}
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ export const LithologyTab = () => {
|
|||||||
isError={isError}
|
isError={isError}
|
||||||
columns={selectingTableColumns}
|
columns={selectingTableColumns}
|
||||||
data={sedimentaryStructuresData}
|
data={sedimentaryStructuresData}
|
||||||
|
title="Sedimentary structures"
|
||||||
fieldName="now_ss"
|
fieldName="now_ss"
|
||||||
idFieldName="ss_value"
|
idFieldName="ss_value"
|
||||||
editingAction={(newSed: SedimentaryStructureValues) => {
|
editingAction={(newSed: SedimentaryStructureValues) => {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export const MuseumTab = () => {
|
|||||||
<SelectingTable<Museum, LocalityDetailsType>
|
<SelectingTable<Museum, LocalityDetailsType>
|
||||||
buttonText="Select Museum"
|
buttonText="Select Museum"
|
||||||
data={museumData}
|
data={museumData}
|
||||||
|
title="Museums"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
fieldName="now_mus"
|
fieldName="now_mus"
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export const ProjectTab = () => {
|
|||||||
<SelectingTable<Project, LocalityDetailsType>
|
<SelectingTable<Project, LocalityDetailsType>
|
||||||
buttonText="Select Project"
|
buttonText="Select Project"
|
||||||
data={projectData}
|
data={projectData}
|
||||||
|
title="Projects"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
isError={isError}
|
isError={isError}
|
||||||
idFieldName="pid"
|
idFieldName="pid"
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ export const SpeciesTab = () => {
|
|||||||
<SelectingTable<Species, LocalityDetailsType>
|
<SelectingTable<Species, LocalityDetailsType>
|
||||||
buttonText="Select Species"
|
buttonText="Select Species"
|
||||||
data={speciesData}
|
data={speciesData}
|
||||||
|
title="Species"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={speciesColumns}
|
columns={speciesColumns}
|
||||||
fieldName="now_ls"
|
fieldName="now_ls"
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ export const AuthorTab: React.FC<AuthorTabProps> = ({ field_num_param, tab_name
|
|||||||
<SelectingTable<ReferenceAuthorType, ReferenceDetailsType>
|
<SelectingTable<ReferenceAuthorType, ReferenceDetailsType>
|
||||||
buttonText={`Select ${buttonText}`}
|
buttonText={`Select ${buttonText}`}
|
||||||
data={authorData}
|
data={authorData}
|
||||||
|
title="Authors"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={authorColumns}
|
columns={authorColumns}
|
||||||
fieldName="ref_authors"
|
fieldName="ref_authors"
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ export const JournalTab: React.FC<JournalTabProps> = ({ tab_name = 'Journal' })
|
|||||||
<SelectingTable<ReferenceJournalType, ReferenceDetailsType>
|
<SelectingTable<ReferenceJournalType, ReferenceDetailsType>
|
||||||
buttonText="Select Journal"
|
buttonText="Select Journal"
|
||||||
data={journalData}
|
data={journalData}
|
||||||
|
title="Journals"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={journalColumns}
|
columns={journalColumns}
|
||||||
fieldName="ref_journal"
|
fieldName="ref_journal"
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ export const CoordinatorTab = () => {
|
|||||||
<SelectingTable<PersonDetailsType, RegionDetails>
|
<SelectingTable<PersonDetailsType, RegionDetails>
|
||||||
buttonText="Select Coordinator"
|
buttonText="Select Coordinator"
|
||||||
data={personsData}
|
data={personsData}
|
||||||
|
title="Coordinators"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={personTableColumns}
|
columns={personTableColumns}
|
||||||
fieldName="now_reg_coord_people"
|
fieldName="now_reg_coord_people"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export const SequenceTable = ({ selectorFn }: { selectorFn?: (id: Sequence) => v
|
|||||||
selectorFn={selectorFn}
|
selectorFn={selectorFn}
|
||||||
idFieldName="sequence"
|
idFieldName="sequence"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
title="Sequences"
|
||||||
isFetching={isFetching}
|
isFetching={isFetching}
|
||||||
visibleColumns={visibleColumns}
|
visibleColumns={visibleColumns}
|
||||||
data={sequenceQueryData}
|
data={sequenceQueryData}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export const LocalityTab = () => {
|
|||||||
<SelectingTable<Editable<Locality>, SpeciesDetailsType>
|
<SelectingTable<Editable<Locality>, SpeciesDetailsType>
|
||||||
buttonText="Select Locality"
|
buttonText="Select Locality"
|
||||||
columns={columns}
|
columns={columns}
|
||||||
|
title="Localities"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
data={localitiesData}
|
data={localitiesData}
|
||||||
fieldName="now_ls"
|
fieldName="now_ls"
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const TaxonomyTab = () => {
|
|||||||
<SelectingTable<Species, Species>
|
<SelectingTable<Species, Species>
|
||||||
buttonText="Copy existing taxonomy"
|
buttonText="Copy existing taxonomy"
|
||||||
data={speciesQueryData}
|
data={speciesQueryData}
|
||||||
|
title="Species"
|
||||||
isError={isError}
|
isError={isError}
|
||||||
columns={smallSpeciesTableColumns}
|
columns={smallSpeciesTableColumns}
|
||||||
fieldName="order_name" // this doesn't do anything here but is required
|
fieldName="order_name" // this doesn't do anything here but is required
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { usePageContext } from '../Page'
|
|||||||
|
|
||||||
export const TableToolBar = <T extends MRT_RowData>({
|
export const TableToolBar = <T extends MRT_RowData>({
|
||||||
table,
|
table,
|
||||||
|
tableName,
|
||||||
combinedExport,
|
combinedExport,
|
||||||
kmlExport,
|
kmlExport,
|
||||||
svgExport,
|
svgExport,
|
||||||
@@ -21,6 +22,7 @@ export const TableToolBar = <T extends MRT_RowData>({
|
|||||||
showNewButton,
|
showNewButton,
|
||||||
}: {
|
}: {
|
||||||
table: MRT_TableInstance<T>
|
table: MRT_TableInstance<T>
|
||||||
|
tableName: string
|
||||||
combinedExport?: (lids: number[]) => Promise<void>
|
combinedExport?: (lids: number[]) => Promise<void>
|
||||||
kmlExport?: (table: MRT_TableInstance<T>) => void
|
kmlExport?: (table: MRT_TableInstance<T>) => void
|
||||||
svgExport?: (table: MRT_TableInstance<T>) => void
|
svgExport?: (table: MRT_TableInstance<T>) => void
|
||||||
@@ -87,7 +89,7 @@ export const TableToolBar = <T extends MRT_RowData>({
|
|||||||
) : (
|
) : (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
exportRows(table)
|
exportRows(table, tableName)
|
||||||
handleClose()
|
handleClose()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -57,10 +57,9 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
idFieldName: keyof T
|
idFieldName: keyof T
|
||||||
checkRowRestriction?: (row: T) => boolean
|
checkRowRestriction?: (row: T) => boolean
|
||||||
selectorFn?: (id: T) => void
|
selectorFn?: (id: T) => void
|
||||||
// here
|
|
||||||
tableRowAction?: (row: T) => void
|
tableRowAction?: (row: T) => void
|
||||||
url?: string
|
url?: string
|
||||||
title?: string
|
title: string
|
||||||
combinedExport?: (lids: number[]) => Promise<void>
|
combinedExport?: (lids: number[]) => Promise<void>
|
||||||
kmlExport?: (table: MRT_TableInstance<T>) => void
|
kmlExport?: (table: MRT_TableInstance<T>) => void
|
||||||
svgExport?: (table: MRT_TableInstance<T>) => void
|
svgExport?: (table: MRT_TableInstance<T>) => void
|
||||||
@@ -259,6 +258,7 @@ export const TableView = <T extends MRT_RowData>({
|
|||||||
{title && <Box className="title">{title}</Box>}
|
{title && <Box className="title">{title}</Box>}
|
||||||
<TableToolBar<T>
|
<TableToolBar<T>
|
||||||
table={table}
|
table={table}
|
||||||
|
tableName={title}
|
||||||
combinedExport={combinedExport}
|
combinedExport={combinedExport}
|
||||||
kmlExport={kmlExport}
|
kmlExport={kmlExport}
|
||||||
svgExport={svgExport}
|
svgExport={svgExport}
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
import { MRT_RowData, MRT_TableInstance } from 'material-react-table'
|
import { MRT_RowData, MRT_TableInstance } from 'material-react-table'
|
||||||
import { mkConfig, generateCsv, download } from 'export-to-csv'
|
import { mkConfig, generateCsv, download } from 'export-to-csv'
|
||||||
import { AcceptedData } from 'node_modules/export-to-csv/output/lib/types'
|
import { AcceptedData } from 'node_modules/export-to-csv/output/lib/types'
|
||||||
|
import { currentDateAsString } from '@/shared/currentDateAsString'
|
||||||
|
|
||||||
export type ExportFn<T> = (data: T) => { [k: string]: AcceptedData }
|
export type ExportFn<T> = (data: T) => { [k: string]: AcceptedData }
|
||||||
|
|
||||||
export const exportRows = <T extends MRT_RowData>(table: MRT_TableInstance<T>) => {
|
export const exportRows = <T extends MRT_RowData>(table: MRT_TableInstance<T>, tableName: string) => {
|
||||||
const csvConfig = mkConfig({
|
const csvConfig = mkConfig({
|
||||||
fieldSeparator: ',',
|
fieldSeparator: ',',
|
||||||
decimalSeparator: '.',
|
decimalSeparator: '.',
|
||||||
useKeysAsHeaders: true,
|
useKeysAsHeaders: true,
|
||||||
quoteStrings: true, // If true, will wrap all values in double quotes
|
quoteStrings: true, // If true, will wrap all values in double quotes
|
||||||
|
filename: `${tableName.toLowerCase()}-${currentDateAsString()}`,
|
||||||
})
|
})
|
||||||
const rowData = table.getPrePaginationRowModel().rows.map(row => {
|
const rowData = table.getPrePaginationRowModel().rows.map(row => {
|
||||||
const r = {} as Record<string, AcceptedData>
|
const r = {} as Record<string, AcceptedData>
|
||||||
|
|||||||
Reference in New Issue
Block a user