Convert App and localStorage to TS
parent
f86d7aa51c
commit
58ecd992e0
|
@ -1,23 +0,0 @@
|
||||||
import React from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
|
||||||
|
|
||||||
import SideNav from 'src/side_nav'
|
|
||||||
import Notifications from 'shared/components/Notifications'
|
|
||||||
import Overlay from 'shared/components/OverlayTechnology'
|
|
||||||
|
|
||||||
const App = ({children}) => (
|
|
||||||
<div className="chronograf-root">
|
|
||||||
<Overlay />
|
|
||||||
<Notifications />
|
|
||||||
<SideNav />
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
|
|
||||||
const {node} = PropTypes
|
|
||||||
|
|
||||||
App.propTypes = {
|
|
||||||
children: node.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import React, {SFC, ReactChildren} from 'react'
|
||||||
|
|
||||||
|
import SideNav from 'src/side_nav'
|
||||||
|
import Notifications from 'src/shared/components/Notifications'
|
||||||
|
import Overlay from 'src/shared/components/OverlayTechnology'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
children: ReactChildren
|
||||||
|
}
|
||||||
|
|
||||||
|
const App: SFC<Props> = ({children}) => (
|
||||||
|
<div className="chronograf-root">
|
||||||
|
<Overlay />
|
||||||
|
<Notifications />
|
||||||
|
<SideNav />
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default App
|
|
@ -5,7 +5,11 @@ import {
|
||||||
notifyLoadLocalSettingsFailed,
|
notifyLoadLocalSettingsFailed,
|
||||||
} from 'src/shared/copy/notifications'
|
} from 'src/shared/copy/notifications'
|
||||||
|
|
||||||
export const loadLocalStorage = errorsQueue => {
|
import {LocalStorage} from 'src/types/localStorage'
|
||||||
|
|
||||||
|
declare var VERSION: string
|
||||||
|
|
||||||
|
export const loadLocalStorage = (errorsQueue: any[]): LocalStorage | {} => {
|
||||||
try {
|
try {
|
||||||
const serializedState = localStorage.getItem('state')
|
const serializedState = localStorage.getItem('state')
|
||||||
|
|
||||||
|
@ -16,7 +20,7 @@ export const loadLocalStorage = errorsQueue => {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const version = VERSION ? ` (${VERSION})` : ''
|
const version = VERSION ? ` (${VERSION})` : ''
|
||||||
|
|
||||||
console.log(notifyNewVersion(version).message) // eslint-disable-line no-console
|
console.log(notifyNewVersion(version).message) // tslint:disable-line no-console
|
||||||
errorsQueue.push(notifyNewVersion(version))
|
errorsQueue.push(notifyNewVersion(version))
|
||||||
|
|
||||||
if (!state.dashTimeV1) {
|
if (!state.dashTimeV1) {
|
||||||
|
@ -54,23 +58,23 @@ export const saveToLocalStorage = ({
|
||||||
timeRange,
|
timeRange,
|
||||||
dataExplorer,
|
dataExplorer,
|
||||||
dashTimeV1: {ranges},
|
dashTimeV1: {ranges},
|
||||||
}) => {
|
}: LocalStorage): void => {
|
||||||
try {
|
try {
|
||||||
const appPersisted = Object.assign({}, {app: {persisted}})
|
const appPersisted = {app: {persisted}}
|
||||||
const dashTimeV1 = {ranges: normalizer(ranges)}
|
const dashTimeV1 = {ranges: normalizer(ranges)}
|
||||||
|
|
||||||
window.localStorage.setItem(
|
window.localStorage.setItem(
|
||||||
'state',
|
'state',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
...appPersisted,
|
...appPersisted,
|
||||||
dataExplorerQueryConfigs,
|
VERSION,
|
||||||
timeRange,
|
timeRange,
|
||||||
dataExplorer,
|
|
||||||
VERSION, // eslint-disable-line no-undef
|
|
||||||
dashTimeV1,
|
dashTimeV1,
|
||||||
|
dataExplorer,
|
||||||
|
dataExplorerQueryConfigs,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Unable to save data explorer: ', JSON.parse(err)) // eslint-disable-line no-console
|
console.error('Unable to save data explorer: ', JSON.parse(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
import {QueryConfig, TimeRange} from 'src/types'
|
||||||
|
|
||||||
|
export interface LocalStorage {
|
||||||
|
VERSION: VERSION
|
||||||
|
app: App
|
||||||
|
dashTimeV1: DashTimeV1
|
||||||
|
dataExplorer: DataExplorer
|
||||||
|
dataExplorerQueryConfigs: DataExplorerQueryConfigs
|
||||||
|
timeRange: TimeRange
|
||||||
|
}
|
||||||
|
|
||||||
|
export type VERSION = string
|
||||||
|
export type timeRange = TimeRange
|
||||||
|
|
||||||
|
export interface App {
|
||||||
|
persisted: Persisted
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DashTimeV1 {
|
||||||
|
ranges: DashboardTimeRange[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DataExplorer {
|
||||||
|
queryIDs: string[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DataExplorerQueryConfigs {
|
||||||
|
[id: string]: QueryConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DashboardTimeRange {
|
||||||
|
dashboardID: number
|
||||||
|
defaultGroupBy: string
|
||||||
|
format: string
|
||||||
|
inputValue: string
|
||||||
|
lower: string
|
||||||
|
menuOption: string
|
||||||
|
seconds: number
|
||||||
|
upper: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Persisted {
|
||||||
|
autoRefresh: number
|
||||||
|
showTemplateControlBar: boolean
|
||||||
|
}
|
Loading…
Reference in New Issue