From f628f8b9b6d10ea7fad15bab4c38a4d5036753d1 Mon Sep 17 00:00:00 2001 From: Jaco Date: Tue, 3 May 2022 14:37:31 +0200 Subject: [PATCH] Use path refs for combinations (#7509) * Use path refs for combinations * Adjust * Adjust padding * Path variable renames --- packages/page-explorer/src/index.tsx | 47 +++++++++++++++-------- packages/page-extrinsics/src/Decoder.tsx | 2 +- packages/page-extrinsics/src/index.tsx | 27 ++++++++++--- packages/page-staking/src/index.tsx | 29 ++++++++++---- packages/react-components/src/Inspect.tsx | 3 +- 5 files changed, 76 insertions(+), 32 deletions(-) diff --git a/packages/page-explorer/src/index.tsx b/packages/page-explorer/src/index.tsx index af9063e035..92d3521459 100644 --- a/packages/page-explorer/src/index.tsx +++ b/packages/page-explorer/src/index.tsx @@ -1,9 +1,11 @@ // Copyright 2017-2022 @polkadot/app-explorer authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { TFunction } from 'i18next'; +import type { TabItem } from '@polkadot/react-components/Tabs/types'; import type { KeyedEvent } from '@polkadot/react-query/types'; -import React, { useContext, useMemo, useRef } from 'react'; +import React, { useContext, useRef, useState } from 'react'; import { Route, Switch } from 'react-router'; import { Tabs } from '@polkadot/react-components'; @@ -23,13 +25,20 @@ interface Props { newEvents?: KeyedEvent[]; } -function ExplorerApp ({ basePath, className }: Props): React.ReactElement { - const { t } = useTranslation(); - const { api } = useApi(); - const { lastHeaders } = useContext(BlockAuthorsContext); - const { eventCount, events } = useContext(EventsContext); +function createPathRef (basePath: string): Record { + return { + forks: `${basePath}/forks`, + latency: `${basePath}/latency`, + node: `${basePath}/node`, + query: [ + `${basePath}/query/:value`, + `${basePath}/query/` + ] + }; +} - const itemsRef = useRef([ +function createItemsRef (t: TFunction): TabItem[] { + return [ { isRoot: true, name: 'chain', @@ -52,12 +61,17 @@ function ExplorerApp ({ basePath, className }: Props): React.ReactElement name: 'node', text: t('Node info') } - ]); + ]; +} - const hidden = useMemo( - () => api.query.babe ? [] : ['forks'], - [api] - ); +function ExplorerApp ({ basePath, className }: Props): React.ReactElement { + const { t } = useTranslation(); + const { api } = useApi(); + const { lastHeaders } = useContext(BlockAuthorsContext); + const { eventCount, events } = useContext(EventsContext); + const itemsRef = useRef(createItemsRef(t)); + const pathRef = useRef(createPathRef(basePath)); + const hidden = useState(() => api.query.babe ? [] : ['forks']); return (
@@ -67,11 +81,10 @@ function ExplorerApp ({ basePath, className }: Props): React.ReactElement items={itemsRef.current} /> - - - - - + + + +
{ - const { value: encoded } = useParams<{ value: string }>(); + const { encoded } = useParams<{ encoded: string }>(); const [initialValue] = useState(() => defaultValue || encoded); const { t } = useTranslation(); const { api } = useApi(); diff --git a/packages/page-extrinsics/src/index.tsx b/packages/page-extrinsics/src/index.tsx index 87d7937501..0ae16d78d8 100644 --- a/packages/page-extrinsics/src/index.tsx +++ b/packages/page-extrinsics/src/index.tsx @@ -1,6 +1,8 @@ // Copyright 2017-2022 @polkadot/app-extrinsics authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { TFunction } from 'i18next'; +import type { TabItem } from '@polkadot/react-components/Tabs/types'; import type { AppProps as Props } from '@polkadot/react-components/types'; import type { DecodedExtrinsic } from './types'; @@ -13,11 +15,17 @@ import Decoder from './Decoder'; import Submission from './Submission'; import { useTranslation } from './translate'; -function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { - const { t } = useTranslation(); - const [decoded, setDecoded] = useState(null); +function createPathRef (basePath: string): Record { + return { + decode: [ + `${basePath}/decode/:encoded`, + `${basePath}/decode` + ] + }; +} - const itemsRef = useRef([ +function createItemsRef (t: TFunction): TabItem[] { + return [ { isRoot: true, name: 'create', @@ -28,7 +36,14 @@ function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { name: 'decode', text: t('Decode') } - ]); + ]; +} + +function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { + const { t } = useTranslation(); + const [decoded, setDecoded] = useState(null); + const itemsRef = useRef(createItemsRef(t)); + const pathRef = useRef(createPathRef(basePath)); return (
@@ -37,7 +52,7 @@ function ExtrinsicsApp ({ basePath }: Props): React.ReactElement { items={itemsRef.current} /> - + { + return { + bags: `${basePath}/bags`, + payout: `${basePath}/payout`, + pools: `${basePath}/pools`, + query: [ + `${basePath}/query/:value`, + `${basePath}/query` + ], + slashes: `${basePath}/slashes`, + targets: `${basePath}/targets` + }; +} + function StakingApp ({ basePath, className = '' }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); @@ -65,6 +79,7 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement hasAccounts && !!(api.query.imOnline?.authoredBlocks) && !!(api.query.staking.activeEra), @@ -143,29 +158,29 @@ function StakingApp ({ basePath, className = '' }: Props): React.ReactElement - + - + - + - + - + - +