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 2020/12/31 10:09:10 UTC

[GitHub] [incubator-superset] villebro commented on a change in pull request #12154: feat: move filters from superset-ui to incubator

villebro commented on a change in pull request #12154:
URL: https://github.com/apache/incubator-superset/pull/12154#discussion_r550446787



##########
File path: superset-frontend/src/filters/components/Select/AntdSelectFilter.tsx
##########
@@ -0,0 +1,97 @@
+/**
+ * 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 { styled } from '@superset-ui/core';
+import React, { useEffect, useState } from 'react';
+import { Select } from 'src/common/components';
+import { DEFAULT_FORM_DATA, AntdPluginFilterSelectProps } from './types';
+import { AntdPluginFilterStylesProps } from '../types';
+import { getSelectExtraFormData } from '../../utils';
+
+const Styles = styled.div<AntdPluginFilterStylesProps>`
+  height: ${({ height }) => height};
+  width: ${({ width }) => width};
+`;
+
+const { Option } = Select;
+
+export default function AntdPluginFilterSelect(
+  props: AntdPluginFilterSelectProps,
+) {
+  const [values, setValues] = useState<(string | number)[]>([]);
+  const DELIMITER = '!^&@%#*!@';

Review comment:
       While we're moving these over we can probably try to clean up some of this code. As it currently stands I believe we only support single column groupbys, hence we can probably remove the delimiter logic and tackle this properly when we do add multi-column groupby support to the component.

##########
File path: superset-frontend/src/filters/components/Select/transformProps.ts
##########
@@ -0,0 +1,36 @@
+/**
+ * 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, DataRecord } from '@superset-ui/core';
+import { DEFAULT_FORM_DATA } from './types';
+
+export default function transformProps(chartProps: ChartProps) {
+  const { formData, height, hooks, queriesData, width } = chartProps;
+  const newFormData = { ...DEFAULT_FORM_DATA, ...formData };
+  const { setExtraFormData = () => {} } = hooks;
+
+  const data = queriesData[0]?.data as DataRecord[];

Review comment:
       Same here about the typing vs casting

##########
File path: superset-frontend/src/filters/components/Range/transformProps.ts
##########
@@ -0,0 +1,33 @@
+/**
+ * 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, DataRecord } from '@superset-ui/core';
+
+export default function transformProps(chartProps: ChartProps) {
+  const { formData, height, hooks, queriesData, width } = chartProps;
+  const { setExtraFormData } = hooks;
+  const data = queriesData[0]?.data as DataRecord[];

Review comment:
       We can probably do typing here instead of casting, like
   ```suggestion
     const data: DataRecord[] = queriesData[0].data || [] ;
   ```

##########
File path: superset-frontend/src/filters/utils.ts
##########
@@ -0,0 +1,65 @@
+import { QueryObjectFilterClause } from '@superset-ui/core';
+
+export const getSelectExtraFormData = (
+  col: string,
+  value?: undefined | null | string[] | number[],
+  emptyFilter = false,
+  inverseSelection = false,
+) => ({
+  append_form_data: emptyFilter
+    ? {
+        extras: {
+          where: '1 = 0',
+        },
+      }
+    : {
+        filters:
+          value === undefined || value === null || value.length === 0
+            ? []
+            : [
+                {
+                  col,
+                  op: inverseSelection ? ('NOT IN' as const) : ('IN' as const),
+                  val: value,
+                },
+              ],
+      },
+});

Review comment:
       Could we add a few unit tests for this?

##########
File path: superset-frontend/src/filters/utils.ts
##########
@@ -0,0 +1,65 @@
+import { QueryObjectFilterClause } from '@superset-ui/core';
+
+export const getSelectExtraFormData = (
+  col: string,
+  value?: undefined | null | string[] | number[],
+  emptyFilter = false,
+  inverseSelection = false,
+) => ({
+  append_form_data: emptyFilter
+    ? {
+        extras: {
+          where: '1 = 0',
+        },
+      }
+    : {
+        filters:
+          value === undefined || value === null || value.length === 0
+            ? []
+            : [
+                {
+                  col,
+                  op: inverseSelection ? ('NOT IN' as const) : ('IN' as const),
+                  val: value,
+                },
+              ],
+      },
+});
+
+/**
+ * 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 getRangeExtraFormData = (
+  col: string,
+  lower?: number,
+  upper?: number,
+) => {
+  const filters: QueryObjectFilterClause[] = [];
+  if (lower !== undefined && lower !== null) {
+    filters.push({ col, op: '>=', val: lower });
+  }
+  if (upper !== undefined && upper !== null) {
+    filters.push({ col, op: '>=', val: upper });
+  }
+
+  return {
+    append_form_data: {
+      filters,
+    },
+  };
+};

Review comment:
       A few tests for this would also be nice.

##########
File path: superset-frontend/src/filters/utils.ts
##########
@@ -0,0 +1,65 @@
+import { QueryObjectFilterClause } from '@superset-ui/core';
+
+export const getSelectExtraFormData = (
+  col: string,
+  value?: undefined | null | string[] | number[],
+  emptyFilter = false,
+  inverseSelection = false,
+) => ({
+  append_form_data: emptyFilter
+    ? {
+        extras: {
+          where: '1 = 0',
+        },
+      }
+    : {
+        filters:
+          value === undefined || value === null || value.length === 0
+            ? []
+            : [
+                {
+                  col,
+                  op: inverseSelection ? ('NOT IN' as const) : ('IN' as const),
+                  val: value,
+                },
+              ],
+      },
+});
+
+/**
+ * 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.
+ */

Review comment:
       The license header should be moved to the beginning of the file




----------------------------------------------------------------
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:
users@infra.apache.org



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