|
|
@@ -35,7 +35,8 @@ class Schema extends Component {
|
|
|
editSchemaName: '',
|
|
|
data: '',
|
|
|
page: '',
|
|
|
- pageSize: ''
|
|
|
+ pageSize: '',
|
|
|
+ once: 0
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -84,7 +85,6 @@ class Schema extends Component {
|
|
|
})
|
|
|
};
|
|
|
|
|
|
-
|
|
|
fetchData = (referenceID) => {
|
|
|
let schemaData;
|
|
|
if (localStorage.getItem('ecommerce') && localStorage.getItem('bills') && localStorage.getItem('subscribe')) {
|
|
|
@@ -151,7 +151,8 @@ class Schema extends Component {
|
|
|
currentTable: next.location.state === undefined ? '' : next.location.state.create ? 'add' : '',
|
|
|
schemaID: next.schemaID,
|
|
|
schemaName: next.schemaName,
|
|
|
- data: ''
|
|
|
+ data: '',
|
|
|
+ once: 0
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -171,9 +172,23 @@ class Schema extends Component {
|
|
|
}
|
|
|
|
|
|
// let schemaName = data.schema_by_id.schemaName;
|
|
|
+ let reference = data.schema_by_id.reference;
|
|
|
|
|
|
if (data.schema_by_id === null) data = [];
|
|
|
- else data = JSON.parse(data.schema_by_id.schemaData);
|
|
|
+ else {
|
|
|
+ data = JSON.parse(data.schema_by_id.schemaData);
|
|
|
+ if (data.length === 0 && reference !== '' && this.state.once === 0) {
|
|
|
+ this.fetchData(reference).then((data) => {
|
|
|
+ // 会执行好多好多次
|
|
|
+ this.setState({
|
|
|
+ data: JSON.parse(data),
|
|
|
+ once: 1
|
|
|
+ })
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
@@ -409,18 +424,7 @@ class CopySchemaButton extends Component {
|
|
|
<div>
|
|
|
<Mutation
|
|
|
mutation={gql(ADD_SCHEMA)}
|
|
|
- update={(cache, {data: {create_schema}}) => {
|
|
|
- let data = cache.readQuery({query: gql(SHOW_SCHEMA), variables: {user_id: userID}});
|
|
|
- let trialCaseSchemaData = cache.readQuery({query: gql(SHOW_SCHEMA), variables: {user_id: 'ioobot'}});
|
|
|
- let index = schemaName === 'subscribe'? 0: 'bills' ? 1: 2;
|
|
|
- // console.log('trial-case-schemadata', trialCaseSchemaData);
|
|
|
- // console.log('create-schemadata', create_schema.schemaData);
|
|
|
- create_schema.schemaData = trialCaseSchemaData.schema_by_props[index].schemaData;
|
|
|
- // console.log('create-schemadata-after-modify', create_schema.schemaData);
|
|
|
- data.schema_by_props.push(create_schema);
|
|
|
- cache.writeQuery({query: gql(SHOW_SCHEMA), variables: {user_id: userID}, data});
|
|
|
- console.log(cache);
|
|
|
- }}
|
|
|
+ refetchQueries={[{query: gql(SHOW_SCHEMA), variables: {user_id: userID}}]}
|
|
|
>
|
|
|
{(create_schema, {loading, error}) => {
|
|
|
if (loading)
|