Add optional hash to external renders (#2328)

This commit is contained in:
Jaco Greeff 2020-03-15 12:10:21 +01:00 committed by GitHub
parent 6a17f228e0
commit 6530e49c3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 8 deletions

View File

@ -17,6 +17,9 @@ export default {
referendum: 'proposal/referendum',
treasury: 'proposal/treasuryproposal'
},
create: (chain: string, path: string, data: BN | number | string): string =>
`https://commonwealth.im/${chain}/${path}/${data.toString()}`
create: (chain: string, path: string, data: BN | number | string, hash?: string): string => {
const withHash = path === 'proposal/councilmotion';
return `https://commonwealth.im/${chain}/${path}/${withHash ? hash : data.toString()}`;
}
};

View File

@ -10,5 +10,5 @@ export interface ExternalDef {
isActive: boolean;
chains: Record<string, string>;
paths: Partial<Record<LinkTypes, string>>;
create: (chain: string, path: string, data: BN | number | string) => string;
create: (chain: string, path: string, data: BN | number | string, hash?: string) => string;
}

View File

@ -73,6 +73,7 @@ export default function Motion ({ className, isMember, members, motion: { hash,
/>
<LinkExternal
data={index}
hash={hash.toString()}
type='council'
/>
</td>

View File

@ -17,11 +17,12 @@ import Tooltip from './Tooltip';
interface Props {
className?: string;
data: BN | number | string;
hash?: string;
type: LinkTypes;
withShort?: boolean;
}
function genLinks (systemChain: string, { data, type, withShort }: Props): React.ReactNode[] {
function genLinks (systemChain: string, { data, hash, type, withShort }: Props): React.ReactNode[] {
return Object
.entries(linked)
.map(([name, { isActive, chains, paths, create }]): React.ReactNode | null => {
@ -33,7 +34,7 @@ function genLinks (systemChain: string, { data, type, withShort }: Props): React
}
const trigger = `${name}-${type}-${data}`;
const link = create(extChain, extPath, data);
const link = create(extChain, extPath, data, hash);
return (
<a
@ -59,12 +60,12 @@ function genLinks (systemChain: string, { data, type, withShort }: Props): React
.filter((node): node is React.ReactNode => !!node);
}
function LinkExternal ({ className, data, type, withShort }: Props): React.ReactElement<Props> | null {
function LinkExternal ({ className, data, hash, type, withShort }: Props): React.ReactElement<Props> | null {
const { t } = useTranslation();
const { systemChain } = useApi();
const links = useMemo((): React.ReactNode[] => {
return genLinks(systemChain, { data, type, withShort });
}, [systemChain, data, type, withShort]);
return genLinks(systemChain, { data, hash, type, withShort });
}, [systemChain, data, hash, type, withShort]);
if (!links.length) {
return null;