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

Improve Datacontract page #447

Draft
wants to merge 66 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0c38257
Initialize page update
AlexeyTripleA Jan 27, 2025
eb5a8cd
Update tabs container
AlexeyTripleA Jan 27, 2025
9c60d9e
Create DataContractTotalCard
AlexeyTripleA Jan 27, 2025
ed0ae71
Add creation date display
AlexeyTripleA Jan 27, 2025
d9050b7
Update DataContractTotalCard styles
AlexeyTripleA Jan 27, 2025
17ff5f0
Update owner field styles
AlexeyTripleA Jan 27, 2025
603689f
Update data contract styles
AlexeyTripleA Jan 27, 2025
5eb395f
Create $border-radius-medium scss variable
AlexeyTripleA Jan 28, 2025
24f664b
Replace border radius values with variable
AlexeyTripleA Jan 28, 2025
2dca2c8
Create DigestCard mixin
AlexeyTripleA Jan 28, 2025
0c4d442
Add overflow props for InfoLine value
AlexeyTripleA Jan 28, 2025
df713dc
Add transactionsIcon and DocumentsIcon
AlexeyTripleA Jan 28, 2025
b6221d6
Create DataContractDigestCard component
AlexeyTripleA Jan 28, 2025
c759b37
Update IdentityDigestCard with DigestCard mixin
AlexeyTripleA Jan 28, 2025
5f1876a
Update DataContract page styles
AlexeyTripleA Jan 28, 2025
a89c0ed
Implement DataContractDigestCard on datacontract page
AlexeyTripleA Jan 28, 2025
c2cf142
Upload DataContractDigestCard.js
AlexeyTripleA Jan 28, 2025
6e15997
Remove unused file
AlexeyTripleA Jan 28, 2025
1f90c9f
Update styles import
AlexeyTripleA Jan 28, 2025
7682b5a
Update DataContract Cards styles
AlexeyTripleA Jan 28, 2025
42c25b2
Update DataContractDigestCard styles
AlexeyTripleA Jan 28, 2025
106feca
Update responsive styles of Identifier
AlexeyTripleA Jan 28, 2025
0a072a4
Set style props for Identifiers in DataContractTotalCard
AlexeyTripleA Jan 28, 2025
b42c63a
Update responsive styles
AlexeyTripleA Jan 28, 2025
05b12d2
Create NotActive component for display not active text
AlexeyTripleA Jan 28, 2025
ca73113
Add conditions for display data in DataContractDigestCard
AlexeyTripleA Jan 28, 2025
971df03
Add rate fetch to DataContract page
AlexeyTripleA Jan 28, 2025
823775b
Refactoring DocumentsListItem NotActive text
AlexeyTripleA Jan 29, 2025
7b73259
Refactoring InfoLine NotActive text
AlexeyTripleA Jan 29, 2025
30a084b
Fix document list error state styles
AlexeyTripleA Jan 29, 2025
6e07c27
Refactoring NotActive text inf CreditsBlock with NotActive component
AlexeyTripleA Jan 29, 2025
a942b98
Refactoring PublicKeysListItem code with NotActive component
AlexeyTripleA Jan 29, 2025
3b2fee8
Refactoring TimeDelta with NotActive component
AlexeyTripleA Jan 29, 2025
d2ad0df
Remove overflow hidden from InfoLine
AlexeyTripleA Jan 29, 2025
1893054
Fix error state in TransfersListItem and implement NotActive component
AlexeyTripleA Jan 29, 2025
5348995
Refactoring TransactionsListItem code with NotActive component
AlexeyTripleA Jan 29, 2025
eae569e
Remove unused mixin __NotActiveText
AlexeyTripleA Jan 29, 2025
e4c9b4f
Update responsive size of DataContractDigestCard
AlexeyTripleA Jan 29, 2025
97b9c68
Update ValueCard styles
AlexeyTripleA Jan 29, 2025
8172ec9
Update CodeBlock initial size animation
AlexeyTripleA Jan 29, 2025
e626e7f
Update DataContract Schema initial size
AlexeyTripleA Jan 29, 2025
81f9b8c
Remove unused code from DataContractTotalCard
AlexeyTripleA Jan 29, 2025
0eb7b34
Fix linter error
AlexeyTripleA Jan 30, 2025
0961254
Update fetches and pagination handler in DataContract.js
AlexeyTripleA Jan 30, 2025
6c13547
Update imports
AlexeyTripleA Jan 30, 2025
df583ac
Add documents count to tabs
AlexeyTripleA Jan 30, 2025
8f80e2a
Update default ValueCard and ValueContainer background
AlexeyTripleA Jan 30, 2025
7df0695
Update DigestCard mixin
AlexeyTripleA Jan 30, 2025
26fcb4f
Update DigestCard mixin
AlexeyTripleA Jan 30, 2025
8dc1c9f
Update EntityCard mixin
AlexeyTripleA Jan 30, 2025
8544804
Remove unused code
AlexeyTripleA Jan 30, 2025
53454a5
Remove empty line
AlexeyTripleA Jan 30, 2025
5117b53
Merge branch 'develop' into feat/datacontract-page
AlexeyTripleA Feb 3, 2025
07adb87
Merge branch 'develop' into feat/datacontract-page
AlexeyTripleA Feb 6, 2025
821b046
Remove flex-direction prop from IdentityDigestCard.scss
AlexeyTripleA Feb 6, 2025
636ff2d
Update Documents list order in DataContract page
AlexeyTripleA Feb 6, 2025
b91c08c
remove mock comment
AlexeyTripleA Feb 6, 2025
5317f78
Implement Breadcrumbs on DataContract page
AlexeyTripleA Feb 6, 2025
818fbeb
Update Breadcrumbs paddings
AlexeyTripleA Feb 6, 2025
581660c
Add names display in Breadcrumbs in DataContract page
AlexeyTripleA Feb 6, 2025
1ec9564
Add getDataContractTransactions method to api
AlexeyTripleA Feb 7, 2025
14af972
Add transactions list to DataContract page
AlexeyTripleA Feb 7, 2025
aeff1e7
Add transactions count in DataContract
AlexeyTripleA Feb 7, 2025
d83286a
Update Gas spent display
AlexeyTripleA Feb 7, 2025
97c731f
Update getDataContractTransactions fetch on DataContract page
AlexeyTripleA Feb 7, 2025
40d03d4
Change transactions order
AlexeyTripleA Feb 7, 2025
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
301 changes: 114 additions & 187 deletions packages/frontend/src/app/dataContract/[identifier]/DataContract.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
'use client'

