aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/project-admin/store
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-07-29 16:08:36 +0200
committerGitHub <noreply@github.com>2016-07-29 16:08:36 +0200
commit0b1226871a26f136739f29050de52088b2aa1c3e (patch)
tree1124abd73a6cf58d45e17cc0fb075a4076ca4320 /server/sonar-web/src/main/js/apps/project-admin/store
parent3e3e4b1e16c0e5ebf8a485d3014cb7bd2577e192 (diff)
downloadsonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.tar.gz
sonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.zip
SONAR-7920 Rewrite Links project page (#1127)
Diffstat (limited to 'server/sonar-web/src/main/js/apps/project-admin/store')
-rw-r--r--server/sonar-web/src/main/js/apps/project-admin/store/actions.js34
-rw-r--r--server/sonar-web/src/main/js/apps/project-admin/store/links.js45
-rw-r--r--server/sonar-web/src/main/js/apps/project-admin/store/linksByProject.js49
-rw-r--r--server/sonar-web/src/main/js/apps/project-admin/store/rootReducer.js13
4 files changed, 140 insertions, 1 deletions
diff --git a/server/sonar-web/src/main/js/apps/project-admin/store/actions.js b/server/sonar-web/src/main/js/apps/project-admin/store/actions.js
index cad25a70e7a..083a28bfa92 100644
--- a/server/sonar-web/src/main/js/apps/project-admin/store/actions.js
+++ b/server/sonar-web/src/main/js/apps/project-admin/store/actions.js
@@ -23,6 +23,7 @@ import {
dissociateProject
} from '../../../api/quality-profiles';
import { getProfileByKey } from './rootReducer';
+import { getProjectLinks, createLink } from '../../../api/projectLinks';
export const RECEIVE_PROFILES = 'RECEIVE_PROFILES';
export const receiveProfiles = profiles => ({
@@ -68,3 +69,36 @@ export const setProjectProfile = (projectKey, oldKey, newKey) =>
dispatch(setProjectProfileAction(projectKey, oldKey, newKey));
});
};
+
+export const RECEIVE_PROJECT_LINKS = 'RECEIVE_PROJECT_LINKS';
+export const receiveProjectLinks = (projectKey, links) => ({
+ type: RECEIVE_PROJECT_LINKS,
+ projectKey,
+ links
+});
+
+export const fetchProjectLinks = projectKey => dispatch => {
+ getProjectLinks(projectKey).then(links => {
+ dispatch(receiveProjectLinks(projectKey, links));
+ });
+};
+
+export const ADD_PROJECT_LINK = 'ADD_PROJECT_LINK';
+const addProjectLink = (projectKey, link) => ({
+ type: ADD_PROJECT_LINK,
+ projectKey,
+ link
+});
+
+export const createProjectLink = (projectKey, name, url) => dispatch => {
+ return createLink(projectKey, name, url).then(link => {
+ dispatch(addProjectLink(projectKey, link));
+ });
+};
+
+export const DELETE_PROJECT_LINK = 'DELETE_PROJECT_LINK';
+export const deleteProjectLink = (projectKey, linkId) => ({
+ type: DELETE_PROJECT_LINK,
+ projectKey,
+ linkId
+});
diff --git a/server/sonar-web/src/main/js/apps/project-admin/store/links.js b/server/sonar-web/src/main/js/apps/project-admin/store/links.js
new file mode 100644
index 00000000000..9a79d3d7905
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/project-admin/store/links.js
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import keyBy from 'lodash/keyBy';
+import omit from 'lodash/omit';
+import { RECEIVE_PROJECT_LINKS, DELETE_PROJECT_LINK } from './actions';
+import { ADD_PROJECT_LINK } from './actions';
+
+const links = (state = {}, action = {}) => {
+ if (action.type === RECEIVE_PROJECT_LINKS) {
+ const newLinksById = keyBy(action.links, 'id');
+ return { ...state, ...newLinksById };
+ }
+
+ if (action.type === ADD_PROJECT_LINK) {
+ return { ...state, [action.link.id]: action.link };
+ }
+
+ if (action.type === DELETE_PROJECT_LINK) {
+ return omit(state, action.linkId);
+ }
+
+ return state;
+};
+
+export default links;
+
+export const getLink = (state, id) =>
+ state[id];
diff --git a/server/sonar-web/src/main/js/apps/project-admin/store/linksByProject.js b/server/sonar-web/src/main/js/apps/project-admin/store/linksByProject.js
new file mode 100644
index 00000000000..dd48ff45f98
--- /dev/null
+++ b/server/sonar-web/src/main/js/apps/project-admin/store/linksByProject.js
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import without from 'lodash/without';
+import {
+ RECEIVE_PROJECT_LINKS,
+ DELETE_PROJECT_LINK,
+ ADD_PROJECT_LINK
+} from './actions';
+
+const linksByProject = (state = {}, action = {}) => {
+ if (action.type === RECEIVE_PROJECT_LINKS) {
+ const linkIds = action.links.map(link => link.id);
+ return { ...state, [action.projectKey]: linkIds };
+ }
+
+ if (action.type === ADD_PROJECT_LINK) {
+ const byProject = state[action.projectKey] || [];
+ const ids = [...byProject, action.link.id];
+ return { ...state, [action.projectKey]: ids };
+ }
+
+ if (action.type === DELETE_PROJECT_LINK) {
+ const ids = without(state[action.projectKey], action.linkId);
+ return { ...state, [action.projectKey]: ids };
+ }
+
+ return state;
+};
+
+export default linksByProject;
+
+export const getLinks = (state, projectKey) => state[projectKey] || [];
diff --git a/server/sonar-web/src/main/js/apps/project-admin/store/rootReducer.js b/server/sonar-web/src/main/js/apps/project-admin/store/rootReducer.js
index 5f5dc3d7899..e8174f53aa0 100644
--- a/server/sonar-web/src/main/js/apps/project-admin/store/rootReducer.js
+++ b/server/sonar-web/src/main/js/apps/project-admin/store/rootReducer.js
@@ -23,10 +23,14 @@ import profiles, {
getAllProfiles as nextGetAllProfiles
} from './profiles';
import profilesByProject, { getProfiles } from './profilesByProject';
+import links, { getLink } from './links';
+import linksByProject, { getLinks } from './linksByProject';
const rootReducer = combineReducers({
profiles,
- profilesByProject
+ profilesByProject,
+ links,
+ linksByProject
});
export default rootReducer;
@@ -40,3 +44,10 @@ export const getAllProfiles = state =>
export const getProjectProfiles = (state, projectKey) =>
getProfiles(state.profilesByProject, projectKey)
.map(profileKey => getProfileByKey(state, profileKey));
+
+export const getLinkById = (state, linkId) =>
+ getLink(state.links, linkId);
+
+export const getProjectLinks = (state, projectKey) =>
+ getLinks(state.linksByProject, projectKey)
+ .map(linkId => getLinkById(state, linkId));