-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
fix(dashboard): FilterBox JS error when datasets API is slow #15993
Merged
serenajiang
merged 3 commits into
apache:master
from
airbnb:filterbox-datasource-lazyload-fix
Jul 31, 2021
Merged
Changes from all commits
Commits
Show all changes
3 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
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
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 |
---|---|---|
|
@@ -16,11 +16,11 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import { snakeCase } from 'lodash'; | ||
import { snakeCase, isEqual } from 'lodash'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { SuperChart, logging, Behavior } from '@superset-ui/core'; | ||
import { Logger, LOG_ACTIONS_RENDER_CHART } from '../logger/LogUtils'; | ||
import { Logger, LOG_ACTIONS_RENDER_CHART } from 'src/logger/LogUtils'; | ||
|
||
const propTypes = { | ||
annotationData: PropTypes.object, | ||
|
@@ -93,7 +93,7 @@ class ChartRenderer extends React.Component { | |
nextProps.queriesResponse !== this.props.queriesResponse; | ||
return ( | ||
this.hasQueryResponseChange || | ||
nextProps.datasource !== this.props.datasource || | ||
!isEqual(nextProps.datasource, this.props.datasource) || | ||
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. 👍 |
||
nextProps.annotationData !== this.props.annotationData || | ||
nextProps.ownState !== this.props.ownState || | ||
nextProps.filterState !== this.props.filterState || | ||
|
@@ -183,8 +183,8 @@ class ChartRenderer extends React.Component { | |
const { | ||
width, | ||
height, | ||
annotationData, | ||
datasource, | ||
annotationData, | ||
initialValues, | ||
ownState, | ||
filterState, | ||
|
@@ -224,7 +224,7 @@ class ChartRenderer extends React.Component { | |
width={width} | ||
height={height} | ||
annotationData={annotationData} | ||
datasource={datasource || {}} | ||
datasource={datasource} | ||
initialValues={initialValues} | ||
formData={formData} | ||
ownState={ownState} | ||
|
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
import { DatasourceType } from '@superset-ui/core'; | ||
import { Datasource } from 'src/dashboard/types'; | ||
/** | ||
* 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. | ||
*/ | ||
export const PLACEHOLDER_DATASOURCE: Datasource = { | ||
id: 0, | ||
type: DatasourceType.Table, | ||
uid: '_placeholder_', | ||
datasource_name: '', | ||
table_name: '', | ||
columns: [], | ||
column_types: [], | ||
metrics: [], | ||
column_format: {}, | ||
verbose_map: {}, | ||
main_dttm_col: '', | ||
description: '', | ||
}; |
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
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* 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 { ChartProps, Datasource } from '@superset-ui/core'; | ||
|
||
export interface FilterConfig { | ||
column: string; | ||
label: string; | ||
} | ||
|
||
export type FilterBoxChartProps = ChartProps & { | ||
datasource?: Datasource; | ||
formData: ChartProps['formData'] & { filterConfigs: FilterConfig[] }; | ||
}; |
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 |
---|---|---|
|
@@ -287,20 +287,30 @@ def data_for_slices(self, slices: List[Slice]) -> Dict[str, Any]: | |
for param in METRIC_FORM_DATA_PARAMS: | ||
for metric in utils.get_iterable(form_data.get(param) or []): | ||
metric_names.add(utils.get_metric_name(metric)) | ||
|
||
if utils.is_adhoc_metric(metric): | ||
column_names.add( | ||
(metric.get("column") or {}).get("column_name") | ||
) | ||
|
||
# pull out all required columns from the form_data | ||
for filter_ in form_data.get("adhoc_filters") or []: | ||
if filter_["clause"] == "WHERE" and filter_.get("subject"): | ||
column_names.add(filter_.get("subject")) | ||
# Columns used in query filters | ||
column_names.update( | ||
filter_["subject"] | ||
for filter_ in form_data.get("adhoc_filters") or [] | ||
if filter_.get("clause") == "WHERE" and filter_.get("subject") | ||
) | ||
|
||
for param in COLUMN_FORM_DATA_PARAMS: | ||
for column in utils.get_iterable(form_data.get(param) or []): | ||
column_names.add(column) | ||
# columns used by Filter Box | ||
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. ONE LINER CHALLENGE! column_names.update(filter_config["column"] for filter_config in form_data.get("filter_configs", []) if filter_config and "column" in filter_config) |
||
column_names.update( | ||
filter_config["column"] | ||
for filter_config in form_data.get("filter_configs") or [] | ||
if "column" in filter_config | ||
) | ||
|
||
column_names.update( | ||
column | ||
for column in utils.get_iterable(form_data.get(param) or []) | ||
for param in COLUMN_FORM_DATA_PARAMS | ||
) | ||
|
||
filtered_metrics = [ | ||
metric | ||
|
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.
Allow more
if
branches instead of suppressing thetoo-many-branches
error inline.cc @villebro @john-bodley @etr2460
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.
Yikes! This is an anti-pattern in my opinion. The check is there for a reason to prevent non-readable code. If one must override this, it should be done locally and not globally.