From 6bd9bfacc5fb184fff9709cba3b54f06769e44e1 Mon Sep 17 00:00:00 2001 From: bufan Date: Thu, 25 Jan 2024 04:07:22 +0800 Subject: [PATCH] update new composite action --- .../src/components/model/ModelList.tsx | 215 +++++++++--------- 1 file changed, 112 insertions(+), 103 deletions(-) diff --git a/packages/client/dashboard/src/components/model/ModelList.tsx b/packages/client/dashboard/src/components/model/ModelList.tsx index 52abaa9..c1edacd 100644 --- a/packages/client/dashboard/src/components/model/ModelList.tsx +++ b/packages/client/dashboard/src/components/model/ModelList.tsx @@ -1,7 +1,17 @@ import { useSession } from '@us3r-network/auth-with-rainbowkit' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' -import { Button, Dialog, DialogTrigger, Menu, MenuItem, MenuTrigger, Modal, ModalOverlay, Popover } from 'react-aria-components' -import { useLocation, useNavigate, useSearchParams } from 'react-router-dom' +import { + Button, + Dialog, + DialogTrigger, + Menu, + MenuItem, + MenuTrigger, + Modal, + ModalOverlay, + Popover +} from 'react-aria-components' +import { useLocation, useNavigate } from 'react-router-dom' import styled from 'styled-components' import { deleteDappComposites, getDappComposites } from '../../api/composite' import { updateDapp } from '../../api/dapp' @@ -10,7 +20,12 @@ import { useAppCtx } from '../../context/AppCtx' import { useCeramicNodeCtx } from '../../context/CeramicNodeCtx' import useIsOwner from '../../hooks/useIsOwner' import useSelectedDapp from '../../hooks/useSelectedDapp' -import { CeramicStatus, DappCompositeDto, ModelStream, Network } from '../../types.d' +import { + CeramicStatus, + DappCompositeDto, + ModelStream, + Network +} from '../../types.d' import { shortPubKey } from '../../utils/shortPubKey' import CopyTint from '../common/CopyTint' import MergeIcon from '../icons/MergeIcon' @@ -23,6 +38,16 @@ import FavoriteModel from './FavoriteModal' import MergeModal from './MergeModal' import { getCompositeDefaultSchema } from '../../utils/composedb-types/schemas' +enum OPEN_MODAL { + NONE, + CREATE_NEW_MODEL, + ADD_FROM_ALL_MODELS, + ADD_FROM_FAVORITE_MODELS, + CREATE_NEW_COMPOSITE, + ADD_FROM_ALL_COMPOSITES, + ADD_FROM_FAVORITE_COMPOSITES +} + export default function ModelList ({ editable, selectComposite, @@ -159,6 +184,7 @@ export default function ModelList ({ const isMetrics = location.pathname.endsWith('statistic') const isSdk = location.pathname.endsWith('sdk') + const [openModal, setOpenModal] = useState(OPEN_MODAL.NONE) if (loading) { return ( @@ -173,8 +199,6 @@ export default function ModelList ({

Models

- - {editable && isOwner && (!currCeramicNode || @@ -200,15 +224,15 @@ export default function ModelList ({ { if (id === 'explore') { - navigate(`/dapp/${appId}/explore`) + navigate(`/dapp/${appId}/explore/model`) return } if (id === 'favorite') { - document.getElementById('add-from-favorite')?.click() + setOpenModal(OPEN_MODAL.ADD_FROM_FAVORITE_MODELS) return } if (id === 'create') { - document.getElementById('create-new')?.click() + setOpenModal(OPEN_MODAL.CREATE_NEW_MODEL) return } }} @@ -244,12 +268,48 @@ export default function ModelList ({ <>

Composites

- {editable && isOwner && ( - - )} + {editable && + isOwner && + (!currCeramicNode || + currCeramicNode.status !== CeramicStatus.RUNNING ? ( + + + + + + {({ close }) => ( + + )} + + + + + ) : ( + + + + { + if (id === 'explore') { + navigate(`/dapp/${appId}/explore/composite`) + return + } + if (id === 'create') { + setOpenModal(OPEN_MODAL.CREATE_NEW_COMPOSITE) + return + } + }} + > + Explore Composites + Create New Composites + + + + ))}
)} + setOpenModal(OPEN_MODAL.NONE)} + > + {({ close }) => } + + setOpenModal(OPEN_MODAL.NONE)} + > + + {({ close }) => ( + + )} + + + setOpenModal(OPEN_MODAL.NONE)} + > + {({ close }) => } + {editable && isOwner && ( @@ -322,11 +408,11 @@ function DappCompositeList ({ >
{item.name}
{editable && ( - { + { await removeAction(item.id) }} - streamId={item.id + ''} + id={item.id + ''} /> )}
@@ -374,9 +460,9 @@ function DappModelList ({ >
{item.stream_content.name}
{editable && ( - )} @@ -402,12 +488,12 @@ function DappModelList ({ ) } -function ModelListItemTrash ({ - streamId, - removeModelAction +function RemoveButton ({ + id, + removeAction }: { - streamId: string - removeModelAction: (modelId: string) => Promise + id: string + removeAction: (id: string) => Promise }) { const [removing, setRemoving] = useState(false) if (removing) { @@ -422,7 +508,7 @@ function ModelListItemTrash ({ onClick={async e => { e.stopPropagation() setRemoving(true) - await removeModelAction(streamId) + await removeAction(id) setRemoving(false) }} > @@ -431,83 +517,6 @@ function ModelListItemTrash ({ ) } -function Favorite () { - return ( - - - - - {({ close }) => } - - - - ) -} - -function CreateNew () { - const [searchParams] = useSearchParams() - useEffect(() => { - if (searchParams.get('create-new') === 'true') { - document.getElementById('create-new')?.click() - } - }, [searchParams]) - return ( - - - - - - {({ close }) => } - - - - - ) -} - -function CreateComposite ({ - loadDappComposites, - dappModels -}: { - loadDappComposites: () => Promise - dappModels: ModelStream[] -}) { - return ( - - - - - - {({ close }) => ( - - )} - - - - - ) -} - const ListBox = styled.div` background: #1b1e23; border: 1px solid #39424c;