AdminCustomizeContainer.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import { Container } from 'unstated';
  2. /**
  3. * Service container for admin customize setting page (Customize.jsx)
  4. * @extends {Container} unstated Container
  5. */
  6. export default class AdminCustomizeContainer extends Container {
  7. constructor(appContainer) {
  8. super();
  9. this.appContainer = appContainer;
  10. this.state = {
  11. currentTheme: appContainer.config.themeType,
  12. currentLayout: appContainer.config.layoutType,
  13. currentBehavior: appContainer.config.behaviorType,
  14. isEnabledTimeline: appContainer.config.isEnabledTimeline,
  15. isSavedStatesOfTabChanges: appContainer.config.isSavedStatesOfTabChanges,
  16. isEnabledAttachTitleHeader: appContainer.config.isEnabledAttachTitleHeader,
  17. currentRecentCreatedLimit: appContainer.config.recentCreatedLimit,
  18. };
  19. }
  20. /**
  21. * Workaround for the mangling in production build to break constructor.name
  22. */
  23. static getClassName() {
  24. return 'AdminCustomizeContainer';
  25. }
  26. /**
  27. * Switch layoutType
  28. */
  29. switchLayoutType(lauoutName) {
  30. this.setState({ currentLayout: lauoutName });
  31. }
  32. /**
  33. * Switch themeType
  34. */
  35. switchThemeType(themeName) {
  36. // can't choose theme when kibela
  37. if (this.state.currentLayout === 'kibela') {
  38. return;
  39. }
  40. this.setState({ currentTheme: themeName });
  41. }
  42. /**
  43. * Switch behaviorType
  44. */
  45. switchBehaviorType(behaviorName) {
  46. this.setState({ currentBehavior: behaviorName });
  47. }
  48. /**
  49. * Switch enabledTimeLine
  50. */
  51. switchEnableTimeline() {
  52. this.setState({ isEnabledTimeline: !this.state.isEnabledTimeline });
  53. }
  54. /**
  55. * Switch savedStatesOfTabChanges
  56. */
  57. switchSavedStatesOfTabChanges() {
  58. this.setState({ isSavedStatesOfTabChanges: !this.state.isSavedStatesOfTabChanges });
  59. }
  60. /**
  61. * Switch enabledAttachTitleHeader
  62. */
  63. switchEnabledAttachTitleHeader() {
  64. this.setState({ isEnabledAttachTitleHeader: !this.state.isEnabledAttachTitleHeader });
  65. }
  66. /**
  67. * Switch recentCreatedLimit
  68. */
  69. switchRecentCreatedLimit(value) {
  70. this.setState({ currentRecentCreatedLimit: value });
  71. }
  72. /**
  73. * Update layout
  74. * @memberOf AdminCustomizeContainer
  75. * @return {Array} Appearance
  76. */
  77. async updateCustomizeLayoutAndTheme() {
  78. const response = await this.appContainer.apiv3.put('/customize-setting/layoutTheme', {
  79. layoutType: this.state.currentLayout,
  80. themeType: this.state.currentTheme,
  81. });
  82. const { customizedParams } = response.data;
  83. return customizedParams;
  84. }
  85. /**
  86. * Update behavior
  87. * @memberOf AdminCustomizeContainer
  88. * @return {string} Behavior
  89. */
  90. async updateCustomizeBehavior() {
  91. const response = await this.appContainer.apiv3.put('/customize-setting/behavior', {
  92. behaviorType: this.state.currentBehavior,
  93. });
  94. const { customizedParams } = response.data;
  95. return customizedParams;
  96. }
  97. /**
  98. * Update function
  99. * @memberOf AdminCustomizeContainer
  100. * @return {string} Functions
  101. */
  102. async updateCustomizeFunction() {
  103. // TODO GW-506 create apiV3
  104. }
  105. }