Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notebook): start jupyterlab servers from any branch and commit #472

Merged
merged 1 commit into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"react-motion": "^0.5.2",
"react-redux": "^5.0.6",
"react-router-dom": "^4.2.2",
"reactstrap": "^5.0.0-alpha.4",
"reactstrap": "^8.0.0",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0",
"styled-jsx": "^2.2.6",
Expand Down
46 changes: 38 additions & 8 deletions src/api-client/notebook-servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,67 @@ function cleanAnnotations(annotations, domain) {
}

function addNotebookServersMethods(client) {
client.getNotebookServers = (id) => {
let headers = client.getBasicHeaders();
client.getNotebookServers = (id, branch, commit) => {
// TODO: add filtering logic here, remove from Notebook
const headers = client.getBasicHeaders();
const url = `${client.baseUrl}/notebooks/servers`;
return client.clientFetch(url, {
method: 'GET',
headers: headers
headers
}).then(resp => {
const { servers } = resp.data;
let { servers } = resp.data;
if (id) {
// TODO: remove this filter when this API will support projectId filtering
const filteredServers = Object.keys(servers)
servers = Object.keys(servers)
.filter(server => servers[server].annotations["renku.io/projectId"] === id)
.reduce((obj, key) => {obj[key] = servers[key]; return obj}, {});
return { "data": filteredServers };
}
return { "data": servers };
});
}

client.stopNotebookServer = (serverName) => {
let headers = client.getBasicHeaders();
const headers = client.getBasicHeaders();
const url = `${client.baseUrl}/notebooks/servers/${serverName}`;

return client.clientFetch(url, {
method: 'DELETE',
headers: headers
headers
}, "text")
.then(resp => {
return true;
});
}

client.getNotebookServerOptions = (projectUrl, commitId) => {
const headers = client.getBasicHeaders();
const url = `${client.baseUrl}/notebooks/${projectUrl}/${commitId}/server_options`;

return client.clientFetch(url, {
method: 'GET',
headers
}).then((resp) => {
let { data } = resp;
Object.keys(data).forEach(key => {
data[key].selected = data[key].default;
})
return data;
});
}

client.startNotebook = (projectUrl, branchName, commitId, options) => {
const headers = client.getBasicHeaders();
const url = `${client.baseUrl}/notebooks/${projectUrl}/${commitId}`;

return client.clientFetch(url, {
method: 'POST',
headers,
queryParams: { branch: branchName },
body: JSON.stringify(options)
}).then((resp) => {
return resp.data;
});
}
}

export { cleanAnnotations, ExpectedAnnotations };
Expand Down
13 changes: 12 additions & 1 deletion src/model/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ const SpecialPropVal = {
UPDATING: 'is_updating'
};

const StatusHelper = {
isUpdating: (value) => {
return value === SpecialPropVal.UPDATING ? true : false;
}
}

class FieldSpec {
constructor(spec) {
Object.keys(spec).forEach((prop) => {
Expand Down Expand Up @@ -271,6 +277,11 @@ class SubModel {
this.baseModel.setUpdating(fullOptions);
}

isUpdating(propAccessorString) {
const fullPropAccessorString = this.baseModelPath + (propAccessorString ? '.' + propAccessorString : '');
return StatusHelper.isUpdating(this.baseModel.get(fullPropAccessorString));
}

mapStateToProps = _mapStateToProps.bind(this);

subModel = (path) => new SubModel(this.baseModel, this.baseModelPath + '.' + path);
Expand Down Expand Up @@ -460,4 +471,4 @@ function _mapStateToProps(state, ownProps) {
}


export { Schema, StateModel, StateKind , SubModel, SpecialPropVal}
export { Schema, StateModel, StateKind , SubModel, SpecialPropVal, StatusHelper }
Loading