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: {
|
||||
include: {
|
||||
now_sr: {
|
||||
select: {
|
||||
include: {
|
||||
ref_ref: {
|
||||
select: {
|
||||
include: {
|
||||
ref_authors: 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 { EditingModal } from '@/components/DetailView/common/EditingModal'
|
||||
import { SimpleTable } from '@/components/DetailView/common/SimpleTable'
|
||||
@@ -18,9 +25,16 @@ const makeNameList = (names: Array<string | null>) => {
|
||||
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) => {
|
||||
// php version: html/include/database.php -> referenceCitation()
|
||||
//const ref = referenceOfUpdate.ref_ref
|
||||
const authors = makeNameList(ref.ref_authors.map(author => author.author_surname))
|
||||
const issue = ref.issue ? ` (${ref.issue}) ` : ''
|
||||
if (ref.ref_type_id === 1) {
|
||||
@@ -37,6 +51,7 @@ const ReferenceList = ({ references, big }: { references: ReferenceOfUpdate[]; b
|
||||
// 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 (
|
||||
<Stack>
|
||||
{references.map(ref => (
|
||||
@@ -44,7 +59,7 @@ const ReferenceList = ({ references, big }: { references: ReferenceOfUpdate[]; b
|
||||
key={ref.rid}
|
||||
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 && (
|
||||
<div>
|
||||
<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,
|
||||
header: 'Reference',
|
||||
Cell: ({ row }: { row: MRT_Row<UpdateType> }) => (
|
||||
<ReferenceList
|
||||
references={(row.original[refFieldName] as { ref_ref: ReferenceOfUpdate }[]).map(item => item.ref_ref)}
|
||||
big={false}
|
||||
/>
|
||||
<ReferenceList references={row.original[refFieldName]} big={false} />
|
||||
),
|
||||
},
|
||||
{
|
||||
@@ -105,7 +117,7 @@ export const UpdateTab = <T, UpdateType extends MRT_RowData & { updates: UpdateL
|
||||
coordinator={row.original[`${prefix}_coordinator`] as string}
|
||||
updates={row.original.updates}
|
||||
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,
|
||||
references,
|
||||
comment,
|
||||
@@ -127,7 +139,7 @@ const DetailsModal = <RefType extends { ref_ref: ReferenceOfUpdate }>({
|
||||
coordinator,
|
||||
}: {
|
||||
updates: UpdateLog[]
|
||||
references: RefType[]
|
||||
references: Array<LocalityReference | SpeciesReference | TimeUnitReference | TimeBoundReference>
|
||||
comment: string
|
||||
date: Date
|
||||
authorizer: string
|
||||
@@ -179,11 +191,7 @@ const DetailsModal = <RefType extends { ref_ref: ReferenceOfUpdate }>({
|
||||
</Card>
|
||||
<Divider />
|
||||
<h3>References</h3>
|
||||
{references.length === 0 ? (
|
||||
<Box>Update has no references.</Box>
|
||||
) : (
|
||||
<ReferenceList references={references.map(ref => ref.ref_ref)} big />
|
||||
)}
|
||||
{references.length === 0 ? <Box>Update has no references.</Box> : <ReferenceList references={references} big />}
|
||||
<Divider />
|
||||
<h3>Changed database values</h3>
|
||||
<SimpleTable columns={columns} data={updates} />
|
||||
|
||||
@@ -24,7 +24,7 @@ export const SpeciesDetails = () => {
|
||||
document.title = 'New species'
|
||||
}
|
||||
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 navigate = useNavigate()
|
||||
const [deleteMutation, { isSuccess: deleteSuccess, isError: deleteError }] = useDeleteSpeciesMutation()
|
||||
|
||||
@@ -443,8 +443,10 @@ export type ReferenceOfUpdate = Prisma.ref_ref & {
|
||||
ref_journal: Prisma.ref_journal
|
||||
}
|
||||
|
||||
export type LocalityReference = Prisma.now_lr & ReferenceOfUpdate
|
||||
export type SpeciesReference = Prisma.now_sr & ReferenceOfUpdate
|
||||
export type LocalityReference = Prisma.now_lr & { ref_ref: 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 = {
|
||||
journal_id?: number
|
||||
|
||||
Reference in New Issue
Block a user