ghost-portal/packages/page-coretime/src/ParachainsTable.tsx
Daria c24c90ec8c
Adding Filters for the Coretime - Overview Tab according to feedback (#11217)
* added Expires soon warning on everything that is not Reservation and expires within 7 days

* added subscan links to the table, link for the project and for the block

* filter by parachain id

* filter by parachain name

* filter by type

* sorting filters by lastBlock

* filters working together

* filtering update

* lint

* refactor

* unused var

* flipped arrows for ASC and DESC

* lint

* lint

* lint
2025-02-10 21:20:50 +13:00

80 lines
2.2 KiB
TypeScript

// Copyright 2017-2025 @polkadot/app-coretime authors & contributors
// SPDX-License-Identifier: Apache-2.0
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Table } from '@polkadot/react-components';
import { type CoretimeInformation } from '@polkadot/react-hooks/types';
import Filters from './Overview/Filters.js';
import ParachainTableRow from './ParachainTableRow.js';
import { useTranslation } from './translate.js';
interface Props {
coretimeInfo: CoretimeInformation
}
function ParachainsTable ({ coretimeInfo }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
[t('parachains'), 'start'],
[t('name'), 'start media--800'],
[t('core number'), 'start'],
[t('type'), 'start'],
[t('last block'), 'start media--800'],
[t('end'), 'start media--1000'],
[t('renewal'), 'start media--1200'],
[t('renewal price'), 'start media--1200'],
[t('links'), 'start media--800'],
[t('other cores'), 'end']
]);
const [taskIds, setTaskIds] = useState<number[]>([]);
const onFilter = useCallback((filteredData: number[]) => {
setTaskIds(filteredData);
}, []);
useEffect(() => {
if (coretimeInfo?.taskIds) {
setTaskIds(coretimeInfo?.taskIds);
}
}, [coretimeInfo?.taskIds]);
return (
<>
<Filters
chainInfo={coretimeInfo?.chainInfo}
data={coretimeInfo?.taskIds}
onFilter={onFilter}
/>
<Table
emptySpinner={false}
header={headerRef.current}
isSplit={false}
>
{taskIds?.map((taskId: number) => {
const chain = coretimeInfo.chainInfo[taskId];
if (!chain) {
return null;
}
return (
<ParachainTableRow
chain={chain}
key={chain.id}
lastCommittedTimeslice={coretimeInfo.status.lastCommittedTimeslice}
regionBegin={coretimeInfo.salesInfo.regionBegin}
regionEnd={coretimeInfo.salesInfo.regionEnd}
/>
);
})}
</Table>
</>
);
}
export default React.memo(ParachainsTable);