Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
affb04a3
Commit
affb04a3
authored
Oct 26, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved state to redux, renamed entities
parent
a98f7e54
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
172 additions
and
92 deletions
+172
-92
public/app/core/components/Picker/SimplePicker.tsx
+13
-3
public/app/features/org/OrgDetailsPage.tsx
+43
-43
public/app/features/org/OrgPreferences.tsx
+16
-16
public/app/features/org/state/actions.ts
+70
-12
public/app/features/org/state/reducers.ts
+20
-8
public/app/store/configureStore.ts
+2
-2
public/app/types/index.ts
+4
-4
public/app/types/organization.ts
+4
-4
No files found.
public/app/core/components/Picker/SimplePicker.tsx
View file @
affb04a3
...
...
@@ -6,18 +6,28 @@ import ResetStyles from './ResetStyles';
interface
Props
{
options
:
any
[];
className
?:
string
;
placeholder
?:
string
;
width
:
number
;
onSelected
:
(
item
:
any
)
=>
{}
|
void
;
getOptionValue
:
(
item
:
any
)
=>
string
;
getOptionLabel
:
(
item
:
any
)
=>
string
;
}
const
SimplePicker
:
SFC
<
Props
>
=
({
className
,
getOptionLabel
,
getOptionValue
,
onSelected
,
options
})
=>
{
const
SimplePicker
:
SFC
<
Props
>
=
({
className
,
getOptionLabel
,
getOptionValue
,
onSelected
,
options
,
placeholder
,
width
,
})
=>
{
return
(
<
Select
isSearchable=
{
false
}
classNamePrefix=
{
`gf-form-select-box`
}
className=
{
`width-
7
gf-form-input gf-form-input--form-dropdown ${className || ''}`
}
placeholder=
"Choose"
className=
{
`width-
${width}
gf-form-input gf-form-input--form-dropdown ${className || ''}`
}
placeholder=
{
placeholder
||
'Choose'
}
options=
{
options
}
onChange=
{
onSelected
}
components=
{
{
...
...
public/app/features/org/OrgDetailsPage.tsx
View file @
affb04a3
...
...
@@ -3,88 +3,84 @@ import { hot } from 'react-hot-loader';
import
{
connect
}
from
'react-redux'
;
import
PageHeader
from
'../../core/components/PageHeader/PageHeader'
;
import
PageLoader
from
'../../core/components/PageLoader/PageLoader'
;
import
{
loadOrganization
,
loadOrganizationPreferences
}
from
'./state/actions'
;
import
{
DashboardAcl
,
NavModel
,
Organization
,
OrganisationPreferences
,
StoreState
}
from
'app/types'
;
import
{
getNavModel
}
from
'../../core/selectors/navModel'
;
import
OrgProfile
from
'./OrgProfile'
;
import
OrgPreferences
from
'./OrgPreferences'
;
import
{
loadOrganization
,
loadOrganizationPreferences
,
setOrganizationName
,
setOrganizationTheme
,
setOrganizationHomeDashboard
,
setOrganizationTimezone
,
}
from
'./state/actions'
;
import
{
DashboardAcl
,
NavModel
,
Organization
,
OrganizationPreferences
,
StoreState
}
from
'app/types'
;
import
{
getNavModel
}
from
'../../core/selectors/navModel'
;
export
interface
Props
{
navModel
:
NavModel
;
organization
:
Organization
;
preferences
:
Organi
s
ationPreferences
;
preferences
:
Organi
z
ationPreferences
;
starredDashboards
:
DashboardAcl
[];
loadOrganization
:
typeof
loadOrganization
;
loadOrganizationPreferences
:
typeof
loadOrganizationPreferences
;
setOrganizationName
:
typeof
setOrganizationName
;
setOrganizationHomeDashboard
:
typeof
setOrganizationHomeDashboard
;
setOrganizationTheme
:
typeof
setOrganizationTheme
;
setOrganizationTimezone
:
typeof
setOrganizationTimezone
;
}
interface
State
{
orgName
:
string
;
theme
:
string
;
isReady
:
boolean
;
selectedDashboard
:
DashboardAcl
;
}
export
class
OrgDetailsPage
extends
PureComponent
<
Props
,
State
>
{
state
=
{
orgName
:
''
,
theme
:
''
,
isReady
:
false
,
selectedDashboard
:
null
,
};
export
class
OrgDetailsPage
extends
PureComponent
<
Props
>
{
async
componentDidMount
()
{
this
.
fetchOrganisation
();
}
async
fetchOrganisation
()
{
const
organization
=
await
this
.
props
.
loadOrganization
();
// const preferences = await this.props.loadOrganizationPreferences();
this
.
setState
({
orgName
:
organization
.
name
,
// theme: preferences.theme,
isReady
:
true
,
});
await
this
.
props
.
loadOrganization
();
await
this
.
props
.
loadOrganizationPreferences
();
}
onOrgNameChange
=
event
=>
{
this
.
setState
({
orgName
:
event
.
target
.
value
,
});
this
.
props
.
setOrganizationName
(
event
.
target
.
value
);
};
onSubmitForm
=
()
=>
{};
onSubmitPreferences
=
()
=>
{};
onDashboardSelected
=
dashboard
=>
{
this
.
setState
({
selectedDashboard
:
dashboard
,
});
onThemeChange
=
theme
=>
{
this
.
props
.
setOrganizationTheme
(
theme
);
};
onHomeDashboardChange
=
dashboardId
=>
{
this
.
props
.
setOrganizationHomeDashboard
(
dashboardId
);
};
onTimeZoneChange
=
timeZone
=>
{
this
.
props
.
setOrganizationTimezone
(
timeZone
);
};
render
()
{
const
{
navModel
,
preferences
,
starredDashboards
}
=
this
.
props
;
const
{
navModel
,
organization
,
preferences
,
starredDashboards
}
=
this
.
props
;
return
(
<
div
>
<
PageHeader
model=
{
navModel
}
/>
<
div
className=
"page-container page-body"
>
{
!
this
.
state
.
isReady
?
(
<
PageLoader
pageName=
"Organi
s
ation"
/>
{
Object
.
keys
(
organization
).
length
===
0
||
Object
.
keys
(
preferences
).
length
===
0
?
(
<
PageLoader
pageName=
"Organi
z
ation"
/>
)
:
(
<
div
>
<
OrgProfile
onOrgNameChange=
{
name
=>
this
.
onOrgNameChange
(
name
)
}
onSubmit=
{
this
.
onSubmitForm
}
orgName=
{
this
.
state
.
orgN
ame
}
orgName=
{
organization
.
n
ame
}
/>
<
OrgPreferences
preferences=
{
preferences
}
starredDashboards=
{
starredDashboards
}
onDashboardSelected=
{
dashboard
=>
this
.
onDashboardSelected
(
dashboard
)
}
onTimeZoneChange=
{
()
=>
{}
}
onDashboardChange=
{
dashboardId
=>
this
.
onHomeDashboardChange
(
dashboardId
)
}
onThemeChange=
{
theme
=>
this
.
onThemeChange
(
theme
)
}
onTimeZoneChange=
{
timeZone
=>
this
.
onTimeZoneChange
(
timeZone
)
}
onSubmit=
{
this
.
onSubmitPreferences
}
/>
</
div
>
...
...
@@ -98,15 +94,19 @@ export class OrgDetailsPage extends PureComponent<Props, State> {
function
mapStateToProps
(
state
:
StoreState
)
{
return
{
navModel
:
getNavModel
(
state
.
navIndex
,
'org-settings'
),
organi
sation
:
state
.
organisation
.
organis
ation
,
preferences
:
state
.
organi
s
ation
.
preferences
,
starredDashboards
:
state
.
organi
s
ation
.
starredDashboards
,
organi
zation
:
state
.
organization
.
organiz
ation
,
preferences
:
state
.
organi
z
ation
.
preferences
,
starredDashboards
:
state
.
organi
z
ation
.
starredDashboards
,
};
}
const
mapDispatchToProps
=
{
loadOrganization
,
loadOrganizationPreferences
,
setOrganizationName
,
setOrganizationTheme
,
setOrganizationHomeDashboard
,
setOrganizationTimezone
,
};
export
default
hot
(
module
)(
connect
(
mapStateToProps
,
mapDispatchToProps
)(
OrgDetailsPage
));
public/app/features/org/OrgPreferences.tsx
View file @
affb04a3
import
React
,
{
SFC
}
from
'react'
;
import
Tooltip
from
'../../core/components/Tooltip/Tooltip'
;
import
{
DashboardAcl
,
OrganisationPreferences
}
from
'app/types'
;
import
SimplePicker
from
'../../core/components/Picker/SimplePicker'
;
import
{
DashboardAcl
,
OrganizationPreferences
}
from
'app/types'
;
interface
Props
{
preferences
:
Organi
s
ationPreferences
;
preferences
:
Organi
z
ationPreferences
;
starredDashboards
:
DashboardAcl
[];
onDashboard
Selected
:
(
dashboard
:
DashboardAcl
)
=>
void
;
onDashboard
Change
:
(
dashboardId
:
number
)
=>
void
;
onTimeZoneChange
:
(
timeZone
:
string
)
=>
void
;
onThemeChange
:
(
theme
:
string
)
=>
void
;
onSubmit
:
()
=>
void
;
}
const
OrgPreferences
:
SFC
<
Props
>
=
({
preferences
,
starredDashboards
,
onDashboard
Selected
,
onDashboard
Change
,
onSubmit
,
onTimeZoneChange
,
onThemeChange
,
})
=>
{
const
themes
=
[{
value
:
''
,
text
:
'Default'
},
{
value
:
'dark'
,
text
:
'Dark'
},
{
value
:
'light'
,
text
:
'Light'
}];
...
...
@@ -35,9 +37,8 @@ const OrgPreferences: SFC<Props> = ({
options=
{
themes
}
getOptionValue=
{
i
=>
i
.
value
}
getOptionLabel=
{
i
=>
i
.
text
}
onSelected=
{
theme
=>
{
console
.
log
(
theme
);
}
}
onSelected=
{
theme
=>
onThemeChange
(
theme
)
}
width=
{
20
}
/>
</
div
>
<
div
className=
"gf-form"
>
...
...
@@ -52,23 +53,22 @@ const OrgPreferences: SFC<Props> = ({
</
Tooltip
>
</
span
>
<
SimplePicker
getOptionLabel=
{
i
=>
i
.
title
}
getOptionValue=
{
i
=>
i
.
id
}
onSelected=
{
dashboard
=>
onDashboardSelected
(
dashboard
)
}
getOptionLabel=
{
i
=>
i
.
title
}
onSelected=
{
(
dashboard
:
DashboardAcl
)
=>
onDashboardChange
(
dashboard
.
id
)
}
options=
{
starredDashboards
}
placeholder=
"Chose default dashboard"
width=
{
20
}
/>
</
div
>
<
div
className=
"gf-form"
>
<
label
className=
"gf-form-label width-11"
>
Timezone
</
label
>
<
SimplePicker
className=
"gf-form-input"
onSelected=
{
timezone
=>
{
console
.
log
(
timezone
);
}
}
options=
{
timezones
}
getOptionLabel=
{
i
=>
i
.
text
}
getOptionValue=
{
i
=>
i
.
value
}
getOptionLabel=
{
i
=>
i
.
text
}
onSelected=
{
timezone
=>
onTimeZoneChange
(
timezone
)
}
options=
{
timezones
}
width=
{
20
}
/>
</
div
>
<
div
className=
"gf-form-button-row"
>
...
...
public/app/features/org/state/actions.ts
View file @
affb04a3
import
{
ThunkAction
}
from
'redux-thunk'
;
import
{
DashboardAcl
,
Organization
,
Organi
s
ationPreferences
,
StoreState
}
from
'app/types'
;
import
{
DashboardAcl
,
Organization
,
Organi
z
ationPreferences
,
StoreState
}
from
'app/types'
;
import
{
getBackendSrv
}
from
'../../../core/services/backend_srv'
;
type
ThunkResult
<
R
>
=
ThunkAction
<
R
,
StoreState
,
undefined
,
any
>
;
export
enum
ActionTypes
{
LoadOrgani
s
ation
=
'LOAD_ORGANISATION'
,
LoadOrgani
z
ation
=
'LOAD_ORGANISATION'
,
LoadPreferences
=
'LOAD_PREFERENCES'
,
LoadStarredDashboards
=
'LOAD_STARRED_DASHBOARDS'
,
SetOrganizationName
=
'SET_ORGANIZATION_NAME'
,
SetOrganizationTheme
=
'SET_ORGANIZATION_THEME'
,
SetOrganizationHomeDashboard
=
'SET_ORGANIZATION_HOME_DASHBOARD'
,
SetOrganizationTimezone
=
'SET_ORGANIZATION_TIMEZONE'
,
}
interface
LoadOrganizationAction
{
type
:
ActionTypes
.
LoadOrgani
s
ation
;
type
:
ActionTypes
.
LoadOrgani
z
ation
;
payload
:
Organization
;
}
interface
LoadPreferencesAction
{
type
:
ActionTypes
.
LoadPreferences
;
payload
:
Organi
s
ationPreferences
;
payload
:
Organi
z
ationPreferences
;
}
interface
LoadStarredDashboardsAction
{
...
...
@@ -23,12 +29,32 @@ interface LoadStarredDashboardsAction {
payload
:
DashboardAcl
[];
}
interface
SetOrganizationNameAction
{
type
:
ActionTypes
.
SetOrganizationName
;
payload
:
string
;
}
interface
SetOrganizationThemeAction
{
type
:
ActionTypes
.
SetOrganizationTheme
;
payload
:
string
;
}
interface
SetOrganizationHomeDashboardAction
{
type
:
ActionTypes
.
SetOrganizationHomeDashboard
;
payload
:
number
;
}
interface
SetOrganizationTimezoneAction
{
type
:
ActionTypes
.
SetOrganizationTimezone
;
payload
:
string
;
}
const
organisationLoaded
=
(
organisation
:
Organization
)
=>
({
type
:
ActionTypes
.
LoadOrgani
s
ation
,
type
:
ActionTypes
.
LoadOrgani
z
ation
,
payload
:
organisation
,
});
const
preferencesLoaded
=
(
preferences
:
Organi
s
ationPreferences
)
=>
({
const
preferencesLoaded
=
(
preferences
:
Organi
z
ationPreferences
)
=>
({
type
:
ActionTypes
.
LoadPreferences
,
payload
:
preferences
,
});
...
...
@@ -38,12 +64,38 @@ const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({
payload
:
dashboards
,
});
export
type
Action
=
LoadOrganizationAction
|
LoadPreferencesAction
|
LoadStarredDashboardsAction
;
type
ThunkResult
<
R
>
=
ThunkAction
<
R
,
StoreState
,
undefined
,
any
>
;
export
const
setOrganizationName
=
(
orgName
:
string
)
=>
({
type
:
ActionTypes
.
SetOrganizationName
,
payload
:
orgName
,
});
export
const
setOrganizationTheme
=
(
theme
:
string
)
=>
({
type
:
ActionTypes
.
SetOrganizationTheme
,
payload
:
theme
,
});
export
const
setOrganizationHomeDashboard
=
(
id
:
number
)
=>
({
type
:
ActionTypes
.
SetOrganizationHomeDashboard
,
payload
:
id
,
});
export
const
setOrganizationTimezone
=
(
timezone
:
string
)
=>
({
type
:
ActionTypes
.
SetOrganizationTimezone
,
payload
:
timezone
,
});
export
type
Action
=
|
LoadOrganizationAction
|
LoadPreferencesAction
|
LoadStarredDashboardsAction
|
SetOrganizationNameAction
|
SetOrganizationThemeAction
|
SetOrganizationHomeDashboardAction
|
SetOrganizationTimezoneAction
;
export
function
loadOrganization
():
ThunkResult
<
void
>
{
return
async
dispatch
=>
{
const
organisationResponse
=
await
getBackendSrv
().
get
(
'/api/org'
);
const
organisationResponse
=
await
loadOrg
(
);
dispatch
(
organisationLoaded
(
organisationResponse
));
return
organisationResponse
;
...
...
@@ -52,12 +104,18 @@ export function loadOrganization(): ThunkResult<void> {
export
function
loadOrganizationPreferences
():
ThunkResult
<
void
>
{
return
async
dispatch
=>
{
const
preferencesResponse
=
await
getBackendSrv
().
get
(
'/api/org/preferences'
);
const
preferencesResponse
=
await
loadPreferences
(
);
dispatch
(
preferencesLoaded
(
preferencesResponse
));
const
starredDashboards
=
await
getBackendSrv
().
search
({
starred
:
true
});
dispatch
(
starredDashboardsLoaded
(
starredDashboards
));
return
preferencesResponse
;
};
}
export
async
function
loadOrg
()
{
return
await
await
getBackendSrv
().
get
(
'/api/org'
);
}
export
async
function
loadPreferences
()
{
return
await
getBackendSrv
().
get
(
'/api/org/preferences'
);
}
public/app/features/org/state/reducers.ts
View file @
affb04a3
import
{
DashboardAcl
,
Organization
,
Organi
sationPreferences
,
Organis
ationState
}
from
'app/types'
;
import
{
DashboardAcl
,
Organization
,
Organi
zationPreferences
,
Organiz
ationState
}
from
'app/types'
;
import
{
Action
,
ActionTypes
}
from
'./actions'
;
const
initialState
:
Organi
s
ationState
=
{
organi
s
ation
:
{}
as
Organization
,
preferences
:
{}
as
Organi
s
ationPreferences
,
const
initialState
:
Organi
z
ationState
=
{
organi
z
ation
:
{}
as
Organization
,
preferences
:
{}
as
Organi
z
ationPreferences
,
starredDashboards
:
[]
as
DashboardAcl
[],
};
const
organi
sationReducer
=
(
state
=
initialState
,
action
:
Action
):
Organis
ationState
=>
{
const
organi
zationReducer
=
(
state
=
initialState
,
action
:
Action
):
Organiz
ationState
=>
{
switch
(
action
.
type
)
{
case
ActionTypes
.
LoadOrgani
s
ation
:
return
{
...
state
,
organi
s
ation
:
action
.
payload
};
case
ActionTypes
.
LoadOrgani
z
ation
:
return
{
...
state
,
organi
z
ation
:
action
.
payload
};
case
ActionTypes
.
LoadPreferences
:
return
{
...
state
,
preferences
:
action
.
payload
};
case
ActionTypes
.
LoadStarredDashboards
:
return
{
...
state
,
starredDashboards
:
action
.
payload
};
case
ActionTypes
.
SetOrganizationName
:
return
{
...
state
,
organization
:
{
...
state
.
organization
,
name
:
action
.
payload
}
};
case
ActionTypes
.
SetOrganizationTheme
:
return
{
...
state
,
preferences
:
{
...
state
.
preferences
,
theme
:
action
.
payload
}
};
case
ActionTypes
.
SetOrganizationHomeDashboard
:
return
{
...
state
,
preferences
:
{
...
state
.
preferences
,
homeDashboardId
:
action
.
payload
}
};
case
ActionTypes
.
SetOrganizationTimezone
:
return
{
...
state
,
preferences
:
{
...
state
.
preferences
,
timezone
:
action
.
payload
}
};
}
return
state
;
};
export
default
{
organi
sation
:
organis
ationReducer
,
organi
zation
:
organiz
ationReducer
,
};
public/app/store/configureStore.ts
View file @
affb04a3
...
...
@@ -10,7 +10,7 @@ import dashboardReducers from 'app/features/dashboard/state/reducers';
import
pluginReducers
from
'app/features/plugins/state/reducers'
;
import
dataSourcesReducers
from
'app/features/datasources/state/reducers'
;
import
usersReducers
from
'app/features/users/state/reducers'
;
import
organi
s
ationReducers
from
'app/features/org/state/reducers'
;
import
organi
z
ationReducers
from
'app/features/org/state/reducers'
;
const
rootReducers
=
{
...
sharedReducers
,
...
...
@@ -22,7 +22,7 @@ const rootReducers = {
...
pluginReducers
,
...
dataSourcesReducers
,
...
usersReducers
,
...
organi
s
ationReducers
,
...
organi
z
ationReducers
,
};
export
let
store
;
...
...
public/app/types/index.ts
View file @
affb04a3
...
...
@@ -22,7 +22,7 @@ import {
}
from
'./series'
;
import
{
PanelProps
}
from
'./panel'
;
import
{
PluginDashboard
,
PluginMeta
,
Plugin
,
PluginsState
}
from
'./plugins'
;
import
{
Organization
,
Organi
sationPreferences
,
Organis
ationState
}
from
'./organization'
;
import
{
Organization
,
Organi
zationPreferences
,
Organiz
ationState
}
from
'./organization'
;
export
{
Team
,
...
...
@@ -72,8 +72,8 @@ export {
DataQueryOptions
,
PluginDashboard
,
Organization
,
Organi
s
ationState
,
Organi
s
ationPreferences
,
Organi
z
ationState
,
Organi
z
ationPreferences
,
};
export
interface
StoreState
{
...
...
@@ -86,5 +86,5 @@ export interface StoreState {
dashboard
:
DashboardState
;
dataSources
:
DataSourcesState
;
users
:
UsersState
;
organi
sation
:
Organis
ationState
;
organi
zation
:
Organiz
ationState
;
}
public/app/types/organization.ts
View file @
affb04a3
...
...
@@ -5,14 +5,14 @@ export interface Organization {
id
:
number
;
}
export
interface
Organi
s
ationPreferences
{
export
interface
Organi
z
ationPreferences
{
homeDashboardId
:
number
;
theme
:
string
;
timezone
:
string
;
}
export
interface
Organi
s
ationState
{
organi
s
ation
:
Organization
;
preferences
:
Organi
s
ationPreferences
;
export
interface
Organi
z
ationState
{
organi
z
ation
:
Organization
;
preferences
:
Organi
z
ationPreferences
;
starredDashboards
:
DashboardAcl
[];
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment