useIneligibleProjects.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import ProjectsStore from 'sentry/stores/projectsStore';
  2. import {useOrganizationSDKUpdates} from 'sentry/utils/useOrganizationSDKUpdates';
  3. import {semverCompare} from 'sentry/utils/versions';
  4. import {MIN_SDK_VERSION_BY_PLATFORM} from 'sentry/views/performance/database/settings';
  5. interface Options {
  6. enabled?: boolean;
  7. projectId?: string[];
  8. }
  9. /**
  10. * Returns a list of projects that are not eligible for span metrics
  11. * due to SDK requirements.
  12. *
  13. * @param options Additional options
  14. * @param options.projectId List of project IDs to check against. If omitted, checks all organization projects
  15. * @returns List of projects
  16. */
  17. export function useIneligibleProjects(options?: Options) {
  18. const response = useOrganizationSDKUpdates(options ?? {});
  19. const {data: availableUpdates} = response;
  20. const ineligibleProjects = (availableUpdates ?? [])
  21. .filter(update => {
  22. const platform = removeFlavorFromSDKName(update.sdkName);
  23. const minimumRequiredVersion = MIN_SDK_VERSION_BY_PLATFORM[platform];
  24. if (!minimumRequiredVersion) {
  25. // If a minimum version is not specified, assume that the platform
  26. // doesn't have any support at all
  27. return true;
  28. }
  29. return semverCompare(update.sdkVersion, minimumRequiredVersion) === -1;
  30. })
  31. .map(update => update.projectId)
  32. .map(projectId => {
  33. return ProjectsStore.getById(projectId);
  34. })
  35. .filter((item): item is NonNullable<typeof item> => Boolean(item));
  36. return {
  37. ...response,
  38. ineligibleProjects,
  39. };
  40. }
  41. /**
  42. * Strips the SDK flavour from its name
  43. *
  44. * @param sdkName Name of the SDK, like `"sentry.javascript.react"
  45. * @returns Platform name like `"sentry.javascript"`
  46. */
  47. function removeFlavorFromSDKName(sdkName: string): string {
  48. return sdkName.split('.').slice(0, 2).join('.');
  49. }