OSDN Git Service

add page for update asset alias
authorYongfeng LI <wliyongfeng@gmail.com>
Wed, 18 Apr 2018 02:41:20 +0000 (10:41 +0800)
committerYongfeng LI <wliyongfeng@gmail.com>
Wed, 18 Apr 2018 02:41:20 +0000 (10:41 +0800)
src/features/assets/components/AssetShow.jsx
src/features/assets/components/AssetUpdate.jsx
src/features/assets/routes.js
src/features/shared/actions/update.js
src/sdk/api/assets.js

index c83ab82..c6605ab 100644 (file)
@@ -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},
index fca7bb2..c01adfd 100644 (file)
@@ -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 = <span>
-      {lang === 'zh' ? '编辑资产tags' : 'Edit asset tags '}
+      {lang === 'zh' ? '编辑资产alias' : 'Edit asset alias '}
       <code>{item.alias ? item.alias :item.id}</code>
     </span>
 
-    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 <FormContainer
       error={error}
       label={title}
@@ -67,20 +55,12 @@ class Form extends React.Component {
       submitting={submitting}
       lang={lang}>
 
-    <FormSection title='Asset Tags'>
-        <JsonField
-          height={JsonFieldHeight}
-          fieldProps={tags}
-          lang={lang} />
-
-        <p>
-          { 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. '
-          )}
-        </p>
+      <FormSection title='Asset Alias'>
+        <TextField
+          placeholder={ lang === 'zh' ? '请输入资产Alias' : 'Please entered asset alias' }
+          fieldProps={alias}
+          type= 'text'
+        />
       </FormSection>
     </FormContainer>
   }
@@ -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(
index 70b6d74..7ed3913 100644 (file)
@@ -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
+}
index 3b0b458..2df6198 100644 (file)
@@ -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))
 
index df8e602..81a6938 100644 (file)
@@ -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}),