TrialCase.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, {Component} from 'react';
  2. import {Layout, Menu} from 'antd';
  3. import {FormattedMessage} from 'react-intl';
  4. import GenerateJs from "./component/generateJs/GenerateJs";
  5. import Deploy from '../common/deploy/Deploy';
  6. import Manage from '../common/manage/Manage';
  7. import Schema from './component/schema/Schema';
  8. import Graphql from "./component/graphql/Graphql";
  9. import CaseMetabase from "./component/caseMetabase/CaseMetabase";
  10. import Application from "./component/application/Application";
  11. import axios from 'axios';
  12. import {getIdUrl} from "../../config";
  13. import classnames from 'classnames';
  14. axios.defaults.withCredentials = true;
  15. const {Content} = Layout;
  16. class TrialCase extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. menuLevel2: "schema",
  21. // default user
  22. userID: "ioobot",
  23. showPadding: true,
  24. api: ''
  25. }
  26. }
  27. switchMenu = (menuName, e) => {
  28. this.setState({
  29. [menuName]: e.key,
  30. });
  31. };
  32. switchAPI = (api) => {
  33. this.setState({
  34. api
  35. })
  36. };
  37. componentWillMount() {
  38. let _this = this;
  39. axios.get(getIdUrl)
  40. .then((res) => {
  41. if (res.data !== '') {
  42. _this.setState({
  43. userID: res.data
  44. })
  45. }
  46. })
  47. .catch(function (err) {
  48. console.log(err);
  49. });
  50. }
  51. render() {
  52. let schemaID = this.props.location.state ? this.props.location.state.schemaID : "ecommerce_schemaID";
  53. let schemaName = this.props.location.state ? this.props.location.state.schemaName : "ecommerce";
  54. let projectID = this.props.location.state ? this.props.location.state.projectID : "";
  55. return (
  56. <div>
  57. <Menu
  58. mode="horizontal"
  59. defaultSelectedKeys={['schema']}
  60. style={{padding: '0 24px', position: 'fixed', width: '100%', zIndex: '5',lineHeight:'50px',fontWeight:600}}
  61. onClick={(e) => this.switchMenu('menuLevel2', e)}
  62. selectedKeys={[this.state.menuLevel2]}
  63. >
  64. <Menu.Item key="schema"><FormattedMessage id="schema"/></Menu.Item>
  65. <Menu.Item key="deploy"><FormattedMessage id="deploy"/></Menu.Item>
  66. <Menu.Item key="manage"><FormattedMessage id="manage"/></Menu.Item>
  67. <Menu.Item key="graphiql"><FormattedMessage id="graphql IDE"/></Menu.Item>
  68. <Menu.Item key="template"><FormattedMessage id="template"/></Menu.Item>
  69. <Menu.Item key="preview"><FormattedMessage id="preview"/></Menu.Item>
  70. <Menu.Item key="metabase"><FormattedMessage id="metabase"/></Menu.Item>
  71. </Menu>
  72. <Layout style={{padding: '24px', zIndex: '0'}}>
  73. <Content className={classnames({'layout-content': this.state.showPadding})}>
  74. {
  75. (() => {
  76. switch (this.state.menuLevel2) {
  77. case 'schema':
  78. return <Schema trialcase={true} userID={this.state.userID} projectID={projectID} schemaName={schemaName} schemaID={schemaID} history={this.props.history} location={this.props.location}/>;
  79. case 'deploy':
  80. return <Deploy trialcase={true} userID={this.state.userID} projectID={projectID}/>;
  81. case 'manage':
  82. return <Manage trialcase={true} userID={this.state.userID} projectID={projectID} switchMenu={this.switchMenu}/>;
  83. case 'graphiql':
  84. return <Graphql api={this.state.api} projectID={projectID}/>;
  85. case 'template':
  86. return <GenerateJs schemaID={schemaID} schemaName={schemaName}/>;
  87. case 'preview':
  88. return <Application location={this.props.location}/>;
  89. case 'metabase':
  90. return <CaseMetabase/>;
  91. default:
  92. return <Graphql/>;
  93. }
  94. })()
  95. }
  96. </Content>
  97. </Layout>
  98. </div>
  99. )
  100. }
  101. }
  102. export default TrialCase;