villebro commented on a change in pull request #14869:
URL: https://github.com/apache/superset/pull/14869#discussion_r642412820
##########
File path:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
##########
@@ -49,9 +48,9 @@ import {
import FilterBar from 'src/dashboard/components/nativeFilters/FilterBar';
import { StickyVerticalBar } from '../StickyVerticalBar';
import { shouldFocusTabs, getRootLevelTabsComponent } from './utils';
-import { useFilters } from '../nativeFilters/FilterBar/state';
-import { Filter } from '../nativeFilters/types';
import DashboardContainer from './DashboardContainer';
+import Loading from '../../../components/Loading';
Review comment:
nit
```
import Loading from 's/components/Loading';
```
##########
File path: superset-frontend/src/dashboard/components/DashboardBuilder/state.ts
##########
@@ -0,0 +1,89 @@
+/**
+ * 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 {
+ useFilters,
+ useNativeFiltersDataMask,
+} from '../nativeFilters/FilterBar/state';
+import { Filter } from '../nativeFilters/types';
+import { RootState } from '../../types';
+
+// eslint-disable-next-line import/prefer-default-export
+export const useNativeFilters = () => {
+ const [isInitialized, setIsInitialized] = useState(false);
+ const [dashboardFiltersOpen, setDashboardFiltersOpen] = useState(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
+ ? true
+ : !nativeFiltersEnabled ||
+ !(
+ nativeFiltersEnabled &&
+ requiredFirstFilter.length &&
+ requiredFirstFilter.find(
Review comment:
This seems simpler
```suggestion
const showDashboard =
isInitialized ||
!nativeFiltersEnabled ||
!(
nativeFiltersEnabled &&
requiredFirstFilter.length &&
requiredFirstFilter.find(
({ id }) => dataMask[id]?.filterState?.value === undefined,
)
);
```
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
##########
@@ -599,9 +601,11 @@ const FiltersConfigForm = (
if (hasValue) {
return Promise.resolve();
}
- return Promise.reject(
- new Error(t('Default value is required')),
- );
+ return Promise.resolve();
+ // TODO: Some values does default value empty and
disabled so there is no value
+ // return Promise.reject(
+ // new Error(t('Default value is required')),
+ // );
Review comment:
I don't think we need to make this change - AFAIK it's enough to set the
"default to first value" option and save, so no need to check the "default
value" checkbox. I'd rather state in the description tooltip of the "default to
first value" option that when using this option, setting a default value is not
possible.
##########
File path:
superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
##########
@@ -159,15 +138,12 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () =>
{
(hideDashboardHeader ? 0 : HEADER_HEIGHT) +
(topLevelTabs ? TABS_HEIGHT : 0);
- useEffect(() => {
- if (
- filterValues.length === 0 &&
- dashboardFiltersOpen &&
- nativeFiltersEnabled
- ) {
- toggleDashboardFiltersOpen(false);
- }
- }, [filterValues.length]);
+ const {
+ showDashboard,
+ dashboardFiltersOpen,
+ toggleDashboardFiltersOpen,
+ nativeFiltersEnabled,
+ } = useNativeFilters();
Review comment:
good idea to split out into own hook 👍
##########
File path:
superset-frontend/src/filters/components/Select/SelectFilterPlugin.tsx
##########
@@ -16,6 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+/* eslint-disable no-param-reassign */
Review comment:
thought: if we want to encourage use of `useImmerReducer`, we should
probably disable this linting rule.
##########
File path:
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DefaultValue.tsx
##########
@@ -62,7 +62,7 @@ const DefaultValue: FC<DefaultValueProps> = ({
) : (
<SuperChart
height={25}
- width={250}
+ width={180}
Review comment:
This feels slightly tight:

Maybe we should leave this change to a separate PR if it's needed so we can
concentrate on the design aspects there and make this PR focus only on
functional fixes related to the first value option?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]