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

feat(console): add datastore result view to job #2486

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions console/src/pages/Job/JobOverviewLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useParams } from 'react-router-dom'
import { INavItem } from '@/components/BaseSidebar'
import { fetchJob } from '@job/services/job'
import BaseSubLayout from '@/pages/BaseSubLayout'
import IconFont from '@starwhale/ui/IconFont'

export interface IJobLayoutProps {
children: React.ReactNode
Expand Down Expand Up @@ -48,11 +47,14 @@ function JobOverviewLayout({ children }: IJobLayoutProps) {

const navItems: INavItem[] = useMemo(() => {
const items = [
{
title: t('Results'),
path: `/projects/${projectId}/jobs/${jobId}/results`,
},
{
title: t('Tasks'),
path: `/projects/${projectId}/jobs/${jobId}/tasks`,
pattern: '/\\/tasks\\/?',
icon: <IconFont type='tasks' />,
},
]
return items
Expand Down
158 changes: 0 additions & 158 deletions console/src/pages/Job/JobResults.tsx

This file was deleted.

90 changes: 90 additions & 0 deletions console/src/pages/Job/JobWidgetResults.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useCallback, useEffect } from 'react'
import { FullTablesEditor } from '@/components/Editor/FullTablesEditor'
import { useParams } from 'react-router-dom'
import { Select } from '@starwhale/ui'
import { useJob } from '@/domain/job/hooks/useJob'
import { fetchPanelSetting, updatePanelSetting } from '@/domain/panel/services/panel'
import { toaster } from 'baseui/toast'
import { fetchModelVersionPanelSetting } from '@model/services/modelVersion'
import { getToken } from '@/api'
import { tryParseSimplified } from '@/domain/panel/utils'
import { useProject } from '@project/hooks/useProject'
import useTranslation from '@/hooks/useTranslation'

interface Layout {
name: string
content: string | object
label: string
}

function JobWidgetResults() {
const [t] = useTranslation()
const { projectId: projectFromUri } = useParams<{ jobId: string; projectId: string }>()
const { project } = useProject()
const projectId = project?.id ?? projectFromUri
const { job } = useJob()
const storeKey = job?.modelName ? ['evaluation-model', job?.modelName].join('-') : ''
const [currentLayout, setCurrentLayout] = React.useState<Layout | undefined>(undefined)
const [layouts, setLayouts] = React.useState<Layout[]>([])
const onStateChange = async (data: any) => {
await updatePanelSetting(projectId, storeKey, data)
toaster.positive(t('panel.save.success'), { autoHideDuration: 2000 })
}

const updateLayout = useCallback((layout: Layout) => {
setLayouts((prevState) => {
const others = prevState.filter((i) => i.name !== layout.name)
others.push(layout)
return others
})
}, [])

useEffect(() => {
fetchModelVersionPanelSetting(project?.name, job?.modelName, job?.modelVersion, getToken()).then((data) => {
if (!data) return
const layout = tryParseSimplified(data) ?? data
updateLayout({ name: 'model-builtin', content: layout, label: t('panel.view.config.model-buildin') })
})
}, [project, job, updateLayout, t])

useEffect(() => {
if (!storeKey) {
return
}
fetchPanelSetting(projectId, storeKey).then((data) => {
if (!data) return
// try simplified version for standalone usage
const parsed = tryParseSimplified(JSON.parse(data)) ?? data
const layout = { name: 'custom', content: parsed, label: t('panel.view.config.custom') }
setCurrentLayout(layout)
updateLayout(layout)
})
}, [projectId, job, storeKey, updateLayout, t])

return (
<div style={{ width: '100%', height: 'auto' }}>
<div style={{ height: '50px', display: 'flex', justifyContent: 'space-between' }}>
<div style={{ display: 'flex' }}>
<Select
overrides={{
ControlContainer: {
style: {
width: '200px',
},
},
}}
clearable={false}
options={layouts.map((layout) => ({ id: layout.name, label: layout.label }))}
value={currentLayout ? [{ id: currentLayout.name, label: currentLayout.name }] : []}
onChange={({ value }) => {
const layout = layouts.find((l) => l.name === value[0].id)
if (layout) setCurrentLayout(layout)
}}
/>
</div>
</div>
<FullTablesEditor initialState={currentLayout?.content} onStateChange={onStateChange} />
</div>
)
}
export default JobWidgetResults
2 changes: 1 addition & 1 deletion console/src/pages/Project/ProjectListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const ProjectCard = ({ project, onEdit, onRefresh }: IProjectCardProps) => {
<div className={styles.projectCard}>
<div className={styles.row}>
<div className={styles.name}>
<TextLink className={styles.text} to={`/projects/${project.id}/evaluations`}>
<TextLink className={styles.text} to={`/projects/${project.id}/jobs`}>
{[project.owner?.name, project.name].join('/')}
</TextLink>
</div>
Expand Down
4 changes: 2 additions & 2 deletions console/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import DatasetOverviewLayout from '@/pages/Dataset/DatasetOverviewLayout'
import JobNewCard from '@/pages/Project/JobNewCard'
import ApiHeader from '@/api/ApiHeader'
import JobTasks from '@/pages/Job/JobTasks'
import JobResults from '@/pages/Job/JobResults'
import JobWidgetResults from '@/pages/Job/JobWidgetResults'
import JobOverviewLayout from '@/pages/Job/JobOverviewLayout'
import SettingsOverviewLayout from '@/pages/Settings/SettingsOverviewLayout'
import SettingAgentListCard from '@/pages/Settings/SettingAgentListCard'
Expand Down Expand Up @@ -168,7 +168,7 @@ const Routes = () => {
<Route
exact
path='/projects/:projectId/jobs/:jobId/results'
component={JobResults}
component={JobWidgetResults}
/>
<Redirect
from='/projects/:projectId/jobs/:jobId'
Expand Down
Loading