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.

component.ts 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 { LightComponent } from './types';
  21. export enum Visibility {
  22. Public = 'public',
  23. Private = 'private'
  24. }
  25. export enum ComponentQualifier {
  26. Application = 'APP',
  27. Directory = 'DIR',
  28. Developper = 'DEV',
  29. File = 'FIL',
  30. Portfolio = 'VW',
  31. Project = 'TRK',
  32. SubPortfolio = 'SVW',
  33. SubProject = 'BRC',
  34. TestFile = 'UTS'
  35. }
  36. export enum ProjectKeyValidationResult {
  37. Valid = 'valid',
  38. Empty = 'empty',
  39. TooLong = 'too_long',
  40. InvalidChar = 'invalid_char',
  41. OnlyDigits = 'only_digits'
  42. }
  43. export interface TreeComponent extends LightComponent {
  44. id?: string;
  45. name: string;
  46. path?: string;
  47. refId?: string;
  48. refKey?: string;
  49. tags?: string[];
  50. visibility: Visibility;
  51. }
  52. export interface TreeComponentWithPath extends TreeComponent {
  53. path: string;
  54. }
  55. export function isPortfolioLike(
  56. componentQualifier?: string | ComponentQualifier
  57. ): componentQualifier is ComponentQualifier.Portfolio | ComponentQualifier.SubPortfolio {
  58. return Boolean(
  59. componentQualifier &&
  60. [
  61. ComponentQualifier.Portfolio.toString(),
  62. ComponentQualifier.SubPortfolio.toString()
  63. ].includes(componentQualifier)
  64. );
  65. }
  66. export function isApplication(
  67. componentQualifier?: string | ComponentQualifier
  68. ): componentQualifier is ComponentQualifier.Application {
  69. return componentQualifier === ComponentQualifier.Application;
  70. }
  71. export function isProject(
  72. componentQualifier?: string | ComponentQualifier
  73. ): componentQualifier is ComponentQualifier.Project {
  74. return componentQualifier === ComponentQualifier.Project;
  75. }
  76. export function isFile(componentQualifier?: string | ComponentQualifier): boolean {
  77. return [ComponentQualifier.File, ComponentQualifier.TestFile].includes(
  78. componentQualifier as ComponentQualifier
  79. );
  80. }
  81. export function isView(componentQualifier?: string | ComponentQualifier): boolean {
  82. return [
  83. ComponentQualifier.Portfolio,
  84. ComponentQualifier.SubPortfolio,
  85. ComponentQualifier.Application
  86. ].includes(componentQualifier as ComponentQualifier);
  87. }