mirror of
https://github.com/nowcommunity/nowdatabase.git
synced 2026-10-12 19:13:52 +03:00
fix bug with update tab key props, and update references now show details properly, and the view link works, also change typing a lot
This commit is contained in:
@@ -94,14 +94,13 @@ export const getSpeciesDetails = async (id: number) => {
|
|||||||
now_sau: {
|
now_sau: {
|
||||||
include: {
|
include: {
|
||||||
now_sr: {
|
now_sr: {
|
||||||
select: {
|
include: {
|
||||||
ref_ref: {
|
ref_ref: {
|
||||||
select: {
|
include: {
|
||||||
ref_authors: true,
|
ref_authors: true,
|
||||||
ref_journal: true,
|
ref_journal: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rid: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import { ReferenceOfUpdate, UpdateLog } from '@/shared/types'
|
import {
|
||||||
|
LocalityReference,
|
||||||
|
ReferenceOfUpdate,
|
||||||
|
SpeciesReference,
|
||||||
|
TimeBoundReference,
|
||||||
|
TimeUnitReference,
|
||||||
|
UpdateLog,
|
||||||
|
} from '@/shared/types'
|
||||||
import { useDetailContext } from '@/components/DetailView/Context/DetailContext'
|
import { useDetailContext } from '@/components/DetailView/Context/DetailContext'
|
||||||
import { EditingModal } from '@/components/DetailView/common/EditingModal'
|
import { EditingModal } from '@/components/DetailView/common/EditingModal'
|
||||||
import { SimpleTable } from '@/components/DetailView/common/SimpleTable'
|
import { SimpleTable } from '@/components/DetailView/common/SimpleTable'
|
||||||
@@ -18,9 +25,16 @@ const makeNameList = (names: Array<string | null>) => {
|
|||||||
return names[0] ?? ''
|
return names[0] ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
const ReferenceList = ({ references, big }: { references: ReferenceOfUpdate[]; big: boolean }) => {
|
const ReferenceList = ({
|
||||||
|
references,
|
||||||
|
big,
|
||||||
|
}: {
|
||||||
|
references: Array<LocalityReference | SpeciesReference | TimeUnitReference | TimeBoundReference>
|
||||||
|
big: boolean
|
||||||
|
}) => {
|
||||||
const getReferenceText = (ref: ReferenceOfUpdate) => {
|
const getReferenceText = (ref: ReferenceOfUpdate) => {
|
||||||
// php version: html/include/database.php -> referenceCitation()
|
// php version: html/include/database.php -> referenceCitation()
|
||||||
|
//const ref = referenceOfUpdate.ref_ref
|
||||||
const authors = makeNameList(ref.ref_authors.map(author => author.author_surname))
|
const authors = makeNameList(ref.ref_authors.map(author => author.author_surname))
|
||||||
const issue = ref.issue ? ` (${ref.issue}) ` : ''
|
const issue = ref.issue ? ` (${ref.issue}) ` : ''
|
||||||
if (ref.ref_type_id === 1) {
|
if (ref.ref_type_id === 1) {
|
||||||
@@ -37,6 +51,7 @@ const ReferenceList = ({ references, big }: { references: ReferenceOfUpdate[]; b
|
|||||||
// All other types
|
// All other types
|
||||||
return `${authors} ${ref.date_primary ? `(${ref.date_primary}). ` : ''} ${ref.title_primary?.concat('. ') ?? ''}${ref.title_secondary?.concat('. ') ?? ''}${ref.title_series?.concat('. ') ?? ''}${ref.gen_notes?.concat('.') ?? ''}`
|
return `${authors} ${ref.date_primary ? `(${ref.date_primary}). ` : ''} ${ref.title_primary?.concat('. ') ?? ''}${ref.title_secondary?.concat('. ') ?? ''}${ref.title_series?.concat('. ') ?? ''}${ref.gen_notes?.concat('.') ?? ''}`
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
{references.map(ref => (
|
{references.map(ref => (
|
||||||
@@ -44,7 +59,7 @@ const ReferenceList = ({ references, big }: { references: ReferenceOfUpdate[]; b
|
|||||||
key={ref.rid}
|
key={ref.rid}
|
||||||
sx={{ padding: '0.4em', margin: '0.5em', maxWidth: big ? '50em' : '30em', backgroundColor: 'lightblue' }}
|
sx={{ padding: '0.4em', margin: '0.5em', maxWidth: big ? '50em' : '30em', backgroundColor: 'lightblue' }}
|
||||||
>
|
>
|
||||||
<div style={{ wordWrap: 'break-word', whiteSpace: 'normal' }}>{getReferenceText(ref)}</div>
|
<div style={{ wordWrap: 'break-word', whiteSpace: 'normal' }}>{getReferenceText(ref.ref_ref)}</div>
|
||||||
{big && (
|
{big && (
|
||||||
<div>
|
<div>
|
||||||
<Link to={`/reference/${ref.rid}`}>View</Link>
|
<Link to={`/reference/${ref.rid}`}>View</Link>
|
||||||
@@ -90,10 +105,7 @@ export const UpdateTab = <T, UpdateType extends MRT_RowData & { updates: UpdateL
|
|||||||
accessorKey: refFieldName as string,
|
accessorKey: refFieldName as string,
|
||||||
header: 'Reference',
|
header: 'Reference',
|
||||||
Cell: ({ row }: { row: MRT_Row<UpdateType> }) => (
|
Cell: ({ row }: { row: MRT_Row<UpdateType> }) => (
|
||||||
<ReferenceList
|
<ReferenceList references={row.original[refFieldName]} big={false} />
|
||||||
references={(row.original[refFieldName] as { ref_ref: ReferenceOfUpdate }[]).map(item => item.ref_ref)}
|
|
||||||
big={false}
|
|
||||||
/>
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -105,7 +117,7 @@ export const UpdateTab = <T, UpdateType extends MRT_RowData & { updates: UpdateL
|
|||||||
coordinator={row.original[`${prefix}_coordinator`] as string}
|
coordinator={row.original[`${prefix}_coordinator`] as string}
|
||||||
updates={row.original.updates}
|
updates={row.original.updates}
|
||||||
comment={row.original[`${prefix}_comment` as keyof UpdateType] as string}
|
comment={row.original[`${prefix}_comment` as keyof UpdateType] as string}
|
||||||
references={row.original[refFieldName] as { ref_ref: ReferenceOfUpdate }[]}
|
references={row.original[refFieldName]}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -118,7 +130,7 @@ export const UpdateTab = <T, UpdateType extends MRT_RowData & { updates: UpdateL
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const DetailsModal = <RefType extends { ref_ref: ReferenceOfUpdate }>({
|
const DetailsModal = ({
|
||||||
updates,
|
updates,
|
||||||
references,
|
references,
|
||||||
comment,
|
comment,
|
||||||
@@ -127,7 +139,7 @@ const DetailsModal = <RefType extends { ref_ref: ReferenceOfUpdate }>({
|
|||||||
coordinator,
|
coordinator,
|
||||||
}: {
|
}: {
|
||||||
updates: UpdateLog[]
|
updates: UpdateLog[]
|
||||||
references: RefType[]
|
references: Array<LocalityReference | SpeciesReference | TimeUnitReference | TimeBoundReference>
|
||||||
comment: string
|
comment: string
|
||||||
date: Date
|
date: Date
|
||||||
authorizer: string
|
authorizer: string
|
||||||
@@ -179,11 +191,7 @@ const DetailsModal = <RefType extends { ref_ref: ReferenceOfUpdate }>({
|
|||||||
</Card>
|
</Card>
|
||||||
<Divider />
|
<Divider />
|
||||||
<h3>References</h3>
|
<h3>References</h3>
|
||||||
{references.length === 0 ? (
|
{references.length === 0 ? <Box>Update has no references.</Box> : <ReferenceList references={references} big />}
|
||||||
<Box>Update has no references.</Box>
|
|
||||||
) : (
|
|
||||||
<ReferenceList references={references.map(ref => ref.ref_ref)} big />
|
|
||||||
)}
|
|
||||||
<Divider />
|
<Divider />
|
||||||
<h3>Changed database values</h3>
|
<h3>Changed database values</h3>
|
||||||
<SimpleTable columns={columns} data={updates} />
|
<SimpleTable columns={columns} data={updates} />
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const SpeciesDetails = () => {
|
|||||||
document.title = 'New species'
|
document.title = 'New species'
|
||||||
}
|
}
|
||||||
const [editSpeciesRequest, { isLoading: mutationLoading }] = useEditSpeciesMutation()
|
const [editSpeciesRequest, { isLoading: mutationLoading }] = useEditSpeciesMutation()
|
||||||
const { isError, isFetching, data } = useGetSpeciesDetailsQuery(id!, { skip: isNew })
|
const { isError, isFetching, data } = useGetSpeciesDetailsQuery(encodeURIComponent(id!), { skip: isNew })
|
||||||
const { notify } = useNotify()
|
const { notify } = useNotify()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [deleteMutation, { isSuccess: deleteSuccess, isError: deleteError }] = useDeleteSpeciesMutation()
|
const [deleteMutation, { isSuccess: deleteSuccess, isError: deleteError }] = useDeleteSpeciesMutation()
|
||||||
|
|||||||
@@ -443,8 +443,10 @@ export type ReferenceOfUpdate = Prisma.ref_ref & {
|
|||||||
ref_journal: Prisma.ref_journal
|
ref_journal: Prisma.ref_journal
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LocalityReference = Prisma.now_lr & ReferenceOfUpdate
|
export type LocalityReference = Prisma.now_lr & { ref_ref: ReferenceOfUpdate }
|
||||||
export type SpeciesReference = Prisma.now_sr & ReferenceOfUpdate
|
export type SpeciesReference = Prisma.now_sr & { ref_ref: ReferenceOfUpdate }
|
||||||
|
export type TimeUnitReference = Prisma.now_tr & { ref_ref: ReferenceOfUpdate }
|
||||||
|
export type TimeBoundReference = Prisma.now_br & { ref_ref: ReferenceOfUpdate }
|
||||||
|
|
||||||
export type ReferenceJournalType = {
|
export type ReferenceJournalType = {
|
||||||
journal_id?: number
|
journal_id?: number
|
||||||
|
|||||||
Reference in New Issue
Block a user