Skip to content
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

Merged
merged 5 commits into from
Mar 24, 2021

Conversation

AAfghahi
Copy link
Member

@AAfghahi AAfghahi commented Mar 3, 2021

SUMMARY

Changed the ScheduleQueryButton into a TypeScript function using react hooks.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen Shot 2021-03-03 at 1 40 38 PM

TEST PLAN

ADDITIONAL INFORMATION

@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch 2 times, most recently from e31d8f9 to adfa61d Compare March 4, 2021 22:17
}
WTF_CSRF_ENABLED = False
ENABLE_SCHEDULED_EMAIL_REPORTS = True
ENABLE_ALERTS = True
Copy link
Member

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.

Copy link
Member Author

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.

@pull-request-size pull-request-size bot added size/L and removed size/XL labels Mar 4, 2021
@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from e3a7513 to b3a288a Compare March 4, 2021 23:54
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.
Copy link
Member

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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getJSONSchema() {
const getJSONSchema = () => {

return {};
}

function getUISchema() {
Copy link
Member

@hughhhh hughhhh Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getUISchema() {
const getUISchema = () => {

return window.featureFlags.SCHEDULED_QUERIES?.UISCHEMA;
}

function getValidationRules() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getValidationRules() {
const getValidationRules = () => {

@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from b3a288a to f3a1f35 Compare March 8, 2021 23:27
import './ScheduleQueryButton.less';
import Button from 'src/components/Button';

const validators = {
Copy link
Member

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

Copy link
Member

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`
Copy link
Member

@eschutho eschutho Mar 19, 2021

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?

Copy link
Member Author

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.

Copy link
Member

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,
Copy link
Member

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 = '',
Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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>) => {
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

@eschutho eschutho Mar 19, 2021

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;
};

Copy link
Member Author

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!

@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch 3 times, most recently from b15046c to 4834d50 Compare March 19, 2021 19:53
@eschutho eschutho force-pushed the ScheduleQueryButton branch from 4834d50 to f3a1f35 Compare March 19, 2021 20:25
Copy link
Member

@eschutho eschutho left a 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}
Copy link
Member

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.

@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch 2 times, most recently from 8e0d4f7 to f5d99a7 Compare March 22, 2021 19:05
@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from f5d99a7 to 8cd3177 Compare March 22, 2021 20:23
@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from 8cd3177 to e85195e Compare March 22, 2021 20:24
@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #13443 (872f808) into master (452b530) will increase coverage by 0.24%.
The diff coverage is 28.12%.

❗ Current head 872f808 differs from pull request most recent head 318ba2a. Consider uploading reports for the commit 318ba2a to get more accurate results
Impacted file tree graph

@@            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     
Flag Coverage Δ
cypress 56.26% <14.81%> (+0.03%) ⬆️
javascript 63.55% <28.12%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...perset-frontend/src/components/FormLabel/index.tsx 100.00% <ø> (ø)
...tend/src/SqlLab/components/ScheduleQueryButton.tsx 28.12% <28.12%> (ø)
superset-frontend/src/chart/chartAction.js 78.60% <0.00%> (+9.85%) ⬆️
superset-frontend/src/chart/chartReducer.ts 66.19% <0.00%> (+17.59%) ⬆️
superset-frontend/src/middleware/asyncEvent.ts 78.03% <0.00%> (+24.48%) ⬆️
superset-frontend/src/dashboard/index.jsx 100.00% <0.00%> (+60.00%) ⬆️
superset-frontend/src/explore/index.jsx 100.00% <0.00%> (+62.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 452b530...318ba2a. Read the comment docs.

@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from 42e9ddf to 90473e3 Compare March 23, 2021 14:29
@AAfghahi AAfghahi force-pushed the ScheduleQueryButton branch from 90473e3 to 318ba2a Compare March 23, 2021 14:37
@eschutho
Copy link
Member

@hughhhh will finish the review on this.. thanks @AAfghahi for everything!

@hughhhh hughhhh merged commit 2c3d9e9 into apache:master Mar 24, 2021
hughhhh added a commit that referenced this pull request Mar 24, 2021
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants