Predefine columns for Table favorites/expander (#8690)
* Predefine columns for Table favorites/expander * Adjust header definition types * Additional header typings * lint override * Add Table.Column.Id * Use Table.Column.Favorite for staking
This commit is contained in:
parent
fdefbf00d7
commit
453a505d58
@ -15,7 +15,7 @@ import styled from 'styled-components';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import useAccountLocks from '@polkadot/app-referenda/useAccountLocks';
|
||||
import { AddressInfo, AddressSmall, Badge, Button, ChainLock, Columar, CryptoType, ExpandButton, Forget, Icon, LinkExternal, Menu, Popup, StatusContext, Tags } from '@polkadot/react-components';
|
||||
import { AddressInfo, AddressSmall, Badge, Button, ChainLock, Columar, CryptoType, Forget, LinkExternal, Menu, Popup, StatusContext, Table, Tags } from '@polkadot/react-components';
|
||||
import { useAccountInfo, useApi, useBalancesAll, useBestNumber, useCall, useLedger, useStakingInfo, useToggle } from '@polkadot/react-hooks';
|
||||
import { keyring } from '@polkadot/ui-keyring';
|
||||
import { BN, BN_ZERO, formatBalance, formatNumber, isFunction } from '@polkadot/util';
|
||||
@ -243,11 +243,6 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
[accName, filter, tags]
|
||||
);
|
||||
|
||||
const _onFavorite = useCallback(
|
||||
() => toggleFavorite(address),
|
||||
[address, toggleFavorite]
|
||||
);
|
||||
|
||||
const _onForget = useCallback(
|
||||
(): void => {
|
||||
if (!address) {
|
||||
@ -471,13 +466,11 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
return (
|
||||
<>
|
||||
<tr className={`${className} packedBottom`}>
|
||||
<td className='favorite'>
|
||||
<Icon
|
||||
color={isFavorite ? 'orange' : 'gray'}
|
||||
icon='star'
|
||||
onClick={_onFavorite}
|
||||
/>
|
||||
</td>
|
||||
<Table.Column.Favorite
|
||||
address={address}
|
||||
isFavorite={isFavorite}
|
||||
toggle={toggleFavorite}
|
||||
/>
|
||||
<td className='address all relative'>
|
||||
<AddressSmall
|
||||
parentAddress={meta.parentAddress}
|
||||
@ -704,14 +697,10 @@ function Account ({ account: { address, meta }, className = '', delegation, filt
|
||||
/>
|
||||
</Button.Group>
|
||||
</td>
|
||||
<td className='actions button'>
|
||||
<div>
|
||||
<ExpandButton
|
||||
expanded={isExpanded}
|
||||
onClick={toggleIsExpanded}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
<Table.Column.Expand
|
||||
isExpanded={isExpanded}
|
||||
toggle={toggleIsExpanded}
|
||||
/>
|
||||
</tr>
|
||||
<tr className={`${className} isExpanded packedTop`}>
|
||||
<td />
|
||||
|
||||
@ -170,18 +170,21 @@ function VanityApp ({ className = '', onStatusChange }: Props): React.ReactEleme
|
||||
}
|
||||
}, [_executeGeneration, isRunning]);
|
||||
|
||||
const header = useMemo(() => [
|
||||
[t('matches'), 'start', 2],
|
||||
[t('Evaluated {{count}} keys in {{elapsed}}s ({{avg}} keys/s)', {
|
||||
replace: {
|
||||
avg: (keyCount / (elapsed / 1000)).toFixed(3),
|
||||
count: keyCount,
|
||||
elapsed: (elapsed / 1000).toFixed(2)
|
||||
}
|
||||
}), 'start'],
|
||||
[t('secret'), 'start'],
|
||||
[]
|
||||
], [elapsed, keyCount, t]);
|
||||
const header = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => [
|
||||
[t('matches'), 'start', 2],
|
||||
[t('Evaluated {{count}} keys in {{elapsed}}s ({{avg}} keys/s)', {
|
||||
replace: {
|
||||
avg: (keyCount / (elapsed / 1000)).toFixed(3),
|
||||
count: keyCount,
|
||||
elapsed: (elapsed / 1000).toFixed(2)
|
||||
}
|
||||
}), 'start'],
|
||||
[t('secret'), 'start'],
|
||||
[]
|
||||
],
|
||||
[elapsed, keyCount, t]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
|
||||
@ -8,7 +8,7 @@ import React, { useCallback, useEffect, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Transfer from '@polkadot/app-accounts/modals/Transfer';
|
||||
import { AddressInfo, AddressSmall, Button, ChainLock, Columar, ExpandButton, Forget, Icon, LinkExternal, Menu, Popup, Tags } from '@polkadot/react-components';
|
||||
import { AddressInfo, AddressSmall, Button, ChainLock, Columar, Forget, LinkExternal, Menu, Popup, Table, Tags } from '@polkadot/react-components';
|
||||
import { useApi, useBalancesAll, useDeriveAccountInfo, useToggle } from '@polkadot/react-hooks';
|
||||
import { keyring } from '@polkadot/ui-keyring';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
@ -121,11 +121,6 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
|
||||
[address]
|
||||
);
|
||||
|
||||
const _onFavorite = useCallback(
|
||||
(): void => toggleFavorite(address),
|
||||
[address, toggleFavorite]
|
||||
);
|
||||
|
||||
const _toggleForget = useCallback(
|
||||
(): void => setIsForgetOpen(!isForgetOpen),
|
||||
[isForgetOpen]
|
||||
@ -184,13 +179,11 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
|
||||
return (
|
||||
<>
|
||||
<tr className={`${className} packedBottom`}>
|
||||
<td className='favorite'>
|
||||
<Icon
|
||||
color={isFavorite ? 'orange' : 'gray'}
|
||||
icon='star'
|
||||
onClick={_onFavorite}
|
||||
/>
|
||||
</td>
|
||||
<Table.Column.Favorite
|
||||
address={address}
|
||||
isFavorite={isFavorite}
|
||||
toggle={toggleFavorite}
|
||||
/>
|
||||
<td className='address all'>
|
||||
<AddressSmall
|
||||
value={address}
|
||||
@ -231,14 +224,10 @@ function Address ({ address, className = '', filter, isFavorite, toggleFavorite
|
||||
<Popup value={PopupDropdown} />
|
||||
</Button.Group>
|
||||
</td>
|
||||
<td className='actions button'>
|
||||
<div>
|
||||
<ExpandButton
|
||||
expanded={isExpanded}
|
||||
onClick={toggleIsExpanded}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
<Table.Column.Expand
|
||||
isExpanded={isExpanded}
|
||||
toggle={toggleIsExpanded}
|
||||
/>
|
||||
</tr>
|
||||
<tr className={`${className} isExpanded packedTop`}>
|
||||
<td />
|
||||
|
||||
@ -26,7 +26,7 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen
|
||||
const [filterOn, setFilter] = useState<string>('');
|
||||
const isLoading = useLoadingDelay();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('contacts'), 'start', 4]
|
||||
]);
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
function Announcements ({ accouncements, className }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const annRef = useRef([
|
||||
const annRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t<string>('annoucements'), 'start'],
|
||||
[t<string>('version'), 'number'],
|
||||
[t<string>('codec'), 'number'],
|
||||
|
||||
@ -28,7 +28,7 @@ function Overview ({ className, members, prime, rule, unscrupulous, voters }: Pr
|
||||
const [isJoinOpen, toggleJoin] = useToggle();
|
||||
const bestNumber = useBestNumber();
|
||||
|
||||
const hdrRef = useRef([
|
||||
const hdrRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t<string>('members'), 'start', 2],
|
||||
[t<string>('deposit'), 'number'],
|
||||
[t<string>('role'), 'number'],
|
||||
|
||||
@ -19,11 +19,11 @@ interface Props {
|
||||
function Unscrupulous ({ className, unscrupulous }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const accRef = useRef([
|
||||
const accRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t<string>('accounts'), 'start']
|
||||
]);
|
||||
|
||||
const webRef = useRef([
|
||||
const webRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t<string>('websites'), 'start']
|
||||
]);
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ function Balances ({ className, infos = [] }: Props): React.ReactElement<Props>
|
||||
const [info, setInfo] = useState<AssetInfoComplete | null>(null);
|
||||
const balances = useBalances(info?.id);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('accounts'), 'start'],
|
||||
[t('frozen'), 'start'],
|
||||
[t('sufficient'), 'start'],
|
||||
|
||||
@ -5,9 +5,8 @@ import type { AssetInfo } from '../types';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { AddressSmall } from '@polkadot/react-components';
|
||||
import { AddressSmall, Table } from '@polkadot/react-components';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import Mint from './Mint';
|
||||
|
||||
@ -26,7 +25,7 @@ function Asset ({ className, value: { details, id, isIssuerMe, metadata } }: Pro
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='together'>{metadata?.name.toUtf8()}</td>
|
||||
<td className='address media--1000'>{details && <AddressSmall value={details.owner} />}</td>
|
||||
<td className='address media--1300'>{details && <AddressSmall value={details.admin} />}</td>
|
||||
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
function Assets ({ className, infos }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('assets'), 'start', 2],
|
||||
[t('owner'), 'address media--1000'],
|
||||
[t('admin'), 'address media--1300'],
|
||||
|
||||
@ -25,7 +25,7 @@ function Bounties ({ className }: Props): React.ReactElement {
|
||||
[info]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('bounties'), 'start', 3],
|
||||
[t('value'), 'start'],
|
||||
[t('curator'), 'start'],
|
||||
|
||||
@ -7,10 +7,9 @@ import type { BlockNumber, Bounty as BountyType, BountyIndex } from '@polkadot/t
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { AddressSmall, Columar, ExpandButton, LinkExternal } from '@polkadot/react-components';
|
||||
import { AddressSmall, Columar, ExpandButton, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useToggle } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import BountyActionMessage from './BountyNextActionInfo/BountyActionMessage';
|
||||
import { getProposalToDisplay } from './helpers/extendedStatuses';
|
||||
@ -58,7 +57,7 @@ function Bounty ({ bestNumber, bounty, className = '', description, index, propo
|
||||
return (
|
||||
<>
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<td
|
||||
className='description-column'
|
||||
data-testid='description'
|
||||
|
||||
@ -20,7 +20,7 @@ function Collators ({ className }: Props): React.ReactElement<Props> {
|
||||
const collators = useCollators();
|
||||
const { byAuthor } = useContext(BlockAuthorsContext);
|
||||
|
||||
const hdrRef = useRef([
|
||||
const hdrRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t<string>('collators'), 'start', 2],
|
||||
[t<string>('deposit'), 'number'],
|
||||
[t<string>('balance'), 'number'],
|
||||
|
||||
@ -7,7 +7,7 @@ import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell';
|
||||
import { Icon, LinkExternal } from '@polkadot/react-components';
|
||||
import { Icon, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useAccounts, useCollectiveInstance, useVotingStatus } from '@polkadot/react-hooks';
|
||||
import { BlockToTime } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
@ -58,7 +58,7 @@ function Motion ({ className = '', isMember, members, motion: { hash, proposal,
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<ProposalCell
|
||||
imageHash={hash}
|
||||
proposal={proposal}
|
||||
|
||||
@ -25,7 +25,7 @@ function Proposals ({ className = '', motions, prime }: Props): React.ReactEleme
|
||||
const { t } = useTranslation();
|
||||
const { isMember, members } = useCollectiveMembers('council');
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('motions'), 'start', 2],
|
||||
[t('threshold')],
|
||||
[t('voting end')],
|
||||
|
||||
@ -20,13 +20,13 @@ interface Props {
|
||||
function Candidates ({ allVotes = {}, electionsInfo }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerCandidatesRef = useRef([
|
||||
const headerCandidatesRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('candidates'), 'start'],
|
||||
[],
|
||||
[]
|
||||
]);
|
||||
|
||||
const headerRunnersRef = useRef([
|
||||
const headerRunnersRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('runners up'), 'start'],
|
||||
[t('backing'), 'expand'],
|
||||
[t('votes')]
|
||||
|
||||
@ -22,7 +22,7 @@ interface Props {
|
||||
function Members ({ allVotes = {}, className = '', electionsInfo, hasElections, prime }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('members'), 'start'],
|
||||
[hasElections ? t('backing') : undefined, 'expand'],
|
||||
[hasElections ? t('votes') : undefined]
|
||||
|
||||
@ -20,7 +20,7 @@ function Externals ({ className }: Props): React.ReactElement<Props> | null {
|
||||
const { api } = useApi();
|
||||
const external = useCall<DeriveProposalExternal | null>(api.derive.democracy.nextExternal);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('external'), 'start'],
|
||||
[t('proposer'), 'address'],
|
||||
[t('locked')],
|
||||
|
||||
@ -5,10 +5,9 @@ import type { DeriveProposal } from '@polkadot/api-derive/types';
|
||||
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
|
||||
import { AddressMini, Button, Columar, ExpandButton, ExpanderScroll, LinkExternal } from '@polkadot/react-components';
|
||||
import { AddressMini, Button, Columar, ExpandButton, ExpanderScroll, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useToggle } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import PreImageButton from './PreImageButton';
|
||||
@ -44,7 +43,7 @@ function Proposal ({ className = '', value: { balance, image, imageHash, index,
|
||||
return (
|
||||
<>
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<ProposalCell
|
||||
imageHash={imageHash}
|
||||
proposal={image?.proposal}
|
||||
|
||||
@ -20,7 +20,7 @@ function Proposals ({ className }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const proposals = useCall<DeriveProposal[]>(api.derive.democracy.proposals);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('proposals'), 'start', 2],
|
||||
[t('proposer'), 'address'],
|
||||
[t('locked'), 'media--1200'],
|
||||
|
||||
@ -7,7 +7,7 @@ import type { Balance } from '@polkadot/types/interfaces';
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { Badge, Button, Columar, ExpandButton, Icon, LinkExternal, Progress } from '@polkadot/react-components';
|
||||
import { Badge, Button, Columar, ExpandButton, Icon, LinkExternal, Progress, Table } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi, useBestNumber, useCall, useToggle } from '@polkadot/react-hooks';
|
||||
import { BlockToTime } from '@polkadot/react-query';
|
||||
import { BN, BN_ONE, formatNumber, isBoolean } from '@polkadot/util';
|
||||
@ -92,7 +92,7 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
|
||||
return (
|
||||
<>
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<ProposalCell
|
||||
imageHash={imageHash}
|
||||
proposal={image?.proposal}
|
||||
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
function Referendums ({ className = '', referendums }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('referenda'), 'start', 2],
|
||||
[t('remaining'), 'media--1200'],
|
||||
[t('activate'), 'media--1400'],
|
||||
|
||||
@ -17,7 +17,7 @@ interface Props {
|
||||
function BlockHeaders ({ headers }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('recent blocks'), 'start', 3]
|
||||
]);
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ interface State {
|
||||
runtimeVersion?: RuntimeVersionPartial;
|
||||
}
|
||||
|
||||
const EMPTY_HEADER = [['...', 'start', 6]];
|
||||
const EMPTY_HEADER: [React.ReactNode?, string?, number?][] = [['...', 'start', 6]];
|
||||
|
||||
function transformResult ([[runtimeVersion, events], getBlock, getHeader]: [[RuntimeVersionPartial, EventRecord[] | null], SignedBlock, HeaderExtended?]): State {
|
||||
return {
|
||||
@ -97,7 +97,7 @@ function BlockByHash ({ className = '', error, value }: Props): React.ReactEleme
|
||||
});
|
||||
}, [api, mountedRef, value]);
|
||||
|
||||
const header = useMemo(
|
||||
const header = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => getHeader
|
||||
? [
|
||||
[formatNumber(getHeader.number.unwrap()), 'start', 1],
|
||||
|
||||
@ -25,12 +25,15 @@ interface Props {
|
||||
function Extrinsics ({ blockNumber, className = '', events, label, maxBlockWeight, value, withLink }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const header = useMemo(() => [
|
||||
[label || t<string>('extrinsics'), 'start', 2],
|
||||
[t('events'), 'start media--1000', 2],
|
||||
[t('weight'), 'media--1400'],
|
||||
[undefined, 'address media--1200']
|
||||
], [label, t]);
|
||||
const header = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => [
|
||||
[label || t<string>('extrinsics'), 'start', 2],
|
||||
[t('events'), 'start media--1000', 2],
|
||||
[t('weight'), 'media--1400'],
|
||||
[undefined, 'address media--1200']
|
||||
],
|
||||
[label, t]
|
||||
);
|
||||
|
||||
return (
|
||||
<Table
|
||||
|
||||
@ -38,7 +38,7 @@ function formatTuple (tuple: Tuple): React.ReactNode {
|
||||
function JustificationList ({ value }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('justifications'), 'start']
|
||||
]);
|
||||
|
||||
|
||||
@ -101,7 +101,7 @@ function formatItem (item: DigestItem): React.ReactNode {
|
||||
function Logs ({ value }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('logs'), 'start']
|
||||
]);
|
||||
|
||||
|
||||
@ -25,9 +25,12 @@ interface Props {
|
||||
function Events ({ className = '', emptyLabel, error, eventClassName, events, label }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const header = useMemo(() => [
|
||||
[label || t<string>('recent events'), 'start']
|
||||
], [label, t]);
|
||||
const header = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => [
|
||||
[label || t<string>('recent events'), 'start']
|
||||
],
|
||||
[label, t]
|
||||
);
|
||||
|
||||
return (
|
||||
<Table
|
||||
|
||||
@ -19,7 +19,7 @@ interface Props {
|
||||
function Peers ({ className = '', peers }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('connected peers'), 'start'],
|
||||
[t('role'), 'start'],
|
||||
[t('best #'), 'number'],
|
||||
|
||||
@ -5,6 +5,7 @@ import type { QueueTotal } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { Table } from '@polkadot/react-components';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
@ -16,9 +17,7 @@ interface Props {
|
||||
function Queue ({ className, value: { balance, index, numItems } }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'>
|
||||
<h1>{formatNumber(index)}</h1>
|
||||
</td>
|
||||
<Table.Column.Id value={index} />
|
||||
<td className='number all'>
|
||||
{formatNumber(numItems)}
|
||||
</td>
|
||||
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
function Queues ({ className, queueTotals }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('queues'), 'start'],
|
||||
[t('participants'), 'number'],
|
||||
[t('balance'), 'number']
|
||||
|
||||
@ -5,8 +5,7 @@ import type { ItemInfo } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AddressSmall, IconLink } from '@polkadot/react-components';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
import { AddressSmall, IconLink, Table } from '@polkadot/react-components';
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
@ -20,7 +19,7 @@ function Item ({ className, collectionName, value: { account, id, ipfsData } }:
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='together all'>
|
||||
{ name && imageLink
|
||||
? (
|
||||
|
||||
@ -54,7 +54,7 @@ function AccountItems ({ className, infos = [] }: Props): React.ReactElement<Pro
|
||||
[completeInfos, NO_NAME]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('items'), 'start', 2],
|
||||
[t('owner'), 'address media--1000']
|
||||
]);
|
||||
|
||||
@ -6,7 +6,7 @@ import type { CollectionInfo } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AddressSmall, IconLink } from '@polkadot/react-components';
|
||||
import { AddressSmall, IconLink, Table } from '@polkadot/react-components';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
@ -23,7 +23,7 @@ function Collection ({ className, value: { details, id, ipfsData } }: Props): Re
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='together all'>
|
||||
{ name && imageLink
|
||||
? (
|
||||
|
||||
@ -18,7 +18,7 @@ interface Props {
|
||||
function Collections ({ className, infos }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('collections'), 'start', 2],
|
||||
[t('owner'), 'address media--1000'],
|
||||
[t('status')],
|
||||
|
||||
@ -26,7 +26,7 @@ function Auction ({ auctionInfo, campaigns, className, winningData }: Props): Re
|
||||
const rangeMax = useLeaseRangeMax();
|
||||
const newRaise = useCall<ParaId[]>(api.query.crowdloan.newRaise);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('bids'), 'start', 3],
|
||||
[t('bidder'), 'address'],
|
||||
[t('crowdloan')],
|
||||
|
||||
@ -6,7 +6,7 @@ import type { AuctionInfo, WinnerData } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AddressMini, ParaLink } from '@polkadot/react-components';
|
||||
import { AddressMini, ParaLink, Table } from '@polkadot/react-components';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
@ -34,7 +34,7 @@ function WinRanges ({ auctionInfo, blockNumber, className = '', isFirst, isLates
|
||||
}</h1>
|
||||
)}
|
||||
</td>
|
||||
<td className='number'><h1>{formatNumber(paraId)}</h1></td>
|
||||
<Table.Column.Id value={paraId} />
|
||||
<td className='badge'><ParaLink id={paraId} /></td>
|
||||
<td className='address'><AddressMini value={accountId} /></td>
|
||||
<td className='all number'>{isCrowdloan ? t<string>('Yes') : t<string>('No')}</td>
|
||||
|
||||
@ -6,7 +6,7 @@ import type { Campaign, LeasePeriod } from '../types';
|
||||
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { AddressMini, Expander, Icon, ParaLink, Spinner, TxButton } from '@polkadot/react-components';
|
||||
import { AddressMini, Expander, Icon, ParaLink, Spinner, Table, TxButton } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi, useParaEndpoints } from '@polkadot/react-hooks';
|
||||
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
@ -79,7 +79,7 @@ function Fund ({ bestHash, bestNumber, className = '', isOngoing, leasePeriod, v
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(paraId)}</h1></td>
|
||||
<Table.Column.Id value={paraId} />
|
||||
<td className='badge'><ParaLink id={paraId} /></td>
|
||||
<td className='media--800'>
|
||||
{isWinner
|
||||
|
||||
@ -67,7 +67,7 @@ function Funds ({ bestNumber, className, leasePeriod, value }: Props): React.Rea
|
||||
[active, ended, hasLinksMap]
|
||||
);
|
||||
|
||||
const headerActiveRef = useRef([
|
||||
const headerActiveRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('ongoing'), 'start', 2],
|
||||
[undefined, 'media--800'],
|
||||
[undefined, 'media--2000'],
|
||||
@ -78,7 +78,7 @@ function Funds ({ bestNumber, className, leasePeriod, value }: Props): React.Rea
|
||||
[undefined, 'media--1000']
|
||||
]);
|
||||
|
||||
const headedEndedRef = useRef([
|
||||
const headedEndedRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('completed'), 'start', 2],
|
||||
[undefined, 'media--800'],
|
||||
[undefined, 'media--2000'],
|
||||
|
||||
@ -8,7 +8,7 @@ import type { EventMapInfo, ValidatorInfo } from './types';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { AddressMini, Badge, Expander, ParaLink } from '@polkadot/react-components';
|
||||
import { AddressMini, Badge, Expander, ParaLink, Table } from '@polkadot/react-components';
|
||||
import { BlockToTime } from '@polkadot/react-query';
|
||||
import { BN, formatNumber } from '@polkadot/util';
|
||||
|
||||
@ -90,9 +90,7 @@ function Parachain ({ bestNumber, className = '', id, lastBacked, lastInclusion,
|
||||
|
||||
return (
|
||||
<tr className={`${className} ${(lastBacked || lastInclusion || paraInfo.watermark) ? '' : 'isDisabled'}`}>
|
||||
<td className='number'>
|
||||
<h1>{formatNumber(id)}</h1>
|
||||
</td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='badge together'>
|
||||
{paraInfo.paraInfo?.locked?.isFalse
|
||||
? (
|
||||
|
||||
@ -58,7 +58,7 @@ function Parachains ({ actionsQueue, ids, leasePeriod, scheduled }: Props): Reac
|
||||
const hasLinksMap = useIsParasLinked(ids);
|
||||
const [validators, validatorMap] = useValidators(ids);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('parachains'), 'start', 2],
|
||||
['', 'media--1400'],
|
||||
[t('head'), 'start media--1500'],
|
||||
|
||||
@ -6,9 +6,8 @@ import type { LeaseInfo, LeasePeriod, QueuedAction } from '../types';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { AddressSmall, ParaLink, TxButton } from '@polkadot/react-components';
|
||||
import { AddressSmall, ParaLink, Table, TxButton } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi } from '@polkadot/react-hooks';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import Lifecycle from '../Overview/Lifecycle';
|
||||
// import ParachainInfo from '../Overview/ParachainInfo';
|
||||
@ -39,7 +38,7 @@ function Parathread ({ id, leasePeriod, leases, nextAction }: Props): React.Reac
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td className='number'><h1>{formatNumber(id)}</h1></td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='badge'><ParaLink id={id} /></td>
|
||||
<td className='address media--2000'>{manager && <AddressSmall value={manager} />}</td>
|
||||
<td className='start together hash media--1500'>{headHex}</td>
|
||||
|
||||
@ -25,7 +25,7 @@ function Parathreads ({ actionsQueue, className, ids, leasePeriod, ownedIds }: P
|
||||
const { t } = useTranslation();
|
||||
const leaseMap = useParaMap(ids);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('parathreads'), 'start', 2],
|
||||
['', 'media--2000'],
|
||||
[t('head'), 'start media--1500'],
|
||||
|
||||
@ -6,7 +6,7 @@ import type { ScheduledProposals } from '../types';
|
||||
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
|
||||
import { AddressMini, AddressSmall, Badge, Expander, ParaLink, TxButton } from '@polkadot/react-components';
|
||||
import { AddressMini, AddressSmall, Badge, Expander, ParaLink, Table, TxButton } from '@polkadot/react-components';
|
||||
import { useAccounts, useApi, useSudo } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
@ -59,7 +59,7 @@ function Proposal ({ approvedIds, id, scheduled }: Props): React.ReactElement<Pr
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td className='number together'><h1>{formatNumber(id)}</h1></td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='badge together'>
|
||||
{(proposal.isApproved || proposal.isScheduled) && (
|
||||
<Badge
|
||||
|
||||
@ -22,7 +22,7 @@ function Proposals ({ proposals }: Props): React.ReactElement<Props> {
|
||||
[proposals]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('proposals'), 'start', 3],
|
||||
[],
|
||||
[],
|
||||
|
||||
@ -24,7 +24,7 @@ function Hashes ({ className }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const hashes = usePreimages();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('preimages'), 'start', 2],
|
||||
[undefined, 'media--1300'],
|
||||
[t('size'), 'media--1000'],
|
||||
|
||||
@ -18,7 +18,8 @@ interface Props {
|
||||
|
||||
function Members ({ className, members }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const headerRef = useRef([
|
||||
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('members'), 'start']
|
||||
]);
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ function Group ({ activeIssuance, className, isMember, members, palletReferenda,
|
||||
);
|
||||
|
||||
const [header, key] = useMemo(
|
||||
() => [
|
||||
(): [([React.ReactNode?, string?, number?] | null)[], string] => [
|
||||
[
|
||||
[trackName ? <>{trackName}<div className='sub'>{trackInfo?.text}</div></> : t('referenda'), 'start', 8],
|
||||
null && [headerButton]
|
||||
|
||||
@ -10,7 +10,7 @@ import type { CurveGraph, ReferendumProps as Props } from '../types';
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { Chart, Columar, ExpandButton, LinkExternal } from '@polkadot/react-components';
|
||||
import { Chart, Columar, ExpandButton, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useBestNumber, useBlockInterval, useToggle } from '@polkadot/react-hooks';
|
||||
import { calcBlockTime } from '@polkadot/react-hooks/useBlockTime';
|
||||
import { BN_MILLION, BN_THOUSAND, bnMax, bnToBn, formatNumber, objectSpread } from '@polkadot/util';
|
||||
@ -371,9 +371,7 @@ function Referendum (props: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<>
|
||||
<tr className={className}>
|
||||
<td className='number'>
|
||||
<h1>{formatNumber(id)}</h1>
|
||||
</td>
|
||||
<Table.Column.Id value={id} />
|
||||
<Component {...props} />
|
||||
<td className='actions'>
|
||||
<div>
|
||||
|
||||
@ -7,7 +7,7 @@ import React from 'react';
|
||||
|
||||
import PreImageButton from '@polkadot/app-democracy/Overview/PreImageButton';
|
||||
import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell';
|
||||
import { LinkExternal } from '@polkadot/react-components';
|
||||
import { LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useBestNumber } from '@polkadot/react-hooks';
|
||||
import { BlockToTime } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
@ -21,7 +21,7 @@ function DispatchEntry ({ value: { at, image, imageHash, index } }: Props): Reac
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<ProposalCell
|
||||
imageHash={imageHash}
|
||||
proposal={image?.proposal}
|
||||
|
||||
@ -29,7 +29,7 @@ function DispatchQueue ({ className }: Props): React.ReactElement<Props> | null
|
||||
[bestNumber, queued]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('dispatch queue'), 'start', 2],
|
||||
[t('enact')],
|
||||
[],
|
||||
|
||||
@ -92,7 +92,7 @@ function Schedule ({ className = '' }: Props): React.ReactElement<Props> {
|
||||
[bestNumber, items]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('scheduled'), 'start'],
|
||||
[t('id'), 'start'],
|
||||
[t('remaining')],
|
||||
|
||||
@ -44,7 +44,7 @@ function Extensions ({ chainInfo, className }: Props): React.ReactElement<Props>
|
||||
[chainInfo, extensions, selectedIndex, toggleBusy]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('Extensions'), 'start']
|
||||
]);
|
||||
|
||||
|
||||
@ -94,8 +94,8 @@ function NetworkSpecs ({ chainInfo, className }: Props): React.ReactElement<Prop
|
||||
[networkSpecs]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('chain specifications'), 'start', '2']
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('chain specifications'), 'start', 2]
|
||||
]);
|
||||
|
||||
if (!isApiReady) {
|
||||
|
||||
@ -20,7 +20,7 @@ function Bids ({ className }: Props): React.ReactElement<Props> {
|
||||
const { api } = useApi();
|
||||
const bids = useCall<PalletSocietyBid[]>(api.query.society.bids);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('bids'), 'start'],
|
||||
[t('bid kind'), 'start'],
|
||||
[t('value')],
|
||||
|
||||
@ -21,7 +21,7 @@ interface Props {
|
||||
function Candidates ({ allMembers, candidates, className = '', isMember, ownMembers }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('candidates'), 'start'],
|
||||
[t('bid kind'), 'start'],
|
||||
[t('value')],
|
||||
|
||||
@ -33,7 +33,7 @@ function Defender ({ className = '', info, isMember, ownMembers }: Props): React
|
||||
const { api } = useApi();
|
||||
const votes = useCall<VoteType[]>(api.derive.society.members, undefined, OPT_VOTES);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('defender'), 'start'],
|
||||
[undefined, 'expand'],
|
||||
[]
|
||||
|
||||
@ -20,7 +20,7 @@ function Members ({ className = '', mapMembers }: Props): React.ReactElement<Pro
|
||||
const { t } = useTranslation();
|
||||
const bestNumber = useBestNumber();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('members'), 'start', 2],
|
||||
[t('voted on'), 'start'],
|
||||
[t('strikes')],
|
||||
|
||||
@ -54,10 +54,10 @@ function Suspended ({ className }: Props): React.ReactElement<Props> {
|
||||
[t('candidates'), 'start'],
|
||||
[t('bid kind'), 'start'],
|
||||
[t('value')]
|
||||
],
|
||||
] as [React.ReactNode?, string?, number?][],
|
||||
members: [
|
||||
[t('members'), 'start', 3]
|
||||
]
|
||||
] as [React.ReactNode?, string?, number?][]
|
||||
});
|
||||
|
||||
return (
|
||||
|
||||
@ -26,7 +26,7 @@ interface Props {
|
||||
function Accounts ({ allSlashes, className, footer, isInElection, list, minCommission, targets }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const hdrRef = useRef([
|
||||
const hdrRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('stashes'), 'start', 2],
|
||||
[t('controller'), 'address'],
|
||||
[t('rewards'), 'start media--1200'],
|
||||
|
||||
@ -28,7 +28,7 @@ function Pools ({ className, list, targets }: Props): React.ReactElement<Props>
|
||||
const { api } = useApi();
|
||||
const sessionProgress = useCall<DeriveSessionProgress>(api.derive.session.progress);
|
||||
|
||||
const hdrRef = useRef([
|
||||
const hdrRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('pools'), 'start', 2],
|
||||
[t('account'), 'address'],
|
||||
[t('bonded')],
|
||||
|
||||
@ -37,7 +37,7 @@ function Bags ({ className, ownStashes }: Props): React.ReactElement<Props> {
|
||||
const bags = useBagsList();
|
||||
const mapOwn = useBagsNodes(stashIds);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('bags')],
|
||||
[t('max'), 'number'],
|
||||
[t('min'), 'number'],
|
||||
|
||||
@ -185,15 +185,18 @@ function Payouts ({ className = '', historyDepth, isInElection, ownPools, ownVal
|
||||
[allRewards]
|
||||
);
|
||||
|
||||
const headerStashes = useMemo(() => [
|
||||
[myStashesIndex ? t('payout/stash') : t('overall/validator'), 'start', 2],
|
||||
[t('eras'), 'start'],
|
||||
[myStashesIndex ? t('own') : t('total')],
|
||||
[('remaining')],
|
||||
[undefined, undefined, 3]
|
||||
], [myStashesIndex, t]);
|
||||
const headerStashes = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => [
|
||||
[myStashesIndex ? t('payout/stash') : t('overall/validator'), 'start', 2],
|
||||
[t('eras'), 'start'],
|
||||
[myStashesIndex ? t('own') : t('total')],
|
||||
[('remaining')],
|
||||
[undefined, undefined, 3]
|
||||
],
|
||||
[myStashesIndex, t]
|
||||
);
|
||||
|
||||
const headerValidatorsRef = useRef([
|
||||
const headerValidatorsRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('payout/validator'), 'start', 2],
|
||||
[t('eras'), 'start'],
|
||||
[t('own')],
|
||||
|
||||
@ -7,10 +7,9 @@ import type { MembersMapEntry, Params } from './types';
|
||||
import React, { useCallback } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { AddressMini, ExpandButton, ExpanderScroll, Spinner } from '@polkadot/react-components';
|
||||
import { AddressMini, ExpandButton, ExpanderScroll, Spinner, Table } from '@polkadot/react-components';
|
||||
import { useToggle } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import Join from './Join';
|
||||
@ -56,7 +55,7 @@ function Pool ({ className = '', members, ownAccounts, params, poolId }: Props):
|
||||
return (
|
||||
<>
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(poolId)}</h1></td>
|
||||
<Table.Column.Id value={poolId} />
|
||||
<td className='start'>
|
||||
{info && (
|
||||
<div className={isExpanded ? '' : 'clamp'}>{info.metadata}</div>
|
||||
|
||||
@ -46,13 +46,16 @@ function Pools ({ className, ids, ownPools, params }: Props): React.ReactElement
|
||||
[ids, ownPools, typeIndex]
|
||||
);
|
||||
|
||||
const header = useMemo(() => [
|
||||
[t('pools'), 'start', 2],
|
||||
[t('state'), 'media--1100'],
|
||||
[t('points')],
|
||||
[t('claimable'), 'media--1400'],
|
||||
[undefined, undefined, 3]
|
||||
], [t]);
|
||||
const header = useMemo<[React.ReactNode?, string?, number?][]>(
|
||||
() => [
|
||||
[t('pools'), 'start', 2],
|
||||
[t('state'), 'media--1100'],
|
||||
[t('points')],
|
||||
[t('claimable'), 'media--1400'],
|
||||
[undefined, undefined, 3]
|
||||
],
|
||||
[t]
|
||||
);
|
||||
|
||||
const poolTypes = useRef([
|
||||
{ text: t('Own pools'), value: 'mine' },
|
||||
|
||||
@ -48,7 +48,7 @@ function Slashes ({ buttons, councilId, councilThreshold, slash }: Props): React
|
||||
};
|
||||
});
|
||||
|
||||
const headerRef = useRef<([string?, string?, number?] | false)[]>([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('era {{era}}/unapplied', {
|
||||
replace: {
|
||||
era: api.query.staking.earliestUnappliedSlash || !api.consts.staking.slashDeferDuration
|
||||
|
||||
@ -5,7 +5,7 @@ import type { StakerState } from '@polkadot/react-hooks/types';
|
||||
import type { UnappliedSlash } from '@polkadot/types/interfaces';
|
||||
import type { Slash, SlashEra } from './types';
|
||||
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
|
||||
import { getSlashProposalThreshold } from '@polkadot/apps-config';
|
||||
import { Table, ToggleGroup } from '@polkadot/react-components';
|
||||
@ -116,11 +116,15 @@ function Slashes ({ ownStashes = [], slashes }: Props): React.ReactElement<Props
|
||||
[allAccounts, members]
|
||||
);
|
||||
|
||||
const emptyHeader = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('unapplied'), 'start']
|
||||
]);
|
||||
|
||||
if (!rows.length) {
|
||||
return (
|
||||
<Table
|
||||
empty={t<string>('There are no unapplied/pending slashes')}
|
||||
header={[[t('unapplied'), 'start']]}
|
||||
header={emptyHeader.current}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import type { NominatedBy, ValidatorInfo } from '../types';
|
||||
|
||||
import React, { useCallback, useMemo } from 'react';
|
||||
|
||||
import { AddressSmall, Badge, Checkbox, Icon } from '@polkadot/react-components';
|
||||
import { AddressSmall, Badge, Checkbox, Icon, Table } from '@polkadot/react-components';
|
||||
import { checkVisibility } from '@polkadot/react-components/util';
|
||||
import { useApi, useBlockTime, useDeriveAccountInfo } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
@ -15,7 +15,6 @@ import { formatNumber } from '@polkadot/util';
|
||||
|
||||
import MaxBadge from '../MaxBadge';
|
||||
import { useTranslation } from '../translate';
|
||||
import Favorite from '../Validators/Address/Favorite';
|
||||
|
||||
interface Props {
|
||||
allSlashes?: [BN, UnappliedSlash[]][];
|
||||
@ -69,12 +68,12 @@ function Validator ({ allSlashes, canSelect, filterName, info: { accountId, bond
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<Table.Column.Favorite
|
||||
address={key}
|
||||
isFavorite={isFavorite}
|
||||
toggle={toggleFavorite}
|
||||
/>
|
||||
<td className='badge together'>
|
||||
<Favorite
|
||||
address={key}
|
||||
isFavorite={isFavorite}
|
||||
toggleFavorite={toggleFavorite}
|
||||
/>
|
||||
{isNominated
|
||||
? (
|
||||
<Badge
|
||||
|
||||
@ -288,12 +288,14 @@ function Targets ({ className = '', isInElection, nominatedBy, ownStashes, targe
|
||||
[]
|
||||
);
|
||||
|
||||
const header = useMemo(() => [
|
||||
[t('validators'), 'start', 3],
|
||||
// False positive, this is part of the type...
|
||||
// eslint-disable-next-line func-call-spacing
|
||||
const header = useMemo<[React.ReactNode?, string?, number?, (() => void)?][]>(() => [
|
||||
[t('validators'), 'start', 4],
|
||||
[t('payout'), 'media--1400'],
|
||||
[t('nominators'), 'media--1200', 2],
|
||||
[t('comm.'), 'media--1100'],
|
||||
...(SORT_KEYS as (keyof typeof labelsRef.current)[]).map((header) => [
|
||||
...(SORT_KEYS as (keyof typeof labelsRef.current)[]).map((header): [React.ReactNode?, string?, number?, (() => void)?] => [
|
||||
<>{labelsRef.current[header]}<Icon icon={sortBy === header ? (sortFromMax ? 'chevron-down' : 'chevron-up') : 'minus'} /></>,
|
||||
`${sorted ? `isClickable ${sortBy === header ? 'highlight--border' : ''} number` : 'number'} ${CLASSES[header] || ''}`,
|
||||
1,
|
||||
|
||||
@ -1,34 +0,0 @@
|
||||
// Copyright 2017-2023 @polkadot/app-staking authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import React, { useCallback } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { Icon } from '@polkadot/react-components';
|
||||
|
||||
interface Props {
|
||||
address: string;
|
||||
className?: string;
|
||||
isFavorite: boolean;
|
||||
toggleFavorite: (accountId: string) => void;
|
||||
}
|
||||
|
||||
function Favorite ({ address, className, isFavorite, toggleFavorite }: Props): React.ReactElement<Props> {
|
||||
const _onFavorite = useCallback(
|
||||
() => toggleFavorite(address),
|
||||
[address, toggleFavorite]
|
||||
);
|
||||
|
||||
return (
|
||||
<Icon
|
||||
className={className}
|
||||
color={isFavorite ? 'orange' : 'gray'}
|
||||
icon='star'
|
||||
onClick={_onFavorite}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(styled(Favorite)`
|
||||
margin-right: 1rem;
|
||||
`);
|
||||
@ -11,13 +11,12 @@ import type { NominatorValue } from './types';
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { AddressSmall, Icon, LinkExternal } from '@polkadot/react-components';
|
||||
import { AddressSmall, Icon, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { checkVisibility } from '@polkadot/react-components/util';
|
||||
import { useApi, useCall, useDeriveAccountInfo } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import Favorite from './Favorite';
|
||||
import NominatedBy from './NominatedBy';
|
||||
import StakeOther from './StakeOther';
|
||||
import Status from './Status';
|
||||
@ -117,12 +116,12 @@ function Address ({ address, className = '', filterName, hasQueries, isElected,
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<Table.Column.Favorite
|
||||
address={address}
|
||||
isFavorite={isFavorite}
|
||||
toggle={toggleFavorite}
|
||||
/>
|
||||
<td className='badge together'>
|
||||
<Favorite
|
||||
address={address}
|
||||
isFavorite={isFavorite}
|
||||
toggleFavorite={toggleFavorite}
|
||||
/>
|
||||
<Status
|
||||
isChilled={isChilled}
|
||||
isElected={isElected}
|
||||
|
||||
@ -138,17 +138,17 @@ function CurrentList ({ className, favorites, hasQueries, isIntentions, isOwn, m
|
||||
[targets]
|
||||
);
|
||||
|
||||
const headerRef = useRef(
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>(
|
||||
isIntentions
|
||||
? [
|
||||
[t('intentions'), 'start', 2],
|
||||
[t('intentions'), 'start', 3],
|
||||
[t('nominators'), 'expand'],
|
||||
[t('commission'), 'number'],
|
||||
[],
|
||||
[]
|
||||
]
|
||||
: [
|
||||
[t('validators'), 'start', 2],
|
||||
[t('validators'), 'start', 3],
|
||||
[t('other stake'), 'expand'],
|
||||
[t('own stake'), 'media--1100'],
|
||||
[t('commission')],
|
||||
|
||||
@ -16,7 +16,7 @@ interface Props {
|
||||
function Members ({ className = '', members, prime }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('members'), 'start', 3]
|
||||
]);
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import type { Hash } from '@polkadot/types/interfaces';
|
||||
import React from 'react';
|
||||
|
||||
import ProposalCell from '@polkadot/app-democracy/Overview/ProposalCell';
|
||||
import { AddressMini } from '@polkadot/react-components';
|
||||
import { AddressMini, Table } from '@polkadot/react-components';
|
||||
import { useApi, useCall, useCollectiveInstance, useVotingStatus } from '@polkadot/react-hooks';
|
||||
import { BlockToTime } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
@ -39,7 +39,7 @@ function Proposal ({ className = '', imageHash, isMember, members, prime, type }
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'><h1>{formatNumber(index)}</h1></td>
|
||||
<Table.Column.Id value={index} />
|
||||
<ProposalCell
|
||||
imageHash={imageHash}
|
||||
proposal={derive.proposal}
|
||||
|
||||
@ -22,7 +22,7 @@ interface Props extends ComponentProps {
|
||||
function Proposals ({ className = '', defaultProposal, defaultThreshold, filter, isMember, members, prime, proposalHashes, type }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<[React.ReactNode?, string?, number?][]>([
|
||||
[t('proposals'), 'start', 2],
|
||||
[t('threshold')],
|
||||
[t('voting end')],
|
||||
|
||||
@ -5,10 +5,10 @@ import type { DeriveTreasuryProposal } from '@polkadot/api-derive/types';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
|
||||
import { AddressMini, AddressSmall, LinkExternal } from '@polkadot/react-components';
|
||||
import { AddressMini, AddressSmall, LinkExternal, Table } from '@polkadot/react-components';
|
||||
import { useApi } from '@polkadot/react-hooks';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber, isFunction } from '@polkadot/util';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import Council from './Council';
|
||||
@ -36,9 +36,7 @@ function ProposalDisplay ({ className = '', isMember, members, proposal: { counc
|
||||
|
||||
return (
|
||||
<tr className={className}>
|
||||
<td className='number'>
|
||||
<h1>{formatNumber(id)}</h1>
|
||||
</td>
|
||||
<Table.Column.Id value={id} />
|
||||
<td className='address all'>
|
||||
<AddressSmall value={proposal.proposer} />
|
||||
</td>
|
||||
|
||||
@ -21,7 +21,7 @@ interface Props {
|
||||
function ProposalsBase ({ className = '', isApprovals, isMember, members, proposals }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const header = useMemo(() => [
|
||||
const header = useMemo<([React.ReactNode?, string?, number?] | false)[]>(() => [
|
||||
[isApprovals ? t<string>('Approved') : t<string>('Proposals'), 'start', 2],
|
||||
[t('beneficiary'), 'address'],
|
||||
[t('payment')],
|
||||
|
||||
@ -61,7 +61,7 @@ function Tips ({ className = '', defaultId, hashes, isMember, members, onSelectT
|
||||
[hashes, tipsWithHashes]
|
||||
);
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('tips'), 'start'],
|
||||
[t('finder'), 'address media--1400'],
|
||||
[t('reason'), 'start'],
|
||||
|
||||
@ -22,7 +22,7 @@ function Hashes ({ className }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const hashes = useHashes();
|
||||
|
||||
const headerRef = useRef([
|
||||
const headerRef = useRef<([React.ReactNode?, string?, number?] | false)[]>([
|
||||
[t('calls'), 'start'],
|
||||
[undefined, 'all'],
|
||||
[undefined, 'media--1300']
|
||||
|
||||
50
packages/react-components/src/Table/Column/Expand.tsx
Normal file
50
packages/react-components/src/Table/Column/Expand.tsx
Normal file
@ -0,0 +1,50 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ColExpandProps as Props } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Icon from '../../Icon';
|
||||
|
||||
function Expand ({ className = '', isExpanded, toggle }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<td
|
||||
className={`ui--Table-Column-Expand ${className}`}
|
||||
onClick={toggle}
|
||||
>
|
||||
<div>
|
||||
<Icon
|
||||
icon={
|
||||
isExpanded
|
||||
? 'caret-up'
|
||||
: 'caret-down'
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(styled(Expand)`
|
||||
&& {
|
||||
box-sizing: content-box;
|
||||
cursor: pointer;
|
||||
min-width: 1.7rem;
|
||||
padding-left: 0;
|
||||
text-align: left;
|
||||
width: 1.7rem;
|
||||
|
||||
> div {
|
||||
align-items: center;
|
||||
border: 1px solid var(--border-table);
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
display: inline-flex;
|
||||
height: 1.7rem;
|
||||
justify-content: center;
|
||||
width: 1.7rem;
|
||||
}
|
||||
}
|
||||
`);
|
||||
43
packages/react-components/src/Table/Column/Favorite.tsx
Normal file
43
packages/react-components/src/Table/Column/Favorite.tsx
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ColFavoriteProps as Props } from '../types';
|
||||
|
||||
import React, { useCallback } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Icon from '../../Icon';
|
||||
|
||||
function Favorite ({ address, className = '', isFavorite, toggle }: Props): React.ReactElement<Props> {
|
||||
const onClick = useCallback(
|
||||
() => toggle(address),
|
||||
[address, toggle]
|
||||
);
|
||||
|
||||
return (
|
||||
<td
|
||||
className={`ui--Table-Column-Favorite ${className}`}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Icon
|
||||
color={
|
||||
isFavorite
|
||||
? 'orange'
|
||||
: 'gray'
|
||||
}
|
||||
icon='star'
|
||||
/>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(styled(Favorite)`
|
||||
&& {
|
||||
box-sizing: content-box;
|
||||
cursor: pointer;
|
||||
min-width: 1rem;
|
||||
padding-right: 0.35rem;
|
||||
text-align: right;
|
||||
width: 1rem;
|
||||
}
|
||||
`);
|
||||
30
packages/react-components/src/Table/Column/Id.tsx
Normal file
30
packages/react-components/src/Table/Column/Id.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ColIdProps as Props } from '../types';
|
||||
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
function Id ({ className = '', value }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<td className={`ui--Table-Column-Id ${className}`}>
|
||||
<h1>{formatNumber(value)}</h1>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
// We want 5.5ch (which should be ok-ish for 5 decimals, i.e. 99,999), however
|
||||
// we wrap the display in an h1 with text at 1.75rem, so multiply it out
|
||||
const WIDTH = `${(5.5 * 1.75).toFixed(3)}ch`;
|
||||
|
||||
export default React.memo(styled(Id)`
|
||||
&& {
|
||||
box-sizing: content-box;
|
||||
min-width: ${WIDTH};
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
width: ${WIDTH};
|
||||
`);
|
||||
433
packages/react-components/src/Table/Table.tsx
Normal file
433
packages/react-components/src/Table/Table.tsx
Normal file
@ -0,0 +1,433 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { TableProps as Props } from './types';
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Columar from '../Columar';
|
||||
import Body from './Body';
|
||||
import Foot from './Foot';
|
||||
import Head from './Head';
|
||||
|
||||
function extractBodyChildren (children: React.ReactNode): [boolean, React.ReactNode | React.ReactNode[]] {
|
||||
if (!Array.isArray(children)) {
|
||||
return [!children, children];
|
||||
}
|
||||
|
||||
const kids = children.filter((child) => !!child);
|
||||
const isEmpty = kids.length === 0;
|
||||
|
||||
return [isEmpty, isEmpty ? null : kids];
|
||||
}
|
||||
|
||||
function Table ({ children, className = '', empty, emptySpinner, filter, footer, header, headerChildren, isFixed, isInline, isSplit, legend, noBodyTag }: Props): React.ReactElement<Props> {
|
||||
const [isEmpty, bodyChildren] = extractBodyChildren(children);
|
||||
|
||||
const splitBody = useMemo(
|
||||
(): [React.ReactNode[], React.ReactNode[]] | null => {
|
||||
if (!isSplit || isEmpty || !Array.isArray(bodyChildren) || bodyChildren.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const half = Math.ceil(bodyChildren.length / 2);
|
||||
|
||||
return [bodyChildren.slice(0, half), bodyChildren.slice(half)];
|
||||
},
|
||||
[bodyChildren, isEmpty, isSplit]
|
||||
);
|
||||
|
||||
const tableClassName = `${(isFixed && !isEmpty) ? 'isFixed' : 'isNotFixed'} ${isInline ? 'isInline' : ''}`;
|
||||
const headerNode = (
|
||||
<Head
|
||||
filter={filter}
|
||||
header={header}
|
||||
isEmpty={isEmpty}
|
||||
>
|
||||
{headerChildren}
|
||||
</Head>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`ui--Table ${className} ${splitBody ? 'isSplit' : ''}`}>
|
||||
{legend}
|
||||
{splitBody
|
||||
? (
|
||||
<>
|
||||
<table className={`${tableClassName} noMargin`}>
|
||||
{headerNode}
|
||||
</table>
|
||||
<Columar isPadded={false}>
|
||||
<Columar.Column>
|
||||
<table className={`${tableClassName} noMargin`}>
|
||||
<Body>
|
||||
{splitBody[0]}
|
||||
</Body>
|
||||
</table>
|
||||
</Columar.Column>
|
||||
<Columar.Column>
|
||||
<table className={tableClassName}>
|
||||
<Body>
|
||||
{splitBody[1]}
|
||||
</Body>
|
||||
</table>
|
||||
</Columar.Column>
|
||||
</Columar>
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<table className={tableClassName}>
|
||||
{headerNode}
|
||||
<Body
|
||||
empty={empty}
|
||||
emptySpinner={emptySpinner}
|
||||
noBodyTag={noBodyTag}
|
||||
>
|
||||
{bodyChildren}
|
||||
</Body>
|
||||
<Foot
|
||||
footer={footer}
|
||||
isEmpty={isEmpty}
|
||||
/>
|
||||
</table>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const BORDER_WIDTH_BT = '2px';
|
||||
const BORDER_WIDTH_LR = '1px'; // 50% of bottom/top for isSplit
|
||||
|
||||
export default React.memo(styled(Table)`
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
|
||||
&.isSplit {
|
||||
> .ui--Columar {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
table {
|
||||
border-spacing: 0;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
|
||||
&.isFixed {
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
&:not(.isInline):not(.noMargin) {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
&.isInline {
|
||||
tbody tr td {
|
||||
border-top-width: 1px;
|
||||
padding: 0.25rem 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
tr {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
|
||||
td,
|
||||
&:not(.filter) th {
|
||||
&:first-child {
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
padding-right: 0.75rem;
|
||||
}
|
||||
|
||||
&.all {
|
||||
width: 100%;
|
||||
|
||||
&:not(.overflow) {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
summary {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbody, thead {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
tr {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
tbody {
|
||||
position: relative;
|
||||
|
||||
td {
|
||||
border-top: ${BORDER_WIDTH_BT} solid var(--border-table);
|
||||
padding: 0.5rem 1rem;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
|
||||
> article.mark {
|
||||
margin-left: 0rem;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
border-left: ${BORDER_WIDTH_LR} solid var(--border-table);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-right: ${BORDER_WIDTH_LR} solid var(--border-table);
|
||||
}
|
||||
|
||||
label {
|
||||
display: block !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
div.empty {
|
||||
opacity: 0.6;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.ui--Spinner {
|
||||
margin: 0 auto;
|
||||
|
||||
.text {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.actions {
|
||||
padding-left: 0.35rem;
|
||||
width: 1%;
|
||||
|
||||
> div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-end;
|
||||
|
||||
& > * + * {
|
||||
margin-left: 0.35rem;
|
||||
}
|
||||
|
||||
.ui--Button {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(:last-child) {
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.address {
|
||||
min-width: 11rem;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
&.badge {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
&.balance {
|
||||
min-width: 20rem;
|
||||
padding: 0.5rem 0 0.75rem;
|
||||
}
|
||||
|
||||
&.button {
|
||||
padding: 0.25rem 0.35rem 0.5rem;
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
|
||||
> * {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ui--Toggle {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
|
||||
label {
|
||||
display: inline-block !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.chart {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.combined {
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
&.expand {
|
||||
&:not(.left) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ui--Expander + .ui--Expander {
|
||||
margin-top: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.hash {
|
||||
font: var(--font-mono);
|
||||
}
|
||||
|
||||
&.links {
|
||||
padding: 0.5rem 0.75rem;
|
||||
text-align: center;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
&.no-pad-left {
|
||||
padding-left: 0.125rem;
|
||||
}
|
||||
|
||||
&.no-pad-right {
|
||||
padding-right: 0.125rem;
|
||||
}
|
||||
|
||||
&.no-pad-top {
|
||||
padding-top: 0.125rem;
|
||||
}
|
||||
|
||||
&.number {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
&.relative {
|
||||
position: relative;
|
||||
|
||||
.absolute {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 0.75rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
&.overflow {
|
||||
max-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: none;
|
||||
}
|
||||
|
||||
&.start {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
&.together {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&.top {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
&.columar {
|
||||
vertical-align: top;
|
||||
|
||||
.ui--Columar .ui--Column {
|
||||
margin: 1rem 0 0.75rem 0;
|
||||
padding: 0;
|
||||
|
||||
* + h5 {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.middle {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&.mini {
|
||||
padding: 0 !important;
|
||||
width: fit-content;
|
||||
white-space: normal;
|
||||
|
||||
> div {
|
||||
margin-right: 0.75rem;
|
||||
max-width: 3.8rem;
|
||||
min-width: 3.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.upper {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.ui--Button-Group .ui--Button:not(.isToplevel) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
tr {
|
||||
background: var(--bg-table);
|
||||
|
||||
& + tr.isExpanded {
|
||||
td {
|
||||
border-top: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedBottom {
|
||||
td {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedTop {
|
||||
td {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedAll {
|
||||
td {
|
||||
padding-bottom: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.transparent {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&.isCollapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ui--Button-Group {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ui--Button:not(.isIcon):not(:hover) {
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.ui.toggle.checkbox input:checked ~ .box:before,
|
||||
.ui.toggle.checkbox input:checked ~ label:before {
|
||||
background-color: #eee !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
@ -1,455 +1,25 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import type { ColExpandProps, ColFavoriteProps, ColIdProps, TableProps } from './types';
|
||||
|
||||
import Columar from '../Columar';
|
||||
import Body from './Body';
|
||||
import Foot from './Foot';
|
||||
import Head from './Head';
|
||||
import React from 'react';
|
||||
|
||||
interface TableProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
empty?: React.ReactNode | false;
|
||||
emptySpinner?: React.ReactNode;
|
||||
filter?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
header?: [React.ReactNode?, string?, number?, (() => void)?][];
|
||||
headerChildren?: React.ReactNode;
|
||||
isFixed?: boolean;
|
||||
isInline?: boolean;
|
||||
isSplit?: boolean;
|
||||
legend?: React.ReactNode;
|
||||
noBodyTag?: boolean;
|
||||
}
|
||||
import Expand from './Column/Expand';
|
||||
import Favorite from './Column/Favorite';
|
||||
import Id from './Column/Id';
|
||||
import TableBase from './Table';
|
||||
|
||||
function extractBodyChildren (children: React.ReactNode): [boolean, React.ReactNode | React.ReactNode[]] {
|
||||
if (!Array.isArray(children)) {
|
||||
return [!children, children];
|
||||
type TableType = React.ComponentType<TableProps> & {
|
||||
Column: {
|
||||
Expand: React.ComponentType<ColExpandProps>;
|
||||
Favorite: React.ComponentType<ColFavoriteProps>;
|
||||
Id: React.ComponentType<ColIdProps>;
|
||||
}
|
||||
};
|
||||
|
||||
const kids = children.filter((child) => !!child);
|
||||
const isEmpty = kids.length === 0;
|
||||
const Table = TableBase as unknown as TableType;
|
||||
|
||||
return [isEmpty, isEmpty ? null : kids];
|
||||
}
|
||||
Table.Column = { Expand, Favorite, Id };
|
||||
|
||||
function Table ({ children, className = '', empty, emptySpinner, filter, footer, header, headerChildren, isFixed, isInline, isSplit, legend, noBodyTag }: TableProps): React.ReactElement<TableProps> {
|
||||
const [isEmpty, bodyChildren] = extractBodyChildren(children);
|
||||
|
||||
const splitBody = useMemo(
|
||||
(): [React.ReactNode[], React.ReactNode[]] | null => {
|
||||
if (!isSplit || isEmpty || !Array.isArray(bodyChildren) || bodyChildren.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const half = Math.ceil(bodyChildren.length / 2);
|
||||
|
||||
return [bodyChildren.slice(0, half), bodyChildren.slice(half)];
|
||||
},
|
||||
[bodyChildren, isEmpty, isSplit]
|
||||
);
|
||||
|
||||
const tableClassName = `${(isFixed && !isEmpty) ? 'isFixed' : 'isNotFixed'} ${isInline ? 'isInline' : ''}`;
|
||||
const headerNode = (
|
||||
<Head
|
||||
filter={filter}
|
||||
header={header}
|
||||
isEmpty={isEmpty}
|
||||
>
|
||||
{headerChildren}
|
||||
</Head>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`ui--Table ${className} ${splitBody ? 'isSplit' : ''}`}>
|
||||
{legend}
|
||||
{splitBody
|
||||
? (
|
||||
<>
|
||||
<table className={`${tableClassName} noMargin`}>
|
||||
{headerNode}
|
||||
</table>
|
||||
<Columar isPadded={false}>
|
||||
<Columar.Column>
|
||||
<table className={`${tableClassName} noMargin`}>
|
||||
<Body>
|
||||
{splitBody[0]}
|
||||
</Body>
|
||||
</table>
|
||||
</Columar.Column>
|
||||
<Columar.Column>
|
||||
<table className={tableClassName}>
|
||||
<Body>
|
||||
{splitBody[1]}
|
||||
</Body>
|
||||
</table>
|
||||
</Columar.Column>
|
||||
</Columar>
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<table className={tableClassName}>
|
||||
{headerNode}
|
||||
<Body
|
||||
empty={empty}
|
||||
emptySpinner={emptySpinner}
|
||||
noBodyTag={noBodyTag}
|
||||
>
|
||||
{bodyChildren}
|
||||
</Body>
|
||||
<Foot
|
||||
footer={footer}
|
||||
isEmpty={isEmpty}
|
||||
/>
|
||||
</table>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const BORDER_WIDTH_BT = '2px';
|
||||
const BORDER_WIDTH_LR = '1px'; // 50% of bottom/top for isSplit
|
||||
|
||||
export default React.memo(styled(Table)`
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
|
||||
&.isSplit {
|
||||
> .ui--Columar {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
table {
|
||||
border-spacing: 0;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
z-index: 1;
|
||||
|
||||
&.isFixed {
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
&:not(.isInline):not(.noMargin) {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
&.isInline {
|
||||
tbody tr td {
|
||||
border-top-width: 1px;
|
||||
padding: 0.25rem 0.75rem;
|
||||
}
|
||||
}
|
||||
|
||||
tr {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
|
||||
td,
|
||||
&:not(.filter) th {
|
||||
&:first-child {
|
||||
padding-left: 1.5rem;
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
padding-right: 0.75rem;
|
||||
}
|
||||
|
||||
&.all {
|
||||
width: 100%;
|
||||
|
||||
&:not(.overflow) {
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
summary {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbody, thead {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
tr {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
tbody {
|
||||
position: relative;
|
||||
|
||||
td {
|
||||
border-top: ${BORDER_WIDTH_BT} solid var(--border-table);
|
||||
padding: 0.5rem 1rem;
|
||||
text-align: left;
|
||||
vertical-align: middle;
|
||||
|
||||
> article.mark {
|
||||
margin-left: 0rem;
|
||||
}
|
||||
|
||||
&:first-child {
|
||||
border-left: ${BORDER_WIDTH_LR} solid var(--border-table);
|
||||
}
|
||||
|
||||
&:last-child {
|
||||
border-right: ${BORDER_WIDTH_LR} solid var(--border-table);
|
||||
}
|
||||
|
||||
label {
|
||||
display: block !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
div.empty {
|
||||
opacity: 0.6;
|
||||
padding: 0.25rem;
|
||||
}
|
||||
|
||||
.ui--Spinner {
|
||||
margin: 0 auto;
|
||||
|
||||
.text {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.actions {
|
||||
padding-left: 0.35rem;
|
||||
width: 1%;
|
||||
|
||||
> div {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-end;
|
||||
|
||||
& > * + * {
|
||||
margin-left: 0.35rem;
|
||||
}
|
||||
|
||||
.ui--Button {
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
&:not(:last-child) {
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.address {
|
||||
min-width: 11rem;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
&.badge {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
&.balance {
|
||||
min-width: 20rem;
|
||||
padding: 0.5rem 0 0.75rem;
|
||||
}
|
||||
|
||||
&.button {
|
||||
padding: 0.25rem 0.35rem 0.5rem;
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
|
||||
> * {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ui--Toggle {
|
||||
display: inline-block;
|
||||
white-space: nowrap;
|
||||
|
||||
label {
|
||||
display: inline-block !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.chart {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.combined {
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
&.expand {
|
||||
&:not(.left) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ui--Expander + .ui--Expander {
|
||||
margin-top: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.hash {
|
||||
font: var(--font-mono);
|
||||
}
|
||||
|
||||
&.links {
|
||||
padding: 0.5rem 0.75rem;
|
||||
text-align: center;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
&.no-pad-left {
|
||||
padding-left: 0.125rem;
|
||||
}
|
||||
|
||||
&.no-pad-right {
|
||||
padding-right: 0.125rem;
|
||||
}
|
||||
|
||||
&.no-pad-top {
|
||||
padding-top: 0.125rem;
|
||||
}
|
||||
|
||||
&.number {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
&.relative {
|
||||
position: relative;
|
||||
|
||||
.absolute {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 0.75rem;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
&.overflow {
|
||||
max-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: none;
|
||||
}
|
||||
|
||||
&.start {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
&.together {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&.top {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
&.columar {
|
||||
vertical-align: top;
|
||||
|
||||
.ui--Columar .ui--Column {
|
||||
margin: 1rem 0 0.75rem 0;
|
||||
padding: 0;
|
||||
|
||||
* + h5 {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.middle {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&.mini {
|
||||
padding: 0 !important;
|
||||
width: fit-content;
|
||||
white-space: normal;
|
||||
|
||||
> div {
|
||||
margin-right: 0.75rem;
|
||||
max-width: 3.8rem;
|
||||
min-width: 3.8rem;
|
||||
}
|
||||
}
|
||||
|
||||
&.upper {
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
&.favorite {
|
||||
padding-right: 0;
|
||||
|
||||
.ui--Icon.isSelected {
|
||||
color: darkorange;
|
||||
}
|
||||
}
|
||||
|
||||
.ui--Button-Group .ui--Button:not(.isToplevel) {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
tr {
|
||||
background: var(--bg-table);
|
||||
|
||||
& + tr.isExpanded {
|
||||
td {
|
||||
border-top: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedBottom {
|
||||
td {
|
||||
padding-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedTop {
|
||||
td {
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.packedAll {
|
||||
td {
|
||||
padding-bottom: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.transparent {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&.isCollapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ui--Button-Group {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ui--Button:not(.isIcon):not(:hover) {
|
||||
background: transparent !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.ui.toggle.checkbox input:checked ~ .box:before,
|
||||
.ui.toggle.checkbox input:checked ~ label:before {
|
||||
background-color: #eee !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
export default Table;
|
||||
|
||||
38
packages/react-components/src/Table/types.ts
Normal file
38
packages/react-components/src/Table/types.ts
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2017-2023 @polkadot/react-components authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
export interface ColExpandProps {
|
||||
className?: string;
|
||||
isExpanded: boolean;
|
||||
toggle: () => void;
|
||||
}
|
||||
|
||||
export interface ColFavoriteProps {
|
||||
address: string;
|
||||
className?: string;
|
||||
isFavorite: boolean;
|
||||
toggle: (address: string) => void;
|
||||
}
|
||||
|
||||
export interface ColIdProps {
|
||||
className?: string;
|
||||
value: BN | number;
|
||||
}
|
||||
|
||||
export interface TableProps {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
empty?: React.ReactNode | false;
|
||||
emptySpinner?: React.ReactNode;
|
||||
filter?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
header?: ([React.ReactNode?, string?, number?, (() => void)?] | false | null | undefined)[];
|
||||
headerChildren?: React.ReactNode;
|
||||
isFixed?: boolean;
|
||||
isInline?: boolean;
|
||||
isSplit?: boolean;
|
||||
legend?: React.ReactNode;
|
||||
noBodyTag?: boolean;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user