import { useState, useEffect } from 'react'
import Link from 'next/link'
import * as Api from '../../../util/Api'
import DocumentsList from '../../../components/documents/DocumentsList'
import { LoadingLine, LoadingBlock } from '../../../components/loading'
import { LoadingBlock } from '../../../components/loading'
import { ErrorMessageBlock } from '../../../components/Errors'
import { fetchHandlerSuccess, fetchHandlerError } from '../../../util'
import ImageGenerator from '../../../components/imageGenerator'
import { fetchHandlerSuccess, fetchHandlerError, setLoadingProp, paginationHandler } from '../../../util'
import { usePathname, useRouter, useSearchParams } from 'next/navigation'
import { CodeBlock } from '../../../components/data'
import {
Box,
Container,
TableContainer, Table, Thead, Tbody, Tr, Th, Td,
Tabs, TabList, TabPanels, Tab, TabPanel
} from '@chakra-ui/react'
import { InfoContainer, PageDataContainer } from '../../../components/ui/containers'
import { DataContractDigestCard, DataContractTotalCard } from '../../../components/dataContracts'
import { Container, Tabs, TabList, TabPanels, Tab, TabPanel } from '@chakra-ui/react'
import { useBreadcrumbs } from '../../../contexts/BreadcrumbsContext'
import { TransactionsList } from '../../../components/transactions'
import './DataContract.scss'

