forked from apache/superset
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into feat/fileter_set
* upstream/master: fix(explore): Datepicker glitch on hover outside the modal (apache#15033) Add ming-height to empty tab (apache#14878) Remove nowrap (apache#14954) display all metric results in editor (apache#15031) feat: Add "is_select_query" method to base engine spec to make it possible to override it (apache#15013) fix(dashboard): custom css should be removed on unmount (apache#15025) feat(filter-box): hide druid options if druid not enabled (apache#14921) fix: adding additional configs and colors for queryHistory (apache#14995) chore: rename 'Source' to 'Database' for consistency (apache#15021) chore(ci): fix ci conflict (apache#15016) fix(native-filters): avoid double load on initialization (apache#15012) feat(native-filters): Support default to first value in select filter (apache#14869) docs: required information for OAuth2 configuration (apache#15010) Update index.mdx (apache#14990)
- Loading branch information
Showing
32 changed files
with
497 additions
and
246 deletions.
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
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
93 changes: 93 additions & 0 deletions
93
superset-frontend/src/dashboard/components/DashboardBuilder/state.ts
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,93 @@ | ||
/** | ||
* 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 { useSelector } from 'react-redux'; | ||
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags'; | ||
import { useEffect, useState } from 'react'; | ||
import { URL_PARAMS } from 'src/constants'; | ||
import { getUrlParam } from 'src/utils/urlUtils'; | ||
import { RootState } from 'src/dashboard/types'; | ||
import { | ||
useFilters, | ||
useNativeFiltersDataMask, | ||
} from '../nativeFilters/FilterBar/state'; | ||
import { Filter } from '../nativeFilters/types'; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const useNativeFilters = () => { | ||
const [isInitialized, setIsInitialized] = useState(false); | ||
const [dashboardFiltersOpen, setDashboardFiltersOpen] = useState( | ||
getUrlParam(URL_PARAMS.showFilters) ?? true, | ||
); | ||
const showNativeFilters = useSelector<RootState, boolean>( | ||
state => state.dashboardInfo.metadata?.show_native_filters, | ||
); | ||
const canEdit = useSelector<RootState, boolean>( | ||
({ dashboardInfo }) => dashboardInfo.dash_edit_perm, | ||
); | ||
|
||
const filters = useFilters(); | ||
const filterValues = Object.values<Filter>(filters); | ||
|
||
const nativeFiltersEnabled = | ||
showNativeFilters && | ||
isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) && | ||
(canEdit || (!canEdit && filterValues.length !== 0)); | ||
|
||
const requiredFirstFilter = filterValues.filter( | ||
({ requiredFirst }) => requiredFirst, | ||
); | ||
const dataMask = useNativeFiltersDataMask(); | ||
const showDashboard = | ||
isInitialized || | ||
!nativeFiltersEnabled || | ||
!( | ||
nativeFiltersEnabled && | ||
requiredFirstFilter.length && | ||
requiredFirstFilter.find( | ||
({ id }) => dataMask[id]?.filterState?.value === undefined, | ||
) | ||
); | ||
|
||
const toggleDashboardFiltersOpen = (visible?: boolean) => { | ||
setDashboardFiltersOpen(visible ?? !dashboardFiltersOpen); | ||
}; | ||
|
||
useEffect(() => { | ||
if ( | ||
filterValues.length === 0 && | ||
dashboardFiltersOpen && | ||
nativeFiltersEnabled | ||
) { | ||
toggleDashboardFiltersOpen(false); | ||
} | ||
}, [filterValues.length]); | ||
|
||
useEffect(() => { | ||
if (showDashboard) { | ||
setIsInitialized(true); | ||
} | ||
}, [showDashboard]); | ||
|
||
return { | ||
showDashboard, | ||
dashboardFiltersOpen, | ||
toggleDashboardFiltersOpen, | ||
nativeFiltersEnabled, | ||
}; | ||
}; |
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
Oops, something went wrong.