Skip to content

Commit

Permalink
refactor(environments): use commit data from project coordinator (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-cavazzi committed Apr 29, 2020
1 parent 7b961c2 commit 4e38152
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
32 changes: 23 additions & 9 deletions src/notebooks/Notebooks.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { StartNotebookServer as StartNotebookServerPresent, NotebooksDisabled }
import { Notebooks as NotebooksPresent } from "./Notebooks.present";
import { CheckNotebookIcon } from "./Notebooks.present";
import { StatusHelper } from "../model/Model";
import { ProjectCoordinator } from "../project";

/**
* Display the list of Notebook servers
Expand Down Expand Up @@ -145,6 +146,9 @@ class StartNotebookServer extends Component {
this.model = props.model.subModel("notebooks");
this.userModel = props.model.subModel("user");
this.coordinator = new NotebooksCoordinator(props.client, this.model, this.userModel);
// TODO: this should go away when moving all project content to projectCoordinator
this.projectModel = props.model.subModel("project");
this.projectCoordinator = new ProjectCoordinator(props.client, props.model.subModel("project"));
// temporarily reset data since notebooks model was not designed to be static
this.coordinator.reset();

Expand Down Expand Up @@ -243,13 +247,19 @@ class StartNotebookServer extends Component {

async refreshCommits() {
if (this._isMounted) {
if (this.model.get("data.fetching"))
return;
if (!this.projectModel.get("commits.fetching"))
await this.projectCoordinator.fetchCommits();
this.selectCommitWhenReady();
}
}

await this.coordinator.fetchCommits();
if (this._isMounted)
// TODO: ugly workaround until branches and commits will be unified in projectCoordinator
async selectCommitWhenReady() {
if (this._isMounted) {
if (this.projectModel.get("commits.fetching"))
setTimeout(() => { this.selectCommitWhenReady(); }, 100);
else
this.selectCommit();

}
}

Expand All @@ -258,8 +268,8 @@ class StartNotebookServer extends Component {
// filter the list of commits according to the constraints
const maximum = this.model.get("filters.displayedCommits");
const commits = maximum && parseInt(maximum) > 0 ?
this.model.get("data.commits").slice(0, maximum) :
this.model.get("data.commits");
this.projectModel.get("commits.list").slice(0, maximum) :
this.projectModel.get("commits.list");
let commit = commits[0];

// find the proper commit or return
Expand Down Expand Up @@ -339,7 +349,9 @@ class StartNotebookServer extends Component {
const augmentedState = {
...state.notebooks,
data: {
...state.notebooks.data,
fetched: state.project.commits.fetched,
fetching: state.project.commits.fetching,
commits: state.project.commits.list,
branches: ownProps.inherited.branches,
autosaved: ownProps.inherited.autosaved
},
Expand Down Expand Up @@ -388,6 +400,8 @@ class CheckNotebookStatus extends Component {
this.model = props.model.subModel("notebooks");
this.userModel = props.model.subModel("user");
this.coordinator = new NotebooksCoordinator(props.client, this.model, this.userModel);
// TODO: this should go away when moving all project content to projectCoordinator
this.projectCoordinator = new ProjectCoordinator(props.client, props.model.subModel("project"));
// temporarily reset data since notebooks model was not designed to be static
this.coordinator.reset();

Expand All @@ -402,7 +416,7 @@ class CheckNotebookStatus extends Component {
if (!scope.branch || !scope.commit)
return;
if (scope.commit === "latest") {
let commits = await this.coordinator.fetchCommits();
let commits = await this.projectCoordinator.fetchCommits();
scope.commit = commits[0];
this.coordinator.setNotebookFilters(scope);
}
Expand Down
23 changes: 0 additions & 23 deletions src/notebooks/Notebooks.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,29 +699,6 @@ class NotebooksCoordinator {
throw error;
});
}


// * Fetch commits -- to be moved * //
async fetchCommits() {
this.model.set("data.fetching", true);
const filters = this.model.get("filters");
const projectPathWithNamespace = `${encodeURIComponent(filters.namespace)}%2F${filters.project}`;
return this.client.getCommits(projectPathWithNamespace, filters.branch.name)
.then(resp => {
this.model.setObject({
data: {
fetching: false,
fetched: new Date(),
commits: { $set: resp.data }
}
});
return resp.data;
})
.catch(error => {
this.model.set("data.fetching", false);
throw error;
});
}
}

export { NotebooksHelper, ExpectedAnnotations, NotebooksCoordinator };

0 comments on commit 4e38152

Please sign in to comment.