Repository: hasura/graphql-engine
File: console/src/telemetry/Actions.ts (TypeScript)

Code before:
import { Dispatch } from 'redux';
import Endpoints, { globalCookiePolicy } from '../Endpoints';
import requestAction from '../utils/requestAction';
import dataHeaders from '../components/Services/Data/Common/Headers';
import defaultTelemetryState from './State';
import { getRunSqlQuery } from '../components/Common/utils/v1QueryUtils';
import {
  showErrorNotification,
  showSuccessNotification,
} from '../components/Services/Common/Notification';

const SET_CONSOLE_OPTS = 'Telemetry/SET_CONSOLE_OPTS';
const SET_NOTIFICATION_SHOWN = 'Telemetry/SET_NOTIFICATION_SHOWN';
const SET_HASURA_UUID = 'Telemetry/SET_HASURA_UUID';

type Opts = {
  telemetryNotificationShown: boolean;
  disablePreReleaseUpdateNotifications: boolean;
};
type SuccessCb = (arg: object) => void;
type ErrorCb = (arg: Error) => void;
type SetConsoleOptsInDB = (opts: Partial<Opts>, successCb: SuccessCb, errorCb: ErrorCb) => (dispatch: Dispatch<any>, getState: any) => void

const setConsoleOptsInDB: SetConsoleOptsInDB = (opts, successCb, errorCb) => (
  dispatch,
  getState
) => {
  const url = Endpoints.getSchema;

  const { hasura_uuid, console_opts } = getState().telemetry;

  const consoleState = {
    ...console_opts,
    ...opts,
  };

  const options = {
    credentials: globalCookiePolicy,
    method: 'POST',
    headers: dataHeaders(getState),
    body: JSON.stringify(
      getRunSqlQuery(
        `update hdb_catalog.hdb_version set console_state = '${JSON.stringify(
          consoleState
        )}' where hasura_uuid='${hasura_uuid}';`
      )
    ),
  };


Review comment (suggestion):
Let's remove above types (as they are not needed anywhere else, and just inline types of `setConsoleOptsInDB`:
```ts
const setConsoleOptsInDB = (
  opts: Opts,
  successCb: (arg: object) => void,
  errorCb: (arg: Error) => void
) => (
  dispatch: Dispatch<any>,
  getState: () => { telemetry: TelemetryState }
) => {
```

Code after:
import { Dispatch, AnyAction } from 'redux';
import { ThunkDispatch } from 'redux-thunk';
import Endpoints, { globalCookiePolicy } from '../Endpoints';
import requestAction from '../utils/requestAction';
import dataHeaders from '../components/Services/Data/Common/Headers';
import {
  getRunSqlQuery,
  getConsoleOptsQuery,
} from '../components/Common/utils/v1QueryUtils';
import {
  showErrorNotification,
  showSuccessNotification,
} from '../components/Services/Common/Notification';
import globals from '../Globals';
import defaultTelemetryState, { TelemetryState } from './state';
import { GetReduxState, ReduxState } from '../types';

const SET_CONSOLE_OPTS = 'Telemetry/SET_CONSOLE_OPTS';
const SET_NOTIFICATION_SHOWN = 'Telemetry/SET_NOTIFICATION_SHOWN';
const SET_HASURA_UUID = 'Telemetry/SET_HASURA_UUID';

type Telemetry = {
  console_state: TelemetryState['console_opts'];
  hasura_uuid: string;
};

const setConsoleOptsInDB = (
  opts: TelemetryState['console_opts'],
  successCb: (arg: object) => void,
  errorCb: (arg: Error) => void
) => (
  dispatch: ThunkDispatch<ReduxState, {}, AnyAction>,
  getState: GetReduxState
) => {
  const url = Endpoints.getSchema;

  const { hasura_uuid, console_opts } = getState().telemetry;

  const consoleState = {
    ...console_opts,
    ...opts,
  };

  if (!hasura_uuid) {
    dispatch(
      showErrorNotification(
        'Opt out of pre-release notifications failed',
        'Internal error: missing hasura_uuid'
      )