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
59b5b146
Commit
59b5b146
authored
Sep 10, 2018
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: began folder to redux migration
parent
6c90a536
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
222 additions
and
162 deletions
+222
-162
public/app/containers/ManageDashboards/FolderSettings.tsx
+0
-160
public/app/features/manage-dashboards/FolderSettingsPage.test.tsx
+0
-0
public/app/features/manage-dashboards/FolderSettingsPage.tsx
+180
-0
public/app/features/manage-dashboards/state/actions.ts
+29
-0
public/app/features/manage-dashboards/state/reducers.ts
+0
-0
public/app/routes/routes.ts
+2
-2
public/app/types/dashboard.ts
+7
-0
public/app/types/index.ts
+4
-0
No files found.
public/app/containers/ManageDashboards/FolderSettings.tsx
deleted
100644 → 0
View file @
6c90a536
import
React
from
'react'
;
import
{
hot
}
from
'react-hot-loader'
;
import
{
inject
,
observer
}
from
'mobx-react'
;
import
{
toJS
}
from
'mobx'
;
import
PageHeader
from
'app/core/components/PageHeader/PageHeader'
;
import
ContainerProps
from
'app/containers/ContainerProps'
;
import
{
getSnapshot
}
from
'mobx-state-tree'
;
import
appEvents
from
'app/core/app_events'
;
@
inject
(
'nav'
,
'folder'
,
'view'
)
@
observer
export
class
FolderSettings
extends
React
.
Component
<
ContainerProps
,
any
>
{
formSnapshot
:
any
;
componentDidMount
()
{
this
.
loadStore
();
}
loadStore
()
{
const
{
nav
,
folder
,
view
}
=
this
.
props
;
return
folder
.
load
(
view
.
routeParams
.
get
(
'uid'
)
as
string
).
then
(
res
=>
{
this
.
formSnapshot
=
getSnapshot
(
folder
);
view
.
updatePathAndQuery
(
`
${
res
.
url
}
/settings`
,
{},
{});
return
nav
.
initFolderNav
(
toJS
(
folder
.
folder
),
'manage-folder-settings'
);
});
}
onTitleChange
(
evt
)
{
this
.
props
.
folder
.
setTitle
(
this
.
getFormSnapshot
().
folder
.
title
,
evt
.
target
.
value
);
}
getFormSnapshot
()
{
if
(
!
this
.
formSnapshot
)
{
this
.
formSnapshot
=
getSnapshot
(
this
.
props
.
folder
);
}
return
this
.
formSnapshot
;
}
save
(
evt
)
{
if
(
evt
)
{
evt
.
stopPropagation
();
evt
.
preventDefault
();
}
const
{
nav
,
folder
,
view
}
=
this
.
props
;
folder
.
saveFolder
({
overwrite
:
false
})
.
then
(
newUrl
=>
{
view
.
updatePathAndQuery
(
newUrl
,
{},
{});
appEvents
.
emit
(
'dashboard-saved'
);
appEvents
.
emit
(
'alert-success'
,
[
'Folder saved'
]);
})
.
then
(()
=>
{
return
nav
.
initFolderNav
(
toJS
(
folder
.
folder
),
'manage-folder-settings'
);
})
.
catch
(
this
.
handleSaveFolderError
.
bind
(
this
));
}
delete
(
evt
)
{
if
(
evt
)
{
evt
.
stopPropagation
();
evt
.
preventDefault
();
}
const
{
folder
,
view
}
=
this
.
props
;
const
title
=
folder
.
folder
.
title
;
appEvents
.
emit
(
'confirm-modal'
,
{
title
:
'Delete'
,
text
:
`Do you want to delete this folder and all its dashboards?`
,
icon
:
'fa-trash'
,
yesText
:
'Delete'
,
onConfirm
:
()
=>
{
return
folder
.
deleteFolder
().
then
(()
=>
{
appEvents
.
emit
(
'alert-success'
,
[
'Folder Deleted'
,
`
${
title
}
has been deleted`
]);
view
.
updatePathAndQuery
(
'dashboards'
,
''
,
''
);
});
},
});
}
handleSaveFolderError
(
err
)
{
if
(
err
.
data
&&
err
.
data
.
status
===
'version-mismatch'
)
{
err
.
isHandled
=
true
;
const
{
nav
,
folder
,
view
}
=
this
.
props
;
appEvents
.
emit
(
'confirm-modal'
,
{
title
:
'Conflict'
,
text
:
'Someone else has updated this folder.'
,
text2
:
'Would you still like to save this folder?'
,
yesText
:
'Save & Overwrite'
,
icon
:
'fa-warning'
,
onConfirm
:
()
=>
{
folder
.
saveFolder
({
overwrite
:
true
})
.
then
(
newUrl
=>
{
view
.
updatePathAndQuery
(
newUrl
,
{},
{});
appEvents
.
emit
(
'dashboard-saved'
);
appEvents
.
emit
(
'alert-success'
,
[
'Folder saved'
]);
})
.
then
(()
=>
{
return
nav
.
initFolderNav
(
toJS
(
folder
.
folder
),
'manage-folder-settings'
);
});
},
});
}
}
render
()
{
const
{
nav
,
folder
}
=
this
.
props
;
if
(
!
folder
.
folder
||
!
nav
.
main
)
{
return
<
h2
>
Loading
</
h2
>;
}
return
(
<
div
>
<
PageHeader
model=
{
nav
as
any
}
/>
<
div
className=
"page-container page-body"
>
<
h2
className=
"page-sub-heading"
>
Folder Settings
</
h2
>
<
div
className=
"section gf-form-group"
>
<
form
name=
"folderSettingsForm"
onSubmit=
{
this
.
save
.
bind
(
this
)
}
>
<
div
className=
"gf-form"
>
<
label
className=
"gf-form-label width-7"
>
Name
</
label
>
<
input
type=
"text"
className=
"gf-form-input width-30"
value=
{
folder
.
folder
.
title
}
onChange=
{
this
.
onTitleChange
.
bind
(
this
)
}
/>
</
div
>
<
div
className=
"gf-form-button-row"
>
<
button
type=
"submit"
className=
"btn btn-success"
disabled=
{
!
folder
.
folder
.
canSave
||
!
folder
.
folder
.
hasChanged
}
>
<
i
className=
"fa fa-save"
/>
Save
</
button
>
<
button
className=
"btn btn-danger"
onClick=
{
this
.
delete
.
bind
(
this
)
}
disabled=
{
!
folder
.
folder
.
canSave
}
>
<
i
className=
"fa fa-trash"
/>
Delete
</
button
>
</
div
>
</
form
>
</
div
>
</
div
>
</
div
>
);
}
}
export
default
hot
(
module
)(
FolderSettings
);
public/app/
containers/ManageDashboards/FolderSettings
.test.tsx
→
public/app/
features/manage-dashboards/FolderSettingsPage
.test.tsx
View file @
59b5b146
File moved
public/app/features/manage-dashboards/FolderSettingsPage.tsx
0 → 100644
View file @
59b5b146
import
React
,
{
PureComponent
}
from
'react'
;
import
{
hot
}
from
'react-hot-loader'
;
import
{
connect
}
from
'react-redux'
;
import
PageHeader
from
'app/core/components/PageHeader/PageHeader'
;
import
appEvents
from
'app/core/app_events'
;
import
{
getNavModel
}
from
'app/core/selectors/navModel'
;
import
{
NavModel
,
StoreState
}
from
'app/types'
;
import
{
getFolderByUid
}
from
'./state/actions'
;
export
interface
Props
{
navModel
:
NavModel
;
folderUid
:
string
;
getFolderByUid
:
typeof
getFolderByUid
;
}
export
class
FolderSettingsPage
extends
PureComponent
<
Props
>
{
// formSnapshot: any;
//
componentDidMount
()
{
this
.
props
.
getFolderByUid
(
this
.
props
.
folderUid
);
}
//
// loadStore() {
// const { nav, folder, view } = this.props;
//
// return folder.load(view.routeParams.get('uid') as string).then(res => {
// this.formSnapshot = getSnapshot(folder);
// view.updatePathAndQuery(`${res.url}/settings`, {}, {});
//
// return nav.initFolderNav(toJS(folder.folder), 'manage-folder-settings');
// });
// }
// onTitleChange(evt) {
// this.props.folder.setTitle(this.getFormSnapshot().folder.title, evt.target.value);
// }
//
// getFormSnapshot() {
// if (!this.formSnapshot) {
// this.formSnapshot = getSnapshot(this.props.folder);
// }
//
// return this.formSnapshot;
// }
//
// save(evt) {
// if (evt) {
// evt.stopPropagation();
// evt.preventDefault();
// }
//
// const { nav, folder, view } = this.props;
//
// folder
// .saveFolder({ overwrite: false })
// .then(newUrl => {
// view.updatePathAndQuery(newUrl, {}, {});
//
// appEvents.emit('dashboard-saved');
// appEvents.emit('alert-success', ['Folder saved']);
// })
// .then(() => {
// return nav.initFolderNav(toJS(folder.folder), 'manage-folder-settings');
// })
// .catch(this.handleSaveFolderError.bind(this));
// }
//
// delete(evt) {
// if (evt) {
// evt.stopPropagation();
// evt.preventDefault();
// }
//
// const { folder, view } = this.props;
// const title = folder.folder.title;
//
// appEvents.emit('confirm-modal', {
// title: 'Delete',
// text: `Do you want to delete this folder and all its dashboards?`,
// icon: 'fa-trash',
// yesText: 'Delete',
// onConfirm: () => {
// return folder.deleteFolder().then(() => {
// appEvents.emit('alert-success', ['Folder Deleted', `${title} has been deleted`]);
// view.updatePathAndQuery('dashboards', '', '');
// });
// },
// });
// }
//
// handleSaveFolderError(err) {
// if (err.data && err.data.status === 'version-mismatch') {
// err.isHandled = true;
//
// const { nav, folder, view } = this.props;
//
// appEvents.emit('confirm-modal', {
// title: 'Conflict',
// text: 'Someone else has updated this folder.',
// text2: 'Would you still like to save this folder?',
// yesText: 'Save & Overwrite',
// icon: 'fa-warning',
// onConfirm: () => {
// folder
// .saveFolder({ overwrite: true })
// .then(newUrl => {
// view.updatePathAndQuery(newUrl, {}, {});
//
// appEvents.emit('dashboard-saved');
// appEvents.emit('alert-success', ['Folder saved']);
// })
// .then(() => {
// return nav.initFolderNav(toJS(folder.folder), 'manage-folder-settings');
// });
// },
// });
// }
// }
render
()
{
const
{
navModel
}
=
this
.
props
;
// if (!folder.folder || !nav.main) {
// return <h2>Loading</h2>;
// }
return
(
<
div
>
<
PageHeader
model=
{
navModel
}
/>
<
div
className=
"page-container page-body"
>
<
h2
className=
"page-sub-heading"
>
Folder Settings
</
h2
>
</
div
>
</
div
>
);
}
// asd() {
// <div className="section gf-form-group">
// <form name="folderSettingsForm" onSubmit={this.save.bind(this)}>
// <div className="gf-form">
// <label className="gf-form-label width-7">Name</label>
// <input
// type="text"
// className="gf-form-input width-30"
// value={folder.folder.title}
// onChange={this.onTitleChange.bind(this)}
// />
// </div>
// <div className="gf-form-button-row">
// <button
// type="submit"
// className="btn btn-success"
// disabled={!folder.folder.canSave || !folder.folder.hasChanged}
// >
// <i className="fa fa-save" /> Save
// </button>
// <button className="btn btn-danger" onClick={this.delete.bind(this)} disabled={!folder.folder.canSave}>
// <i className="fa fa-trash" /> Delete
// </button>
// </div>
// </form>
// </div>
//
// }
}
const
mapStateToProps
=
(
state
:
StoreState
)
=>
{
const
uid
=
state
.
location
.
routeParams
.
uid
;
return
{
navModel
:
getNavModel
(
state
.
navIndex
,
`folder-settings-
${
uid
}
`
),
folderUid
:
uid
,
};
};
const
mapDispatchToProps
=
{
getFolderByUid
,
};
export
default
hot
(
module
)(
connect
(
mapStateToProps
,
mapDispatchToProps
)(
FolderSettingsPage
));
public/app/features/manage-dashboards/state/actions.ts
0 → 100644
View file @
59b5b146
import
{
getBackendSrv
}
from
'app/core/services/backend_srv'
;
import
{
StoreState
}
from
'app/types'
;
import
{
ThunkAction
}
from
'redux-thunk'
;
import
{
FolderDTO
}
from
'app/types'
;
export
enum
ActionTypes
{
LoadFolder
=
'LOAD_FOLDER'
,
}
export
interface
LoadFolderAction
{
type
:
ActionTypes
.
LoadFolder
;
payload
:
FolderDTO
;
}
export
const
loadFolder
=
(
folder
:
FolderDTO
):
LoadFolderAction
=>
({
type
:
ActionTypes
.
LoadFolder
,
payload
:
folder
,
});
export
type
Action
=
LoadFolderAction
;
type
ThunkResult
<
R
>
=
ThunkAction
<
R
,
StoreState
,
undefined
,
Action
>
;
export
function
getFolderByUid
(
uid
:
string
):
ThunkResult
<
void
>
{
return
async
dispatch
=>
{
const
folder
=
await
getBackendSrv
().
getFolderByUid
(
uid
);
dispatch
(
loadFolder
(
folder
));
};
}
public/app/features/manage-dashboards/state/reducers.ts
0 → 100644
View file @
59b5b146
public/app/routes/routes.ts
View file @
59b5b146
...
...
@@ -4,7 +4,7 @@ import './ReactContainer';
import
ServerStats
from
'app/features/admin/ServerStats'
;
import
AlertRuleList
from
'app/features/alerting/AlertRuleList'
;
import
FolderPermissions
from
'app/containers/ManageDashboards/FolderPermissions'
;
import
FolderSettings
from
'app/containers/ManageDashboards/FolderSettings
'
;
import
FolderSettings
Page
from
'app/features/manage-dashboards/FolderSettingsPage
'
;
import
TeamPages
from
'app/containers/Teams/TeamPages'
;
import
TeamList
from
'app/containers/Teams/TeamList'
;
...
...
@@ -99,7 +99,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
.
when
(
'/dashboards/f/:uid/:slug/settings'
,
{
template
:
'<react-container />'
,
resolve
:
{
component
:
()
=>
FolderSettings
,
component
:
()
=>
FolderSettings
Page
,
},
})
.
when
(
'/dashboards/f/:uid/:slug'
,
{
...
...
public/app/types/dashboard.ts
0 → 100644
View file @
59b5b146
export
interface
FolderDTO
{
id
:
number
;
title
:
string
;
url
:
string
;
version
:
number
;
hasAcl
:
boolean
;
}
public/app/types/index.ts
View file @
59b5b146
import
{
FolderDTO
}
from
'./dashboard'
;
export
{
FolderDTO
};
//
// Location
//
...
...
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