-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Migrate CreateDashboardDialog to React (#3826)
- Loading branch information
1 parent
5dff5b9
commit 9480d89
Showing
9 changed files
with
97 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
client/app/components/dashboards/CreateDashboardDialog.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { trim } from 'lodash'; | ||
import React, { useRef, useState, useEffect } from 'react'; | ||
import Modal from 'antd/lib/modal'; | ||
import Input from 'antd/lib/input'; | ||
import DynamicComponent from '@/components/DynamicComponent'; | ||
import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; | ||
import { $location, $http } from '@/services/ng'; | ||
import recordEvent from '@/services/recordEvent'; | ||
import { policy } from '@/services/policy'; | ||
|
||
function CreateDashboardDialog({ dialog }) { | ||
const [name, setName] = useState(''); | ||
const [isValid, setIsValid] = useState(false); | ||
const [saveInProgress, setSaveInProgress] = useState(false); | ||
const inputRef = useRef(); | ||
const isCreateDashboardEnabled = policy.isCreateDashboardEnabled(); | ||
|
||
// ANGULAR_REMOVE_ME Replace all this with `autoFocus` attribute (it does not work | ||
// if dialog is opened from Angular code, but works fine if open dialog from React code) | ||
useEffect(() => { | ||
const timer = setTimeout(() => { | ||
if (inputRef.current) { | ||
inputRef.current.focus(); | ||
} | ||
}, 100); | ||
return () => clearTimeout(timer); | ||
}, []); | ||
|
||
function handleNameChange(event) { | ||
const value = trim(event.target.value); | ||
setName(value); | ||
setIsValid(value !== ''); | ||
} | ||
|
||
function save() { | ||
if (name !== '') { | ||
setSaveInProgress(true); | ||
|
||
$http.post('api/dashboards', { name }) | ||
.then(({ data }) => { | ||
dialog.close(); | ||
$location.path(`/dashboard/${data.slug}`).search('edit').replace(); | ||
}); | ||
recordEvent('create', 'dashboard'); | ||
} | ||
} | ||
|
||
return ( | ||
<Modal | ||
{...dialog.props} | ||
{...(isCreateDashboardEnabled ? {} : { footer: null })} | ||
title="New Dashboard" | ||
okText="Save" | ||
cancelText="Close" | ||
okButtonProps={{ | ||
disabled: !isValid || saveInProgress, | ||
loading: saveInProgress, | ||
'data-test': 'DashboardSaveButton', | ||
}} | ||
cancelButtonProps={{ | ||
disabled: saveInProgress, | ||
}} | ||
onOk={save} | ||
closable={!saveInProgress} | ||
maskClosable={!saveInProgress} | ||
wrapProps={{ | ||
'data-test': 'CreateDashboardDialog', | ||
}} | ||
> | ||
<DynamicComponent name="CreateDashboardDialogExtra" disabled={!isCreateDashboardEnabled}> | ||
<Input | ||
ref={inputRef} | ||
defaultValue={name} | ||
onChange={handleNameChange} | ||
onPressEnter={save} | ||
placeholder="Dashboard Name" | ||
disabled={saveInProgress} | ||
/> | ||
</DynamicComponent> | ||
</Modal> | ||
); | ||
} | ||
|
||
CreateDashboardDialog.propTypes = { | ||
dialog: DialogPropType.isRequired, | ||
}; | ||
|
||
export default wrapDialog(CreateDashboardDialog); |
19 changes: 0 additions & 19 deletions
19
client/app/components/dashboards/edit-dashboard-dialog.html
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,11 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import { react2angular } from 'react2angular'; | ||
import classNames from 'classnames'; | ||
import { $uibModal } from '@/services/ng'; | ||
import CreateDashboardDialog from '@/components/dashboards/CreateDashboardDialog'; | ||
import { currentUser } from '@/services/auth'; | ||
import organizationStatus from '@/services/organizationStatus'; | ||
import './empty-state.less'; | ||
|
||
function createDashboard() { | ||
$uibModal.open({ | ||
component: 'editDashboardDialog', | ||
resolve: { | ||
dashboard: () => ({ name: null, layout: null }), | ||
}, | ||
}); | ||
} | ||
|
||
function Step({ show, completed, text, url, urlText, onClick }) { | ||
if (!show) { | ||
return null; | ||
|
@@ -131,7 +122,7 @@ export function EmptyState({ | |
<Step | ||
show={isAvailable.dashboard} | ||
completed={isCompleted.dashboard} | ||
onClick={createDashboard} | ||
onClick={() => CreateDashboardDialog.showModal()} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
kravets-levko
Author
Collaborator
|
||
urlText="Create" | ||
text="your first Dashboard" | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think this is a CSP regression: #4039