-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate Parameters component to React #4006
Merged
Merged
Changes from 36 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
0408f28
Start Parameters Migration
gabrieldutra 3cdc232
Merge branch 'master' into react-parameters
gabrieldutra 15419f6
Add dirtyCount
gabrieldutra 61541d4
Use workaround with setState
gabrieldutra d9dbef5
Apply Changes
gabrieldutra 2fe9a16
Add EditSettingsDialog
gabrieldutra 1d51a66
Add Cmd/Ctrl + Enter behavior
gabrieldutra 0ede83a
Remove isApplying
gabrieldutra cf49952
Delete Angular version of parameters
gabrieldutra f2ab142
Update tests
gabrieldutra 33db3bc
Remove angular stuff
gabrieldutra cdac798
Merge branch 'master' into react-parameters
gabrieldutra 5f81f3f
Merge branch 'master' into react-parameters
gabrieldutra 3fb3e3f
Update jest
gabrieldutra 01bca17
Drag placeholder
gabrieldutra 2c73726
Update events
gabrieldutra 9f0d1ab
Use old button styling and move css
gabrieldutra 7499226
Merge branch 'master' into react-parameters
gabrieldutra 0b928c0
Reviewing code
gabrieldutra 00d633d
Add parameter rearrange test
gabrieldutra 95f1a42
Add Parameter Settings title change test
gabrieldutra 9598d95
Update Parameter Settings button styling
gabrieldutra dab94d5
Move parameter url logic back to Parameters
gabrieldutra dfa60b6
Disable url update when query is new
gabrieldutra 2082493
Merge branch 'master' into react-parameters
gabrieldutra 0c0bf6e
Styling changes (#4019)
ranbena 649aaf5
Merge branch 'master' into react-parameters
gabrieldutra ed848ab
Ran's title width styling
gabrieldutra aab7058
Update drag test
gabrieldutra 9e679b9
Improve sizing for Number inputs
gabrieldutra 6cfb271
Fix issue with dragged parameter wrapping
gabrieldutra 5baf71e
Don't reevaluate dirtyParamCount
gabrieldutra 69fe667
Merge branch 'master' into react-parameters
gabrieldutra efc987f
Merge branch 'react-parameters' of github.com:getredash/redash into r…
gabrieldutra 8b7eec1
Merge branch 'master' into react-parameters
gabrieldutra cad5ff0
Allow multiple values :)
gabrieldutra 542f650
Fix parameter alignments
ranbena f2be99b
Fix Select width on search
gabrieldutra 58b1b72
Update client/app/components/Parameters.less
gabrieldutra aa097e3
Merge branch 'master' into react-parameters
gabrieldutra 5d22e49
Humanize param.name
gabrieldutra 2a28a18
Make sure angular updates Execute disabled status
gabrieldutra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,12 @@ | |
.parameter-input { | ||
display: inline-block; | ||
position: relative; | ||
width: 100%; | ||
|
||
.@{ant-prefix}-input[type="text"] { | ||
width: 195px; | ||
.@{ant-prefix}-input, | ||
.@{ant-prefix}-input-number, | ||
.@{ant-prefix}-select { | ||
ranbena marked this conversation as resolved.
Show resolved
Hide resolved
|
||
min-width: 100% !important; | ||
} | ||
|
||
&[data-dirty] { | ||
|
@@ -18,65 +21,3 @@ | |
} | ||
} | ||
} | ||
|
||
.parameter-container { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved to |
||
position: relative; | ||
|
||
.parameter-apply-button { | ||
display: none; // default for mobile | ||
|
||
// "floating" on desktop | ||
@media (min-width: 768px) { | ||
position: absolute; | ||
bottom: -42px; | ||
left: -15px; | ||
border-radius: 2px; | ||
z-index: 1; | ||
transition: opacity 150ms ease-out; | ||
box-shadow: 0 4px 9px -3px rgba(102, 136, 153, 0.15); | ||
background-color: #ffffff; | ||
padding: 4px; | ||
padding-left: 16px; | ||
opacity: 0; | ||
display: block; | ||
pointer-events: none; // so tooltip doesn't remain after button hides | ||
} | ||
|
||
&[data-show="true"] { | ||
opacity: 1; | ||
display: block; | ||
pointer-events: auto; | ||
} | ||
|
||
button { | ||
padding: 0 8px 0 6px; | ||
color: #2096f3; | ||
border-color: #50acf6; | ||
|
||
// smaller on desktop | ||
@media (min-width: 768px) { | ||
font-size: 12px; | ||
height: 27px; | ||
} | ||
|
||
&:hover, &:focus, &:active { | ||
background-color: #eef7fe; | ||
} | ||
|
||
i { | ||
margin-right: 3px; | ||
} | ||
} | ||
|
||
.ant-badge-count { | ||
min-width: 15px; | ||
height: 15px; | ||
padding: 0 5px; | ||
font-size: 10px; | ||
line-height: 15px; | ||
background: #f77b74; | ||
border-radius: 7px; | ||
box-shadow: 0px 0px 0 1px white, -1px 1px 0 1px #5d6f7d85; | ||
} | ||
} | ||
} |
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,202 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { size, filter, forEach, extend } from 'lodash'; | ||
import { react2angular } from 'react2angular'; | ||
import { sortableContainer, sortableElement, sortableHandle } from 'react-sortable-hoc'; | ||
import { $location } from '@/services/ng'; | ||
import { Parameter } from '@/services/query'; | ||
import ParameterApplyButton from '@/components/ParameterApplyButton'; | ||
import ParameterValueInput from '@/components/ParameterValueInput'; | ||
import EditParameterSettingsDialog from './EditParameterSettingsDialog'; | ||
|
||
import './Parameters.less'; | ||
|
||
const DragHandle = sortableHandle(({ parameterName }) => ( | ||
<div className="drag-handle" data-test={`DragHandle-${parameterName}`} /> | ||
)); | ||
|
||
const SortableItem = sortableElement(({ className, parameterName, disabled, children }) => ( | ||
<div className={className} data-editable={!disabled || null}> | ||
{!disabled && <DragHandle parameterName={parameterName} />} | ||
{children} | ||
</div> | ||
)); | ||
const SortableContainer = sortableContainer(({ children }) => children); | ||
|
||
function updateUrl(parameters) { | ||
const params = extend({}, $location.search()); | ||
parameters.forEach((param) => { | ||
extend(params, param.toUrlParams()); | ||
}); | ||
Object.keys(params).forEach(key => params[key] == null && delete params[key]); | ||
$location.search(params); | ||
} | ||
|
||
export class Parameters extends React.Component { | ||
static propTypes = { | ||
parameters: PropTypes.arrayOf(PropTypes.instanceOf(Parameter)), | ||
editable: PropTypes.bool, | ||
disableUrlUpdate: PropTypes.bool, | ||
onValuesChange: PropTypes.func, | ||
onParametersEdit: PropTypes.func, | ||
}; | ||
|
||
static defaultProps = { | ||
parameters: [], | ||
editable: false, | ||
disableUrlUpdate: false, | ||
onValuesChange: () => {}, | ||
onParametersEdit: () => {}, | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
const { parameters } = props; | ||
this.state = { parameters, dragging: false }; | ||
if (!props.disableUrlUpdate) { | ||
updateUrl(parameters); | ||
} | ||
} | ||
|
||
componentDidUpdate = (prevProps) => { | ||
const { parameters, disableUrlUpdate } = this.props; | ||
if (prevProps.parameters !== parameters) { | ||
this.setState({ parameters }); | ||
if (!disableUrlUpdate) { | ||
updateUrl(parameters); | ||
} | ||
} | ||
}; | ||
|
||
handleKeyDown = (e) => { | ||
// Cmd/Ctrl/Alt + Enter | ||
if (e.keyCode === 13 && (e.ctrlKey || e.metaKey || e.altKey)) { | ||
e.stopPropagation(); | ||
gabrieldutra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.applyChanges(); | ||
} | ||
}; | ||
|
||
setPendingValue = (param, value, isDirty) => { | ||
this.setState(({ parameters }) => { | ||
if (isDirty) { | ||
param.setPendingValue(value); | ||
} else { | ||
param.clearPendingValue(); | ||
} | ||
return { parameters }; | ||
}); | ||
}; | ||
|
||
moveParameter = ({ oldIndex, newIndex }) => { | ||
const { onParametersEdit } = this.props; | ||
if (oldIndex !== newIndex) { | ||
this.setState(({ parameters }) => { | ||
parameters.splice(newIndex, 0, parameters.splice(oldIndex, 1)[0]); | ||
onParametersEdit(); | ||
return { parameters }; | ||
}); | ||
} | ||
this.setState({ dragging: false }); | ||
}; | ||
|
||
onBeforeSortStart = () => { | ||
this.setState({ dragging: true }); | ||
}; | ||
|
||
applyChanges = () => { | ||
const { onValuesChange, disableUrlUpdate } = this.props; | ||
this.setState(({ parameters }) => { | ||
forEach(parameters, p => p.applyPendingValue()); | ||
onValuesChange(); | ||
if (!disableUrlUpdate) { | ||
updateUrl(parameters); | ||
} | ||
return { parameters }; | ||
}); | ||
}; | ||
|
||
showParameterSettings = (parameter, index) => { | ||
const { onParametersEdit } = this.props; | ||
EditParameterSettingsDialog | ||
.showModal({ parameter }) | ||
.result.then((updated) => { | ||
this.setState(({ parameters }) => { | ||
const updatedParameter = extend(parameter, updated); | ||
parameters[index] = new Parameter(updatedParameter, updatedParameter.parentQueryId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same idea here, but reconstructing the Parameter instead. |
||
onParametersEdit(); | ||
return { parameters }; | ||
}); | ||
}); | ||
}; | ||
|
||
renderParameter(param, index) { | ||
const { editable } = this.props; | ||
return ( | ||
<div | ||
key={param.name} | ||
className="di-block" | ||
data-test={`ParameterName-${param.name}`} | ||
> | ||
<div className="parameter-heading"> | ||
<label>{param.title || param.name}</label> | ||
{editable && ( | ||
<button | ||
className="btn btn-default btn-xs m-l-5" | ||
onClick={() => this.showParameterSettings(param, index)} | ||
data-test={`ParameterSettings-${param.name}`} | ||
type="button" | ||
> | ||
<i className="fa fa-cog" /> | ||
</button> | ||
)} | ||
</div> | ||
<ParameterValueInput | ||
type={param.type} | ||
value={param.normalizedValue} | ||
parameter={param} | ||
enumOptions={param.enumOptions} | ||
queryId={param.queryId} | ||
allowMultipleValues={!!param.multiValuesOptions} | ||
onSelect={(value, isDirty) => this.setPendingValue(param, value, isDirty)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
render() { | ||
const { parameters, dragging } = this.state; | ||
const { editable } = this.props; | ||
const dirtyParamCount = size(filter(parameters, 'hasPendingValue')); | ||
return ( | ||
<SortableContainer | ||
axis="xy" | ||
useDragHandle | ||
lockToContainerEdges | ||
helperClass="parameter-dragged" | ||
updateBeforeSortStart={this.onBeforeSortStart} | ||
onSortEnd={this.moveParameter} | ||
> | ||
<div | ||
className="parameter-container" | ||
onKeyDown={dirtyParamCount ? this.handleKeyDown : null} | ||
data-draggable={editable || null} | ||
data-dragging={dragging || null} | ||
> | ||
{parameters.map((param, index) => ( | ||
<SortableItem className="parameter-block" key={param.name} index={index} parameterName={param.name} disabled={!editable}> | ||
{this.renderParameter(param, index)} | ||
</SortableItem> | ||
))} | ||
|
||
<ParameterApplyButton onClick={this.applyChanges} paramCount={dirtyParamCount} /> | ||
</div> | ||
</SortableContainer> | ||
); | ||
} | ||
} | ||
|
||
export default function init(ngModule) { | ||
ngModule.component('parameters', react2angular(Parameters)); | ||
} | ||
|
||
init.init = true; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
isApplying
as it was not affecting anything.