AdminHomeContainer.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { Container } from 'unstated';
  2. import loggerFactory from '~/utils/logger';
  3. import { toastError } from '../util/apiNotification';
  4. // eslint-disable-next-line no-unused-vars
  5. const logger = loggerFactory('growi:services:AdminHomeContainer');
  6. /**
  7. * Service container for admin home page (AdminHome.jsx)
  8. * @extends {Container} unstated Container
  9. */
  10. export default class AdminHomeContainer extends Container {
  11. constructor(appContainer) {
  12. super();
  13. this.appContainer = appContainer;
  14. this.copyStateValues = {
  15. DEFAULT: 'default',
  16. DONE: 'done',
  17. };
  18. this.timer = null;
  19. this.state = {
  20. retrieveError: null,
  21. growiVersion: '',
  22. nodeVersion: '',
  23. npmVersion: '',
  24. yarnVersion: '',
  25. copyState: this.copyStateValues.DEFAULT,
  26. installedPlugins: [],
  27. isV5Compatible: null,
  28. };
  29. }
  30. /**
  31. * Workaround for the mangling in production build to break constructor.name
  32. */
  33. static getClassName() {
  34. return 'AdminHomeContainer';
  35. }
  36. componentWillUnmount() {
  37. clearTimeout(this.timer);
  38. }
  39. /**
  40. * retrieve admin home data
  41. */
  42. async retrieveAdminHomeData() {
  43. try {
  44. const response = await this.appContainer.apiv3.get('/admin-home/');
  45. const { adminHomeParams } = response.data;
  46. this.setState(prevState => ({
  47. ...prevState,
  48. growiVersion: adminHomeParams.growiVersion,
  49. nodeVersion: adminHomeParams.nodeVersion,
  50. npmVersion: adminHomeParams.npmVersion,
  51. yarnVersion: adminHomeParams.yarnVersion,
  52. installedPlugins: adminHomeParams.installedPlugins,
  53. envVars: adminHomeParams.envVars,
  54. isV5Compatible: adminHomeParams.isV5Compatible,
  55. }));
  56. }
  57. catch (err) {
  58. logger.error(err);
  59. toastError(new Error('Failed to fetch data'));
  60. }
  61. }
  62. /**
  63. * sets button text when copying system information
  64. */
  65. onCopyPrefilledHostInformation() {
  66. this.setState(prevState => ({
  67. ...prevState,
  68. copyState: this.copyStateValues.DONE,
  69. }));
  70. this.timer = setTimeout(() => {
  71. this.setState(prevState => ({
  72. ...prevState,
  73. copyState: this.copyStateValues.DEFAULT,
  74. }));
  75. }, 500);
  76. }
  77. /**
  78. * generates prefilled host information as markdown
  79. */
  80. generatePrefilledHostInformationMarkdown() {
  81. return `| item | version |
  82. | --- | --- |
  83. |OS ||
  84. |GROWI |${this.state.growiVersion}|
  85. |node.js |${this.state.nodeVersion}|
  86. |npm |${this.state.npmVersion}|
  87. |yarn |${this.state.yarnVersion}|
  88. |Using Docker|yes/no|
  89. |Using [growi-docker-compose][growi-docker-compose]|yes/no|
  90. [growi-docker-compose]: https://github.com/weseek/growi-docker-compose
  91. *(Accessing https://{GROWI_HOST}/admin helps you to fill in above versions)*`;
  92. }
  93. }