Explorer query updates (#1127)
This commit is contained in:
parent
f3ed50489e
commit
0681375865
@ -9,6 +9,7 @@ import { withCalls, withMulti } from '@polkadot/ui-api';
|
||||
import { isHex } from '@polkadot/util';
|
||||
import { BlockNumber } from '@polkadot/types';
|
||||
|
||||
import Query from '../Query';
|
||||
import BlockByHash from './ByHash';
|
||||
import BlockByNumber from './ByNumber';
|
||||
|
||||
@ -53,19 +54,19 @@ class Entry extends React.Component<Props, State> {
|
||||
return null;
|
||||
}
|
||||
|
||||
return isHex(value)
|
||||
? (
|
||||
<BlockByHash
|
||||
const Component = isHex(value)
|
||||
? BlockByHash
|
||||
: BlockByNumber;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Query />
|
||||
<Component
|
||||
key={value}
|
||||
value={value}
|
||||
/>
|
||||
)
|
||||
: (
|
||||
<BlockByNumber
|
||||
key={value}
|
||||
value={value}
|
||||
/>
|
||||
);
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import React from 'react';
|
||||
|
||||
import BlockHeaders from './BlockHeaders';
|
||||
import EventsRecent from './EventsRecent';
|
||||
import Query from './Query';
|
||||
import Summary from './Summary';
|
||||
import translate from './translate';
|
||||
|
||||
@ -19,6 +20,7 @@ class Main extends React.PureComponent<Props> {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Query />
|
||||
<Summary />
|
||||
<div className='explorer--Overview ui--flex-medium'>
|
||||
<div className='column'>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { Button, Input } from '@polkadot/ui-app';
|
||||
import { Button, FilterOverlay, Input } from '@polkadot/ui-app';
|
||||
import { isHex } from '@polkadot/util';
|
||||
|
||||
import translate from './translate';
|
||||
@ -34,26 +34,23 @@ class Query extends React.PureComponent<Props, State> {
|
||||
const { value, isValid } = this.state;
|
||||
|
||||
return (
|
||||
<summary className='explorer--query'>
|
||||
<div className='ui--row'>
|
||||
<div className='storage--actionrow head'>
|
||||
<Input
|
||||
className='storage--actionrow-value'
|
||||
defaultValue={this.props.value}
|
||||
isError={!isValid && value.length !== 0}
|
||||
placeholder={t('block hash or number to query')}
|
||||
onChange={this.setHash}
|
||||
withLabel={false}
|
||||
/>
|
||||
<Button
|
||||
icon='play'
|
||||
isDisabled={!isValid}
|
||||
isPrimary
|
||||
onClick={this.onQuery}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</summary>
|
||||
<FilterOverlay>
|
||||
<Input
|
||||
className='explorer--query'
|
||||
defaultValue={this.props.value}
|
||||
isError={!isValid && value.length !== 0}
|
||||
placeholder={t('block hash or number to query')}
|
||||
onChange={this.setHash}
|
||||
onEnter={this.onQuery}
|
||||
withLabel={false}
|
||||
>
|
||||
<Button
|
||||
icon='play'
|
||||
isPrimary
|
||||
onClick={this.onQuery}
|
||||
/>
|
||||
</Input>
|
||||
</FilterOverlay>
|
||||
);
|
||||
}
|
||||
|
||||
@ -63,10 +60,12 @@ class Query extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private onQuery = () => {
|
||||
const { value } = this.state;
|
||||
private onQuery = (): void => {
|
||||
const { isValid, value } = this.state;
|
||||
|
||||
window.location.hash = `/explorer/query/${value}`;
|
||||
if (isValid && value.length !== 0) {
|
||||
window.location.hash = `/explorer/query/${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
private stateFromValue (value: string): State {
|
||||
@ -61,7 +61,6 @@ class ExplorerApp extends React.Component<Props, State> {
|
||||
basePath={basePath}
|
||||
hidden={hidden}
|
||||
items={items}
|
||||
query={[undefined, 'query']}
|
||||
/>
|
||||
</header>
|
||||
<Switch>
|
||||
|
||||
@ -21,7 +21,7 @@ const Wrapper = styled.div`
|
||||
top: 0.4rem;
|
||||
|
||||
> div {
|
||||
max-width: 35rem;
|
||||
max-width: 35rem !important;
|
||||
}
|
||||
|
||||
.ui--Labelled label {
|
||||
|
||||
@ -28,6 +28,7 @@ type Props = BareProps & {
|
||||
maxLength?: number,
|
||||
min?: any,
|
||||
name?: string,
|
||||
onEnter?: () => void,
|
||||
onChange?: (value: string) => void,
|
||||
onBlur?: (event: React.KeyboardEvent<Element>) => void,
|
||||
onKeyDown?: (event: React.KeyboardEvent<Element>) => void,
|
||||
@ -172,11 +173,15 @@ export default class Input extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private onKeyUp = (event: React.KeyboardEvent<Element>): void => {
|
||||
const { onKeyUp } = this.props;
|
||||
const { onEnter, onKeyUp } = this.props;
|
||||
|
||||
if (onKeyUp) {
|
||||
onKeyUp(event);
|
||||
}
|
||||
|
||||
if (onEnter && event.keyCode === 13) {
|
||||
onEnter();
|
||||
}
|
||||
}
|
||||
|
||||
private onPaste = (event: React.ClipboardEvent<Element>): void => {
|
||||
|
||||
@ -8,8 +8,6 @@ import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
import { classes } from './util';
|
||||
import Query from './Query';
|
||||
import { FilterOverlay } from '@polkadot/ui-app';
|
||||
|
||||
export type TabItem = {
|
||||
hasParams?: boolean,
|
||||
@ -20,13 +18,12 @@ export type TabItem = {
|
||||
type Props = BareProps & {
|
||||
basePath: string,
|
||||
hidden?: Array<string>,
|
||||
items: Array<TabItem>,
|
||||
query?: Array<string | undefined>
|
||||
items: Array<TabItem>
|
||||
};
|
||||
|
||||
export default class Tabs extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { className, hidden = [], items, query, style } = this.props;
|
||||
const { className, hidden = [], items, style } = this.props;
|
||||
return (
|
||||
<div
|
||||
className={classes('ui--Menu ui menu tabular', className)}
|
||||
@ -37,11 +34,6 @@ export default class Tabs extends React.PureComponent<Props> {
|
||||
.filter(({ name }) => !hidden.includes(name))
|
||||
.map(this.renderItem)
|
||||
}
|
||||
<FilterOverlay>
|
||||
{query && query.includes(window.location.hash.split('/')[2]) && (
|
||||
<Query/>
|
||||
)}
|
||||
</FilterOverlay>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user