useModuleTitle.tsx 823 B

1234567891011121314151617181920212223
  1. import {useMemo} from 'react';
  2. import {DOMAIN_VIEW_MODULE_TITLES} from 'sentry/views/insights/common/utils/moduleTitles';
  3. import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  4. import {MODULE_TITLES} from 'sentry/views/insights/settings';
  5. import type {ModuleName} from 'sentry/views/insights/types';
  6. export const useModuleTitles = (): Record<ModuleName, string> => {
  7. const {isInDomainView, view} = useDomainViewFilters();
  8. const moduleTitles = useMemo(() => {
  9. let titles = {...MODULE_TITLES};
  10. if (isInDomainView && view) {
  11. titles = {...MODULE_TITLES, ...DOMAIN_VIEW_MODULE_TITLES[view]};
  12. }
  13. return titles;
  14. }, [isInDomainView, view]);
  15. return moduleTitles;
  16. };
  17. export const useModuleTitle = (moduleName: ModuleName): string => {
  18. return useModuleTitles()[moduleName];
  19. };