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

perf(api): split all project interface #209

Merged
merged 2 commits into from
Jun 5, 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
44 changes: 31 additions & 13 deletions src/components/IDE/CurrentProject/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Flex, Box } from '@chakra-ui/react';
import { Flex, Box, Spinner } from '@chakra-ui/react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@/store/index';
import dynamic from 'next/dynamic';
Expand Down Expand Up @@ -31,21 +31,39 @@ const DynamicSettings = dynamic(() => import('../Settings'), {

const CurrentProject = observer(() => {
const {
w3s: { showContent }
w3s,
w3s: { showContent },
lang: { t }
} = useStore();
const { projectDetail } = w3s.project;

return (
<Flex w="100%" minH="100%" position="relative">
<ToolBar borderRadius="8px" overflowY="auto" />
<Box ml="220px" w="calc(100% - 220px)" minH="100%" p="12px 24px" bg="#fff" borderRadius="8px">
{showContent === 'METRICS' && <DynamicMetrics />}
{showContent === 'CURRENT_PUBLISHERS' && <DynamicPublishers />}
{(showContent === 'CONTRACT_LOGS' || showContent === 'CHAIN_TX' || showContent === 'CHAIN_HEIGHT') && <DynamicTriggers />}
{showContent === 'DB_TABLE' && <DynamicDBTable />}
{showContent === 'CURRENT_EVENT_LOGS' && <DynamicEventLogs />}
{showContent === 'SETTINGS' && <DynamicSettings />}
</Box>
</Flex>
<>
{/* {projectDetail.loading.value ? (
<Flex h="calc(100vh - 158px)" alignItems={'center'} justifyContent={'center'}>
<Spinner color="#946FFF" />
</Flex>
) : ( */}
<Flex w="100%" minH="100%" position="relative">
<ToolBar borderRadius="8px" overflowY="auto" />
<Box ml="220px" w="calc(100% - 220px)" minH="100%" p="12px 24px" bg="#fff" borderRadius="8px">
{!projectDetail.value ? (
<Flex h="calc(100vh - 158px)" alignItems={'center'} justifyContent={'center'}>
<Spinner color="#946FFF" />
</Flex>
) : (
<>
{showContent === 'METRICS' && <DynamicMetrics />}
{showContent === 'CURRENT_PUBLISHERS' && <DynamicPublishers />}
{(showContent === 'CONTRACT_LOGS' || showContent === 'CHAIN_TX' || showContent === 'CHAIN_HEIGHT') && <DynamicTriggers />}
{showContent === 'DB_TABLE' && <DynamicDBTable />}
{showContent === 'CURRENT_EVENT_LOGS' && <DynamicEventLogs />}
{showContent === 'SETTINGS' && <DynamicSettings />}
</>
)}
</Box>
</Flex>
</>
);
});

Expand Down
9 changes: 5 additions & 4 deletions src/components/IDE/Projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Projects = observer(() => {
base: { confirm },
lang: { t }
} = useStore();
const { allProjects, selectedNames } = w3s.project;
const { allProjects, selectedNames, projectDetail } = w3s.project;

if (allProjects.value.length) {
return (
Expand Down Expand Up @@ -145,8 +145,9 @@ const Projects = observer(() => {
onClick={async (e) => {
e.stopPropagation();
if (instance) {
allProjects.onSelect(index);
w3s.showContent = 'METRICS';
allProjects.onSelect(index);
projectDetail.call();
} else {
await w3s.applet.uploadWASM({
projectName: project.name,
Expand Down Expand Up @@ -251,7 +252,7 @@ const Projects = observer(() => {
});
eventBus.emit('instance.handle');
toast.success(t('success.suspended.msg'));
} catch (error) { }
} catch (error) {}
}}
>
<Icon ml="20px" as={AiOutlinePauseCircle} boxSize={'1.25rem'} color="#946FFF" cursor="pointer" _hover={{ color: '#7D44FF' }} />
Expand All @@ -271,7 +272,7 @@ const Projects = observer(() => {
});
eventBus.emit('instance.handle');
toast.success(t('success.started.msg'));
} catch (error) { }
} catch (error) {}
}}
>
<Icon ml="14px" as={AiOutlinePlayCircle} boxSize={'1.25rem'} color="#946FFF" cursor="pointer" _hover={{ color: '#7D44FF' }} />
Expand Down
70 changes: 36 additions & 34 deletions src/components/IDE/ToolBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Flex, BoxProps, Box, Icon, Text, Popover, PopoverTrigger, PopoverContent, useDisclosure } from '@chakra-ui/react';
import { Flex, BoxProps, Box, Icon, Text, Popover, PopoverTrigger, PopoverContent, useDisclosure, Spinner } from '@chakra-ui/react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@/store/index';
import { BiBarChartSquare } from 'react-icons/bi';
Expand All @@ -10,20 +10,18 @@ import { ChevronDownIcon } from '@chakra-ui/icons';
import { INSTANCE_STATUS } from '@/components/JSONTable/FieldRender';
import toast from 'react-hot-toast';

interface ToolBar extends BoxProps { }
interface ToolBar extends BoxProps {}

const ToolBar = (props: ToolBar) => {
const {
w3s,
w3s: {
project: {
curProject,
allProjects
},
project: { curProject, allProjects },
metrics,
instances,
instances
},
lang: { t } } = useStore();
lang: { t }
} = useStore();
const { onOpen, onClose, isOpen } = useDisclosure();

const curProjectStatus = INSTANCE_STATUS[instances.curInstance?.f_state || 0];
Expand All @@ -32,14 +30,18 @@ const ToolBar = (props: ToolBar) => {
<Box position={'fixed'} h="100%" overflow={'auto'}>
<Flex minW="200px" h="100%" direction="column" align="center" p="14px" bg="#fff" {...props}>
<Popover isOpen={isOpen} onOpen={onOpen} onClose={onClose}>
<PopoverTrigger >
<Flex w="168px" cursor={'pointer'} borderRadius={'8px'} px="14px" py="8px" alignItems={'center'} mb="20px" border={'1px solid #EDEDED'}>
<Box flex="none" mr="8px" w={'6px'} h="6px" borderRadius={'50%'} bg={curProjectStatus?.color}></Box>
<Text mr="10px" w="130px" fontSize={"14px"} color={curProjectStatus?.color} whiteSpace={'nowrap'} overflow={'hidden'} textOverflow={'ellipsis'}>
{curProject?.name}
</Text>
<ChevronDownIcon fontSize={'24px'} color={'#7A7A7A'} />
</Flex>
<PopoverTrigger>
{curProject ? (
<Flex w="168px" cursor={'pointer'} borderRadius={'8px'} px="14px" py="8px" alignItems={'center'} mb="20px" border={'1px solid #EDEDED'}>
<Box flex="none" mr="8px" w={'6px'} h="6px" borderRadius={'50%'} bg={curProjectStatus?.color}></Box>
<Text mr="10px" w="130px" fontSize={'14px'} color={curProjectStatus?.color} whiteSpace={'nowrap'} overflow={'hidden'} textOverflow={'ellipsis'}>
{curProject?.name}
</Text>
<ChevronDownIcon fontSize={'24px'} color={'#7A7A7A'} />
</Flex>
) : (
<></>
)}
</PopoverTrigger>
<PopoverContent
bg="#F8F8FA"
Expand Down Expand Up @@ -71,7 +73,7 @@ const ToolBar = (props: ToolBar) => {
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000)
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000);
metrics.activeDevices.call(yesterday, now);
metrics.dataMessages.call(yesterday, now);
metrics.blockchainTransaction.call(yesterday, now);
Expand All @@ -88,7 +90,7 @@ const ToolBar = (props: ToolBar) => {
justifyContent="flex-start"
>
<Box flex="none" mr="8px" w={'6px'} h="6px" borderRadius={'50%'} bg={status?.color}></Box>
<Text color={curProject.name === item.name ? status?.color : ''}>{item.name}</Text>
<Text color={curProject?.name === item.name ? status?.color : ''}>{item.name}</Text>
</Flex>
);
})}
Expand Down Expand Up @@ -209,29 +211,29 @@ const ToolBar = (props: ToolBar) => {
export function getSelectedStyles(selected: boolean) {
return selected
? {
sx: {
background: 'rgba(148, 111, 255, 0.1)',
'& > svg': {
color: '#946FFF'
},
'& > div': {
color: '#946FFF'
}
}
}
: {
sx: {
':hover': {
sx: {
background: 'rgba(148, 111, 255, 0.1)',
'& > svg': {
color: '#946FFF'
},
'& > div': {
color: '#946FFF'
},
background: 'rgba(148, 111, 255, 0.1)'
}
}
}
};
: {
sx: {
':hover': {
'& > svg': {
color: '#946FFF'
},
'& > div': {
color: '#946FFF'
},
background: 'rgba(148, 111, 255, 0.1)'
}
}
};
}

export default observer(ToolBar);
7 changes: 3 additions & 4 deletions src/components/IDE/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const DynamicProjects = dynamic(() => import('./Projects'), {

const DynamicLabs = dynamic(() => import('./Labs'), {
ssr: false,
loading: () => <p>Loading</p>,
loading: () => <p>Loading</p>
});

const DynamicFlow = dynamic(() => import('./Flow'), {
Expand All @@ -29,7 +29,6 @@ const DynamicSupport = dynamic(() => import('./Support'), {
ssr: false
});


const IDE = observer(() => {
const {
w3s,
Expand All @@ -40,8 +39,8 @@ const IDE = observer(() => {
<Box w="100vw" h="100vh" overflow="auto" bg="#F8F8FA" paddingTop={'70px'} boxSizing="border-box">
<Header />
<Box w="100%" px="20px" minH="calc(100vh - 70px)">
{w3s.currentHeaderTab === 'PROJECTS' && <>{w3s.project.curProject ? <DynamicCurrentProject /> : <DynamicProjects />}</>}
{w3s.currentHeaderTab === 'LABS' && (<DynamicLabs />)}
{w3s.currentHeaderTab === 'PROJECTS' && <>{w3s.project.allProjects.currentIndex != -1 ? <DynamicCurrentProject /> : <DynamicProjects />}</>}
{w3s.currentHeaderTab === 'LABS' && <DynamicLabs />}
{w3s.currentHeaderTab === 'FLOW' && <DynamicFlow />}
{w3s.currentHeaderTab === 'SUPPORT' && <DynamicSupport />}
</Box>
Expand Down
Loading