Allow InputAddress with no options (#4227)

* Allow InputAddress with no options

* Update packages/react-params/src/Param/index.tsx
This commit is contained in:
Jaco Greeff 2020-12-17 11:07:08 +01:00 committed by GitHub
parent e6a1470d4d
commit 1cf7b5e629
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 12 deletions

View File

@ -133,14 +133,8 @@ class InputAddress extends React.PureComponent<Props, State> {
}
public render (): React.ReactNode {
const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, optionsAll, placeholder, type = DEFAULT_TYPE, withEllipsis, withLabel } = this.props;
const { className = '', defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, labelExtra, options, placeholder, withEllipsis, withLabel } = this.props;
const { lastValue, value } = this.state;
const hasOptions = (options && options.length !== 0) || (optionsAll && Object.keys(optionsAll[type]).length !== 0);
if (!hasOptions && !isDisabled) {
return null;
}
const lastOption = this.getLastOptionValue();
const actualValue = transformToAddress(
isDisabled || (defaultValue && this.hasValue(defaultValue))

View File

@ -1,9 +1,9 @@
// Copyright 2017-2020 @polkadot/react-params authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Props as CProps, Props } from '../types';
import type { Props } from '../types';
import React, { useMemo, useRef } from 'react';
import React, { useMemo } from 'react';
import { encodeTypeDef } from '@polkadot/types/create';
import { isUndefined } from '@polkadot/util';
@ -12,7 +12,10 @@ import findComponent from './findComponent';
import Static from './Static';
function Param ({ className = '', defaultValue, isDisabled, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
const compRef = useRef<React.ComponentType<CProps> | null>(findComponent(registry, type, overrides));
const Component = useMemo(
() => findComponent(registry, type, overrides),
[registry, type, overrides]
);
const label = useMemo(
() => isUndefined(name)
@ -21,7 +24,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption
[name, type]
);
if (!compRef.current) {
if (!Component) {
return null;
}
@ -34,7 +37,7 @@ function Param ({ className = '', defaultValue, isDisabled, isInOption, isOption
/>
)
: (
<compRef.current
<Component
className={`ui--Param ${className}`}
defaultValue={defaultValue}
isDisabled={isDisabled}