useInsightsURL.tsx 1.1 KB

12345678910111213141516171819202122232425
  1. import useOrganization from 'sentry/utils/useOrganization';
  2. import {ModuleName} from 'sentry/views/starfish/types';
  3. type ModuleNameStrings = `${ModuleName}`;
  4. type RoutableModuleNames = Exclude<ModuleNameStrings, '' | 'other'>;
  5. export function useInsightsURL(moduleName: RoutableModuleNames) {
  6. const builder = useInsightsURLBuilder();
  7. return builder(moduleName);
  8. }
  9. type URLBuilder = (moduleName: RoutableModuleNames) => string;
  10. export function useInsightsURLBuilder(): URLBuilder {
  11. const organization = useOrganization({allowNull: true}); // Some parts of the app, like the main sidebar, render even if the organization isn't available (during loading, or at all).
  12. return function (moduleName: RoutableModuleNames) {
  13. // If `insights` flag is present, all Insights modules are routed from `/insights`. If the flag is absent, LLM is routed from `/` and other insights modules are routed of `/performance`
  14. return organization?.features?.includes('performance-insights')
  15. ? 'insights'
  16. : moduleName === ModuleName.AI
  17. ? ''
  18. : 'performance';
  19. };
  20. }