useOutdatedSDKProjects.tsx 1.8 KB

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