const pagintationConfig = {
itemsOnPage: {
Expand All @@ -33,37 +31,34 @@ const tabs = [
const defaultTabName = 'documents'

function DataContract ({ identifier }) {
const { setBreadcrumbs } = useBreadcrumbs()
const [dataContract, setDataContract] = useState({ data: {}, loading: true, error: false })
const [documents, setDocuments] = useState({ data: {}, props: { printCount: 5 }, loading: true, error: false })
const [documents, setDocuments] = useState({ data: {}, props: { currentPage: 0 }, loading: true, error: false })
const [transactions, setTransactions] = useState({ data: {}, props: { currentPage: 0 }, loading: true, error: false })
const [rate, setRate] = useState({ data: {}, loading: true, error: false })
const pageSize = pagintationConfig.itemsOnPage.default
const [total, setTotal] = useState(1)
const [currentPage, setCurrentPage] = useState(0)
const pageCount = Math.ceil(total / pageSize)
const [activeTab, setActiveTab] = useState(tabs.indexOf(defaultTabName.toLowerCase()) !== -1 ? tabs.indexOf(defaultTabName.toLowerCase()) : 0)
const tdTitleWidth = 250
const router = useRouter()
const pathname = usePathname()
const searchParams = useSearchParams()

const fetchData = () => {
Promise.all([
Api.getDataContractByIdentifier(identifier)
.then(res => fetchHandlerSuccess(setDataContract, res))
.catch(err => fetchHandlerError(setDataContract, err)),
Api.getDocumentsByDataContract(
identifier,
pagintationConfig.defaultPage,
pageSize)
.then(res => {
fetchHandlerSuccess(setDocuments, res)
setTotal(res.pagination.total)
})
.catch(err => fetchHandlerError(setDocuments, err))
useEffect(() => {
setBreadcrumbs([
{ label: 'Home', path: '/' },
{ label: 'Data Contracts', path: '/dataContracts' },
{ label: dataContract.data?.name || identifier, avatarSource: identifier }
])
.catch(console.error)
}
}, [setBreadcrumbs, identifier, dataContract])

useEffect(() => {
Api.getDataContractByIdentifier(identifier)
.then(res => fetchHandlerSuccess(setDataContract, res))
.catch(err => fetchHandlerError(setDataContract, err))

useEffect(fetchData, [identifier])
Api.getRate()
.then(res => fetchHandlerSuccess(setRate, res))
.catch(err => fetchHandlerError(setRate, err))
}, [identifier])

useEffect(() => {
const tab = searchParams.get('tab')
Expand All @@ -89,165 +84,97 @@ function DataContract ({ identifier }) {
router.replace(`${pathname}?${urlParameters.toString()}`, { scroll: false })
}, [activeTab])

const handlePageClick = ({ selected }) => {
setDocuments(state => ({ ...state, loading: true }))
setCurrentPage(selected)

Api.getDocumentsByDataContract(
identifier,
selected + 1,
pagintationConfig.itemsOnPage.default)
.then(res => setDocuments({ data: res, loading: false, error: false }))
.catch(err => {
console.error(err)
setDocuments({ data: null, loading: false, error: true })
useEffect(() => {
if (!identifier) return
setLoadingProp(setDocuments)

Api.getDocumentsByDataContract(identifier, documents.props.currentPage + 1, pageSize, 'desc')
.then(res => fetchHandlerSuccess(setDocuments, res))
.catch(err => fetchHandlerError(setDocuments, err))
}, [identifier, documents.props.currentPage])

useEffect(() => {
if (!identifier) return
setLoadingProp(setTransactions)

Api.getDataContractTransactions(identifier, transactions.props.currentPage + 1, pageSize, 'desc')
.then(res => {
fetchHandlerSuccess(setDataContract, { transactionsCount: res?.pagination?.total })
fetchHandlerSuccess(setTransactions, res)
})
}
.catch(err => fetchHandlerError(setTransactions, err))
}, [identifier, transactions.props.currentPage])

return (
<Container
maxW={'container.lg'}
padding={3}
mt={8}
className={'DataContract'}
<PageDataContainer
className={'DataContract'}
title={'Data Contract info'}
>
<TableContainer
maxW={'none'}
borderWidth={'1px'} borderRadius={'block'}
>
{!dataContract.error
? <Table variant={'simple'}>
<Thead>
<Tr>
<Th>Data contract info</Th>
<Th isNumeric className={'TableHeader TableHeader--Name'}>
<div className={'TableHeader__Content'}>
{dataContract?.data?.name || ''}
{dataContract.data?.identifier
? <ImageGenerator className={'TableHeader__Avatar'} username={dataContract.data?.identifier} lightness={50} saturation={50} width={32} height={32}/>
: <Box w={'32px'} h={'32px'} />
}
</div>
</Th>
</Tr>
</Thead>
<Tbody>
<Tr>
<Td w={tdTitleWidth}>Identifier</Td>
<Td className={'Table__Cell--BreakWord Table__Cell--Mono'}>
<LoadingLine loading={dataContract.loading}>{dataContract.data?.identifier}</LoadingLine>
</Td>
</Tr>
{dataContract.data?.name &&
<Tr>
<Td w={tdTitleWidth}>Name</Td>
<Td>
<LoadingLine loading={dataContract.loading}>{dataContract.data?.name}</LoadingLine>
</Td>
</Tr>
}
<Tr>
<Td w={tdTitleWidth}>Owner</Td>
<Td className={'Table__Cell--BreakWord Table__Cell--Mono'}>
<LoadingLine loading={dataContract.loading}>
{dataContract.data?.isSystem
? dataContract.data?.owner
: <Link href={`/identity/${dataContract.data?.owner}`}>{dataContract.data?.owner}</Link>
}
</LoadingLine>
</Td>
</Tr>
<Tr>
<Td w={tdTitleWidth}>System</Td>
<Td>
<LoadingLine loading={dataContract.loading}>{dataContract.data?.isSystem ? 'true' : 'false'}</LoadingLine>
</Td>
</Tr>
{!dataContract.data?.isSystem &&
<Tr>
<Td w={tdTitleWidth}>Created</Td>
<Td>
<LoadingLine loading={dataContract.loading}>{new Date(dataContract.data?.timestamp).toLocaleString()}</LoadingLine>
</Td>
</Tr>
}
<Tr>
<Td w={tdTitleWidth}>Documents Count</Td>
<Td>
<LoadingLine loading={dataContract.loading}>{dataContract.data?.documentsCount}</LoadingLine>
</Td>
</Tr>
<Tr>
<Td w={tdTitleWidth}>Revision</Td>
<Td>
<LoadingLine loading={dataContract.loading}>{dataContract.data?.version}</LoadingLine>
</Td>
</Tr>
{!dataContract.data?.isSystem &&
<Tr w={tdTitleWidth}>
<Td>Transaction</Td>
<Td className={'Table__Cell--BreakWord Table__Cell--Mono'}>
<LoadingLine loading={dataContract.loading}>
<Link href={`/transaction/${dataContract.data?.txHash}`}>{dataContract.data?.txHash}</Link>
</LoadingLine>
</Td>
</Tr>
}
</Tbody>
</Table>
: <Container h={60}><ErrorMessageBlock/></Container>}
</TableContainer>

<Container
width={'100%'}
maxW={'none'}
mt={5}
className={'InfoBlock'}
p={0}
>
<Tabs
onChange={setActiveTab}
index={activeTab}
>
<TabList>
<Tab>Documents</Tab>
<Tab>Schema</Tab>
</TabList>
<TabPanels>
<TabPanel p={0}>
<Box>
{!documents.error
? <Box mt={4}>
<DocumentsList
documents={documents.data.resultSet}
loading={documents.loading}
pagination={{
onPageChange: handlePageClick,
pageCount,
forcePage: currentPage
}}
/>
</Box>
: <Container h={20}><ErrorMessageBlock/></Container>
}
</Box>
</TabPanel>
<TabPanel px={0}>
<Box>
{!dataContract.error
? <LoadingBlock loading={dataContract.loading}>
{dataContract.data?.schema
? <CodeBlock code={dataContract.data?.schema}/>
: <Container h={20}><ErrorMessageBlock/></Container>}
</LoadingBlock>
: <Container h={20}><ErrorMessageBlock/></Container>
}
</Box>
</TabPanel>
</TabPanels>
</Tabs>
</Container>
</Container>
<div className={'DataContract__InfoBlocks'}>
<DataContractTotalCard className={'DataContract__InfoBlock'} dataContract={dataContract}/>
<DataContractDigestCard dataContract={dataContract} rate={rate} loading={dataContract.loading}/>
</div>

<InfoContainer styles={['tabs']}>
<Tabs onChange={(index) => setActiveTab(index)} index={activeTab}>
<TabList>
<Tab>Transactions {transactions.data?.resultSet?.length !== undefined
? <span className={`Tabs__TabItemsCount ${transactions.data?.resultSet?.length === 0 ? 'Tabs__TabItemsCount--Empty' : ''}`}>
{transactions.data?.resultSet?.length}
</span>
: ''}
</Tab>
<Tab>Documents {dataContract.data?.documentsCount !== undefined
? <span className={`Tabs__TabItemsCount ${dataContract.data?.documentsCount === 0 ? 'Tabs__TabItemsCount--Empty' : ''}`}>
{dataContract.data?.documentsCount}
</span>
: ''}
</Tab>
<Tab>Schema</Tab>
</TabList>
<TabPanels>
<TabPanel position={'relative'}>
{!transactions.error
? <TransactionsList
transactions={transactions.data?.resultSet}
loading={transactions.loading}
pagination={{
onPageChange: pagination => paginationHandler(setTransactions, pagination.selected),
pageCount: Math.ceil(transactions.data?.pagination?.total / pageSize) || 1,
forcePage: transactions.props.currentPage
}}
/>
: <Container h={20}><ErrorMessageBlock/></Container>
}
</TabPanel>
<TabPanel position={'relative'}>
{!documents.error
? <DocumentsList
documents={documents.data?.resultSet}
loading={documents.loading}
pagination={{
onPageChange: pagination => paginationHandler(setDocuments, pagination.selected),
pageCount: Math.ceil(documents.data?.pagination?.total / pageSize) || 1,
forcePage: documents.props.currentPage
}}
/>
: <Container h={20}><ErrorMessageBlock/></Container>
}
</TabPanel>
<TabPanel position={'relative'}>
{!dataContract.error
? <LoadingBlock h={'250px'} loading={dataContract.loading}>
{dataContract.data?.schema
? <CodeBlock smoothSize={activeTab === 1} className={'DataContract__Schema'} code={dataContract.data?.schema}/>
: <Container h={20}><ErrorMessageBlock/></Container>}
</LoadingBlock>
: <Container h={20}><ErrorMessageBlock/></Container>
}
</TabPanel>
</TabPanels>
</Tabs>
</InfoContainer>
</PageDataContainer>
)
}

Expand Down
Loading