collapsed state for service items

This commit is contained in:
Sérgio Ramos 2017-01-10 14:58:51 +00:00
parent c9ea9117f0
commit 08a3a0291d
4 changed files with 31 additions and 5 deletions

View File

@ -160,6 +160,7 @@
},
"services": {
"ui": {
"collapsed": [],
"sections": [
"summary",
"instances",

View File

@ -10,5 +10,6 @@ const APP = constantCase(process.env['APP_NAME']);
module.exports = {
...require('@state/thunks'),
updateRouter: createAction(`${APP}/APP/UPDATE_ROUTER`),
toggleHeaderTooltip: createAction(`${APP}/APP/TOGGLE_HEADER_TOOLTIP`)
toggleHeaderTooltip: createAction(`${APP}/APP/TOGGLE_HEADER_TOOLTIP`),
toggleServiceCollapsed: createAction(`${APP}/APP/TOGGLE_SERVICE_COLLAPSED`)
};

View File

@ -1,9 +1,23 @@
const ReduxActions = require('redux-actions');
const actions = require('@state/actions');
const {
handleActions
} = ReduxActions;
const {
toggleServiceCollapsed
} = actions;
module.exports = handleActions({
'x': (state) => state // somehow handleActions needs at least one reducer
[toggleServiceCollapsed.toString()]: (state, action) => ({
...state,
ui: {
...state.ui,
collapsed: state.ui.collapsed.indexOf(action.payload) >= 0
? state.ui.collapsed.filter((uuid) => uuid !== action.payload)
: [...state.ui.collapsed, action.payload]
}
})
}, {});

View File

@ -15,6 +15,7 @@ const serviceUiSections = (state) => get(state, 'services.ui.sections', []);
const orgs = (state) => get(state, 'orgs.data', []);
const projects = (state) => get(state, 'projects.data', []);
const services = (state) => get(state, 'services.data', []);
const collapsedServices = (state) => get(state, 'services.ui.collapsed', []);
const instances = (state) => get(state, 'instances.data', []);
const projectById = (projectId) => createSelector(
@ -45,19 +46,28 @@ const orgSections = (orgId) => createSelector(
);
const servicesByProjectId = (projectId) => createSelector(
[services, projectById(projectId)],
(services, project) =>
[services, projectById(projectId), collapsedServices],
(services, project, collapsed) =>
services.filter((s) => s.project === project.uuid)
.map((service) => ({
...service,
services: services.filter((s) => s.parent === service.uuid)
}))
.filter((s) => !s.parent)
.map((service) => ({
...service,
collapsed: collapsed.indexOf(service.uuid) >= 0,
services: service.services.map((service) => ({
...service,
collapsed: collapsed.indexOf(service.uuid) >= 0
}))
}))
);
const instancesByServiceId = (serviceId) => createSelector(
[instances, serviceById(serviceId)],
(instances, service) => instances.filter((i) => i.service === service.uuid)
(instances, service) =>
instances.filter((i) => i.service === service.uuid)
);