rpcToggle.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import {Flex} from 'sentry/components/container/flex';
  2. import SwitchButton from 'sentry/components/switchButton';
  3. import {t} from 'sentry/locale';
  4. import {space} from 'sentry/styles/space';
  5. import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
  6. import {useQueryParamState} from 'sentry/views/dashboards/widgetBuilder/hooks/useQueryParamState';
  7. export const DASHBOARD_RPC_TOGGLE_KEY = 'dashboards-spans-use-rpc';
  8. function RPCToggle() {
  9. const [_, setIsRpcEnabled] = useQueryParamState<boolean>({
  10. fieldName: 'useRpc',
  11. });
  12. // This is hacky, but we need to access the RPC toggle state in the spans dataset config
  13. // and I don't want to pass it down as a prop when it's only temporary.
  14. const [isRpcEnabled, setRpcLocalStorage] = useLocalStorageState(
  15. DASHBOARD_RPC_TOGGLE_KEY,
  16. false
  17. );
  18. return (
  19. <Flex gap={space(1)}>
  20. <SwitchButton
  21. isActive={isRpcEnabled}
  22. toggle={() => {
  23. const newValue = !isRpcEnabled;
  24. setIsRpcEnabled(newValue);
  25. setRpcLocalStorage(newValue);
  26. }}
  27. />
  28. <div>{t('Use RPC')}</div>
  29. </Flex>
  30. );
  31. }
  32. export default RPCToggle;