Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

1015 B
Raw Blame
import { useFormikContext } from "formik";
import { t } from "ttag";

import type { PreemptiveCachingSwitchProps } from "metabase/plugins";
import { Switch } from "metabase/ui";
import type { DurationStrategy, ScheduleStrategy } from "metabase-types/api";

export const PreemptiveCachingSwitch = ({
  handleSwitchToggle,
}: PreemptiveCachingSwitchProps) => {
  const { values } = useFormikContext<DurationStrategy | ScheduleStrategy>();
  const currentRefreshValue = values.refresh_automatically ?? false;
  return (
    <Switch
      checked={currentRefreshValue}
      onChange={handleSwitchToggle}
      role="switch"
      label={t`Refresh cache automatically`}
      description={t`As soon as cached results expire, run and cache the query again to update the results and refresh
        the cache.`}
      styles={{
        labelWrapper: { paddingLeft: "16px" },
        label: { fontWeight: "bold" },
      }}
      wrapperProps={{
        "data-testid": "preemptive-caching-switch",
      }}
    />
  );
};