Skip to content

Commit 8b5a76f

Browse files
committed
v0.2.0
1 parent e8476e0 commit 8b5a76f

File tree

11 files changed

+134
-29
lines changed

11 files changed

+134
-29
lines changed

app/actions/file_list_actions.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ export function UPDATE_CONTENT(filePath,content) {
4040
}
4141
};
4242
}
43+
export function SAVE_ACTIVE_FILE() {
44+
return {
45+
type: types.SAVE_ACTIVE_FILE
46+
};
47+
}
48+
49+
export function SAVE_ACTIVE_FILE_SUCCESS() {
50+
return {
51+
type: types.SAVE_ACTIVE_FILE_SUCCESS
52+
};
53+
}
4354
export function CLOSE_FILE(file) {
4455
return {
4556
type: types.CLOSE_FILE,

app/components/EonDetail/Console/SegmentsTab.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function mapDispatchToProps(dispatch) {
5757
}
5858

5959
const mapStateToProps = ({ eonDetail }) => {
60-
const { routes,activeRouteId, routesSorted, routesLoading } = eonDetail;
60+
const { routes, activeRouteId, routesSorted, routesLoading } = eonDetail;
6161
// let routeKeys;
6262

6363
if (!routesSorted || !routesSorted.length) return { loading: true };

app/components/EonDetail/Console/index.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,32 @@ import EndpointsTab from './EndpointsTab';
1313
import * as EonActions from '../../../actions/eon_detail_actions';
1414
const TABS = {
1515
'events': {
16+
'id': 'events',
1617
'label': 'Events',
17-
'component': EventsTab
18+
'component': EventsTab,
19+
'requireAuth': false
1820
},
1921
'params': {
22+
'id': 'params',
2023
'label': 'Params',
21-
'component': DataParamsTab
24+
'component': DataParamsTab,
25+
'requireAuth': true
2226
},
2327
'profile': {
28+
'id': 'profile',
2429
'label': 'Profile',
25-
'component': ProfileTab
30+
'component': ProfileTab,
31+
'requireAuth': true
2632
},
2733
// 'routes': {
2834
// 'label': 'Routes',
2935
// 'component': RoutesTab
3036
// },
3137
'segments': {
38+
'id': 'segments',
3239
'label': 'Drives',
33-
'component': SegmentsTab
40+
'component': SegmentsTab,
41+
'requireAuth': true
3442
}
3543
// 'endpoints': {
3644
// 'label': 'Endpoints',
@@ -50,20 +58,22 @@ class Console extends React.Component {
5058
}
5159

5260
setTab(tab) {
53-
if (this.state.activeTab !== tab) {
61+
let disabled = (tab.requireAuth && !this.props.hasAuth);
62+
if (this.state.activeTab !== tab.id && !disabled) {
5463
this.setState({
55-
activeTab: tab
64+
activeTab: tab.id
5665
});
5766
}
5867
}
5968

6069
render() {
70+
const { hasAuth } = this.props;
6171
const tabButtons = TAB_KEYS.map((tabKey) => {
6272
const tab = TABS[tabKey];
63-
73+
const disabled = tab.requireAuth && !hasAuth;
6474
return (
6575
<NavItem className="console-tab" key={`tab-item-${tabKey}`}>
66-
<NavLink className={classnames({ active: this.state.activeTab === tabKey })} onClick={() => { this.setTab(tabKey); }}>
76+
<NavLink className={classnames({ active: this.state.activeTab === tabKey })} onClick={() => { this.setTab(tab); }} disabled={disabled} >
6777
{tab.label}
6878
</NavLink>
6979
</NavItem>
@@ -98,8 +108,18 @@ function mapDispatchToProps(dispatch) {
98108
return bindActionCreators(EonActions, dispatch);
99109
}
100110

101-
const mapStateToProps = (state) => {
102-
return {};
111+
const mapStateToProps = ({eonDetail}) => {
112+
const { auth } = eonDetail;
113+
let hasAuth;
114+
if (auth) {
115+
if (auth.commaUser) {
116+
hasAuth = true;
117+
}
118+
} else {
119+
hasAuth = false;
120+
}
121+
console.log("hasAuth:",hasAuth);
122+
return { hasAuth };
103123
};
104124

105125
export default connect(

app/components/EonDetail/Editor/index.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,42 @@ class Editor extends React.PureComponent {
1818
editorDidMount = (editor, monaco) => {
1919
// console.log('editorDidMount', editor);
2020
editor.focus();
21+
editor.addAction({
22+
// An unique identifier of the contributed action.
23+
id: 'save-op-file',
24+
25+
// A label of the action that will be presented to the user.
26+
label: 'Save File',
27+
28+
// An optional array of keybindings for the action.
29+
keybindings: [
30+
monaco.KeyMod.CtrlCmd | monaco.KeyCode.F10,
31+
// chord
32+
monaco.KeyMod.chord(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S)
33+
],
34+
35+
// A precondition for this action.
36+
precondition: null,
37+
38+
// A rule to evaluate on top of the precondition in order to dispatch the keybindings.
39+
keybindingContext: null,
40+
41+
contextMenuGroupId: 'navigation',
42+
43+
contextMenuOrder: 1.5,
44+
45+
// Method that will be executed when the action is triggered.
46+
// @param editor The editor instance is passed in as a convinience
47+
run: (ed) => {
48+
this.onSave();
49+
return null;
50+
}
51+
});
52+
53+
}
54+
onSave = () => {
55+
this.props.SAVE_ACTIVE_FILE();
2156
}
22-
2357
onChange = (evt, newValue) => {
2458
// console.log('onChange', newValue, e);
2559
// console.log(this);
@@ -29,7 +63,8 @@ class Editor extends React.PureComponent {
2963
const { fileType, name, content, hidden, allowOpen, isDirty, _original } = this.props;
3064
const options = {
3165
selectOnLineNumbers: true,
32-
renderSideBySide: true
66+
renderSideBySide: true,
67+
3368
};
3469
// console.log("rendering...");
3570
return (<div className="editor">

app/components/EonDetail/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EonDetail extends React.PureComponent {
4242
this.props.TOGGLE_DATA();
4343
}
4444
render() {
45-
const { activeTab, connecting, activeCommand, network, eon, serviceIds } = this.props;
45+
const { activeTab,activeFile, connecting, activeCommand, network, eon, serviceIds } = this.props;
4646
const commandKeys = Object.keys(commands);
4747

4848
if (connecting) return (<LoadingOverlay message={"Connecting to EON..."} />);
@@ -80,7 +80,8 @@ class EonDetail extends React.PureComponent {
8080
if (activeCommand) {
8181
CommandPane = commands[activeCommand];
8282
}
83-
83+
const editorHeight = activeFile ? "50%" : 0;
84+
const editorMinSize = activeFile ? 100 : 0;
8485
// const ELEMENT_MAP = {
8586
// files: <FileList directory="/data/openpilot" />,
8687
// states: StateTabs,
@@ -111,7 +112,7 @@ class EonDetail extends React.PureComponent {
111112
</SplitPane>
112113
</div>
113114

114-
<SplitPane split="horizontal" size={"50%"} minSize={100}>
115+
<SplitPane split="horizontal" size={editorHeight} minSize={editorMinSize}>
115116
<div className="editor-container">
116117
<EditorTabs />
117118
<Editor />

app/constants/file_list_action_types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ export const FETCH_DIRECTORY_SUCCESS = 'fileList/FETCH_DIRECTORY_SUCCESS';
77
export const FETCH_FILE = 'fileList/FETCH_FILE';
88
export const FETCH_FILE_SUCCESS = 'fileList/FETCH_FILE_SUCCESS';
99
export const UPDATE_CONTENT = 'fileList/UPDATE_CONTENT';
10+
export const SAVE_ACTIVE_FILE = 'fileList/SAVE_ACTIVE_FILE';
11+
export const SAVE_ACTIVE_FILE_SUCCESS = 'fileList/SAVE_ACTIVE_FILE_SUCCESS';
1012
export const CLOSE_FILE = 'fileList/CLOSE_FILE';

app/containers/EonDetailPage.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {getHasOpenedFiles} from '../selectors/get_opened_files_keys';
77
import getSortedServiceIds from '../selectors/get_sorted_service_ids';
88
// import { debugOnlyWastedRenderDetector } from "wastedrendersdetector";
99

10-
function mapStateToProps({eonDetail,eonList,networkConnection}) {
10+
function mapStateToProps({eonDetail,eonList,networkConnection,fileList}) {
1111
// let hasOpenedFiles = getHasOpenedFiles(fileList.openedFiles);
1212
let serviceIds = getSortedServiceIds();
1313
return {
@@ -21,7 +21,8 @@ function mapStateToProps({eonDetail,eonList,networkConnection}) {
2121
connecting: eonDetail.connecting,
2222
connected: eonDetail.connected,
2323
serviceIds,
24-
services
24+
services,
25+
activeFile: fileList.activeFile
2526
};
2627
}
2728

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "workbench",
33
"productName": "Workbench",
4-
"version": "0.1.3",
4+
"version": "0.2.0",
55
"description": "The Openpilot Workbench is to help people fix problems with EON, Openpilot, etc.",
66
"main": "./main.prod.js",
77
"author": {

app/reducers/file_list_reducer.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,34 @@ export default function fileListReducer(state = initialState, action) {
5050
}
5151
}
5252
};
53+
case types.SAVE_ACTIVE_FILE:
54+
return {
55+
...state,
56+
openedFiles: {
57+
[state.activeFile]: {
58+
...state.openedFiles[state.activeFile],
59+
isSaving: true
60+
}
61+
}
62+
};
63+
case types.SAVE_ACTIVE_FILE_SUCCESS:
64+
return {
65+
...state,
66+
openedFiles: {
67+
[state.activeFile]: {
68+
...state.openedFiles[state.activeFile],
69+
isSaving: false,
70+
_original: state.openedFiles[state.activeFile].content,
71+
isDirty: false
72+
}
73+
}
74+
};
5375
case types.CLOSE_FILE:
5476
delete state.openedFiles[action.payload.filePath];
5577

5678
return {
5779
...state,
80+
activeFile: null,
5881
openedFiles: {
5982
...state.openedFiles
6083
}

app/sagas/eon_sagas.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@ function* connect() {
119119
console.log(`[sftp] Connected to EON (${eon.ip})`);
120120
}
121121

122+
function* saveActiveFile() {
123+
const { fileList } = yield select();
124+
const { activeFile, openedFiles } = fileList;
125+
const currentFile = openedFiles[activeFile];
126+
const contentBuffer = Buffer.from(currentFile.content);
127+
yield connect();
128+
console.log(`[sftp] Saving ${activeFile}...`);
129+
const savedFile = yield app.sftpClient.put(contentBuffer, activeFile);
130+
yield put(fileListActions.SAVE_ACTIVE_FILE_SUCCESS());
131+
return {
132+
savedFile
133+
};
134+
}
135+
122136
function* retrieveFile(remoteFile, mergeWith={}) {
123137
yield connect();
124138
console.log(`[sftp] Retrieving file ${remoteFile}...`);
@@ -167,17 +181,11 @@ function* refreshFileList() {
167181
yield put(eonDetailActions.REFRESH_FILE_LIST_SUCCESS(baseItems));
168182
}
169183

170-
function* fetchEndpoint(endpoint) {
171-
const { eonDetail } = yield select();
172-
const { dataParams } = eonDetail;
173-
console.log("Fetching endpoint...", endpoint);
174-
console.log("dataParams",dataParams);
175-
}
176-
177184
function* apiRequest(endpointUrl) {
178185
const { eonDetail } = yield select();
179186
const { auth } = eonDetail;
180187
const { commaUser } = auth;
188+
181189
const { accessToken } = commaUser;
182190
if (!accessToken) return ;
183191
// console.log(accessToken);
@@ -199,7 +207,7 @@ function buildEndpointUrl(key, tokens = {}) {
199207
let endpoint = ENDPOINTS[key];
200208

201209
let tokenKeys = [];
202-
console.log(endpoint);
210+
// console.log(endpoint);
203211
if (tokens) {
204212
tokenKeys = Object.keys(tokens);
205213
}
@@ -208,7 +216,7 @@ function buildEndpointUrl(key, tokens = {}) {
208216
tokenKeys.forEach((tokenKey) => {
209217
const tokenValue = tokens[tokenKey];
210218
// const length = endpoint.length
211-
console.log(`replacing ${tokenKey} with ${tokenValue}`)
219+
// console.log(`replacing ${tokenKey} with ${tokenValue}`)
212220
endpoint = endpoint.replace(/\{\{([a-zA-Z0-9\.]+)\}\}/,tokenValue);
213221
});
214222
}
@@ -676,6 +684,7 @@ export function* eonSagas() {
676684
takeLatest(eonListTypes.SELECT_EON, handleSelectEon),
677685
// takeEvery(types.CONNECT_FAILED, addEonListError),
678686
takeEvery(types.BOOTSTRAP_EON, handleBootstrapEON),
687+
takeEvery(fileListActionTypes.SAVE_ACTIVE_FILE, saveActiveFile),
679688
takeEvery(fileListActionTypes.FETCH_DIRECTORY, handleFetchDirectory),
680689
takeEvery(fileListActionTypes.FETCH_FILE, handleFetchFile),
681690
// takeEvery(fileListActionTypes.FETCH_DIRECTORY_SUCCESS, handleFetchDirectorySuccess),

0 commit comments

Comments
 (0)