Skip to content

Commit

Permalink
refactor: hoist project state to global model (#1183) (#1568)
Browse files Browse the repository at this point in the history
Fix #1183
  • Loading branch information
cramakri authored and lorenzo-cavazzi committed Nov 26, 2021
1 parent 21c7bfb commit 60f1656
Show file tree
Hide file tree
Showing 20 changed files with 857 additions and 762 deletions.
3 changes: 1 addition & 2 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ function CentralContentContainer(props) {
/>
<Route path="/projects/:subUrl+" render={
p => <Project.View
key={`${p.match.params.projectNamespace}/${p.match.params.projectName}`}
projectPathWithNamespace={`${p.match.params.projectNamespace}/${p.match.params.projectName}`}
key="project/view"
client={props.client}
params={props.params}
model={props.model}
Expand Down
4 changes: 2 additions & 2 deletions client/src/file/KnowledgeGraphStatus.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class KnowledgeGraphStatus extends Component {
this.setState({ graphStatusPoller: poller });
}
})
.catch((err) => {
this.setState({ error: err });
.catch((error) => {
this.setState({ error });
this.stopPollingProgress();
});
}
Expand Down
24 changes: 13 additions & 11 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import ReactDOM from "react-dom";
import { connect } from "react-redux";
import { connect, Provider } from "react-redux";
import { BrowserRouter as Router, Route } from "react-router-dom";
import "bootstrap";
import "jquery";
Expand Down Expand Up @@ -83,16 +83,18 @@ Promise.all([configFetch, privacyFetch]).then(valuesRead => {

const VisibleApp = connect(mapStateToProps)(App);
ReactDOM.render(
<Router>
<Route render={props => {
LoginHelper.handleLoginParams(props.history);
return (
<VisibleApp client={client} params={params} store={model.reduxStore} model={model}
location={props.location} statuspageId={statuspageId}
/>
);
}} />
</Router>,
<Provider store={model.reduxStore}>
<Router>
<Route render={props => {
LoginHelper.handleLoginParams(props.history);
return (
<VisibleApp client={client} params={params} model={model}
location={props.location} statuspageId={statuspageId}
/>
);
}} />
</Router>
</Provider>,
document.getElementById("root")
);
});
Expand Down
143 changes: 86 additions & 57 deletions client/src/model/RenkuModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,8 @@ const projectSchema = new Schema({
core: {
schema: {
available: { initial: null },
created_at: { initial: null, },
last_activity_at: { initial: null, },
id: { initial: null, },
description: { initial: "no description", mandatory: true },
displayId: { initial: "", },
title: { initial: "no title", mandatory: true },
external_url: { initial: "", },
path_with_namespace: { initial: null },
owner: { initial: null },
}
},
Expand All @@ -119,48 +113,20 @@ const projectSchema = new Schema({
schema: {
files: { schema: [] }
}
},
readme: {
schema: {
text: { initial: "", mandatory: false }
}
}
},
},
system: {
schema: {
tag_list: { schema: [] },
star_count: { initial: 0, mandatory: true },
forks_count: { initial: 0, mandatory: true },
forked_from_project: { initial: {} },
ssh_url: { initial: "", },
http_url: { initial: "", },
merge_requests: { schema: [], initial: [] },
branches: { schema: [], initial: [] },
autosaved: { schema: [], initial: [] },
}
},
files: {
schema: {
notebooks: { schema: [] },
data: { schema: [] },
modifiedFiles: { initial: {}, mandatory: true }
}
},
transient: {
schema: {
requests: { initial: {} },
}
},
webhook: {
schema: {
status: { initial: null },
created: { initial: null },
possible: { initial: null },
stop: { initial: null },
progress: { initial: null }
}
},
migration: {
schema: {
migration_required: { initial: null },
Expand Down Expand Up @@ -285,37 +251,60 @@ const projectStatisticsSchema = new Schema({
});

const projectGlobalSchema = new Schema({
metadata: {
branches: {
[Prop.SCHEMA]: new Schema({
exists: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true },

id: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // id
namespace: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // namespace.full_path
path: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // path
pathWithNamespace: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // path_with_namespace
repositoryUrl: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // web_url
starCount: { [Prop.INITIAL]: null }, // star_count
forksCount: { [Prop.INITIAL]: null }, // forks_count

standard: { [Prop.INITIAL]: [], [Prop.MANDATORY]: true },
autosaved: { [Prop.INITIAL]: [], [Prop.MANDATORY]: true },
error: { [Prop.INITIAL]: null },
fetched: { [Prop.INITIAL]: null },
fetching: { [Prop.INITIAL]: false },
})
},
statistics: {
commits: {
[Prop.SCHEMA]: new Schema({
data: { schema: projectStatisticsSchema },
list: { [Prop.INITIAL]: [], [Prop.MANDATORY]: true },
error: { [Prop.INITIAL]: null },

fetched: { [Prop.INITIAL]: null },
fetching: { [Prop.INITIAL]: false },
})
},
commits: {
config: {
[Prop.SCHEMA]: new Schema({
list: { [Prop.INITIAL]: [], [Prop.MANDATORY]: true },
error: { [Prop.INITIAL]: null },

data: { [Prop.INITIAL]: {}, [Prop.MANDATORY]: true },
error: { [Prop.INITIAL]: {}, [Prop.MANDATORY]: true },
fetched: { [Prop.INITIAL]: null },
fetching: { [Prop.INITIAL]: false },

initial: { [Prop.INITIAL]: {} },
input: { [Prop.INITIAL]: {} }
})
},
data: {
[Prop.SCHEMA]: new Schema({
readme: { [Prop.INITIAL]: {} }
})
},
datasets: {
[Prop.SCHEMA]: new Schema({
datasets_kg: { [Prop.INITIAL]: [] },
core: { [Prop.INITIAL]: {
datasets: null,
error: null
} }
})
},
files: {
[Prop.SCHEMA]: new Schema({
notebooks: { [Prop.INITIAL]: [] },
data: { [Prop.INITIAL]: [] },
modifiedFiles: { [Prop.INITIAL]: {}, [Prop.MANDATORY]: true }
})
},
filesTree: {
[Prop.SCHEMA]: new Schema({
hash: { [Prop.INITIAL]: {} },
loaded: { [Prop.INITIAL]: false, [Prop.MANDATORY]: true }
})
},
filters: {
Expand All @@ -324,17 +313,57 @@ const projectGlobalSchema = new Schema({
commit: { [Prop.INITIAL]: { id: "latest" }, [Prop.MANDATORY]: true },
})
},
config: {
forkedFromProject: { [Prop.INITIAL]: {} },
metadata: {
[Prop.SCHEMA]: new Schema({
data: { [Prop.INITIAL]: {}, [Prop.MANDATORY]: true },
error: { [Prop.INITIAL]: {}, [Prop.MANDATORY]: true },
avatarUrl: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // avatar_url
accessLevel: { [Prop.INITIAL]: 0, [Prop.MANDATORY]: true }, // visibility.access_level
createdAt: { [Prop.INITIAL]: "", [Prop.MANDATORY]: true }, // created_at
defaultBranch: { [Prop.INITIAL]: null }, // default_branch
description: { [Prop.INITIAL]: "" },
exists: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true },
externalUrl: { [Prop.INITIAL]: "" }, // external_url
forksCount: { [Prop.INITIAL]: null }, // forks_count
httpUrl: { [Prop.INITIAL]: "", }, // http_url
id: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // id
lastActivityAt: { [Prop.INITIAL]: "", [Prop.MANDATORY]: true }, // last_activity_at
namespace: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // namespace.full_path
owner: { [Prop.INITIAL]: null },
path: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true },
pathWithNamespace: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // path_with_namespace
repositoryUrl: { [Prop.INITIAL]: null, [Prop.MANDATORY]: true }, // web_url
sshUrl: { [Prop.INITIAL]: "", }, // ssh_url
starCount: { [Prop.INITIAL]: null }, // star_count
tagList: { [Prop.INITIAL]: [] }, // tag_list
title: { [Prop.INITIAL]: "" },
visibility: { [Prop.INITIAL]: "private", [Prop.MANDATORY]: true }, // visibility.level

fetched: { [Prop.INITIAL]: null },
fetching: { [Prop.INITIAL]: false },
})
},
statistics: {
[Prop.SCHEMA]: new Schema({
data: { schema: projectStatisticsSchema },

initial: { [Prop.INITIAL]: {} },
input: { [Prop.INITIAL]: {} }
fetched: { [Prop.INITIAL]: null },
fetching: { [Prop.INITIAL]: false },
})
}
},
transient: {
[Prop.SCHEMA]: new Schema({
requests: { [Prop.INITIAL]: {} }
})
},
webhook: {
[Prop.SCHEMA]: {
status: { [Prop.INITIAL]: null },
created: { [Prop.INITIAL]: null },
possible: { [Prop.INITIAL]: null },
stop: { [Prop.INITIAL]: null },
progress: { [Prop.INITIAL]: null }
}
},
});

const notebooksSchema = new Schema({
Expand Down
14 changes: 8 additions & 6 deletions client/src/model/RenkuModels.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* eslint-disable */

import { testClient as client } from "../api-client";
import { StateKind, StateModel } from "../model/Model";
import { StateModel, globalSchema } from "../model";
// import { Project, projectSchema } from "./RenkuModels";
import { ProjectModel } from "../project/Project.state";
import { ProjectCoordinator } from "../project";

const model = new StateModel(globalSchema);

describe("fetch project", () => {
it("fetches project", () => {
const projectId = 3;
const project = new ProjectModel(StateKind.REDUX);
project.fetchProject(client, projectId).then(() => {
expect(project.get("core.id")).toEqual(projectId);
expect(project.get("core.title")).toEqual("A-first-project");
const projectCoordinator = new ProjectCoordinator(client, model.subModel("project"));
projectCoordinator.fetchProject(client, projectId).then(() => {
expect(projectCoordinator.get("metadata.id")).toEqual(projectId);
expect(projectCoordinator.get("metadata.title")).toEqual("A-first-project");
});
});
});
Expand Down
Loading

0 comments on commit 60f1656

Please sign in to comment.