Allow tags in Account/Address edit (#1142)
* Start of tag input * Add tags to account edit * Don't allow edits/tags on dev accounts * Add tags to address book * Update description * Add tags as part of address & account creation * Linting
This commit is contained in:
parent
73429ecb6b
commit
89e77120a7
@ -12,7 +12,7 @@ import FileSaver from 'file-saver';
|
||||
import React from 'react';
|
||||
import { DEV_PHRASE } from '@polkadot/keyring/defaults';
|
||||
import { withApi, withMulti } from '@polkadot/ui-api';
|
||||
import { AddressRow, AddressSummary, Button, Dropdown, Input, Labelled, Modal, Password } from '@polkadot/ui-app';
|
||||
import { AddressSummary, AddressRow, Button, Dropdown, Input, InputTags, Labelled, Modal, Password } from '@polkadot/ui-app';
|
||||
import { InputAddress } from '@polkadot/ui-app/InputAddress';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
@ -51,7 +51,8 @@ type State = {
|
||||
seed: string,
|
||||
seedOptions: Array<SeedOption>,
|
||||
seedType: SeedType,
|
||||
showWarning: boolean
|
||||
showWarning: boolean,
|
||||
tags: Array<string>
|
||||
};
|
||||
|
||||
const DEFAULT_TYPE = 'sr25519';
|
||||
@ -156,7 +157,7 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
|
||||
private renderInput () {
|
||||
const { t } = this.props;
|
||||
const { deriveError, derivePath, isNameValid, isPassValid, isSeedValid, name, pairType, password, seed, seedOptions, seedType } = this.state;
|
||||
const { deriveError, derivePath, isNameValid, isPassValid, isSeedValid, name, pairType, password, seed, seedOptions, seedType, tags } = this.state;
|
||||
const seedLabel = (() => {
|
||||
switch (seedType) {
|
||||
case 'bip':
|
||||
@ -209,6 +210,14 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
value={password}
|
||||
/>
|
||||
</div>
|
||||
<div className='ui--row'>
|
||||
<InputTags
|
||||
help={t('Additional user-specified tags that can be used to identify the account. Tags can be used for categorization and filtering.')}
|
||||
label={t('user-defined tags')}
|
||||
onChange={this.onChangeTags}
|
||||
value={tags}
|
||||
/>
|
||||
</div>
|
||||
<details
|
||||
className='accounts--Creator-advanced'
|
||||
open
|
||||
@ -324,14 +333,15 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
password: '',
|
||||
pairType,
|
||||
seedType,
|
||||
showWarning: false
|
||||
showWarning: false,
|
||||
tags: []
|
||||
};
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
this.setState(
|
||||
(prevState: State, props: Props): State => {
|
||||
const { derivePath = prevState.derivePath, name = prevState.name, pairType = prevState.pairType, password = prevState.password, seed = prevState.seed, seedOptions = prevState.seedOptions, seedType = prevState.seedType, showWarning = prevState.showWarning } = newState;
|
||||
const { derivePath = prevState.derivePath, name = prevState.name, pairType = prevState.pairType, password = prevState.password, seed = prevState.seed, seedOptions = prevState.seedOptions, seedType = prevState.seedType, showWarning = prevState.showWarning, tags = prevState.tags } = newState;
|
||||
let address = prevState.address;
|
||||
const deriveError = deriveValidate(derivePath, pairType);
|
||||
const isNameValid = !!name;
|
||||
@ -362,7 +372,8 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
seed,
|
||||
seedOptions,
|
||||
seedType,
|
||||
showWarning
|
||||
showWarning,
|
||||
tags
|
||||
};
|
||||
}
|
||||
);
|
||||
@ -376,6 +387,10 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
this.nextState({ name } as State);
|
||||
}
|
||||
|
||||
private onChangePairType = (pairType: KeypairType): void => {
|
||||
this.nextState({ pairType } as State);
|
||||
}
|
||||
|
||||
private onChangePass = (password: string): void => {
|
||||
this.nextState({ password } as State);
|
||||
}
|
||||
@ -384,8 +399,8 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
this.nextState({ seed } as State);
|
||||
}
|
||||
|
||||
private onChangePairType = (pairType: KeypairType): void => {
|
||||
this.nextState({ pairType } as State);
|
||||
private onChangeTags = (tags: Array<string>): void => {
|
||||
this.setState({ tags });
|
||||
}
|
||||
|
||||
private onShowWarning = (): void => {
|
||||
@ -398,14 +413,14 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
|
||||
private onCommit = (): void => {
|
||||
const { basePath, onStatusChange, t } = this.props;
|
||||
const { derivePath, name, pairType, password, seed } = this.state;
|
||||
const { derivePath, name, pairType, password, seed, tags } = this.state;
|
||||
|
||||
const status = {
|
||||
action: 'create'
|
||||
} as ActionStatus;
|
||||
|
||||
try {
|
||||
const { json, pair } = keyring.addUri(`${seed}${derivePath}`, password, { name }, pairType);
|
||||
const { json, pair } = keyring.addUri(`${seed}${derivePath}`, password, { name, tags }, pairType);
|
||||
const blob = new Blob([JSON.stringify(json)], { type: 'application/json; charset=utf-8' });
|
||||
|
||||
FileSaver.saveAs(blob, `${pair.address()}.json`);
|
||||
|
||||
@ -9,7 +9,7 @@ import { SubjectInfo } from '@polkadot/ui-keyring/observable/types';
|
||||
import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import { AddressSummary, Button, Dropdown, Input, InputAddress } from '@polkadot/ui-app';
|
||||
import { AddressSummary, Button, Dropdown, Input, InputAddress, InputTags } from '@polkadot/ui-app';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
import uiSettings from '@polkadot/ui-settings';
|
||||
|
||||
@ -28,7 +28,8 @@ type State = {
|
||||
isBackupOpen: boolean,
|
||||
isEdited: boolean,
|
||||
isForgetOpen: boolean,
|
||||
isPasswordOpen: boolean
|
||||
isPasswordOpen: boolean,
|
||||
tags: Array<string>
|
||||
};
|
||||
|
||||
class Editor extends React.PureComponent<Props, State> {
|
||||
@ -104,6 +105,9 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
const type = current
|
||||
? current.type
|
||||
: 'ed25519';
|
||||
const isTesting = current
|
||||
? current.getMeta().isTesting
|
||||
: false;
|
||||
|
||||
return (
|
||||
<div className='ui--grid'>
|
||||
@ -128,7 +132,8 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
<Input
|
||||
className='full'
|
||||
help={t('Name given to this account. You can edit it. To use the account to validate or nominate, it is a good practice to append the function of the account in the name, e.g "name_you_want - stash".')}
|
||||
isEditable
|
||||
isDisabled={isTesting}
|
||||
isEditable={!isTesting}
|
||||
label={t('name')}
|
||||
onChange={this.onChangeName}
|
||||
value={editedName}
|
||||
@ -143,11 +148,36 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
options={uiSettings.availableCryptos}
|
||||
/>
|
||||
</div>
|
||||
{this.renderTags()}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderTags () {
|
||||
const { t } = this.props;
|
||||
const { current, tags } = this.state;
|
||||
|
||||
const showTags = current
|
||||
? !current.getMeta().isTesting
|
||||
: true;
|
||||
|
||||
if (!showTags) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='ui--row'>
|
||||
<InputTags
|
||||
help={t('Additional user-specified tags that can be used to identify the account. Tags can be used for categorization and filtering.')}
|
||||
label={t('user-defined tags')}
|
||||
onChange={this.onChangeTags}
|
||||
value={tags}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderModals () {
|
||||
const { onStatusChange } = this.props;
|
||||
const { current, isBackupOpen, isForgetOpen, isPasswordOpen } = this.state;
|
||||
@ -196,29 +226,35 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
createState (current: KeyringPair | null): State {
|
||||
const meta = current
|
||||
? current.getMeta()
|
||||
: { name: '', tags: [] };
|
||||
|
||||
return {
|
||||
current,
|
||||
editedName: current
|
||||
? current.getMeta().name || ''
|
||||
: '',
|
||||
editedName: meta.name || '',
|
||||
isBackupOpen: false,
|
||||
isEdited: false,
|
||||
isForgetOpen: false,
|
||||
isPasswordOpen: false
|
||||
isPasswordOpen: false,
|
||||
tags: meta.tags || []
|
||||
};
|
||||
}
|
||||
|
||||
nextState (newState: State = {} as State): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
let { current = prevState.current, editedName = prevState.editedName } = newState;
|
||||
let { current = prevState.current, editedName = prevState.editedName, tags = prevState.tags } = newState;
|
||||
const previous = prevState.current || { address: () => undefined };
|
||||
let isEdited = false;
|
||||
|
||||
if (current) {
|
||||
const meta = current.getMeta();
|
||||
|
||||
if (current.address() !== previous.address()) {
|
||||
editedName = current.getMeta().name || '';
|
||||
} else if (editedName !== current.getMeta().name) {
|
||||
editedName = meta.name || '';
|
||||
tags = meta.tags || [];
|
||||
} else if (editedName !== meta.name) {
|
||||
isEdited = true;
|
||||
}
|
||||
} else {
|
||||
@ -231,8 +267,9 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
isBackupOpen: false,
|
||||
isEdited,
|
||||
isForgetOpen: false,
|
||||
isPasswordOpen: false
|
||||
};
|
||||
isPasswordOpen: false,
|
||||
tags
|
||||
} as State;
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -242,18 +279,20 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
? keyring.getPair(accountId)
|
||||
: null;
|
||||
|
||||
this.nextState({
|
||||
current
|
||||
} as State);
|
||||
this.nextState({ current } as State);
|
||||
}
|
||||
|
||||
onChangeName = (editedName: string): void => {
|
||||
this.nextState({ editedName } as State);
|
||||
}
|
||||
|
||||
onChangeTags = (tags: Array<string>): void => {
|
||||
this.setState({ isEdited: true, tags });
|
||||
}
|
||||
|
||||
onCommit = (): void => {
|
||||
const { onStatusChange, t } = this.props;
|
||||
const { current, editedName } = this.state;
|
||||
const { current, editedName, tags } = this.state;
|
||||
|
||||
if (!current) {
|
||||
return;
|
||||
@ -267,14 +306,17 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
try {
|
||||
keyring.saveAccountMeta(current, {
|
||||
name: editedName,
|
||||
tags,
|
||||
whenEdited: Date.now()
|
||||
});
|
||||
|
||||
status.status = current.getMeta().name === editedName ? 'success' : 'error';
|
||||
status.message = t('name edited');
|
||||
status.message = t('account edited');
|
||||
} catch (error) {
|
||||
status.status = 'error';
|
||||
status.message = error.message;
|
||||
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
onStatusChange(status);
|
||||
@ -289,8 +331,11 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
const meta = current.getMeta();
|
||||
|
||||
this.nextState({
|
||||
editedName: current.getMeta().name
|
||||
editedName: meta.name,
|
||||
tags: meta.tags || []
|
||||
} as State);
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AddressSummary, Button, Input } from '@polkadot/ui-app';
|
||||
import { AddressSummary, Button, Input, InputTags } from '@polkadot/ui-app';
|
||||
import { ActionStatus } from '@polkadot/ui-app/Status/types';
|
||||
import { InputAddress } from '@polkadot/ui-app/InputAddress';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
@ -22,7 +22,8 @@ type State = {
|
||||
isAddressValid: boolean,
|
||||
isNameValid: boolean,
|
||||
isValid: boolean,
|
||||
name: string
|
||||
name: string,
|
||||
tags: Array<string>
|
||||
};
|
||||
|
||||
class Creator extends React.PureComponent<Props, State> {
|
||||
@ -75,7 +76,7 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
|
||||
renderInput () {
|
||||
const { t } = this.props;
|
||||
const { address, isAddressValid, isNameValid, name } = this.state;
|
||||
const { address, isAddressValid, isNameValid, name, tags } = this.state;
|
||||
|
||||
return (
|
||||
<div className='grow'>
|
||||
@ -100,6 +101,14 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
value={name}
|
||||
/>
|
||||
</div>
|
||||
<div className='ui--row'>
|
||||
<InputTags
|
||||
help={t('Additional user-specified tags that can be used to identify the address. Tags can be used for categorization and filtering.')}
|
||||
label={t('user-defined tags')}
|
||||
onChange={this.onChangeTags}
|
||||
value={tags}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -111,15 +120,15 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
isAddressValid: false,
|
||||
isNameValid: true,
|
||||
isValid: false,
|
||||
name: 'new address'
|
||||
name: 'new address',
|
||||
tags: []
|
||||
};
|
||||
}
|
||||
|
||||
nextState (newState: State, allowEdit: boolean = false): void {
|
||||
this.setState(
|
||||
(prevState: State, props: Props): State => {
|
||||
let { address = prevState.address, name = prevState.name } = newState;
|
||||
|
||||
let { address = prevState.address, name = prevState.name, tags = prevState.tags } = newState;
|
||||
let isAddressValid = true;
|
||||
let isAddressExisting = false;
|
||||
let newAddress = address;
|
||||
@ -154,7 +163,8 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
isAddressValid,
|
||||
isNameValid,
|
||||
isValid: isAddressValid && isNameValid,
|
||||
name
|
||||
name,
|
||||
tags
|
||||
};
|
||||
}
|
||||
);
|
||||
@ -168,16 +178,20 @@ class Creator extends React.PureComponent<Props, State> {
|
||||
this.nextState({ name } as State, true);
|
||||
}
|
||||
|
||||
onChangeTags = (tags: Array<string>): void => {
|
||||
this.setState({ tags });
|
||||
}
|
||||
|
||||
onCommit = (): void => {
|
||||
const { basePath, onStatusChange, t } = this.props;
|
||||
const { address, isAddressExisting, name } = this.state;
|
||||
const { address, isAddressExisting, name, tags } = this.state;
|
||||
|
||||
const status = {
|
||||
action: 'create'
|
||||
} as ActionStatus;
|
||||
|
||||
try {
|
||||
keyring.saveAddress(address, { name });
|
||||
keyring.saveAddress(address, { name, tags });
|
||||
|
||||
status.account = address;
|
||||
status.status = address ? 'success' : 'error';
|
||||
|
||||
@ -7,7 +7,7 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
import { ComponentProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import { AddressSummary, Button, Input, InputAddress } from '@polkadot/ui-app';
|
||||
import { AddressSummary, Button, Input, InputAddress, InputTags } from '@polkadot/ui-app';
|
||||
import { ActionStatus } from '@polkadot/ui-app/Status/types';
|
||||
import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
@ -20,7 +20,8 @@ type State = {
|
||||
current: KeyringAddress | null,
|
||||
editedName: string,
|
||||
isEdited: boolean,
|
||||
isForgetOpen: boolean
|
||||
isForgetOpen: boolean,
|
||||
tags: Array<string>
|
||||
};
|
||||
|
||||
class Editor extends React.PureComponent<Props, State> {
|
||||
@ -82,7 +83,7 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
|
||||
renderData () {
|
||||
const { t } = this.props;
|
||||
const { current, editedName } = this.state;
|
||||
const { current, editedName, tags } = this.state;
|
||||
|
||||
const address = current
|
||||
? current.address()
|
||||
@ -117,47 +118,61 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
value={editedName}
|
||||
/>
|
||||
</div>
|
||||
<div className='ui--row'>
|
||||
<InputTags
|
||||
help={t('Additional user-specified tags that can be used to identify the address. Tags can be used for categorization and filtering.')}
|
||||
label={t('user-defined tags')}
|
||||
onChange={this.onChangeTags}
|
||||
value={tags}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
createState (current: KeyringAddress | null): State {
|
||||
const { name = '' } = current
|
||||
const meta = current
|
||||
? current.getMeta()
|
||||
: {};
|
||||
|
||||
return {
|
||||
current,
|
||||
editedName: name,
|
||||
editedName: meta.name || '',
|
||||
isEdited: false,
|
||||
isForgetOpen: false
|
||||
isForgetOpen: false,
|
||||
tags: meta.tags || []
|
||||
};
|
||||
}
|
||||
|
||||
nextState (newState: State = {} as State): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
let { current = prevState.current, editedName = prevState.editedName } = newState;
|
||||
let { current = prevState.current, editedName = prevState.editedName, tags = prevState.tags } = newState;
|
||||
const previous = prevState.current || { address: () => null };
|
||||
let isEdited = false;
|
||||
|
||||
if (current && current.isValid()) {
|
||||
const meta = current.getMeta();
|
||||
|
||||
if (current.address() !== previous.address()) {
|
||||
editedName = current.getMeta().name || '';
|
||||
} else if (editedName !== current.getMeta().name) {
|
||||
editedName = meta.name || '';
|
||||
tags = meta.tags || [];
|
||||
} else if (editedName !== meta.name) {
|
||||
isEdited = true;
|
||||
}
|
||||
} else {
|
||||
editedName = '';
|
||||
}
|
||||
|
||||
let isForgetOpen = false;
|
||||
|
||||
return {
|
||||
current,
|
||||
editedName,
|
||||
isEdited,
|
||||
isForgetOpen
|
||||
isForgetOpen,
|
||||
tags
|
||||
};
|
||||
}
|
||||
);
|
||||
@ -175,9 +190,13 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
this.nextState({ editedName } as State);
|
||||
}
|
||||
|
||||
onChangeTags = (tags: Array<string>): void => {
|
||||
this.setState({ isEdited: true, tags });
|
||||
}
|
||||
|
||||
onCommit = (): void => {
|
||||
const { current, editedName } = this.state;
|
||||
const { onStatusChange, t } = this.props;
|
||||
const { current, editedName, tags } = this.state;
|
||||
|
||||
if (!current) {
|
||||
return;
|
||||
@ -191,11 +210,12 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
try {
|
||||
keyring.saveAddress(current.address(), {
|
||||
name: editedName,
|
||||
tags,
|
||||
whenEdited: Date.now()
|
||||
});
|
||||
|
||||
status.status = current.getMeta().name === editedName ? 'success' : 'error';
|
||||
status.message = t('name edited');
|
||||
status.message = t('address edited');
|
||||
} catch (error) {
|
||||
status.status = 'error';
|
||||
status.message = error.message;
|
||||
@ -211,8 +231,11 @@ class Editor extends React.PureComponent<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
const meta = current.getMeta();
|
||||
|
||||
this.nextState({
|
||||
editedName: current.getMeta().name
|
||||
editedName: meta.name,
|
||||
tags: meta.tags || []
|
||||
} as State);
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.4.4",
|
||||
"@polkadot/ui-app": "^0.33.0-beta.54",
|
||||
"@polkadot/ui-assets": "^0.38.1",
|
||||
"@polkadot/ui-assets": "^0.39.0-beta.0",
|
||||
"@polkadot/ui-signer": "^0.33.0-beta.54"
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.4.4",
|
||||
"@polkadot/ui-api": "^0.33.0-beta.54",
|
||||
"@polkadot/ui-identicon": "^0.38.1",
|
||||
"@polkadot/ui-keyring": "^0.38.1",
|
||||
"@polkadot/ui-identicon": "^0.39.0-beta.0",
|
||||
"@polkadot/ui-keyring": "^0.39.0-beta.0",
|
||||
"@polkadot/ui-reactive": "^0.33.0-beta.54",
|
||||
"@polkadot/ui-settings": "^0.38.1",
|
||||
"@polkadot/ui-settings": "^0.39.0-beta.0",
|
||||
"@types/chart.js": "^2.7.45",
|
||||
"@types/classnames": "^2.2.7",
|
||||
"@types/i18next": "^12.1.0",
|
||||
|
||||
@ -13,6 +13,7 @@ import { classes } from './util';
|
||||
import Labelled from './Labelled';
|
||||
|
||||
type Props<Option> = BareProps & {
|
||||
allowAdd?: boolean,
|
||||
defaultValue?: any,
|
||||
dropdownClassName?: string,
|
||||
help?: React.ReactNode,
|
||||
@ -21,6 +22,7 @@ type Props<Option> = BareProps & {
|
||||
isError?: boolean,
|
||||
isMultiple?: boolean,
|
||||
label?: React.ReactNode,
|
||||
onAdd?: (value: any) => void,
|
||||
onChange?: (value: any) => void,
|
||||
onSearch?: (filteredOptions: Array<any>, query: string) => Array<Option>,
|
||||
options: Array<Option>,
|
||||
@ -58,9 +60,10 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
|
||||
}
|
||||
|
||||
render () {
|
||||
const { className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, style, withLabel, value } = this.props;
|
||||
const { allowAdd = false, className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, style, withLabel, value } = this.props;
|
||||
const dropdown = (
|
||||
<SUIDropdown
|
||||
allowAdditions={allowAdd}
|
||||
className={dropdownClassName}
|
||||
button={isButton}
|
||||
compact={isButton}
|
||||
@ -68,11 +71,12 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
|
||||
error={isError}
|
||||
floating={isButton}
|
||||
multiple={isMultiple}
|
||||
onAddItem={this.onAddItem}
|
||||
onChange={this.onChange}
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
renderLabel={renderLabel}
|
||||
search={onSearch}
|
||||
search={!!onSearch || allowAdd}
|
||||
selection
|
||||
value={
|
||||
isUndefined(value)
|
||||
@ -101,6 +105,12 @@ export default class Dropdown<Option> extends React.PureComponent<Props<Option>>
|
||||
);
|
||||
}
|
||||
|
||||
private onAddItem = (_: React.SyntheticEvent<HTMLElement>, { value }: DropdownProps): void => {
|
||||
const { onAdd } = this.props;
|
||||
|
||||
onAdd && onAdd(value);
|
||||
}
|
||||
|
||||
private onChange = (_: React.SyntheticEvent<HTMLElement>, { value }: DropdownProps): void => {
|
||||
const { onChange, transform } = this.props;
|
||||
|
||||
|
||||
81
packages/ui-app/src/InputTags.tsx
Normal file
81
packages/ui-app/src/InputTags.tsx
Normal file
@ -0,0 +1,81 @@
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BareProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import store from 'store';
|
||||
|
||||
import Dropdown from './Dropdown';
|
||||
|
||||
type Option = {
|
||||
key: string,
|
||||
text: string,
|
||||
value: string
|
||||
};
|
||||
|
||||
type Props = BareProps & {
|
||||
allowAdd?: boolean,
|
||||
defaultValue?: Array<string>,
|
||||
help?: React.ReactNode,
|
||||
isDisabled?: boolean,
|
||||
isError?: boolean,
|
||||
label?: React.ReactNode,
|
||||
onChange?: (value: Array<string>) => void,
|
||||
placeholder?: string,
|
||||
value?: Array<string>
|
||||
};
|
||||
|
||||
type State = {
|
||||
options: Array<Option>
|
||||
};
|
||||
|
||||
function loadTags (): Array<string> {
|
||||
return store.get('tags') || ['Default'];
|
||||
}
|
||||
|
||||
function saveTags (tags: Array<string>): void {
|
||||
store.set('tags', tags);
|
||||
}
|
||||
|
||||
const tags = loadTags();
|
||||
|
||||
export default class InputTags extends React.PureComponent<Props> {
|
||||
state: State = {
|
||||
options: tags.map((value) => ({
|
||||
key: value, text: value, value
|
||||
}))
|
||||
};
|
||||
|
||||
render () {
|
||||
const { defaultValue, help, isDisabled, isError, label, onChange, placeholder, value } = this.props;
|
||||
const { options } = this.state;
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
allowAdd={!isDisabled}
|
||||
defaultValue={defaultValue}
|
||||
help={help}
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
isMultiple
|
||||
label={label}
|
||||
onAdd={this.onAdd}
|
||||
onChange={onChange}
|
||||
options={options}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
private onAdd = (value: string): void => {
|
||||
tags.push(value);
|
||||
saveTags(tags);
|
||||
|
||||
this.setState(({ options }: State) => ({
|
||||
options: [...options, { key: value, text: value, value }]
|
||||
}));
|
||||
}
|
||||
}
|
||||
@ -30,6 +30,7 @@ export { default as InputFile } from './InputFile';
|
||||
export { default as InputNumber } from './InputNumber';
|
||||
export { default as InputRpc } from './InputRpc';
|
||||
export { default as InputStorage } from './InputStorage';
|
||||
export { default as InputTags } from './InputTags';
|
||||
export { default as Labelled } from './Labelled';
|
||||
export { default as Menu } from './Menu';
|
||||
export { default as Modal } from './Modal';
|
||||
|
||||
34
yarn.lock
34
yarn.lock
@ -1892,20 +1892,20 @@
|
||||
"@polkadot/keyring" "^0.91.0-beta.1"
|
||||
"@polkadot/util" "^0.91.0-beta.1"
|
||||
|
||||
"@polkadot/ui-assets@^0.38.1":
|
||||
version "0.38.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-assets/-/ui-assets-0.38.1.tgz#493a83e8cfd21e53a2236d30f087c3d73babd6a2"
|
||||
integrity sha512-Oj3yldkpcHFI7A43Prbh34cfUlI8C6ih4nlokjaHsxiSXsi7vYeF+rAns8i4u2oP5QquK6FA/f9hGNigewyoEQ==
|
||||
"@polkadot/ui-assets@^0.39.0-beta.0":
|
||||
version "0.39.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-assets/-/ui-assets-0.39.0-beta.0.tgz#627dc80ea79b97f6137527ad0a39a475b71f20d6"
|
||||
integrity sha512-+QxXiWAUJlnn6avT4CbSAOJP/R9VceOZHPLDdwdob003KXIKdmzX/yGXklbvaRiyssLJwyC1NTZmWmCRcWbeIQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.4.4"
|
||||
|
||||
"@polkadot/ui-identicon@^0.38.1":
|
||||
version "0.38.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-identicon/-/ui-identicon-0.38.1.tgz#2d0883ac145a46b3e635d34c3b6cc632dcad45b4"
|
||||
integrity sha512-B+KbQKS/dAA2U8VfjlEusnnKfHQbUGGjuuFpxZMoH0NXWeuJZFA6Kqmh5HAT9ycVeMtO79r3mTkYUPgqfraPrg==
|
||||
"@polkadot/ui-identicon@^0.39.0-beta.0":
|
||||
version "0.39.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-identicon/-/ui-identicon-0.39.0-beta.0.tgz#9c8c5b0778dcd6fe5b30210d00d68dbb965950db"
|
||||
integrity sha512-4Mgq9UbkpiILFkwpdyp7d8boUN5fqtJQdJrF5TEDa6+WZtfK6kgLri0x7DfbJoohxE4pg/NWyeFxkOmX7bZWrg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.4.4"
|
||||
"@polkadot/ui-settings" "^0.38.1"
|
||||
"@polkadot/ui-settings" "^0.39.0-beta.0"
|
||||
"@types/color" "^3.0.0"
|
||||
"@types/react-copy-to-clipboard" "^4.2.6"
|
||||
color "^3.0.0"
|
||||
@ -1913,20 +1913,20 @@
|
||||
react-copy-to-clipboard "^5.0.1"
|
||||
styled-components "^4.2.0"
|
||||
|
||||
"@polkadot/ui-keyring@^0.38.1":
|
||||
version "0.38.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-keyring/-/ui-keyring-0.38.1.tgz#c9557f010ce217149e164433f9d5a8f61f818b94"
|
||||
integrity sha512-sMQ4sDs8nnvK2i4VICq1oKv1OFzWwfdwk05MBukxgRRajXkOjCfttITzvHuwwq8zcHRRUzWt+Shj96BO97Ufbw==
|
||||
"@polkadot/ui-keyring@^0.39.0-beta.0":
|
||||
version "0.39.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-keyring/-/ui-keyring-0.39.0-beta.0.tgz#5252728942387a8a5aaaec62b53b7af81fc30f93"
|
||||
integrity sha512-EtfifdE4MmzZ8zxX+OzrweeXHnVbPxvGuMOfqPCjdEHI/1pqVn4HVIwswHwdhtF7c9NCcF2vp2E2DtIp+H7+PQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.4.4"
|
||||
"@types/store" "^2.0.1"
|
||||
store "^2.0.12"
|
||||
styled-components "^4.2.0"
|
||||
|
||||
"@polkadot/ui-settings@^0.38.1":
|
||||
version "0.38.1"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-settings/-/ui-settings-0.38.1.tgz#c52ede839a8b04b20b1177131087c96d64f1edb6"
|
||||
integrity sha512-ZpqCcusimDMrkqqcYS+49OuTcmO9RsjrUq6J2+B74vnABJaRQ702YUJJtHPvmehF30fRFIxm3yeBp97y+EPb4w==
|
||||
"@polkadot/ui-settings@^0.39.0-beta.0":
|
||||
version "0.39.0-beta.0"
|
||||
resolved "https://registry.yarnpkg.com/@polkadot/ui-settings/-/ui-settings-0.39.0-beta.0.tgz#a17bccbddd454021dc255095f2daa67e85292bf8"
|
||||
integrity sha512-oo9Fz0oQbvxVxp8wYTKRi44tSikaspUZHht/sb/W/gLSuWWYQKTuTSg9kNDR0eHQr14va1IfkXS2R+m84tQvZg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.4.4"
|
||||
"@types/store" "^2.0.1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user