MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / useTimePeriodMinutes

Function useTimePeriodMinutes

console/src/hooks/useTimePeriodSelect.ts:33–60  ·  view source on GitHub ↗
({
  localStorageKey,
  defaultValue = DEFAULT_TIME_PERIOD,
  timePeriodOptions = DEFAULT_OPTIONS,
}: {
  localStorageKey: string;
  defaultValue?: string;
  timePeriodOptions?: TimePeriodOptions;
})

Source from the content-addressed store, hash-verified

31export const DEFAULT_TIME_PERIOD = Object.keys(DEFAULT_OPTIONS)[0];
32
33export const useTimePeriodMinutes = ({
34 localStorageKey,
35 defaultValue = DEFAULT_TIME_PERIOD,
36 timePeriodOptions = DEFAULT_OPTIONS,
37}: {
38 localStorageKey: string;
39 defaultValue?: string;
40 timePeriodOptions?: TimePeriodOptions;
41}) => {
42 const [timePeriodMinutes, setTimePeriodMinutes] = React.useState(() => {
43 let value = defaultValue;
44 if (storageAvailable("localStorage")) {
45 value = window.localStorage.getItem(localStorageKey) ?? defaultValue;
46 }
47 return timePeriodFromUrl(value, timePeriodOptions);
48 });
49
50 React.useEffect(() => {
51 if (storageAvailable("localStorage")) {
52 window.localStorage.setItem(
53 localStorageKey,
54 timePeriodMinutes.toString(),
55 );
56 }
57 }, [timePeriodMinutes, localStorageKey]);
58
59 return [timePeriodMinutes, setTimePeriodMinutes] as const;
60};
61
62const parseTimePeriod = (
63 periodString: string | null,

Callers 8

ClusterFreshnessFunction · 0.90
SourceOverviewFunction · 0.90
SourceErrorsFunction · 0.90
SinkOverviewFunction · 0.90
SinkErrorsFunction · 0.90
ClusterOverviewFunction · 0.90
ClusterFreshnessFunction · 0.90
MaintainedObjectsLayoutFunction · 0.90

Calls 2

storageAvailableFunction · 0.85
timePeriodFromUrlFunction · 0.85

Tested by

no test coverage detected