-
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
Param fix #3528
Merged
Param fix #3528
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { includes, words, capitalize, clone, isNull } from 'lodash'; | ||
|
||
import { includes, startsWith, words, capitalize, clone, isNull } from 'lodash'; | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Modal from 'antd/lib/modal'; | ||
import Form from 'antd/lib/form'; | ||
import Checkbox from 'antd/lib/checkbox'; | ||
import Button from 'antd/lib/button'; | ||
import Select from 'antd/lib/select'; | ||
import Input from 'antd/lib/input'; | ||
import Divider from 'antd/lib/divider'; | ||
|
@@ -18,8 +20,16 @@ function getDefaultTitle(text) { | |
return capitalize(words(text).join(' ')); // humanize | ||
} | ||
|
||
function NameInput({ name, onChange, existingNames, setValidation }) { | ||
let helpText = `This is what will be added to your query editor {{ ${name} }}`; | ||
function isTypeDate(type) { | ||
return startsWith('date', type) && !isTypeDateRange(type); | ||
} | ||
|
||
function isTypeDateRange(type) { | ||
return startsWith('date-range', type); | ||
} | ||
|
||
function NameInput({ name, type, onChange, existingNames, setValidation }) { | ||
let helpText = ''; | ||
let validateStatus = ''; | ||
|
||
if (!name) { | ||
|
@@ -30,6 +40,16 @@ function NameInput({ name, onChange, existingNames, setValidation }) { | |
setValidation(false); | ||
validateStatus = 'error'; | ||
} else { | ||
if (isTypeDateRange(type)) { | ||
helpText = ( | ||
<React.Fragment> | ||
Appears in query as {' '} | ||
<code style={{ display: 'inline-block', color: 'inherit' }}> | ||
{`{{${name}.start}} {{${name}.end}}`} | ||
</code> | ||
</React.Fragment> | ||
); | ||
} | ||
setValidation(true); | ||
} | ||
|
||
|
@@ -41,7 +61,7 @@ function NameInput({ name, onChange, existingNames, setValidation }) { | |
validateStatus={validateStatus} | ||
{...formItemProps} | ||
> | ||
<Input onChange={e => onChange(e.target.value)} /> | ||
<Input onChange={e => onChange(e.target.value)} autoFocus /> | ||
</Form.Item> | ||
); | ||
} | ||
|
@@ -51,6 +71,7 @@ NameInput.propTypes = { | |
onChange: PropTypes.func.isRequired, | ||
existingNames: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
setValidation: PropTypes.func.isRequired, | ||
type: PropTypes.string.isRequired, | ||
}; | ||
|
||
function EditParameterSettingsDialog(props) { | ||
|
@@ -89,7 +110,7 @@ function EditParameterSettingsDialog(props) { | |
return true; | ||
} | ||
|
||
function onConfirm() { | ||
function onConfirm(e) { | ||
// update title to default | ||
if (!param.title) { | ||
// forced to do this cause param won't update in time for save | ||
|
@@ -98,23 +119,31 @@ function EditParameterSettingsDialog(props) { | |
} | ||
|
||
props.dialog.close(param); | ||
|
||
e.preventDefault(); // stops form redirect | ||
} | ||
|
||
return ( | ||
<Modal | ||
{...props.dialog.props} | ||
title={isNew ? 'Add Parameter' : param.name} | ||
onOk={onConfirm} | ||
okText={isNew ? 'Add Parameter' : null} | ||
okButtonProps={{ disabled: !isFulfilled() }} | ||
width={600} | ||
footer={[( | ||
<Button key="cancel" onClick={props.dialog.dismiss}>Cancel</Button> | ||
), ( | ||
<Button key="submit" htmlType="submit" disabled={!isFulfilled()} type="primary" form="paramForm"> | ||
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. This is way better to handle Forms in Modals 🚀 |
||
{isNew ? 'Add Parameter' : 'OK'} | ||
</Button> | ||
)]} | ||
> | ||
<Form layout="horizontal"> | ||
<Form layout="horizontal" onSubmit={onConfirm} id="paramForm"> | ||
{isNew && ( | ||
<NameInput | ||
name={param.name} | ||
onChange={name => setParam({ ...param, name })} | ||
setValidation={setIsNameValid} | ||
existingNames={props.existingParams} | ||
type={param.type} | ||
/> | ||
)} | ||
<Form.Item label="Title" {...formItemProps}> | ||
|
@@ -143,7 +172,7 @@ function EditParameterSettingsDialog(props) { | |
<Option value="datetime-range-with-seconds">Date and Time Range (with seconds)</Option> | ||
</Select> | ||
</Form.Item> | ||
{includes(['date', 'datetime-local', 'datetime-with-seconds'], param.type) && ( | ||
{isTypeDate(param.type) && ( | ||
arikfr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Form.Item label=" " colon={false} {...formItemProps}> | ||
<Checkbox | ||
defaultChecked={param.useCurrentDateTime} | ||
|
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.
What about date/time range?
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.
🤦♂️ Fixed with
/-range/.test(type);