From f0eb03bf050dd08746333b1b0e181c6ef55d8a21 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Wed, 24 Oct 2018 13:45:12 +0100 Subject: [PATCH] Add editor tabs --- embark-ui/src/actions/index.js | 37 +++++++++------ embark-ui/src/components/ContractDetail.js | 4 +- embark-ui/src/components/TextEditor.js | 34 +++++++++++--- embark-ui/src/components/TextEditorToolbar.js | 3 -- embark-ui/src/containers/EditorContainer.css | 1 + embark-ui/src/containers/EditorContainer.js | 16 +++---- .../src/containers/TextEditorContainer.js | 46 +++++++++++++----- embark-ui/src/index.css | 4 ++ embark-ui/src/reducers/index.js | 15 ++++-- embark-ui/src/reducers/selectors.js | 5 +- embark-ui/src/sagas/index.js | 47 ++++++++++++------- embark-ui/src/services/storage.js | 35 ++++++++++---- 12 files changed, 169 insertions(+), 78 deletions(-) diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index e4a73dd77..1ae7c9a2c 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -282,7 +282,7 @@ export const files = { export const FILE = createRequestTypes('FILE'); export const file = { request: (file) => action(FILE[REQUEST], file), - success: (file) => action(FILE[SUCCESS], file), + success: (file) => action(FILE[SUCCESS], {file}), failure: (error) => action(FILE[FAILURE], {error}) }; @@ -300,20 +300,6 @@ export const removeFile = { failure: (error) => action(REMOVE_FILE[FAILURE], {error}) }; -export const CURRENT_FILE = createRequestTypes('CURRENT_FILE'); -export const currentFile = { - request: () => action(CURRENT_FILE[REQUEST]), - success: (file) => action(CURRENT_FILE[SUCCESS], {currentFiles: [file]}), - failure: () => action(CURRENT_FILE[FAILURE]) -}; - -export const SAVE_CURRENT_FILE = createRequestTypes('SAVE_CURRENT_FILE'); -export const saveCurrentFile = { - request: (file) => action(SAVE_CURRENT_FILE[REQUEST], file), - success: (file) => action(SAVE_CURRENT_FILE[SUCCESS], {currentFiles: [file]}), - failure: () => action(SAVE_CURRENT_FILE[FAILURE]) -}; - export const GAS_ORACLE = createRequestTypes('GAS_ORACLE'); export const gasOracle = { request: () => action(GAS_ORACLE[REQUEST]), @@ -410,6 +396,27 @@ export const debuggerInfo = { success: (data) => action(DEBUGGER_INFO[SUCCESS], {data}) }; +export const FETCH_EDITOR_TABS = createRequestTypes('FETCH_EDITOR_TABS'); +export const fetchEditorTabs = { + request: () => action(FETCH_EDITOR_TABS[REQUEST]), + success: (editorTabs) => action(FETCH_EDITOR_TABS[SUCCESS], {editorTabs}), + failure: () => action(FETCH_EDITOR_TABS[FAILURE]) +}; + +export const ADD_EDITOR_TABS = createRequestTypes('ADD_EDITOR_TABS'); +export const addEditorTabs = { + request: (file) => action(ADD_EDITOR_TABS[REQUEST], {file}), + success: () => action(ADD_EDITOR_TABS[SUCCESS]), + failure: () => action(ADD_EDITOR_TABS[FAILURE]) +}; + +export const REMOVE_EDITOR_TABS = createRequestTypes('REMOVE_EDITOR_TABS'); +export const removeEditorTabs = { + request: (file) => action(REMOVE_EDITOR_TABS[REQUEST], {file}), + success: () => action(REMOVE_EDITOR_TABS[SUCCESS]), + failure: () => action(REMOVE_EDITOR_TABS[FAILURE]) +}; + // Web Socket export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS'; export const STOP_NEW_PROCESS_LOGS = 'STOP_NEW_PROCESS_LOGS'; diff --git a/embark-ui/src/components/ContractDetail.js b/embark-ui/src/components/ContractDetail.js index 5797afa7c..da37a73ad 100644 --- a/embark-ui/src/components/ContractDetail.js +++ b/embark-ui/src/components/ContractDetail.js @@ -1,12 +1,10 @@ import PropTypes from "prop-types"; import React from 'react'; import ReactJson from "react-json-view"; -import {Row, Col, Table} from "reactstrap"; -import {formatContractForDisplay} from '../utils/presentation'; +import {Row, Col} from "reactstrap"; import CopyButton from './CopyButton'; const ContractDetail = ({contract}) => { - const contractDisplay = formatContractForDisplay(contract); return ( diff --git a/embark-ui/src/components/TextEditor.js b/embark-ui/src/components/TextEditor.js index 07fa83933..2e610ca55 100644 --- a/embark-ui/src/components/TextEditor.js +++ b/embark-ui/src/components/TextEditor.js @@ -1,6 +1,8 @@ import React from 'react'; import * as monaco from 'monaco-editor'; import PropTypes from 'prop-types'; +import FontAwesomeIcon from 'react-fontawesome'; +import classNames from 'classnames'; import './TextEditor.css'; @@ -40,7 +42,7 @@ class TextEditor extends React.Component { editor.onMouseDown((e) => { if (e.target.type === GUTTER_GLYPH_MARGIN){ - this.props.toggleBreakpoint(this.props.file.name, e.target.position.lineNumber); + this.props.toggleBreakpoint(this.props.currentFile.name, e.target.position.lineNumber); } }); } @@ -49,7 +51,10 @@ class TextEditor extends React.Component { getLanguage() { - const extension = this.props.file.name.split('.').pop(); + if (!this.props.currentFile.name) { + return DEFAULT_LANGUAGE; + } + const extension = this.props.currentFile.name.split('.').pop(); return SUPPORTED_LANGUAGES[SUPPORTED_LANGUAGES.indexOf(extension)] || DEFAULT_LANGUAGE; } @@ -112,8 +117,8 @@ class TextEditor extends React.Component { } componentDidUpdate(prevProps) { - if (this.props.file.content !== prevProps.file.content) { - editor.setValue(this.props.file.content); + if (this.props.currentFile.content && this.props.currentFile.content !== prevProps.currentFile.content) { + editor.setValue(this.props.currentFile.content); } this.updateMarkers(); @@ -125,9 +130,23 @@ class TextEditor extends React.Component { this.handleResize(); } + renderTabs() { + return ( + + ) + } + render() { return (
+ {this.renderTabs()}
) @@ -136,10 +155,13 @@ class TextEditor extends React.Component { TextEditor.propTypes = { onFileContentChange: PropTypes.func, - file: PropTypes.object, + currentFile: PropTypes.object, toggleBreakpoint: PropTypes.func, breakpoints: PropTypes.array, - debuggerLine: PropTypes.number + debuggerLine: PropTypes.number, + editorTabs: PropTypes.array, + removeEditorTabs: PropTypes.func, + addEditorTabs: PropTypes.func }; export default TextEditor; diff --git a/embark-ui/src/components/TextEditorToolbar.js b/embark-ui/src/components/TextEditorToolbar.js index 61620828f..2b42c89d2 100644 --- a/embark-ui/src/components/TextEditorToolbar.js +++ b/embark-ui/src/components/TextEditorToolbar.js @@ -13,8 +13,6 @@ const TextEditorToolbar = (props) => ( - {props.currentFile.name} - |