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.

ScannerContext.tsx 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 { Spinner } from '@sonarsource/echoes-react';
  21. import { Modal } from 'design-system';
  22. import { noop } from 'lodash';
  23. import * as React from 'react';
  24. import { getTask } from '../../../api/ce';
  25. import { translate } from '../../../helpers/l10n';
  26. import { isDefined } from '../../../helpers/types';
  27. import { Task } from '../../../types/tasks';
  28. interface Props {
  29. onClose: () => void;
  30. task: Pick<Task, 'componentName' | 'id' | 'type'>;
  31. }
  32. interface State {
  33. scannerContext?: string;
  34. }
  35. export default class ScannerContext extends React.PureComponent<Props, State> {
  36. mounted = false;
  37. state: State = {};
  38. componentDidMount() {
  39. this.mounted = true;
  40. this.loadScannerContext();
  41. }
  42. componentWillUnmount() {
  43. this.mounted = false;
  44. }
  45. loadScannerContext() {
  46. getTask(this.props.task.id, ['scannerContext']).then((task) => {
  47. if (this.mounted) {
  48. this.setState({ scannerContext: task.scannerContext });
  49. }
  50. }, noop);
  51. }
  52. render() {
  53. const { task } = this.props;
  54. const { scannerContext } = this.state;
  55. return (
  56. <Modal
  57. body={
  58. <Spinner isLoading={!isDefined(scannerContext)}>
  59. <pre className="it__task-scanner-context">{scannerContext}</pre>
  60. </Spinner>
  61. }
  62. headerTitle={`${translate('background_tasks.scanner_context')}: ${
  63. task.componentName
  64. } [${translate('background_task.type', task.type)}]`}
  65. isLarge
  66. isScrollable
  67. onClose={this.props.onClose}
  68. secondaryButtonLabel={translate('close')}
  69. />
  70. );
  71. }
  72. }