Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

WorkspaceRuleViewer.tsx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 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 * as React from 'react';
  21. import { RuleDescriptor } from './context';
  22. import WorkspaceHeader, { Props as WorkspaceHeaderProps } from './WorkspaceHeader';
  23. import WorkspaceRuleDetails from './WorkspaceRuleDetails';
  24. import WorkspaceRuleTitle from './WorkspaceRuleTitle';
  25. export interface Props extends Omit<WorkspaceHeaderProps, 'children' | 'onClose'> {
  26. rule: RuleDescriptor;
  27. height: number;
  28. onClose: (componentKey: string) => void;
  29. onLoad: (details: { key: string; name: string }) => void;
  30. }
  31. interface State {
  32. loading: boolean;
  33. }
  34. export default class WorkspaceRuleViewer extends React.PureComponent<Props> {
  35. state: State = { loading: true };
  36. componentDidUpdate(prevProps: Props) {
  37. if (prevProps.rule.key !== this.props.rule.key) {
  38. this.setState({ loading: true });
  39. }
  40. }
  41. handleClose = () => {
  42. this.props.onClose(this.props.rule.key);
  43. };
  44. handleLoaded = (rule: { name: string }) => {
  45. this.props.onLoad({ key: this.props.rule.key, name: rule.name });
  46. // Allow time for the actual rendering, and the browser to pick it up.
  47. setTimeout(() => {
  48. this.setState({ loading: false });
  49. }, 1000);
  50. };
  51. render() {
  52. const { rule } = this.props;
  53. const { loading } = this.state;
  54. return (
  55. <div className="workspace-viewer">
  56. <WorkspaceHeader
  57. maximized={this.props.maximized}
  58. onClose={this.handleClose}
  59. onCollapse={this.props.onCollapse}
  60. onMaximize={this.props.onMaximize}
  61. onMinimize={this.props.onMinimize}
  62. onResize={this.props.onResize}>
  63. <WorkspaceRuleTitle rule={rule} />
  64. </WorkspaceHeader>
  65. <div
  66. aria-busy={loading}
  67. aria-live="polite"
  68. className="workspace-viewer-container"
  69. style={{ height: this.props.height }}>
  70. <WorkspaceRuleDetails onLoad={this.handleLoaded} ruleKey={rule.key} />
  71. </div>
  72. </div>
  73. );
  74. }
  75. }