mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 05:29:42 -06:00
e7ae220cde
* Logs: Optional logs label column - reintroduces label column that was removed when log details were introduced - added to explore and also as a new option to logs panel - explore column settings now stored in localstorage - labels are rendered with font size xs - labels that start with `_` or are called `level` or `filename` are not displayed - removed click handlers and moved remaining `LogLabel` logic into `LogLabels` * Added prop to satisfy interface * Review feedback * removed comment * Changed label of label column switch
62 lines
1.4 KiB
TypeScript
62 lines
1.4 KiB
TypeScript
type StoreValue = string | number | boolean | null;
|
|
|
|
export class Store {
|
|
get(key: string) {
|
|
return window.localStorage[key];
|
|
}
|
|
|
|
set(key: string, value: StoreValue) {
|
|
window.localStorage[key] = value;
|
|
}
|
|
|
|
getBool(key: string, def: boolean): boolean {
|
|
if (def !== void 0 && !this.exists(key)) {
|
|
return def;
|
|
}
|
|
return window.localStorage[key] === 'true';
|
|
}
|
|
|
|
getObject(key: string, def?: any) {
|
|
let ret = def;
|
|
if (this.exists(key)) {
|
|
const json = window.localStorage[key];
|
|
try {
|
|
ret = JSON.parse(json);
|
|
} catch (error) {
|
|
console.error(`Error parsing store object: ${key}. Returning default: ${def}. [${error}]`);
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
// Returns true when successfully stored
|
|
setObject(key: string, value: any): boolean {
|
|
let json;
|
|
try {
|
|
json = JSON.stringify(value);
|
|
} catch (error) {
|
|
console.error(`Could not stringify object: ${key}. [${error}]`);
|
|
return false;
|
|
}
|
|
try {
|
|
this.set(key, json);
|
|
} catch (error) {
|
|
// Likely hitting storage quota
|
|
console.error(`Could not save item in localStorage: ${key}. [${error}]`);
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
exists(key: string) {
|
|
return window.localStorage[key] !== void 0;
|
|
}
|
|
|
|
delete(key: string) {
|
|
window.localStorage.removeItem(key);
|
|
}
|
|
}
|
|
|
|
const store = new Store();
|
|
export default store;
|