-
Notifications
You must be signed in to change notification settings - Fork 17.8k
fix(AlertReportModal): Text Area Change #17176
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import { | |
| Position, | ||
| TextMode as OrigTextMode, | ||
| } from 'brace'; | ||
| import AceEditor, { AceEditorProps } from 'react-ace'; | ||
| import AceEditor, { IAceEditorProps } from 'react-ace'; | ||
| import AsyncEsmComponent, { | ||
| PlaceholderProps, | ||
| } from 'src/components/AsyncEsmComponent'; | ||
|
|
@@ -72,7 +72,7 @@ const aceModuleLoaders = { | |
|
|
||
| export type AceModule = keyof typeof aceModuleLoaders; | ||
|
|
||
| export type AsyncAceEditorProps = AceEditorProps & { | ||
| export type AsyncAceEditorProps = IAceEditorProps & { | ||
| keywords?: AceCompleterKeyword[]; | ||
| }; | ||
|
|
||
|
|
@@ -83,7 +83,7 @@ export type AsyncAceEditorOptions = { | |
| defaultTheme?: AceEditorTheme; | ||
| defaultTabSize?: number; | ||
| placeholder?: React.ComponentType< | ||
| PlaceholderProps & Partial<AceEditorProps> | ||
| PlaceholderProps & Partial<IAceEditorProps> | ||
| > | null; | ||
| }; | ||
|
|
||
|
|
@@ -120,7 +120,6 @@ export default function AsyncAceEditor( | |
| theme = inferredTheme, | ||
| tabSize = defaultTabSize, | ||
| defaultValue = '', | ||
| value = '', | ||
| ...props | ||
| }, | ||
| ref, | ||
|
|
@@ -153,7 +152,6 @@ export default function AsyncAceEditor( | |
| theme={theme} | ||
| tabSize={tabSize} | ||
| defaultValue={defaultValue} | ||
| value={value || ''} | ||
|
Member
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. There was a bug that I fixed on sql lab where if you passed in |
||
| {...props} | ||
| /> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,8 @@ | |
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import { TextArea } from 'src/common/components'; | ||
| import { debounce } from 'lodash'; | ||
| import { t } from '@superset-ui/core'; | ||
|
|
||
| import { FAST_DEBOUNCE } from 'src/constants'; | ||
| import Button from 'src/components/Button'; | ||
| import { TextAreaEditor } from 'src/components/AsyncAceEditor'; | ||
| import ModalTrigger from 'src/components/ModalTrigger'; | ||
|
|
@@ -32,7 +30,7 @@ import ControlHeader from 'src/explore/components/ControlHeader'; | |
| const propTypes = { | ||
| name: PropTypes.string, | ||
| onChange: PropTypes.func, | ||
| value: PropTypes.string, | ||
| defaultValue: PropTypes.string, | ||
| height: PropTypes.number, | ||
| minLines: PropTypes.number, | ||
| maxLines: PropTypes.number, | ||
|
|
@@ -51,7 +49,7 @@ const propTypes = { | |
|
|
||
| const defaultProps = { | ||
| onChange: () => {}, | ||
| value: '', | ||
| defaultValue: '', | ||
| height: 250, | ||
| minLines: 3, | ||
| maxLines: 10, | ||
|
|
@@ -60,29 +58,12 @@ const defaultProps = { | |
| }; | ||
|
|
||
| export default class TextAreaControl extends React.Component { | ||
| constructor() { | ||
| super(); | ||
| this.state = { | ||
| value: '', | ||
| }; | ||
| this.onAceChangeDebounce = debounce(value => { | ||
| this.onAceChange(value); | ||
| }, FAST_DEBOUNCE); | ||
| } | ||
|
|
||
| onControlChange(event) { | ||
| const { value } = event.target; | ||
| this.setState({ value }); | ||
| this.props.onChange(value); | ||
| } | ||
|
|
||
| onAceChange(value) { | ||
| this.setState({ value }); | ||
| this.props.onChange(value); | ||
| } | ||
|
|
||
| renderEditor(inModal = false) { | ||
| const value = this.state.value || this.props.value; | ||
| const minLines = inModal ? 40 : this.props.minLines || 12; | ||
| if (this.props.language) { | ||
| const style = { border: '1px solid #CCC' }; | ||
|
|
@@ -95,20 +76,21 @@ export default class TextAreaControl extends React.Component { | |
| style={style} | ||
| minLines={minLines} | ||
| maxLines={inModal ? 1000 : this.props.maxLines} | ||
| onChange={this.onAceChangeDebounce} | ||
| onChange={this.props.onChange} | ||
| width="100%" | ||
| height={`${minLines}em`} | ||
| editorProps={{ $blockScrolling: true }} | ||
| value={value} | ||
| defaultValue={this.props.defaultValue} | ||
| readOnly={this.props.readOnly} | ||
| key={this.props.name} | ||
| /> | ||
| ); | ||
| } | ||
| return ( | ||
| <TextArea | ||
| placeholder={t('textarea')} | ||
| onChange={this.onControlChange.bind(this)} | ||
| value={value} | ||
| value={this.props.defaultValue} | ||
|
Member
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 looks like it will never change value if you type in it?
Member
Author
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. |
||
| disabled={this.props.readOnly} | ||
| style={{ height: this.props.height }} | ||
| /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -440,6 +440,8 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({ | |
| NotificationSetting[] | ||
| >([]); | ||
|
|
||
| const generateKey = () => `${new Date().getTime()}`; | ||
|
|
||
| const onNotificationAdd = () => { | ||
| const settings: NotificationSetting[] = notificationSettings.slice(); | ||
|
|
||
|
|
@@ -1136,7 +1138,8 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({ | |
| maxLines={15} | ||
| onChange={onSQLChange} | ||
| readOnly={false} | ||
| value={currentAlert ? currentAlert.sql : ''} | ||
| defaultValue={currentAlert?.sql} | ||
|
Member
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. I think you want to pass in the resource.sql here. Otherwise you're passing in the latest state and not just the api response. This is likely why the TextArea component is continuing to update, too.
Member
Author
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. ok, that makes sense, though I created a new value prop that is passing in currentAlert?.sql in order to pass it in as value for the TextArea (which is the version that shows up when you don't designate a language).
Member
Author
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. my thought process was that since TextArea, unlike TextAreaControl, is a controlled component that we would need a changing value, which currentAlert.sql is. Looking through the code, there is currently no place where we do use TextArea, we always pass in a language. But I wanted to not accidentally mess something up. |
||
| key={currentAlert?.id || generateKey()} | ||
|
Member
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. does this generate a new key each time it rerenders?
Member
Author
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. yes, and I actually moved it over to the AlertReportModal because of this. Earlier I had done this and the state issue had still persisted, but when I test it now it is working fine. So I must have originally tested it during a bad iteration. |
||
| /> | ||
| </StyledInputContainer> | ||
| <div className="inline-container wrap"> | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.