graceguo-supercat commented on a change in pull request #8404: 
[WIP][feature]Dashboard filter scope selector modal
URL: 
https://github.com/apache/incubator-superset/pull/8404#discussion_r342834253
 
 

 ##########
 File path: 
superset/assets/src/dashboard/components/filterscope/FilterScopeSelector.jsx
 ##########
 @@ -0,0 +1,518 @@
+/**
+ * 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 React from 'react';
+import PropTypes from 'prop-types';
+import cx from 'classnames';
+import { Button } from 'react-bootstrap';
+import { t } from '@superset-ui/translation';
+import { safeStringify } from '../../../utils/safeStringify';
+
+import getFilterScopeNodesTree from '../../util/getFilterScopeNodesTree';
+import getFilterFieldNodesTree from '../../util/getFilterFieldNodesTree';
+import getFilterScopeParentNodes from '../../util/getFilterScopeParentNodes';
+import getCurrentScopeChartIds from '../../util/getCurrentScopeChartIds';
+import getRevertedFilterScope from '../../util/getRevertedFilterScope';
+import FilterScopeTree from './FilterScopeTree';
+import FilterFieldTree from './FilterFieldTree';
+import {
+  getChartIdAndColumnFromFilterKey,
+  getDashboardFilterKey,
+} from '../../util/getDashboardFilterKey';
+
+const propTypes = {
+  dashboardFilters: PropTypes.object.isRequired,
+  layout: PropTypes.object.isRequired,
+  filterImmuneSlices: PropTypes.arrayOf(PropTypes.number).isRequired,
+  filterImmuneSliceFields: PropTypes.object.isRequired,
+  setDirectPathToChild: PropTypes.func.isRequired,
+  onCloseModal: PropTypes.func.isRequired,
+};
+
+export default class FilterScopeSelector extends React.PureComponent {
+  constructor(props) {
+    super(props);
+
+    const {
+      dashboardFilters,
+      filterImmuneSlices,
+      filterImmuneSliceFields,
+      layout,
+    } = props;
+
+    if (Object.keys(dashboardFilters).length > 0) {
+      // display filter fields in tree structure
+      const filterFieldNodes = getFilterFieldNodesTree({
+        dashboardFilters,
+        isSingleEditMode: true,
+      });
+      this.allfilterFields = [];
+      filterFieldNodes.forEach(({ children }) => {
+        children.forEach(child => {
+          this.allfilterFields.push(child.value);
+        });
+      });
+
+      if (filterFieldNodes.length && filterFieldNodes[0].children) {
+        this.defaultFilterKey = filterFieldNodes[0].children[0].value;
+      }
+      const checkedFilterFields = [this.defaultFilterKey];
+      // expand defaultFilterKey
+      const { chartId } = getChartIdAndColumnFromFilterKey(
+        this.defaultFilterKey,
+      );
+      const expandedFilterIds = [chartId];
+
+      // display checkbox tree of whole dashboard layout
+      const filterScopeMap = Object.values(dashboardFilters).reduce(
+        (map, { chartId: filterId, columns }) => {
+          const filterScopeByChartId = Object.keys(columns).reduce(
+            (mapByChartId, columnName) => {
+              const filterKey = getDashboardFilterKey({
+                chartId: filterId,
+                column: columnName,
+              });
+              const nodes = getFilterScopeNodesTree({
+                components: layout,
+                isSingleEditMode: true,
+                checkedFilterFields,
+                selectedChartId: filterId,
+              });
+              const checked = getCurrentScopeChartIds({
+                scopeComponentIds: ['ROOT_ID'], // 
dashboardFilters[chartId].scopes[columnName],
 
 Review comment:
   by default, or all new filter field, their scope should be all dashboard 
charts. But after user change/set new scope for a filter field, the new scope 
object will be stored in redux state (and saved to dashboard metadata in 
backend).
   When user open filter scope selector, the saved filter scope will be 
pre-populated from redux store. This line is mock data for this component. It 
will be changed in the next PR.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to