Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize(console): dataset layout & fullscreen #1585

Merged
merged 7 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions console/packages/starwhale-core/src/form/WidgetPreviewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,7 @@ export default function WidgetPreviewModal({
)}
</div>
</ModalBody>
<ModalFooter>
<div style={{ display: 'flex' }}>
<div style={{ flexGrow: 1 }} />
<Button
size='compact'
kind='secondary'
onClick={() => {
setisPanelModalOpen(false)
}}
>
Cancel
</Button>
</div>
</ModalFooter>
<ModalFooter></ModalFooter>
</Modal>
)
}
2 changes: 1 addition & 1 deletion console/src/components/BaseNavTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function BaseNavTabs({ navItems, fill = 'intrinsic', tabsOverrides, tabOv
const item = navItems
.slice()
.reverse()
.find((item_) => _.startsWith(location.pathname, item_.path))
.find((item_) => _.startsWith(item_.path, location.pathname))
jialeicui marked this conversation as resolved.
Show resolved Hide resolved
return item?.path
}, [location.pathname, navItems])

Expand Down
2 changes: 2 additions & 0 deletions console/src/components/Viewer/ImageGrayscaleViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export default function ImageGrayscaleViewer({ isZoom = false, data }: IImageVie
<div className='dataset-viewer image-grayscale fullsize'>
<ZoomWrapper>
<canvas
width={500}
height={500}
ref={canvasRef}
style={{
zIndex: 1,
Expand Down
3 changes: 2 additions & 1 deletion console/src/components/Viewer/ZoomWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Button from '@starwhale/ui/Button'
import React from 'react'
import { TransformComponent, TransformWrapper } from 'react-zoom-pan-pinch'
import { Button } from '@/components/Button'

export default function ZoomWrapper({ children, isTools }: any) {
return (
Expand All @@ -12,6 +12,7 @@ export default function ZoomWrapper({ children, isTools }: any) {
maxScale={10}
minScale={0.5}
>
{/* eslint-disable-next-line @typescript-eslint/no-unused-vars */}
{({ zoomIn, zoomOut, resetTransform, centerView }) => (
<>
{isTools && (
Expand Down
2 changes: 1 addition & 1 deletion console/src/pages/Dataset/DatasetOverviewLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export default function DatasetOverviewLayout({ children }: IDatasetLayoutProps)
},
{
title: t('Files'),
path: `/projects/${projectId}/datasets/${datasetId}/versions/${datasetVersionId}/files`,
path: `/projects/${projectId}/datasets/${datasetId}/versions/${datasetVersionId}/files?layout=1`,
pattern: '/\\/files\\/?',
},
]
Expand Down
80 changes: 46 additions & 34 deletions console/src/pages/Dataset/DatasetVersionOverviewFilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react'
import Button from '@/components/Button'
import DatasetViewer from '@/components/Viewer/DatasetViewer'
import { Tabs, Tab } from 'baseui/tabs'
import { Modal, ModalBody, ModalFooter, ModalHeader } from 'baseui/modal'
import { createUseStyles } from 'react-jss'
import useTranslation from '../../hooks/useTranslation'
import IconFont from '../../components/IconFont/index'
import { DatasetObject } from '../../domain/dataset/sdk'
import { RAW_COLORS } from '../../components/Viewer/utils'
Expand Down Expand Up @@ -40,6 +40,9 @@ const useStyles = createUseStyles({
position: 'relative',
display: 'flex',
flexDirection: 'column',
marginTop: 0,
marginBottom: 0,
border: '1px solid #CFD7E6',
},
layoutFullscreen: {
position: 'fixed',
Expand All @@ -50,13 +53,6 @@ const useStyles = createUseStyles({
top: 0,
zIndex: 20,
},
exitFullscreen: {
height: '56px',
paddingLeft: '24px',
display: 'flex',
alignItems: 'center',
borderBottom: '1px solid #E2E7F0',
},
wrapper: {
minHeight: '500px',
height: '100%',
Expand Down Expand Up @@ -122,7 +118,6 @@ export default function DatasetVersionFilePreview({
}, [datasets, fileId])

const styles = useStyles()
const [t] = useTranslation()
const [activeKey, setActiveKey] = React.useState('0')
const [hiddenLabels, setHiddenLabels] = React.useState<Set<number>>(new Set())

Expand All @@ -139,6 +134,7 @@ export default function DatasetVersionFilePreview({
/>
)
}
if (!data?.summary || Object.keys(data?.summary).length === 0) return undefined

// eslint-disable-next-line @typescript-eslint/no-use-before-define
return <Summary data={data?.summary ?? {}} />
Expand All @@ -147,33 +143,49 @@ export default function DatasetVersionFilePreview({
if (!isFullscreen) return <></>

return (
<div className={isFullscreen ? styles.layoutFullscreen : styles.layoutNormal}>
{isFullscreen && (
<div className={styles.exitFullscreen}>
<Button
as='link'
startEnhancer={() => <IconFont type='close' />}
onClick={() => setIsFullscreen(false)}
>
{t('Exit Fullscreen')}
</Button>
</div>
)}
<div className={styles.wrapper}>
<div className={styles.panel}>{Panel}</div>
<div className={styles.card}>
<div
role='button'
tabIndex={0}
className={styles.cardFullscreen}
onClick={() => setIsFullscreen((v: boolean) => !v)}
>
<IconFont type='fullscreen' />
<Modal
isOpen={isFullscreen}
onClose={() => setIsFullscreen(false)}
closeable
animate
autoFocus
overrides={{
Dialog: {
style: {
width: '90vw',
maxWidth: '1200px',
maxHeight: '640px',
display: 'flex',
flexDirection: 'column',
},
},
}}
>
<ModalHeader />
<ModalBody
style={{ display: 'flex', gap: '30px', flex: 1, overflow: 'auto' }}
className={styles.layoutNormal}
>
<div className={styles.wrapper}>
{Panel && <div className={styles.panel}>{Panel}</div>}
<div className={styles.card}>
{!isFullscreen && (
<div
role='button'
tabIndex={0}
className={styles.cardFullscreen}
onClick={() => setIsFullscreen((v: boolean) => !v)}
>
<IconFont type='fullscreen' />
</div>
)}

<DatasetViewer data={data} isZoom hiddenLabels={hiddenLabels} />
</div>
<DatasetViewer data={data} isZoom hiddenLabels={hiddenLabels} />
</div>
</div>
</div>
</ModalBody>
<ModalFooter />
</Modal>
)
}

Expand Down
12 changes: 9 additions & 3 deletions console/src/pages/Dataset/DatasetVersionOverviewFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export default function DatasetVersionFiles() {
}
}, [page, layoutKey])

React.useEffect(() => {
setLayoutKey(layoutParam)
}, [layoutParam])

const tables = useQueryDatasetList(datasetVersion?.indexTable, $page, true)

const rowCount = React.useMemo(() => {
Expand Down Expand Up @@ -206,7 +210,6 @@ export default function DatasetVersionFiles() {
)

const Records = React.useMemo(() => {
// if (fileId || !tables.data) return <></>
const { summary = {} } = datasets?.[0] ?? {}

const rowAction = [
Expand Down Expand Up @@ -237,7 +240,10 @@ export default function DatasetVersionFiles() {

switch (row.type) {
case TYPES.IMAGE:
wrapperStyle = { minHeight: '90px', maxWidth: '100px' }
wrapperStyle = {
minHeight: '90px',
maxWidth: layoutKey === LAYOUT.GRID ? undefined : '100px',
}
break
case TYPES.AUDIO:
wrapperStyle = { minHeight: '90px' }
Expand Down Expand Up @@ -296,7 +302,7 @@ export default function DatasetVersionFiles() {
style={{
display: 'grid',
gap: '9px',
gridTemplateColumns: 'repeat(auto-fit, minmax(161px, 200px))',
gridTemplateColumns: 'repeat(auto-fit, minmax(161px, 1fr))',
placeItems: 'center',
}}
>
Expand Down
7 changes: 4 additions & 3 deletions console/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
"src/stories",
"**/iconfont.js",
"baseui/helpers/overrides",
"node_modules/baseui/helpers/**",
"node_modules/baseui/helpers/overrides.js",
"**/__generated__/**"
"**/node_modules/**",
"**/__generated__/**",
"**/build/**"

]
}