-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
refactor: ScheduleQueryButton into functional component #13443
Conversation
e31d8f9
to
adfa61d
Compare
} | ||
WTF_CSRF_ENABLED = False | ||
ENABLE_SCHEDULED_EMAIL_REPORTS = True | ||
ENABLE_ALERTS = True |
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.
you'll want to move this into you superset_config in your root folder so that it's not committed.
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.
is that a folder that I have to create? I don't see it.
e3a7513
to
b3a288a
Compare
const [label, setLabel] = useState(defaultLabel); | ||
const [showSchedule, setShowSchedule] = useState(false); | ||
let saveModal: any; | ||
// this is for the ref that is created in the modal trigger. the modal is created in order to use the .close() function on it. |
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.
is this comment still valid?
less_equal: (a: number, b: number) => a <= b, | ||
}; | ||
|
||
function getJSONSchema() { |
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.
function getJSONSchema() { | |
const getJSONSchema = () => { |
return {}; | ||
} | ||
|
||
function getUISchema() { |
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.
function getUISchema() { | |
const getUISchema = () => { |
return window.featureFlags.SCHEDULED_QUERIES?.UISCHEMA; | ||
} | ||
|
||
function getValidationRules() { |
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.
function getValidationRules() { | |
const getValidationRules = () => { |
b3a288a
to
f3a1f35
Compare
import './ScheduleQueryButton.less'; | ||
import Button from 'src/components/Button'; | ||
|
||
const validators = { |
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.
nit: move this to the /src/utils
directory
@@ -78,7 +78,6 @@ class CeleryConfig(object): | |||
|
|||
CELERY_CONFIG = CeleryConfig | |||
SQLLAB_CTAS_NO_LIMIT = True | |||
|
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.
just for code cleanliness, I would revert this change.
padding-bottom: ${({ theme }) => theme.gridUnit * 2}px; | ||
`; | ||
|
||
const ButtonComponent = styled.div` |
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.
where did these styles come from? Are they new or copied? Can we bring the theming into it?
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.
I copied them from what the styled divs looked like. It is because I switched this from being a div to being a button component because there were TypeScript issues with the div component having an onClick and a disabled option.
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.
You can also (for consistency) call this StyledButtonComponent
and then instead of use a div to wrap the button, you can do styled(Button)` and then you don't have to wrap this around the button element, but just use this as the tag.
Example:
export const CopyButton = styled(Button)` |
(Assume it's called StyledCopyButton though :))
schema, | ||
dbId, | ||
onSchedule = () => {}, | ||
scheduleQueryWarning = null, |
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.
per the props above this will never be undefined so you're not going to hit this default. If you feel you need this default because there's not enough type checking going on with the other files, then you can set the typescript prop as optional, but not sure if you need it. You may have to look through the code to see if it's there intentionally.
dbId, | ||
onSchedule = () => {}, | ||
scheduleQueryWarning = null, | ||
tooltip = '', |
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.
same thing here
const [description, setDescription] = useState(''); | ||
const [label, setLabel] = useState(defaultLabel); | ||
const [showSchedule, setShowSchedule] = useState(false); | ||
let saveModal: any; |
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.
suggestion: can you make this a type of ref or undefined?
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.
Done! What's the reasoning behind it being undefined though?
const [showSchedule, setShowSchedule] = useState(false); | ||
let saveModal: any; | ||
|
||
const onScheduleSubmit = ({ formData }: Record<string, any>) => { |
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.
does this formData have a type? Can you do something like ({ formData }: {formData: HTMLFormData})
? That's just a guess on the type
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.
is this a second deconstruction? {formData: HTMLFormData}
VERSIONED_EXPORT?: boolean; | ||
GLOBAL_ASYNC_QUERIES?: boolean; | ||
ENABLE_TEMPLATE_PROCESSING?: boolean; | ||
ENABLE_EXPLORE_DRAG_AND_DROP?: boolean; |
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.
You should be able to do this instead:
export type FeatureFlagMap = {
[key in Exclude<FeatureFlag, FeatureFlag.SCHEDULED_QUERIES>]?: boolean;
} & {
SCHEDULED_QUERIES?: ScheduleQueriesProps;
};
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.
this looks way better, thank you so much!
b15046c
to
4834d50
Compare
4834d50
to
f3a1f35
Compare
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.
few other suggestions..
<Button | ||
onClick={() => setShowSchedule(!showSchedule)} | ||
buttonSize="small" | ||
tooltip={tooltip} |
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.
I think we lost disabled
here.. also you can add buttonStyle="link"
and it will get you most of the styles that you need.
8e0d4f7
to
f5d99a7
Compare
f5d99a7
to
8cd3177
Compare
8cd3177
to
e85195e
Compare
Codecov Report
@@ Coverage Diff @@
## master #13443 +/- ##
==========================================
+ Coverage 77.16% 77.40% +0.24%
==========================================
Files 933 933
Lines 47383 47190 -193
Branches 5928 5878 -50
==========================================
- Hits 36563 36528 -35
+ Misses 10672 10520 -152
+ Partials 148 142 -6
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
42e9ddf
to
90473e3
Compare
90473e3
to
318ba2a
Compare
…)" This reverts commit 2c3d9e9.
SUMMARY
Changed the ScheduleQueryButton into a TypeScript function using react hooks.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
ADDITIONAL INFORMATION