All files / src/utils local-storage-keys.tsx

55.56% Statements 10/18
50% Branches 4/8
50% Functions 2/4
60% Lines 9/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                    53x                                                   53x         53x       53x 17x 17x     53x 3x 3x              
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
export const LocalStorageKeys = {
  CAPABILITIES_OVERRIDE: 'capabilities-override' as 'capabilities-override',
  INGESTION_SPEC: 'ingestion-spec' as 'ingestion-spec',
  DATASOURCE_TABLE_COLUMN_SELECTION: 'datasource-table-column-selection' as 'datasource-table-column-selection',
  SEGMENT_TABLE_COLUMN_SELECTION: 'segment-table-column-selection' as 'segment-table-column-selection',
  SUPERVISOR_TABLE_COLUMN_SELECTION: 'supervisor-table-column-selection' as 'supervisor-table-column-selection',
  TASK_TABLE_COLUMN_SELECTION: 'task-table-column-selection' as 'task-table-column-selection',
  SERVICE_TABLE_COLUMN_SELECTION: 'service-table-column-selection' as 'service-table-column-selection',
  LOOKUP_TABLE_COLUMN_SELECTION: 'lookup-table-column-selection' as 'lookup-table-column-selection',
  QUERY_KEY: 'druid-console-query' as 'druid-console-query',
  QUERY_CONTEXT: 'query-context' as 'query-context',
  INGESTION_VIEW_PANE_SIZE: 'ingestion-view-pane-size' as 'ingestion-view-pane-size',
  QUERY_VIEW_PANE_SIZE: 'query-view-pane-size' as 'query-view-pane-size',
  TASKS_REFRESH_RATE: 'task-refresh-rate' as 'task-refresh-rate',
  DATASOURCES_REFRESH_RATE: 'datasources-refresh-rate' as 'datasources-refresh-rate',
  SEGMENTS_REFRESH_RATE: 'segments-refresh-rate' as 'segments-refresh-rate',
  SERVICES_REFRESH_RATE: 'services-refresh-rate' as 'services-refresh-rate',
  SUPERVISORS_REFRESH_RATE: 'supervisors-refresh-rate' as 'supervisors-refresh-rate',
  LOOKUPS_REFRESH_RATE: 'lookups-refresh-rate' as 'lookups-refresh-rate',
  QUERY_HISTORY: 'query-history' as 'query-history',
  AUTO_RUN: 'auto-run' as 'auto-run',
};
export type LocalStorageKeys = typeof LocalStorageKeys[keyof typeof LocalStorageKeys];
 
// ----------------------------
 
export function localStorageSet(key: LocalStorageKeys, value: string): void {
  if (typeof localStorage === 'undefined') return;
  localStorage.setItem(key, value);
}
 
export function localStorageSetJson(key: LocalStorageKeys, value: any): void {
  localStorageSet(key, JSON.stringify(value));
}
 
export function localStorageGet(key: LocalStorageKeys): string | undefined {
  Iif (typeof localStorage === 'undefined') return;
  return localStorage.getItem(key) || undefined;
}
 
export function localStorageGetJson(key: LocalStorageKeys): any {
  const value = localStorageGet(key);
  Eif (!value) return;
  try {
    return JSON.parse(value);
  } catch {
    return;
  }
}