Navigate to detail page from drawer
This commit is contained in:
parent
499bbabe64
commit
b84bdac78f
|
|
@ -1,4 +1,5 @@
|
||||||
import { Divider, Table, Title } from '@mantine/core';
|
import { StylishText } from '@lib/components/StylishText';
|
||||||
|
import { Divider, Table } from '@mantine/core';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
export interface AttributeRow {
|
export interface AttributeRow {
|
||||||
|
|
@ -22,7 +23,7 @@ export function AttributeGrid({
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Title order={4}>{title}</Title>
|
<StylishText size='md'>{title}</StylishText>
|
||||||
<Table striped withRowBorders={false} fz='sm'>
|
<Table striped withRowBorders={false} fz='sm'>
|
||||||
<Table.Tbody>
|
<Table.Tbody>
|
||||||
{valid.map((item) => (
|
{valid.map((item) => (
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import { Divider, Drawer, LoadingOverlay, Stack } from '@mantine/core';
|
import { Anchor, Divider, Drawer, LoadingOverlay, Stack } from '@mantine/core';
|
||||||
|
|
||||||
import { StylishText } from '@lib/components/StylishText';
|
import { StylishText } from '@lib/components/StylishText';
|
||||||
import { ModelInformationDict } from '@lib/enums/ModelInformation';
|
import { ModelInformationDict } from '@lib/enums/ModelInformation';
|
||||||
import type { ModelType } from '@lib/index';
|
import { type ModelType, getDetailUrl, navigateToLink } from '@lib/index';
|
||||||
import { useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useInstance } from '../../hooks/UseInstance';
|
import { useInstance } from '../../hooks/UseInstance';
|
||||||
import { getModelInfo } from '../render/ModelType';
|
import { getModelInfo } from '../render/ModelType';
|
||||||
import { type PreviewType, getPreviewComponentForModel } from './PreviewType';
|
import { type PreviewType, getPreviewComponentForModel } from './PreviewType';
|
||||||
|
|
@ -26,6 +27,8 @@ export default function PreviewDrawer({
|
||||||
opened: boolean;
|
opened: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}>) {
|
}>) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const modelInfo = modelType ? getModelInfo(modelType) : null;
|
const modelInfo = modelType ? getModelInfo(modelType) : null;
|
||||||
const apiEndpoint = modelType
|
const apiEndpoint = modelType
|
||||||
? ModelInformationDict[modelType].api_endpoint
|
? ModelInformationDict[modelType].api_endpoint
|
||||||
|
|
@ -66,13 +69,32 @@ export default function PreviewDrawer({
|
||||||
return component;
|
return component;
|
||||||
}, [providedPreview, modelType, id, instance]);
|
}, [providedPreview, modelType, id, instance]);
|
||||||
|
|
||||||
|
const clickTitle = useCallback(
|
||||||
|
(event: MouseEvent) => {
|
||||||
|
if (!modelType || !id) return;
|
||||||
|
|
||||||
|
onClose();
|
||||||
|
navigateToLink(getDetailUrl(modelType!, id!), navigate, event);
|
||||||
|
},
|
||||||
|
[modelType, id, navigate]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
position='right'
|
position='right'
|
||||||
size='xl'
|
size='xl'
|
||||||
title={
|
title={
|
||||||
previewComponent ? (
|
previewComponent ? (
|
||||||
<StylishText size='lg'>{previewComponent.title}</StylishText>
|
!!modelType && !!id ? (
|
||||||
|
<Anchor
|
||||||
|
href={getDetailUrl(modelType!, id, true)}
|
||||||
|
onClick={(e) => clickTitle(e)}
|
||||||
|
>
|
||||||
|
<StylishText size='lg'>{previewComponent.title}</StylishText>
|
||||||
|
</Anchor>
|
||||||
|
) : (
|
||||||
|
<StylishText size='lg'>{previewComponent.title}</StylishText>
|
||||||
|
)
|
||||||
) : null
|
) : null
|
||||||
}
|
}
|
||||||
opened={opened}
|
opened={opened}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue