您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AlmTabRenderer.tsx 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2020 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 { FormattedMessage } from 'react-intl';
  22. import { Link } from 'react-router';
  23. import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner';
  24. import { translate } from 'sonar-ui-common/helpers/l10n';
  25. import { AlmSettingsBinding, ALM_KEYS } from '../../../../types/alm-settings';
  26. import AlmPRDecorationForm, { AlmPRDecorationFormChildrenProps } from './AlmPRDecorationForm';
  27. import AlmPRDecorationTable from './AlmPRDecorationTable';
  28. export interface AlmTabRendererProps<B> {
  29. additionalColumnsHeaders: string[];
  30. additionalColumnsKeys: Array<keyof B>;
  31. alm: ALM_KEYS;
  32. editedDefinition?: B;
  33. defaultBinding: B;
  34. definitions: B[];
  35. form: (props: AlmPRDecorationFormChildrenProps<B>) => React.ReactNode;
  36. loading: boolean;
  37. multipleAlmEnabled: boolean;
  38. onCancel: () => void;
  39. onCreate: () => void;
  40. onDelete: (definitionKey: string) => void;
  41. onEdit: (definitionKey: string) => void;
  42. onSubmit: (config: B, originalKey: string) => void;
  43. success: boolean;
  44. }
  45. export default function AlmTabRenderer<B extends AlmSettingsBinding>(
  46. props: AlmTabRendererProps<B>
  47. ) {
  48. const {
  49. additionalColumnsHeaders,
  50. additionalColumnsKeys,
  51. alm,
  52. defaultBinding,
  53. definitions,
  54. editedDefinition,
  55. form,
  56. loading,
  57. multipleAlmEnabled,
  58. success
  59. } = props;
  60. let definition: B | undefined;
  61. let mappedDefinitions: Array<{ key: string; additionalColumns: string[] }> = [];
  62. let showEdit: boolean | undefined;
  63. if (!multipleAlmEnabled) {
  64. definition = editedDefinition;
  65. if (definition === undefined && definitions.length > 0) {
  66. definition = definitions[0];
  67. }
  68. showEdit = definition && editedDefinition === undefined;
  69. } else {
  70. mappedDefinitions = definitions.map(({ key, ...properties }) => {
  71. const additionalColumns = additionalColumnsKeys.map(k => (properties as any)[k]);
  72. return {
  73. key,
  74. additionalColumns
  75. };
  76. });
  77. }
  78. const help = (
  79. <FormattedMessage
  80. defaultMessage={translate(`settings.pr_decoration.${alm}.info`)}
  81. id={`settings.pr_decoration.${alm}.info`}
  82. values={{
  83. link: (
  84. <Link target="_blank" to="/documentation/analysis/pr-decoration/">
  85. {translate('learn_more')}
  86. </Link>
  87. )
  88. }}
  89. />
  90. );
  91. return multipleAlmEnabled ? (
  92. <DeferredSpinner loading={loading}>
  93. <AlmPRDecorationTable
  94. additionalColumnsHeaders={additionalColumnsHeaders}
  95. alm={alm}
  96. definitions={mappedDefinitions}
  97. onCreate={props.onCreate}
  98. onDelete={props.onDelete}
  99. onEdit={props.onEdit}
  100. />
  101. {editedDefinition && (
  102. <AlmPRDecorationForm
  103. alm={alm}
  104. bindingDefinition={editedDefinition}
  105. help={help}
  106. onCancel={props.onCancel}
  107. onSubmit={props.onSubmit}
  108. showInModal={true}>
  109. {form}
  110. </AlmPRDecorationForm>
  111. )}
  112. </DeferredSpinner>
  113. ) : (
  114. <AlmPRDecorationForm
  115. alm={alm}
  116. bindingDefinition={definition || defaultBinding}
  117. help={help}
  118. hideKeyField={true}
  119. loading={loading}
  120. onCancel={props.onCancel}
  121. onDelete={definition ? props.onDelete : undefined}
  122. onEdit={showEdit ? props.onEdit : undefined}
  123. onSubmit={props.onSubmit}
  124. readOnly={showEdit}
  125. success={success}>
  126. {form}
  127. </AlmPRDecorationForm>
  128. );
  129. }