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
0cfcf268
Commit
0cfcf268
authored
Sep 10, 2018
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
actions for group sync
parent
b1fe0c4c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
29 deletions
+113
-29
public/app/features/teams/TeamGroupSync.test.tsx
+0
-0
public/app/features/teams/TeamGroupSync.tsx
+44
-23
public/app/features/teams/TeamPages.tsx
+1
-2
public/app/features/teams/state/actions.ts
+64
-4
public/app/features/teams/state/reducers.ts
+3
-0
public/app/features/teams/state/selectors.ts
+1
-0
No files found.
public/app/features/teams/TeamGroupSync.test.tsx
0 → 100644
View file @
0cfcf268
public/app/features/teams/TeamGroupSync.tsx
View file @
0cfcf268
import
React
from
'react'
;
import
{
hot
}
from
'react-hot-loader
'
;
import
React
,
{
PureComponent
}
from
'react'
;
import
{
connect
}
from
'react-redux
'
;
import
SlideDown
from
'app/core/components/Animations/SlideDown'
;
import
Tooltip
from
'app/core/components/Tooltip/Tooltip'
;
import
{
Team
,
TeamGroup
}
from
'../../types'
;
interface
Props
{
team
:
Team
;
import
{
TeamGroup
}
from
'../../types'
;
import
{
addTeamGroup
,
loadTeamGroups
,
removeTeamGroup
}
from
'./state/actions'
;
import
{
getTeamGroups
}
from
'./state/selectors'
;
export
interface
Props
{
groups
:
TeamGroup
[];
loadTeamGroups
:
typeof
loadTeamGroups
;
addTeamGroup
:
typeof
addTeamGroup
;
removeTeamGroup
:
typeof
removeTeamGroup
;
}
interface
State
{
...
...
@@ -15,27 +20,18 @@ interface State {
const
headerTooltip
=
`Sync LDAP or OAuth groups with your Grafana teams.`
;
export
class
TeamGroupSync
extends
React
.
Component
<
Props
,
State
>
{
export
class
TeamGroupSync
extends
Pure
Component
<
Props
,
State
>
{
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{
isAdding
:
false
,
newGroupId
:
''
};
}
componentDidMount
()
{
// this.props.team.load
Groups();
this
.
fetchTeam
Groups
();
}
renderGroup
(
group
:
TeamGroup
)
{
return
(
<
tr
key=
{
group
.
groupId
}
>
<
td
>
{
group
.
groupId
}
</
td
>
<
td
style=
{
{
width
:
'1%'
}
}
>
<
a
className=
"btn btn-danger btn-mini"
onClick=
{
()
=>
this
.
onRemoveGroup
(
group
)
}
>
<
i
className=
"fa fa-remove"
/>
</
a
>
</
td
>
</
tr
>
);
async
fetchTeamGroups
()
{
await
this
.
props
.
loadTeamGroups
();
}
onToggleAdding
=
()
=>
{
...
...
@@ -47,21 +43,34 @@ export class TeamGroupSync extends React.Component<Props, State> {
};
onAddGroup
=
()
=>
{
// this.props.team.add
Group(this.state.newGroupId);
this
.
props
.
addTeam
Group
(
this
.
state
.
newGroupId
);
this
.
setState
({
isAdding
:
false
,
newGroupId
:
''
});
};
onRemoveGroup
=
(
group
:
TeamGroup
)
=>
{
// this.props.team.remove
Group(group.groupId);
this
.
props
.
removeTeam
Group
(
group
.
groupId
);
};
isNewGroupValid
()
{
return
this
.
state
.
newGroupId
.
length
>
1
;
}
renderGroup
(
group
:
TeamGroup
)
{
return
(
<
tr
key=
{
group
.
groupId
}
>
<
td
>
{
group
.
groupId
}
</
td
>
<
td
style=
{
{
width
:
'1%'
}
}
>
<
a
className=
"btn btn-danger btn-mini"
onClick=
{
()
=>
this
.
onRemoveGroup
(
group
)
}
>
<
i
className=
"fa fa-remove"
/>
</
a
>
</
td
>
</
tr
>
);
}
render
()
{
const
{
isAdding
,
newGroupId
}
=
this
.
state
;
const
groups
=
this
.
props
.
team
.
groups
;
const
groups
=
this
.
props
.
groups
;
return
(
<
div
>
...
...
@@ -144,4 +153,16 @@ export class TeamGroupSync extends React.Component<Props, State> {
}
}
export
default
hot
(
module
)(
TeamGroupSync
);
function
mapStateToProps
(
state
)
{
return
{
groups
:
getTeamGroups
(
state
.
team
),
};
}
const
mapDispatchToProps
=
{
loadTeamGroups
,
addTeamGroup
,
removeTeamGroup
,
};
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
TeamGroupSync
);
public/app/features/teams/TeamPages.tsx
View file @
0cfcf268
...
...
@@ -57,7 +57,6 @@ export class TeamPages extends PureComponent<Props, State> {
}
renderPage
()
{
const
{
team
}
=
this
.
props
;
const
{
isSyncEnabled
}
=
this
.
state
;
const
currentPage
=
this
.
getCurrentPage
();
...
...
@@ -69,7 +68,7 @@ export class TeamPages extends PureComponent<Props, State> {
return
<
TeamSettings
/>;
case
PageTypes
.
GroupSync
:
return
isSyncEnabled
&&
<
TeamGroupSync
team=
{
team
}
/>;
return
isSyncEnabled
&&
<
TeamGroupSync
/>;
}
return
null
;
...
...
public/app/features/teams/state/actions.ts
View file @
0cfcf268
import
{
ThunkAction
}
from
'redux-thunk'
;
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
NavModelItem
,
StoreState
,
Team
,
TeamMember
}
from
'../../../types'
;
import
{
NavModelItem
,
StoreState
,
Team
,
Team
Group
,
Team
Member
}
from
'../../../types'
;
import
{
updateNavIndex
}
from
'../../../core/actions'
;
import
{
UpdateNavIndexAction
}
from
'../../../core/actions/navModel'
;
import
config
from
'app/core/config'
;
export
enum
ActionTypes
{
LoadTeams
=
'LOAD_TEAMS'
,
...
...
@@ -10,6 +11,7 @@ export enum ActionTypes {
SetSearchQuery
=
'SET_SEARCH_QUERY'
,
SetSearchMemberQuery
=
'SET_SEARCH_MEMBER_QUERY'
,
LoadTeamMembers
=
'TEAM_MEMBERS_LOADED'
,
LoadTeamGroups
=
'TEAM_GROUPS_LOADED'
,
}
export
interface
LoadTeamsAction
{
...
...
@@ -27,6 +29,11 @@ export interface LoadTeamMembersAction {
payload
:
TeamMember
[];
}
export
interface
LoadTeamGroupsAction
{
type
:
ActionTypes
.
LoadTeamGroups
;
payload
:
TeamGroup
[];
}
export
interface
SetSearchQueryAction
{
type
:
ActionTypes
.
SetSearchQuery
;
payload
:
string
;
...
...
@@ -42,7 +49,8 @@ export type Action =
|
SetSearchQueryAction
|
LoadTeamAction
|
LoadTeamMembersAction
|
SetSearchMemberQueryAction
;
|
SetSearchMemberQueryAction
|
LoadTeamGroupsAction
;
type
ThunkResult
<
R
>
=
ThunkAction
<
R
,
StoreState
,
undefined
,
Action
|
UpdateNavIndexAction
>
;
...
...
@@ -61,6 +69,11 @@ const teamMembersLoaded = (teamMembers: TeamMember[]): LoadTeamMembersAction =>
payload
:
teamMembers
,
});
const
teamGroupsLoaded
=
(
teamGroups
:
TeamGroup
[]):
LoadTeamGroupsAction
=>
({
type
:
ActionTypes
.
LoadTeamGroups
,
payload
:
teamGroups
,
});
export
const
setSearchMemberQuery
=
(
searchQuery
:
string
):
SetSearchMemberQueryAction
=>
({
type
:
ActionTypes
.
SetSearchMemberQuery
,
payload
:
searchQuery
,
...
...
@@ -79,7 +92,7 @@ export function loadTeams(): ThunkResult<void> {
}
function
buildNavModel
(
team
:
Team
):
NavModelItem
{
return
{
const
navModel
=
{
img
:
team
.
avatarUrl
,
id
:
'team-'
+
team
.
id
,
subTitle
:
'Manage members & settings'
,
...
...
@@ -103,6 +116,18 @@ function buildNavModel(team: Team): NavModelItem {
},
],
};
if
(
config
.
buildInfo
.
isEnterprise
)
{
navModel
.
children
.
push
({
active
:
false
,
icon
:
'fa fa-fw fa-refresh'
,
id
:
'team-settings'
,
text
:
'External group sync'
,
url
:
`org/teams/edit/
${
team
.
id
}
/groupsync`
,
});
}
return
navModel
;
}
export
function
loadTeam
(
id
:
number
):
ThunkResult
<
void
>
{
...
...
@@ -117,7 +142,6 @@ export function loadTeam(id: number): ThunkResult<void> {
}
export
function
loadTeamMembers
():
ThunkResult
<
void
>
{
console
.
log
(
'loading team members'
);
return
async
(
dispatch
,
getStore
)
=>
{
const
team
=
getStore
().
team
.
team
;
...
...
@@ -167,6 +191,42 @@ export function updateTeam(name: string, email: string): ThunkResult<void> {
};
}
export
function
loadTeamGroups
():
ThunkResult
<
void
>
{
return
async
(
dispatch
,
getStore
)
=>
{
const
team
=
getStore
().
team
.
team
;
await
getBackendSrv
()
.
get
(
`/api/teams/
${
team
.
id
}
/groups`
)
.
then
(
response
=>
{
dispatch
(
teamGroupsLoaded
(
response
));
});
};
}
export
function
addTeamGroup
(
groupId
:
string
):
ThunkResult
<
void
>
{
return
async
(
dispatch
,
getStore
)
=>
{
const
team
=
getStore
().
team
.
team
;
await
getBackendSrv
()
.
post
(
`/api/teams/
${
team
.
id
}
/groups`
,
{
groupId
:
groupId
})
.
then
(()
=>
{
dispatch
(
loadTeamGroups
());
});
};
}
export
function
removeTeamGroup
(
groupId
:
string
):
ThunkResult
<
void
>
{
return
async
(
dispatch
,
getStore
)
=>
{
const
team
=
getStore
().
team
.
team
;
await
getBackendSrv
()
.
delete
(
`/api/teams/
${
team
.
id
}
/groups/
${
groupId
}
`
)
.
then
(()
=>
{
dispatch
(
loadTeamGroups
());
});
};
}
export
function
deleteTeam
(
id
:
number
):
ThunkResult
<
void
>
{
return
async
dispatch
=>
{
await
getBackendSrv
()
...
...
public/app/features/teams/state/reducers.ts
View file @
0cfcf268
...
...
@@ -30,6 +30,9 @@ export const teamReducer = (state = initialTeamState, action: Action): TeamState
case
ActionTypes
.
SetSearchMemberQuery
:
return
{
...
state
,
searchMemberQuery
:
action
.
payload
};
case
ActionTypes
.
LoadTeamGroups
:
return
{
...
state
,
groups
:
action
.
payload
};
}
return
state
;
...
...
public/app/features/teams/state/selectors.ts
View file @
0cfcf268
export
const
getSearchQuery
=
state
=>
state
.
searchQuery
;
export
const
getSearchMemberQuery
=
state
=>
state
.
searchMemberQuery
;
export
const
getTeamGroups
=
state
=>
state
.
groups
;
export
const
getTeam
=
(
state
,
currentTeamId
)
=>
{
if
(
state
.
team
.
id
===
parseInt
(
currentTeamId
))
{
...
...
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