You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rootReducer.ts 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { combineReducers } from 'redux';
  21. import globalMessages, * as fromGlobalMessages from '../../../store/globalMessages';
  22. import definitions, * as fromDefinitions from './definitions';
  23. import settingsPage, * as fromSettingsPage from './settingsPage';
  24. import values, * as fromValues from './values';
  25. interface State {
  26. definitions: fromDefinitions.State;
  27. globalMessages: fromGlobalMessages.State;
  28. settingsPage: fromSettingsPage.State;
  29. values: fromValues.State;
  30. }
  31. export default combineReducers({ definitions, values, settingsPage, globalMessages });
  32. export function getDefinition(state: State, key: string) {
  33. return fromDefinitions.getDefinition(state.definitions, key);
  34. }
  35. export function getAllDefinitions(state: State) {
  36. return fromDefinitions.getAllDefinitions(state.definitions);
  37. }
  38. export function getAllCategories(state: State) {
  39. return fromDefinitions.getAllCategories(state.definitions);
  40. }
  41. export function getDefaultCategory(state: State) {
  42. return fromDefinitions.getDefaultCategory(state.definitions);
  43. }
  44. export function getValue(state: State, key: string, component?: string) {
  45. return fromValues.getValue(state.values, key, component);
  46. }
  47. export function getSettingsForCategory(state: State, category: string, component?: string) {
  48. return fromDefinitions.getDefinitionsForCategory(state.definitions, category).map(definition => {
  49. const value = getValue(state, definition.key, component);
  50. const hasValue = value !== undefined && value.inherited !== true;
  51. return {
  52. key: definition.key,
  53. hasValue,
  54. ...value,
  55. definition
  56. };
  57. });
  58. }
  59. export function getChangedValue(state: State, key: string) {
  60. return fromSettingsPage.getChangedValue(state.settingsPage, key);
  61. }
  62. export function isLoading(state: State, key: string) {
  63. return fromSettingsPage.isLoading(state.settingsPage, key);
  64. }
  65. export function getValidationMessage(state: State, key: string) {
  66. return fromSettingsPage.getValidationMessage(state.settingsPage, key);
  67. }
  68. export function getGlobalMessages(state: State) {
  69. return fromGlobalMessages.getGlobalMessages(state.globalMessages);
  70. }