Skip to content

Commit c2b70f6

Browse files
committed
Show version in UI
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
1 parent 0718ceb commit c2b70f6

6 files changed

Lines changed: 83 additions & 5 deletions

File tree

docs/rest-api.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,22 @@ curl -X POST \
337337
}
338338
}
339339
```
340+
341+
## GET /version
342+
343+
Returns the current version of the server, gitbase, and bblfshd.
344+
345+
```bash
346+
curl -X GET http://localhost:8080/version
347+
```
348+
349+
```json
350+
{
351+
"status" : 200,
352+
"data" : {
353+
"gitbase" : "8.0.11-undefined",
354+
"bblfsh" : "v2.7.2",
355+
"version" : "dev"
356+
}
357+
}
358+
```

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
},
6363
"/filter": {
6464
"target": "http://localhost:8080"
65+
},
66+
"/version": {
67+
"target": "http://localhost:8080"
6568
}
6669
}
6770
}

frontend/src/App.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class App extends Component {
4545
sql: '',
4646
results: new Map(),
4747
schema: undefined,
48+
version: undefined,
4849
languages: [],
4950
history: [],
5051
lastResult: null,
@@ -246,6 +247,10 @@ AND refs.ref_name = 'HEAD'`
246247
this.loadSchema();
247248
}
248249

250+
if (!this.state.version) {
251+
this.loadVersion();
252+
}
253+
249254
if (this.state.languages.length === 0) {
250255
this.loadLanguages();
251256
}
@@ -304,6 +309,19 @@ AND refs.ref_name = 'HEAD'`
304309
});
305310
}
306311

312+
loadVersion() {
313+
api
314+
.version()
315+
.then(version => {
316+
this.setState({ version });
317+
})
318+
.catch(msgArr => {
319+
// left as console message for now, we don't have UI for errors
320+
// eslint-disable-next-line no-console
321+
console.error(`Error while loading version: ${msgArr}`);
322+
});
323+
}
324+
307325
handleModalClose() {
308326
this.setState({ showModal: false, modalTitle: null, modalContent: null });
309327
}
@@ -330,6 +348,7 @@ AND refs.ref_name = 'HEAD'`
330348
.then(languages => this.setState({ languages }))
331349
.catch(err =>
332350
// we don't have UI for this error
351+
// eslint-disable-next-line no-console
333352
console.error(`Can't get list of languages from bblfsh: ${err}`)
334353
);
335354
}
@@ -338,6 +357,7 @@ AND refs.ref_name = 'HEAD'`
338357
this.setState(loadStateFromStorage());
339358
this.loadSchema();
340359
this.loadLanguages();
360+
this.loadVersion();
341361
this.handleExampleClick(this.exampleQueries[0].sql);
342362
}
343363

@@ -414,6 +434,7 @@ AND refs.ref_name = 'HEAD'`
414434
<Row className="main-row full-height">
415435
<Sidebar
416436
schema={this.state.schema}
437+
version={this.state.version}
417438
onTableClick={this.handleTableClick}
418439
onExampleClick={this.handleExampleClick}
419440
exampleQueries={this.exampleQueries}

frontend/src/api.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,17 @@ function filterUAST(protobufs, filter) {
166166
}).then(res => res.data);
167167
}
168168

169+
function version() {
170+
return apiCall(`/version`).then(res => res.data);
171+
}
172+
169173
export default {
170174
query,
171175
schema,
172176
queryExport,
173177
detectLang,
174178
parseCode,
175179
getLanguages,
176-
filterUAST
180+
filterUAST,
181+
version
177182
};

frontend/src/components/Sidebar.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,26 @@ class Sidebar extends Component {
2020
this.setState({ collapsed: !this.state.collapsed });
2121
}
2222

23-
link(text, url) {
23+
link(text, url, version) {
2424
return (
2525
<div>
2626
<a href={url} target="_blank" rel="noopener noreferrer">
2727
<LinkIcon className="small-icon" />
2828
{text}
2929
</a>
30+
{version && <span className="version">{version}</span>}
3031
</div>
3132
);
3233
}
3334

3435
render() {
35-
const { schema, onTableClick, onExampleClick, exampleQueries } = this.props;
36+
const {
37+
schema,
38+
version,
39+
onTableClick,
40+
onExampleClick,
41+
exampleQueries
42+
} = this.props;
3643
const { collapsed } = this.state;
3744

3845
return (
@@ -57,7 +64,21 @@ class Sidebar extends Component {
5764
</div>
5865
<div className="footer list">
5966
{this.link('go-git', 'https://github.com/src-d/go-git')}
60-
{this.link('babelfish', 'https://doc.bblf.sh')}
67+
{this.link(
68+
'babelfish',
69+
'https://doc.bblf.sh',
70+
version ? version.bblfsh : ''
71+
)}
72+
{this.link(
73+
'gitbase',
74+
'https://docs.sourced.tech/gitbase',
75+
version ? version.gitbase : ''
76+
)}
77+
{this.link(
78+
'gitbase-web',
79+
'https://github.com/src-d/gitbase-web',
80+
version ? version.version : ''
81+
)}
6182
{this.link('source{d} © 2018', 'https://sourced.tech')}
6283
</div>
6384
</div>
@@ -67,6 +88,11 @@ class Sidebar extends Component {
6788

6889
Sidebar.propTypes = {
6990
schema: Schema.propTypes.schema,
91+
version: PropTypes.shape({
92+
version: PropTypes.string.isRequired,
93+
bblfsh: PropTypes.string.isRequired,
94+
gitbase: PropTypes.string.isRequired
95+
}),
7096
onTableClick: PropTypes.func,
7197
onExampleClick: PropTypes.func,
7298
exampleQueries: SampleQueries.propTypes.exampleQueries

frontend/src/components/Sidebar.less

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,16 @@
5252
}
5353

5454
.footer {
55-
font-weight: @bold-font-weight;
5655
padding-left: @big-spacing;
5756

5857
a {
58+
font-weight: @bold-font-weight;
5959
.icon-container-variant(@primary-tint-2);
6060
}
61+
62+
.version {
63+
padding-left: 1.5ex;
64+
}
6165
}
6266

6367
.SplitPane {

0 commit comments

Comments
 (0)