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
5a9fe9af
Commit
5a9fe9af
authored
Jan 17, 2018
by
Johannes Schill
Committed by
Daniel Lee
Jan 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashfolders: Add a Team Picker component and use it on the dashboard permissions page #10275
parent
6b9858c1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
104 additions
and
21 deletions
+104
-21
public/app/core/angular_wrappers.ts
+1
-1
public/app/core/components/Permissions/Permissions.tsx
+9
-3
public/app/core/components/UserPicker/TeamPicker.tsx
+81
-0
public/app/core/components/UserPicker/UserPicker.tsx
+11
-15
public/app/core/components/UserPicker/withPicker.tsx
+1
-1
public/app/features/org/partials/team_details.html
+1
-1
No files found.
public/app/core/angular_wrappers.ts
View file @
5a9fe9af
...
...
@@ -19,7 +19,7 @@ export function registerAngularDirectives() {
[
'onSelect'
,
{
watchDepth
:
'reference'
}],
[
'tagOptions'
,
{
watchDepth
:
'reference'
}],
]);
react2AngularDirective
(
'selectUserPicker'
,
UserPicker
,
[
'backendSrv'
,
'
user
Picked'
]);
react2AngularDirective
(
'selectUserPicker'
,
UserPicker
,
[
'backendSrv'
,
'
handle
Picked'
]);
react2AngularDirective
(
'permissions'
,
Permissions
,
[
'error'
,
'newType'
,
...
...
public/app/core/components/Permissions/Permissions.tsx
View file @
5a9fe9af
...
...
@@ -3,6 +3,7 @@ import PermissionsList from './PermissionsList';
import
DevTools
from
'mobx-react-devtools'
;
import
{
inject
,
observer
}
from
'mobx-react'
;
import
UserPicker
,
{
User
}
from
'app/core/components/UserPicker/UserPicker'
;
import
TeamPicker
,
{
Team
}
from
'app/core/components/UserPicker/TeamPicker'
;
export
interface
DashboardAcl
{
id
?:
number
;
...
...
@@ -61,6 +62,7 @@ class Permissions extends Component<IProps, any> {
this
.
removeItem
=
this
.
removeItem
.
bind
(
this
);
this
.
update
=
this
.
update
.
bind
(
this
);
this
.
userPicked
=
this
.
userPicked
.
bind
(
this
);
this
.
teamPicked
=
this
.
teamPicked
.
bind
(
this
);
permissions
.
load
(
dashboardId
,
isFolder
);
this
.
state
=
{
...
...
@@ -119,6 +121,11 @@ class Permissions extends Component<IProps, any> {
permissions
.
addStoreItem
({
userId
:
user
.
id
,
userLogin
:
user
.
login
,
permission
:
1
});
}
teamPicked
(
team
:
Team
)
{
const
{
permissions
}
=
this
.
props
;
permissions
.
addStoreItem
({
teamId
:
team
.
id
,
team
:
team
.
name
,
permission
:
1
});
}
render
()
{
console
.
log
(
'Permissions render'
);
const
{
error
,
permissions
,
backendSrv
}
=
this
.
props
;
...
...
@@ -167,14 +174,13 @@ class Permissions extends Component<IProps, any> {
refreshList="ctrl.get"
teamMembers="ctrl.teamMembers"
/> */
}
<
UserPicker
backendSrv=
{
backendSrv
}
user
Picked=
{
this
.
userPicked
}
/>
<
UserPicker
backendSrv=
{
backendSrv
}
handle
Picked=
{
this
.
userPicked
}
/>
</
div
>
)
:
null
}
{
newType
===
'Group'
?
(
<
div
className=
"gf-form"
>
Team picker
{
/* <team-picker team-picked="ctrl.groupPicked($group)" /> */
}
<
TeamPicker
backendSrv=
{
backendSrv
}
handlePicked=
{
this
.
teamPicked
}
/>
</
div
>
)
:
null
}
</
div
>
...
...
public/app/core/components/UserPicker/TeamPicker.tsx
0 → 100644
View file @
5a9fe9af
import
React
,
{
Component
}
from
'react'
;
import
Select
from
'react-select'
;
import
UserPickerOption
from
'./UserPickerOption'
;
import
withPicker
from
'./withPicker'
;
import
{
debounce
}
from
'lodash'
;
export
interface
IProps
{
backendSrv
:
any
;
isLoading
:
boolean
;
toggleLoading
:
any
;
handlePicked
:
(
user
)
=>
void
;
}
export
interface
Team
{
id
:
number
;
label
:
string
;
name
:
string
;
avatarUrl
:
string
;
}
class
TeamPicker
extends
Component
<
IProps
,
any
>
{
debouncedSearch
:
any
;
backendSrv
:
any
;
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{};
this
.
search
=
this
.
search
.
bind
(
this
);
// this.handleChange = this.handleChange.bind(this);
this
.
debouncedSearch
=
debounce
(
this
.
search
,
300
,
{
leading
:
true
,
trailing
:
false
,
});
}
search
(
query
?:
string
)
{
const
{
toggleLoading
,
backendSrv
}
=
this
.
props
;
toggleLoading
(
true
);
return
backendSrv
.
get
(
`/api/teams/search?perpage=10&page=1&query=
${
query
}
`
).
then
(
result
=>
{
const
teams
=
result
.
teams
.
map
(
team
=>
{
// return { text: ug.name, value: ug };
return
{
id
:
team
.
id
,
label
:
team
.
name
,
name
:
team
.
name
,
avatarUrl
:
team
.
avatarUrl
,
};
});
toggleLoading
(
false
);
return
{
options
:
teams
};
});
}
render
()
{
const
AsyncComponent
=
this
.
state
.
creatable
?
Select
.
AsyncCreatable
:
Select
.
Async
;
const
{
isLoading
,
handlePicked
}
=
this
.
props
;
return
(
<
div
className=
"user-picker"
>
<
AsyncComponent
valueKey=
"id"
multi=
{
this
.
state
.
multi
}
labelKey=
"label"
cache=
{
false
}
isLoading=
{
isLoading
}
loadOptions=
{
this
.
debouncedSearch
}
loadingPlaceholder=
"Loading..."
onChange=
{
handlePicked
}
className=
"width-8 gf-form-input gf-form-input--form-dropdown"
optionComponent=
{
UserPickerOption
}
placeholder=
"Choose"
/>
</
div
>
);
}
}
export
default
withPicker
(
TeamPicker
);
public/app/core/components/UserPicker/UserPicker.tsx
View file @
5a9fe9af
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Component
}
from
'react'
;
import
Select
from
'react-select'
;
import
UserPickerOption
from
'./UserPickerOption'
;
import
withPicker
from
'./withPicker'
;
...
...
@@ -8,7 +8,7 @@ export interface IProps {
backendSrv
:
any
;
isLoading
:
boolean
;
toggleLoading
:
any
;
user
Picked
:
(
user
)
=>
void
;
handle
Picked
:
(
user
)
=>
void
;
}
export
interface
User
{
...
...
@@ -19,26 +19,21 @@ export interface User {
}
class
UserPicker
extends
Component
<
IProps
,
any
>
{
debouncedSearch
Users
:
any
;
debouncedSearch
:
any
;
backendSrv
:
any
;
constructor
(
props
)
{
super
(
props
);
this
.
state
=
{};
this
.
search
Users
=
this
.
searchUsers
.
bind
(
this
);
this
.
handleChange
=
this
.
handleChange
.
bind
(
this
);
this
.
debouncedSearch
Users
=
debounce
(
this
.
searchUsers
,
300
,
{
this
.
search
=
this
.
search
.
bind
(
this
);
//
this.handleChange = this.handleChange.bind(this);
this
.
debouncedSearch
=
debounce
(
this
.
search
,
300
,
{
leading
:
true
,
trailing
:
false
,
});
}
handleChange
(
user
:
User
)
{
const
{
userPicked
}
=
this
.
props
;
userPicked
(
user
);
}
searchUsers
(
query
?:
string
)
{
search
(
query
?:
string
)
{
const
{
toggleLoading
,
backendSrv
}
=
this
.
props
;
toggleLoading
(
true
);
...
...
@@ -58,6 +53,7 @@ class UserPicker extends Component<IProps, any> {
render
()
{
const
AsyncComponent
=
this
.
state
.
creatable
?
Select
.
AsyncCreatable
:
Select
.
Async
;
const
{
isLoading
,
handlePicked
}
=
this
.
props
;
return
(
<
div
className=
"user-picker"
>
...
...
@@ -66,11 +62,11 @@ class UserPicker extends Component<IProps, any> {
multi=
{
this
.
state
.
multi
}
labelKey=
"label"
cache=
{
false
}
isLoading=
{
this
.
props
.
isLoading
}
loadOptions=
{
this
.
debouncedSearch
Users
}
isLoading=
{
isLoading
}
loadOptions=
{
this
.
debouncedSearch
}
loadingPlaceholder=
"Loading..."
noResultsText=
"No users found"
onChange=
{
this
.
handleChange
}
onChange=
{
handlePicked
}
className=
"width-8 gf-form-input gf-form-input--form-dropdown"
optionComponent=
{
UserPickerOption
}
placeholder=
"Choose"
...
...
public/app/core/components/UserPicker/withPicker.tsx
View file @
5a9fe9af
...
...
@@ -2,7 +2,7 @@
export
interface
IProps
{
backendSrv
:
any
;
userPicked
:
(
user
)
=>
void
;
handlePicked
:
(
data
)
=>
void
;
}
// export interface User {
...
...
public/app/features/org/partials/team_details.html
View file @
5a9fe9af
...
...
@@ -33,7 +33,7 @@
Old picker
<user-picker user-picked="ctrl.userPicked($user)"></user-picker>
-->
<select-user-picker
user
Picked=
"ctrl.userPicked"
backendSrv=
"ctrl.backendSrv"
></select-user-picker>
<select-user-picker
handle
Picked=
"ctrl.userPicked"
backendSrv=
"ctrl.backendSrv"
></select-user-picker>
</div>
</form>
...
...
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