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

add an operator module to the settings page #271

Merged
merged 2 commits into from
Sep 12, 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
80 changes: 11 additions & 69 deletions src/components/IDE/EventLogs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,9 @@ import { VscDebugStart } from 'react-icons/vsc';
import { hooks } from '@/lib/hooks';
import { AiOutlineClear } from 'react-icons/ai';
import { ShowRequestTemplatesButton } from '../PublishEventRequestTemplates';
import { motion, isValidMotionProp } from 'framer-motion';
import toast from 'react-hot-toast';
import { helper } from '@/lib/helper';

const ChakraBox = chakra(motion.div, {
/**
* Allow motion props and non-Chakra props to be forwarded.
*/
shouldForwardProp: (prop) => isValidMotionProp(prop) || shouldForwardProp(prop)
});

const LiveIcon = () => {
return (
<Box w="40px" pos="relative" boxSizing="border-box" transform="scale(0.6)">
<ChakraBox
w="30px"
h="30px"
m="0 auto 5px"
borderRadius="50%"
border="1px solid #946FFF"
opacity="0.8"
boxSizing="border-box"
animate={{
scale: [1, 1.5],
opacity: [0.8, 0]
}}
transition={{
duration: 2,
ease: 'easeInOut',
repeatType: 'loop',
// @ts-ignore
repeat: Infinity
}}
/>
<ChakraBox
pos="absolute"
top="8px"
left="13px"
w="14px"
h="14px"
borderRadius="50%"
opacity="0.8"
boxSizing="border-box"
bg="#946FFF"
_after={{
content: "''",
display: 'block',
border: '2px solid #946FFF',
borderRadius: '50%',
width: '20px',
height: '20px',
top: '-5px',
left: '-5px',
position: 'absolute',
opacity: 0.8
}}
animate={{
scale: [1, 1.5],
opacity: [0.8, 0]
}}
transition={{
duration: 2,
ease: 'easeInOut',
repeatType: 'loop',
// @ts-ignore
repeat: Infinity
}}
/>
</Box>
);
};

