Skip to content

Commit

Permalink
Merge pull request #3 from oslabs-beta/Nancy
Browse files Browse the repository at this point in the history
Nancy completed the save file functionality for the proto file
  • Loading branch information
danst3in authored Jan 23, 2020
2 parents 18ff372 + 0abacf5 commit ad272ba
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 28 deletions.
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions saveProto.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/Users/nancydao/Desktop/book.proto
2 changes: 1 addition & 1 deletion src/assets/style/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@
.collections-container {
min-height: 150px;
max-height: 400px;
width: 45%;
width: 100%;
overflow-y: scroll;
}
.dropdownService, .dropdownRequest {
Expand Down
9 changes: 0 additions & 9 deletions src/client/components/composer/NewRequest/FieldEntryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ class FieldEntryForm extends Component {
});
}
else if (value === 'SERVER STREAMING') {
this.props.setNewRequestFields({
...this.props.newRequestFields,
protocol: 'localhost:',
url: `localhost:${afterProtocol}`,
method: 'SERVER STREAMING',
graphQL: false,
gRPC: true
})

this.props.setNewRequestBody({
...this.props.newRequestBody,
bodyContent: newBody
Expand Down
49 changes: 46 additions & 3 deletions src/client/components/composer/NewRequest/GRPCAutoInputForm.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
import React, { Component } from 'react';
import dropDownArrow from '../../../../assets/icons/arrow_drop_down_white_192x192.png'
import { TouchBarColorPicker } from 'electron';

class GRPCAutoInputForm extends Component {
constructor(props) {
super(props);
this.state = {
show: true,
// ***MOCK DATA***
// services: [
// {
// name: 'BookService',
// rpcs: [
// {
// name: 'GetBook',
// type: 'unary',
// definition: 'rpc GetBook (GetBookRequest) returns (Book) {}',
// messages: [
// {
// name: 'Book',
// definition: [
// {
// number: 1,
// definition: 'int64 isbn = 1'
// },
// {
// number: 2,
// definition: 'string title = 2'
// },
// {
// number: 3,
// definition: 'string author = 3'
// }
// ]
// }
// ]
// }
// ]
// }
// ]
};

this.toggleShow = this.toggleShow.bind(this);
}

Expand All @@ -16,14 +50,23 @@ class GRPCAutoInputForm extends Component {
});
}

// parseData() {

// setServices(mockData) {
// this.setState({
// ...this.state,
// services: mockData.services,
// });
// }


render() {
const arrowClass = this.state.show ? 'composer_subtitle_arrow-open' : 'composer_subtitle_arrow-closed';
const bodyContainerClass = this.state.show ? 'composer_bodyform_container-open' : 'composer_bodyform_container-closed';

// let services = this.state.services;
// for (let i = 0; i < services.length; i++) {
// <option value={i}>services[i].name</option>
// }

return (
<div >
<div className='composer_subtitle' onClick={this.toggleShow} style={this.props.stylesObj}>
Expand All @@ -33,7 +76,7 @@ class GRPCAutoInputForm extends Component {

<select id="dropdownService" name="dropdownService" className={'dropdownService ' + bodyContainerClass}>
<option value="test1" selected="">Service1</option>
<option value="test2">Service2</option>
{/* {optionsList} */}
</select>

<select id="dropdownRequest" name="dropdownRequest" className={'dropdownRequest ' + bodyContainerClass}>
Expand Down
20 changes: 11 additions & 9 deletions src/client/components/composer/NewRequest/GRPCBodyEntryForm.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { Component } from 'react';
import dropDownArrow from '../../../../assets/icons/arrow_drop_down_white_192x192.png'
import { remote } from 'electron';
const fs = require('fs');
import GRPCAutoInputForm from "./GRPCAutoInputForm.jsx";
import fs from 'fs';
import path from 'path';

class GRPCBodyEntryForm extends Component {
constructor(props) {
Expand Down Expand Up @@ -41,15 +42,16 @@ class GRPCBodyEntryForm extends Component {
...this.props.newRequestBody,
bodyContent: data
});
// write to saveProto file
const dirName = remote.app.getAppPath();
fs.writeFileSync(path.join(dirName, 'src/client/components/composer/protos/saveProto.proto'), data, 'utf-8', (err) => {
if(err){
alert("An error ocurred writing the file :" + err.message);
return;
}
console.log('Proto file has been saved')
})
});
// fs.writeFileSync('../protos/saveProto.proto', filePaths, 'utf-8', (err) => {
// console.log('In writeFileSync')
// if(err){
// alert("An error ocurred writing the file :" + err.message);
// return;
// }
// console.log('Proto file has been saved')
// })
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ProtocolSelect extends Component {
const HTTPSStyleClasses = classNames({
composer_protocol_button: true,
http: true,
'composer_protocol_button-selected_http': (this.props.currentProtocol === '' || /https?:\/\//.test(this.props.currentProtocol)) && !this.props.graphQL,
'composer_protocol_button-selected_http': (this.props.currentProtocol === '' || /https?:\/\//.test(this.props.currentProtocol)) && !this.props.graphQL && !this.props.gRPC,
});
const WSStyleClasses = classNames({
composer_protocol_button: true,
Expand Down
36 changes: 36 additions & 0 deletions src/client/components/composer/protos/saveProto.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax = "proto3";

package com.book;

message Book {
int64 isbn = 1;
string title = 2;
string author = 3;
}

message GetBookRequest {
int64 isbn = 1;
}

message GetBookViaAuthor {
string author = 1;
}

service BookService {
rpc GetBook (GetBookRequest) returns (Book) {}
rpc GetBooksViaAuthor (GetBookViaAuthor) returns (stream Book) {}
rpc GetGreatestBook (stream GetBookRequest) returns (Book) {}
rpc GetBooks (stream GetBookRequest) returns (stream Book) {}
}

message BookStore {
string name = 1;
map<int64, string> books = 2;
}

enum EnumSample {
option allow_alias = true;
UNKNOWN = 0;
STARTED = 1;
RUNNING = 1;
}

0 comments on commit ad272ba

Please sign in to comment.