You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/02/18 12:42:25 UTC

[GitHub] [superset] michael-s-molina commented on a change in pull request #18793: [WIP] feat: Adds support to multiple dependencies to the native filters

michael-s-molina commented on a change in pull request #18793:
URL: https://github.com/apache/superset/pull/18793#discussion_r809964276



##########
File path: superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DependencyList.tsx
##########
@@ -0,0 +1,198 @@
+/**
+ * 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, { useState } from 'react';
+import { styled, t } from '@superset-ui/core';
+import Icons from 'src/components/Icons';
+import { Select } from 'src/components';
+import { CollapsibleControl } from './CollapsibleControl';
+
+interface DependencyListProps {
+  availableFilters: { label: string; value: string }[];
+  dependencies: string[];
+  onDependenciesChange: (dependencies: string[]) => void;
+}
+
+const MainPanel = styled.div`
+  display: flex;
+  flex-direction: column;
+`;
+
+const AddFilter = styled.div`
+  ${({ theme }) => `
+    display: inline-flex;
+    flex-direction: row;
+    align-items: center;
+    cursor: pointer;
+    color: ${theme.colors.primary.base};
+    &:hover {
+      color: ${theme.colors.primary.dark1};
+    }
+  `}
+`;
+
+const DeleteFilter = styled(Icons.Trash)`
+  ${({ theme }) => `
+    cursor: pointer;
+    margin-left: ${theme.gridUnit * 2}px;
+    color: ${theme.colors.grayscale.base};
+    &:hover {
+      color: ${theme.colors.grayscale.dark1};
+    }
+  `}
+`;
+
+const RowPanel = styled.div`
+  ${({ theme }) => `
+    display: flex;
+    width: 220px;
+    flex-direction: row;
+    align-items: center;
+    margin-bottom: ${theme.gridUnit}px;
+  `}
+`;
+
+const Label = styled.div`
+  text-transform: uppercase;
+  font-size: ${({ theme }) => theme.typography.sizes.s}px;
+  color: ${({ theme }) => theme.colors.grayscale.base};
+  margin-bottom: ${({ theme }) => theme.gridUnit}px;
+`;
+
+const Row = ({
+  availableFilters,
+  selection,
+  onChange,
+  onDelete,
+}: {
+  availableFilters: { label: string; value: string }[];
+  selection: string;
+  onChange: (id: string, value: string) => void;
+  onDelete: (id: string) => void;
+}) => (
+  <RowPanel>
+    <Select
+      ariaLabel={t('Limit type')}
+      labelInValue
+      options={availableFilters}
+      onChange={option =>
+        onChange(selection, (option as { value: string }).value)
+      }
+      value={availableFilters.find(e => e.value === selection)}
+    />
+    <DeleteFilter iconSize="xl" onClick={() => onDelete(selection)} />
+  </RowPanel>
+);
+
+const List = ({
+  availableFilters = [],
+  dependencies = [],
+  onDependenciesChange,
+}: DependencyListProps) => {
+  const [rows, setRows] = useState<string[]>(dependencies);
+
+  const updateRows = (newRows: string[]) => {
+    setRows(newRows);
+    onDependenciesChange(newRows);
+  };
+
+  const onAdd = () => {
+    const filter = availableFilters.find(e => !rows.includes(e.value));
+    const newRows = [...rows];
+    newRows.push(filter!.value);
+    updateRows(newRows);
+  };
+
+  const onChange = (id: string, value: string) => {
+    const indexOf = rows.findIndex(e => e === id);

Review comment:
       I think this check is not necessary because it will always find the id.




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

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org