type LocalStoreType = {
loading: boolean;
initialized: boolean;
Expand Down Expand Up @@ -366,3 +297,14 @@ const EventLogs = observer(() => {
});

export default EventLogs;

const LiveIcon = () => {
return (
<div className="relative ml-2">
<span className="absolute -top-2 w-4 h-4">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-[#946FFF] opacity-75"></span>
<span className="absolute inline-flex rounded-full w-4 h-4 bg-[#946FFF]"></span>
</span>
</div>
);
};
55 changes: 55 additions & 0 deletions src/components/IDE/UserSettings/Operators/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Flex, Button, Text, Spinner, Center } from '@chakra-ui/react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@/store/index';
import { defaultButtonStyle } from '@/lib/theme';
import JSONTable from '@/components/JSONTable';
import { hooks } from '@/lib/hooks';

export const Operators = observer(() => {
const {
w3s: { operator }
} = useStore();
operator.useOperators();

return (
<>
<Flex>
<Text fontSize={'18px'} fontWeight={600}>
Operators
</Text>
<Button
ml="auto"
size="sm"
fontWeight={400}
{...defaultButtonStyle}
isLoading={operator.createOperator.loading.value}
onClick={async () => {
const formData = await hooks.getFormData({
title: 'Create operator',
size: 'xl',
formList: [
{
form: operator.form
}
]
});
operator.createOperator.call(formData);
}}
>
Create operator
</Button>
</Flex>

<Text fontSize="14px" color="#7a7a7a">
Create your operators
</Text>
{operator.list.loading.value ? (
<Center w="full">
<Spinner />
</Center>
) : (
<JSONTable jsonstate={operator} />
)}
</>
);
});
13 changes: 6 additions & 7 deletions src/components/IDE/UserSettings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
import React, { useEffect } from 'react';
import { Box } from '@chakra-ui/react';
import dynamic from 'next/dynamic';
import { observer } from 'mobx-react-lite';
import { useStore } from '@/store/index';
import Header from '@/components/IDE/Header';
import { ApiKeys } from './ApiKeys';
import { Operators } from './Operators';

const UserSettings = observer(() => {
const {
w3s,
base: { confirm }
} = useStore();
const { w3s } = useStore();

useEffect(() => {
w3s.user.userSetting.call()
w3s.user.userSetting.call();
}, []);

return (
<Box w="100%" h="100%" p="40px 30px" bg="#fff" borderRadius="8px">
<Box mt="30px" p="20px" border="1px solid #eee" borderRadius="8px">
<ApiKeys />
</Box>
<Box mt="30px" p="20px" border="1px solid #eee" borderRadius="8px">
<Operators />
</Box>
</Box>
);
});
Expand Down
52 changes: 30 additions & 22 deletions src/components/JSONTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { Button, Center, Table as ChakraTable, TableContainer, Tbody, Td, Th, Thead, Tr, useDisclosure,Text } from '@chakra-ui/react';
import { Button, Center, Table as ChakraTable, TableContainer, Tbody, Td, Th, Thead, Tr, useDisclosure, Text } from '@chakra-ui/react';
import SimplePagination from '../Common/SimplePagination';
import { ChevronDownIcon, ChevronRightIcon } from '@chakra-ui/icons';
import { ActionButtonType, Column, ExtendedTable, JSONSchemaTableState } from '@/store/standard/JSONSchemaState';
Expand Down Expand Up @@ -34,8 +34,10 @@ const JSONTable = observer(<T,>(props: JSONTableProps<T>) => {
<Tr bg="#F5F5F5">
{needExtendedTable && <Th></Th>}
{columns.map((item) => (
<Th key={item.key} textTransform="none">
<Text fontSize="14px" fontWeight={400} color="blackAlpha.800">{item.label}</Text>
<Th key={item.key} textTransform="none">
<Text fontSize="14px" fontWeight={400} color="blackAlpha.800">
{item.label}
</Text>
</Th>
))}
</Tr>
Expand All @@ -50,19 +52,25 @@ const JSONTable = observer(<T,>(props: JSONTableProps<T>) => {
)}
</Tbody>
</ChakraTable>
{pagination.total == 0 && <Center mt="20px" fontSize={"14px"} color="#7a7a7a">No Data</Center>}
{pagination.total == 0 && (
<Center mt="20px" fontSize={'14px'} color="#7a7a7a">
No Data
</Center>
)}
</TableContainer>
{pagination.total > pagination.limit && <SimplePagination
mt="10px"
total={pagination.total}
limit={pagination.limit}
page={pagination.page}
onPageChange={(currentPage) => {
pagination.setData({
page: currentPage
});
}}
/>}
{pagination.total > pagination.limit && (
<SimplePagination
mt="10px"
total={pagination.total}
limit={pagination.limit}
page={pagination.page}
onPageChange={(currentPage) => {
pagination.setData({
page: currentPage
});
}}
/>
)}
</>
);
});
Expand Down Expand Up @@ -94,12 +102,12 @@ function Body<T>({ item, columns }: { item: T; columns: Column<T>[] }) {
<Tr fontSize="14px" color="#0F0F0F">
{columns.map((column) => {
return (
<Td key={column.key} fontSize={'12px'} border="1px solid #F5F5F5" maxW="200px" overflowX="auto" >
<Td key={column.key} fontSize={'12px'} border="1px solid #F5F5F5" maxW="200px" overflowX="auto">
{column.actions
? column.actions(item).map((btn, index) => <ActionButton key={index} props={btn.props} text={btn.text} />)
: column.render
? column.render(item)
: renderFieldValue(item[column.key])}
? column.render(item)
: renderFieldValue(item[column.key])}
</Td>
);
})}
Expand Down Expand Up @@ -131,8 +139,8 @@ function CollapseBody<T>({ item, columns, extendedTables }: { item: T; columns:
{column.actions
? column.actions(item).map((btn, index) => <ActionButton key={index} props={btn.props} text={btn.text} />)
: column.render
? column.render(item)
: renderFieldValue(item[column.key])}
? column.render(item)
: renderFieldValue(item[column.key])}
</Td>
);
})}
Expand Down Expand Up @@ -166,8 +174,8 @@ function CollapseBody<T>({ item, columns, extendedTables }: { item: T; columns:
{exC.actions
? exC.actions(exItem).map((btn, index) => <ActionButton key={index} props={btn.props} text={btn.text} />)
: exC.render
? exC.render(exItem)
: renderFieldValue(exItem[exC.key])}
? exC.render(exItem)
: renderFieldValue(exItem[exC.key])}
</Td>
);
})}
Expand Down
2 changes: 2 additions & 0 deletions src/store/lib/w3bstream/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import LabModule from './schema/lab';
import CronJobModule from './schema/cronJob';
import ENVModule from './schema/envs';
import ApiKeysModule from './schema/apiKeys';
import OperatorModule from './schema/operator';

configure({
enforceActions: 'never'
Expand All @@ -42,6 +43,7 @@ export class W3bStream {
strategy = new StrategyModule();
contractLogs = new ContractLogModule();
apiKeys = new ApiKeysModule();
operator = new OperatorModule();
chainTx = new ChainTxModule();
chainHeight = new ChainHeightModule();
dbTable = new DBTableModule();
Expand Down
Loading