-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relay Chain Coretime UI bugs (#11043)
* showing multiple core rows for parachains, changed end dates for non extended chains, correct renew status * mobile table * only showing renewals eligibility during the interlude * removed extra tag * styled component $property
- Loading branch information
1 parent
a51f362
commit 069b032
Showing
7 changed files
with
256 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { ChainInformation, ChainWorkTaskInformation } from '@polkadot/react-hooks/types'; | ||
|
||
import React from 'react'; | ||
|
||
import { ExpandButton } from '@polkadot/react-components'; | ||
import { useToggle } from '@polkadot/react-hooks'; | ||
|
||
import Row from './Row.js'; | ||
|
||
interface Props { | ||
chain: ChainInformation | ||
regionEnd: number | ||
regionBegin: number | ||
lastCommittedTimeslice: number | ||
} | ||
|
||
function ParachainTableRow ({ chain, lastCommittedTimeslice, regionBegin, regionEnd }: Props): React.ReactElement<Props> { | ||
const [isExpanded, toggleIsExpanded] = useToggle(false); | ||
const info = chain.workTaskInfo; | ||
const firstRecord = chain.workTaskInfo[0]; | ||
const multiple = info.length > 1; | ||
const expandedContent = info.slice(1); | ||
|
||
if (!firstRecord) { | ||
return <></>; | ||
} | ||
|
||
const renderRow = (record: ChainWorkTaskInformation, idx: number, highlight = false) => | ||
<> | ||
<Row | ||
chainRecord={record} | ||
highlight={highlight} | ||
id={chain.id} | ||
lastCommittedTimeslice={lastCommittedTimeslice} | ||
lease={chain.lease} | ||
regionBegin={regionBegin} | ||
regionEnd={regionEnd} | ||
/> | ||
{idx === 0 && <td style={{ paddingRight: '2rem', textAlign: 'right', verticalAlign: 'top' }}> | ||
|
||
{!!multiple && | ||
<ExpandButton | ||
expanded={isExpanded} | ||
onClick={toggleIsExpanded} | ||
/> | ||
} | ||
</td>} | ||
</>; | ||
|
||
return ( | ||
<> | ||
<tr | ||
className={`isExpanded isFirst ${isExpanded ? '' : 'isLast'}`} | ||
key={chain.id} | ||
> | ||
{renderRow(firstRecord, 0)} | ||
</tr> | ||
{isExpanded && expandedContent?.map((infoRow, idx) => | ||
<tr key={`${chain.id}${idx}`}> | ||
{renderRow(infoRow, idx + 1, true)} | ||
</tr> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default React.memo(ParachainTableRow); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2017-2024 @polkadot/app-coretime authors & contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { FlagColor } from '@polkadot/react-components/types'; | ||
import type { ChainWorkTaskInformation, LegacyLease } from '@polkadot/react-hooks/types'; | ||
|
||
import React from 'react'; | ||
|
||
import { ParaLink, styled, Tag } from '@polkadot/react-components'; | ||
import { ChainRenewalStatus } from '@polkadot/react-hooks/types'; | ||
import { BN, formatBalance, formatNumber } from '@polkadot/util'; | ||
|
||
import { CoreTimeTypes } from './types.js'; | ||
import { estimateTime } from './utils.js'; | ||
|
||
interface Props { | ||
id: number | ||
chainRecord: ChainWorkTaskInformation | ||
regionEnd: number | ||
regionBegin: number | ||
lastCommittedTimeslice: number | ||
lease: LegacyLease | undefined | ||
highlight?: boolean | ||
} | ||
|
||
const colours: Record<string, string> = { | ||
[CoreTimeTypes.Reservation]: 'orange', | ||
[CoreTimeTypes.Lease]: 'blue', | ||
[CoreTimeTypes['Bulk Coretime']]: 'pink' | ||
}; | ||
|
||
const StyledCell = styled.td<{ $p: boolean }>` | ||
&& { | ||
background-color: ${({ $p }) => ($p ? '#F9FAFB' : undefined)}; | ||
} | ||
`; | ||
|
||
function Row ({ chainRecord, highlight = false, id, lastCommittedTimeslice, lease, regionBegin, regionEnd }: Props): React.ReactElement<Props> { | ||
const chainRegionEnd = (chainRecord.renewalStatus === ChainRenewalStatus.Renewed ? regionEnd : regionBegin); | ||
const targetTimeslice = lease?.until || chainRegionEnd; | ||
const showEstimates = !!targetTimeslice && Object.values(CoreTimeTypes)[chainRecord.type] !== CoreTimeTypes.Reservation; | ||
|
||
return ( | ||
<React.Fragment key={`${id}`}> | ||
<StyledCell $p={highlight}>{id}</StyledCell> | ||
<StyledCell | ||
$p={highlight} | ||
className='media--800' | ||
>{<ParaLink id={new BN(id)} />}</StyledCell> | ||
<StyledCell $p={highlight}>{chainRecord?.workload?.core}</StyledCell> | ||
<StyledCell $p={highlight}> | ||
<Tag | ||
color={colours[chainRecord.type] as FlagColor} | ||
label={Object.values(CoreTimeTypes)[chainRecord.type]} | ||
/> | ||
</StyledCell> | ||
<StyledCell | ||
$p={highlight} | ||
className='media--800' | ||
>{showEstimates && formatNumber(targetTimeslice * 80).toString()}</StyledCell> | ||
<StyledCell | ||
$p={highlight} | ||
className='media--1000' | ||
>{showEstimates && estimateTime(targetTimeslice, lastCommittedTimeslice * 80)}</StyledCell> | ||
<StyledCell | ||
$p={highlight} | ||
className='media--1200' | ||
>{chainRecord?.renewalStatus}</StyledCell> | ||
<StyledCell | ||
$p={highlight} | ||
className='media--1200' | ||
>{chainRecord?.renewal ? formatBalance(chainRecord.renewal?.price.toString()) : ''}</StyledCell> | ||
{highlight && <StyledCell $p={highlight} />} | ||
</React.Fragment> | ||
|
||
); | ||
} | ||
|
||
export default React.memo(Row); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.