EditorBottom.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React from 'react'
  21. import { Row, Col, Button, InputNumber, Tooltip, Popover, Tag } from 'antd'
  22. import Styles from '../View.less'
  23. export interface IEditorBottomProps {
  24. sqlLimit: number
  25. loading: boolean
  26. nextDisabled: boolean
  27. isLastExecuteWholeSql: boolean
  28. sqlFragment: string
  29. onSetSqlLimit: (limit: number) => void
  30. onExecuteSql: () => void
  31. onStepChange: (stepChange: number) => void
  32. }
  33. const stepChange = (onStepChange: IEditorBottomProps['onStepChange'], step: number) => () => {
  34. onStepChange(step)
  35. }
  36. export const EditorBottom = (props: IEditorBottomProps) => {
  37. const { sqlLimit, loading, nextDisabled, isLastExecuteWholeSql, sqlFragment, onSetSqlLimit, onExecuteSql, onStepChange } = props
  38. const STATUS_BTN_TEXT = !loading ? '执行' : '中止'
  39. const SELECT_CONTENT_BTN_TEXT = sqlFragment ? '选中内容' : ''
  40. const NEXT_DISABLED_AS_EXECUTE_FRAGMENT_TEXT = !isLastExecuteWholeSql ? '执行完整sql后可用' : ''
  41. const NEXT_DISABLED_AS_SQL_CHANGED_TEXT = nextDisabled ? '执行后下一步可用' : NEXT_DISABLED_AS_EXECUTE_FRAGMENT_TEXT
  42. const shortcutsContent = (
  43. <Row>
  44. <Col span={8}>执行 / 中止:</Col>
  45. <Col span={16}>
  46. <Tag color="orange">Ctrl + Enter</Tag>(Windows)
  47. </Col>
  48. <Col offset={8} span={16}>
  49. <Tag color="orange">Cmd + Enter</Tag>(Mac OS)
  50. </Col>
  51. </Row>
  52. )
  53. return (
  54. <Row className={Styles.bottom} type="flex" align="middle" justify="start">
  55. <Col span={12} className={Styles.previewInput}>
  56. <span>展示前</span>
  57. <InputNumber value={sqlLimit} onChange={onSetSqlLimit} />
  58. <span>条数据</span>
  59. </Col>
  60. <Col span={12} className={Styles.toolBtns}>
  61. <Popover
  62. title="快捷键"
  63. content={shortcutsContent}
  64. overlayClassName={Styles.shortcuts}
  65. >
  66. <i className="iconfont icon-shortcuts_icon" />
  67. </Popover>
  68. <Button onClick={stepChange(onStepChange, -1)}>取消</Button>
  69. <Button
  70. type="primary"
  71. icon={!loading ? 'caret-right' : 'pause-circle'}
  72. onClick={onExecuteSql}
  73. >
  74. {STATUS_BTN_TEXT + SELECT_CONTENT_BTN_TEXT}
  75. </Button>
  76. <Tooltip title={NEXT_DISABLED_AS_SQL_CHANGED_TEXT}>
  77. <Button onClick={stepChange(onStepChange, 1)} disabled={nextDisabled || !isLastExecuteWholeSql}>
  78. 下一步
  79. </Button>
  80. </Tooltip>
  81. </Col>
  82. </Row>
  83. )
  84. }
  85. export default React.memo(EditorBottom)