querySymbol.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import styled from '@emotion/styled';
  2. import {space} from 'sentry/styles/space';
  3. import {useDDMContext} from 'sentry/views/ddm/context';
  4. const indexToChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  5. export const getQuerySymbol = (index: number) => {
  6. let result = '';
  7. let i = index;
  8. do {
  9. result = indexToChar[i % indexToChar.length] + result;
  10. i = Math.floor(i / indexToChar.length) - 1;
  11. } while (i >= 0);
  12. return result;
  13. };
  14. const Symbol = styled('div')`
  15. display: flex;
  16. width: 16px;
  17. height: 16px;
  18. padding: ${space(0.5)};
  19. justify-content: center;
  20. align-items: center;
  21. flex-shrink: 0;
  22. border-radius: 50%;
  23. font-weight: 500;
  24. color: ${p => p.theme.black};
  25. font-size: 10px;
  26. background: ${p => p.theme.yellow300};
  27. `;
  28. export function QuerySymbol({
  29. index,
  30. ...props
  31. }: React.ComponentProps<typeof Symbol> & {index: number}) {
  32. const {showQuerySymbols} = useDDMContext();
  33. if (!showQuerySymbols) {
  34. return null;
  35. }
  36. return (
  37. <Symbol {...props}>
  38. <span>{getQuerySymbol(index)}</span>
  39. </Symbol>
  40. );
  41. }