ProposalCell with top alignment (#2353)

* ProposalCell to top

* Cleanup docs formatting
This commit is contained in:
Jaco Greeff 2020-03-09 08:02:27 +01:00 committed by GitHub
parent 0f59bb1bc6
commit 723f4d6487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash, Proposal } from '@polkadot/types/interfaces';
import { FunctionMetadataLatest, Hash, Proposal } from '@polkadot/types/interfaces';
import React from 'react';
import { registry } from '@polkadot/react-api';
@ -16,12 +16,27 @@ interface Props {
proposalHash: Hash | string;
}
function formatDocs (meta?: FunctionMetadataLatest): React.ReactNode | null {
if (!meta) {
return null;
}
const strings = meta.documentation.map((doc): string => doc.toString().trim());
const firstEmpty = strings.findIndex((doc): boolean => !doc.length);
if (!firstEmpty) {
return null;
}
return strings.slice(0, firstEmpty).join(' ');
}
export default function ProposalCell ({ className, proposal, proposalHash }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
if (!proposal) {
return (
<td className={`${className} all`}>
<td className={`${className} all top`}>
<label>{t('preimage hash')}</label>
{proposalHash.toString()}
</td>
@ -31,10 +46,10 @@ export default function ProposalCell ({ className, proposal, proposalHash }: Pro
const { meta, method, section } = registry.findMetaCall(proposal.callIndex);
return (
<td className={`${className} all`}>
<td className={`${className} all top`}>
<div>{section}.{method}</div>
<details>
<summary>{meta?.documentation.join(' ') || t('Details')}</summary>
<summary>{formatDocs(meta) || t('Details')}</summary>
<Call
labelHash={t('proposal hash')}
value={proposal}

View File

@ -30,7 +30,7 @@ function formatMeta (meta?: FunctionMetadataLatest): React.ReactNode | null {
}
const strings = meta.documentation.map((doc): string => doc.toString().trim());
const firstEmpty = strings.findIndex((doc): boolean => doc.length === 0);
const firstEmpty = strings.findIndex((doc): boolean => !doc.length);
if (!firstEmpty) {
return null;