From a405d75738b2c6a8b5327b6425c98fe6d2a0b529 Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Wed, 18 Apr 2018 10:41:20 +0800 Subject: [PATCH] add page for update asset alias --- src/features/assets/components/AssetShow.jsx | 2 +- src/features/assets/components/AssetUpdate.jsx | 54 ++++++-------------------- src/features/assets/routes.js | 12 +++++- src/features/shared/actions/update.js | 4 +- src/sdk/api/assets.js | 8 ++++ 5 files changed, 32 insertions(+), 48 deletions(-) diff --git a/src/features/assets/components/AssetShow.jsx b/src/features/assets/components/AssetShow.jsx index c83ab82..c6605ab 100644 --- a/src/features/assets/components/AssetShow.jsx +++ b/src/features/assets/components/AssetShow.jsx @@ -36,7 +36,7 @@ class AssetShow extends BaseShow { ]} items={[ {label: 'ID', value: item.id}, - {label: 'Alias', value: item.alias}, + {label: 'Alias', value: item.alias, editUrl: item.alias === 'BTM' ? null : `/assets/${item.id}/alias`}, {label: 'Definition', value: item.definition}, {label: 'xpubs', value: (item.xpubs || []).length}, {label: 'Quorum', value: item.quorum}, diff --git a/src/features/assets/components/AssetUpdate.jsx b/src/features/assets/components/AssetUpdate.jsx index fca7bb2..c01adfd 100644 --- a/src/features/assets/components/AssetUpdate.jsx +++ b/src/features/assets/components/AssetUpdate.jsx @@ -1,5 +1,5 @@ import React from 'react' -import { BaseUpdate, FormContainer, FormSection, JsonField, NotFound } from 'features/shared/components' +import { BaseUpdate, FormContainer, FormSection, NotFound, TextField } from 'features/shared/components' import { reduxForm } from 'redux-form' class Form extends React.Component { @@ -37,29 +37,17 @@ class Form extends React.Component { } const { - fields: { tags }, + fields: { alias }, error, handleSubmit, submitting } = this.props const title = - {lang === 'zh' ? '编辑资产tags' : 'Edit asset tags '} + {lang === 'zh' ? '编辑资产alias' : 'Edit asset alias '} {item.alias ? item.alias :item.id} - const tagsString = Object.keys(item.tags || {}).length === 0 ? '{\n\t\n}' : JSON.stringify(item.tags || {}, null, 1) - const tagLines = tagsString.split(/\r\n|\r|\n/).length - let JsonFieldHeight - - if (tagLines < 5) { - JsonFieldHeight = '80px' - } else if (tagLines < 20) { - JsonFieldHeight = `${tagLines * 17}px` - } else { - JsonFieldHeight = '340px' - } - return - - - -

- { lang === 'zh' ? ('注意:资产标签可用于查询交易,unspent outputs和余额。查询反映了提交交易时出现的资产标签。只有新的交易活动才会反映更新后的标签。 ' - ) :( - 'Note: Asset tags can be used for querying transactions, unspent outputs, and balances. ' + - 'Queries reflect the asset tags that are present when transactions are submitted.' + - ' Only new transaction activity will reflect the updated tags. ' - )} -

+ +
} @@ -94,10 +74,9 @@ const mapStateToProps = (state, ownProps) => ({ const initialValues = (state, ownProps) => { const item = state.asset.items[ownProps.params.id] if (item) { - const tags = Object.keys(item.tags || {}).length === 0 ? '{\n\t\n}' : JSON.stringify(item.tags || {}, null, 1) return { initialValues: { - tags: tags + alias: item.alias } } } @@ -106,18 +85,7 @@ const initialValues = (state, ownProps) => { const updateForm = reduxForm({ form: 'updateAssetForm', - fields: ['tags'], - validate: values => { - const errors = {} - - const jsonFields = ['tags'] - jsonFields.forEach(key => { - const fieldError = JsonField.validator(values[key]) - if (fieldError) { errors[key] = fieldError } - }) - - return errors - } + fields: ['alias'], }, initialValues)(Form) export default BaseUpdate.connect( diff --git a/src/features/assets/routes.js b/src/features/assets/routes.js index 70b6d74..7ed3913 100644 --- a/src/features/assets/routes.js +++ b/src/features/assets/routes.js @@ -1,4 +1,12 @@ -import { List, New, AssetShow } from './components' +import { List, New, AssetShow, AssetUpdate } from './components' import { makeRoutes } from 'features/shared' -export default (store) => makeRoutes(store, 'asset', List, New, AssetShow, {name_zh: '资产'}) +export default (store) => { + const routes = makeRoutes(store, 'asset', List, New, AssetShow, {name_zh: '资产'}) + routes.childRoutes.push({ + path: ':id/alias', + component: AssetUpdate + }) + + return routes +} diff --git a/src/features/shared/actions/update.js b/src/features/shared/actions/update.js index 3b0b458..2df6198 100644 --- a/src/features/shared/actions/update.js +++ b/src/features/shared/actions/update.js @@ -11,9 +11,9 @@ export default function(type, options = {}) { let promise = Promise.resolve() return function(dispatch) { - return promise.then(() => clientApi.updateTags({ + return promise.then(() => clientApi.updateAlias({ id: id, - tags: JSON.parse(data.tags), + alias: data.alias, }).then((resp) => { dispatch(updated(resp)) diff --git a/src/sdk/api/assets.js b/src/sdk/api/assets.js index df8e602..81a6938 100644 --- a/src/sdk/api/assets.js +++ b/src/sdk/api/assets.js @@ -15,6 +15,14 @@ const assetsAPI = (client) => { return shared.singletonBatchRequest(client, '/update-asset-tags', finalParams, cb) }, + updateAlias: (params, cb) => { + const finalParams = { + id: params.id, + alias: params.alias + } + return shared.singletonBatchRequest(client, '/update-asset-alias', finalParams, cb) + }, + updateTagsBatch: (params, cb) => shared.batchRequest(client, '/update-asset-tags', params, cb), query: (params, cb) => shared.query(client, 'assets', '/list-assets', params, {cb}), -- 2.11.0