From cdae1e848d104165e906a62ab9afb090f99bd104 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Tue, 7 Jan 2025 12:10:47 -0800 Subject: [PATCH] refactor(weave): dedicated component for dataset versions --- .../Browse3/datasets/DatasetVersionPage.tsx | 145 ++++++++++++++++++ .../Home/Browse3/pages/ObjectVersionPage.tsx | 16 +- 2 files changed, 152 insertions(+), 9 deletions(-) create mode 100644 weave-js/src/components/PagePanelComponents/Home/Browse3/datasets/DatasetVersionPage.tsx diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/datasets/DatasetVersionPage.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/datasets/DatasetVersionPage.tsx new file mode 100644 index 000000000000..be970af34243 --- /dev/null +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/datasets/DatasetVersionPage.tsx @@ -0,0 +1,145 @@ +import Box from '@mui/material/Box'; +import React, {useMemo} from 'react'; + +import {Icon} from '../../../../Icon'; +import {LoadingDots} from '../../../../LoadingDots'; +import {Tailwind} from '../../../../Tailwind'; +import {WeaveCHTableSourceRefContext} from '../pages/CallPage/DataTableView'; +import {ObjectViewerSection} from '../pages/CallPage/ObjectViewerSection'; +import {objectVersionText} from '../pages/common/Links'; +import {CenteredAnimatedLoader} from '../pages/common/Loader'; +import { + ScrollableTabContent, + SimplePageLayoutWithHeader, +} from '../pages/common/SimplePageLayout'; +import {TabUseDataset} from '../pages/TabUseDataset'; +import {useWFHooks} from '../pages/wfReactInterface/context'; +import {objectVersionKeyToRefUri} from '../pages/wfReactInterface/utilities'; +import {ObjectVersionSchema} from '../pages/wfReactInterface/wfDataModelHooksInterface'; +import {CustomWeaveTypeProjectContext} from '../typeViews/CustomWeaveTypeDispatcher'; + +export const DatasetVersionPage: React.FC<{ + objectVersion: ObjectVersionSchema; +}> = ({objectVersion}) => { + const {useRootObjectVersions, useRefsData} = useWFHooks(); + const entityName = objectVersion.entity; + const projectName = objectVersion.project; + const objectName = objectVersion.objectId; + const objectVersionIndex = objectVersion.versionIndex; + + const objectVersions = useRootObjectVersions( + entityName, + projectName, + { + objectIds: [objectName], + }, + undefined, + true + ); + const objectVersionCount = (objectVersions.result ?? []).length; + const refUri = objectVersionKeyToRefUri(objectVersion); + + const data = useRefsData([refUri]); + const viewerData = useMemo(() => { + if (data.loading) { + return {}; + } + return data.result?.[0] ?? {}; + }, [data.loading, data.result]); + + const viewerDataAsObject = useMemo(() => { + const dataIsPrimitive = + typeof viewerData !== 'object' || + viewerData === null || + Array.isArray(viewerData); + if (dataIsPrimitive) { + return {_result: viewerData}; + } + return viewerData; + }, [viewerData]); + + return ( + +
+
+ +
+ {objectVersionText(objectName, objectVersionIndex)} +
+ + } + headerContent={ + +
+
+

Name

+
+
+ {objectName} + {objectVersions.loading ? ( + + ) : ( + + ({objectVersionCount} version + {objectVersionCount !== 1 ? 's' : ''}) + + )} +
+
+
+
+

Version

+

{objectVersionIndex}

+
+
+
+ } + tabs={[ + { + label: 'Rows', + content: ( + + + {data.loading ? ( + + ) : ( + + + + + + )} + + + ), + }, + { + label: 'Use', + content: ( + + + + + + ), + }, + ]} + /> + ); +}; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ObjectVersionPage.tsx b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ObjectVersionPage.tsx index 085587a64d8c..1b0bb491f1c0 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ObjectVersionPage.tsx +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ObjectVersionPage.tsx @@ -7,6 +7,7 @@ import {Icon, IconName} from '../../../../Icon'; import {LoadingDots} from '../../../../LoadingDots'; import {Tailwind} from '../../../../Tailwind'; import {Tooltip} from '../../../../Tooltip'; +import {DatasetVersionPage} from '../datasets/DatasetVersionPage'; import {NotFoundPanel} from '../NotFoundPanel'; import {CustomWeaveTypeProjectContext} from '../typeViews/CustomWeaveTypeDispatcher'; import {WeaveCHTableSourceRefContext} from './CallPage/DataTableView'; @@ -27,7 +28,6 @@ import { } from './common/SimplePageLayout'; import {EvaluationLeaderboardTab} from './LeaderboardTab'; import {TabPrompt} from './TabPrompt'; -import {TabUseDataset} from './TabUseDataset'; import {TabUseModel} from './TabUseModel'; import {TabUseObject} from './TabUseObject'; import {TabUsePrompt} from './TabUsePrompt'; @@ -198,6 +198,10 @@ const ObjectVersionPageInner: React.FC<{ return ; } + if (isDataset) { + return ; + } + return ( + - ) : baseObjectClass === 'Dataset' ? ( - ) : baseObjectClass === 'Model' ? (