-
Notifications
You must be signed in to change notification settings - Fork 14.9k
fix: always pass a string as a value to ace editor #13563
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React, { ReactNode } from 'react'; | ||
import { | ||
render, | ||
fireEvent, | ||
getByText, | ||
waitFor, | ||
} from 'spec/helpers/testing-library'; | ||
import brace from 'brace'; | ||
import { ThemeProvider, supersetTheme } from '@superset-ui/core'; | ||
|
||
import TemplateParamsEditor from 'src/SqlLab/components/TemplateParamsEditor'; | ||
|
||
const ThemeWrapper = ({ children }: { children: ReactNode }) => ( | ||
<ThemeProvider theme={supersetTheme}>{children}</ThemeProvider> | ||
); | ||
|
||
describe('TemplateParamsEditor', () => { | ||
it('should render with a title', () => { | ||
const { container } = render( | ||
<TemplateParamsEditor code="FOO" language="json" onChange={() => {}} />, | ||
{ wrapper: ThemeWrapper }, | ||
); | ||
expect(container.querySelector('div[role="button"]')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should open a modal with the ace editor', async () => { | ||
const { container, baseElement } = render( | ||
<TemplateParamsEditor code="FOO" language="json" onChange={() => {}} />, | ||
{ wrapper: ThemeWrapper }, | ||
); | ||
fireEvent.click(getByText(container, 'Parameters')); | ||
const spy = jest.spyOn(brace, 'acequire'); | ||
spy.mockReturnValue({ setCompleters: () => 'foo' }); | ||
await waitFor(() => { | ||
expect(baseElement.querySelector('#brace-editor')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -119,6 +119,7 @@ export default function AsyncAceEditor( | |||||||
mode = inferredMode, | ||||||||
theme = inferredTheme, | ||||||||
tabSize = defaultTabSize, | ||||||||
defaultValue = '', | ||||||||
...props | ||||||||
}, | ||||||||
ref, | ||||||||
|
@@ -150,7 +151,8 @@ export default function AsyncAceEditor( | |||||||
mode={mode} | ||||||||
theme={theme} | ||||||||
tabSize={tabSize} | ||||||||
{...props} | ||||||||
defaultValue={defaultValue} | ||||||||
{...{ ...props, value: props.value || '' }} | ||||||||
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. The syntax here looks alien. 😄 Why not:
Suggested change
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. ha, yeah, that was my first implementation, but often people like to see the "rest" props at the end, and so I anticipated someone changing this order in the context of "cleanup". I think I found a way around this.. lmk what you think. |
||||||||
/> | ||||||||
); | ||||||||
}, | ||||||||
|
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.
how about this?
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.
When we are convert
SqlEditor.jsx
to the typescript, we can add function parameter type again.superset/superset-frontend/src/SqlLab/components/SqlEditor.jsx
Lines 512 to 518 in d439da2
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.
We should be getting to it soon, and then, yes we'll be able to manage types of props better, ya!