villebro commented on a change in pull request #13210:
URL: https://github.com/apache/superset/pull/13210#discussion_r581981699
##########
File path: superset-frontend/src/explore/components/OptionControls.tsx
##########
@@ -92,7 +92,26 @@ export const LabelsContainer = styled.div`
border-radius: ${({ theme }) => theme.gridUnit}px;
`;
-export const AddControlLabel = styled.div`
+export const DndLabelsContainer = styled.div<{
+ canDrop?: boolean;
+ isOver?: boolean;
+}>`
+ padding: ${({ theme }) => theme.gridUnit}px;
+ border: ${({ canDrop, isOver, theme }) => {
+ if (isOver && canDrop) {
+ return `dashed 1px ${theme.colors.info.dark1}`;
+ }
+ if (isOver && !canDrop) {
+ return `dashed 1px ${theme.colors.error.dark1}`;
+ }
Review comment:
It feels like `dashed 1px` doesn't stick out quite enough. IMO `2px`
looked better, but then the default `1 px` causes this to resize when hovering
in/out, so that doesn't work quite so well without addditional tuning of the
default borders.
##########
File path:
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelectLabel.tsx
##########
@@ -0,0 +1,114 @@
+/**
+ * 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 { useDrop } from 'react-dnd';
+import { isEmpty } from 'lodash';
+import { t, useTheme } from '@superset-ui/core';
+import { BaseControlConfig, ColumnMeta } from '@superset-ui/chart-controls';
+import ControlHeader from 'src/explore/components/ControlHeader';
+import {
+ AddControlLabel,
+ HeaderContainer,
+ LabelsContainer,
+} from 'src/explore/components/OptionControls';
+import {
+ DatasourcePanelDndType,
+ DatasourcePanelDndItem,
+} from 'src/explore/components/DatasourcePanel/types';
+import Icon from 'src/components/Icon';
+import OptionWrapper from './components/OptionWrapper';
+import { OptionSelector } from './utils';
+
+interface LabelProps extends BaseControlConfig {
+ name: string;
+ value: string[] | string | null;
+ onChange: (value: string[] | string | null) => void;
+ options: { string: ColumnMeta };
+}
+
+export default function DndColumnSelectLabel(props: LabelProps) {
Review comment:
Agree with both - this should be made generic, but as a first POC behind
a FF I'm ok with this being more specific and making it more generic later.
##########
File path:
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelectLabel.tsx
##########
@@ -0,0 +1,118 @@
+/**
+ * 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 { useDrop } from 'react-dnd';
+import { isEmpty } from 'lodash';
+import { t, withTheme, SupersetTheme } from '@superset-ui/core';
+import { BaseControlConfig, ColumnMeta } from '@superset-ui/chart-controls';
+import ControlHeader from 'src/explore/components/ControlHeader';
+import {
+ AddControlLabel,
+ HeaderContainer,
+ LabelsContainer,
+} from 'src/explore/components/OptionControls';
+import {
+ DatasourcePanelDndType,
+ DatasourcePanelDndItem,
+} from 'src/explore/components/DatasourcePanel/types';
+import Icon from 'src/components/Icon';
+import OptionWrapper from './components/OptionWrapper';
+import { OptionSelector } from './utils';
+
+interface LabelProps extends BaseControlConfig {
+ name: string;
+ value: string[] | string | null;
+ onChange: (value: string[] | string | null) => void;
+ options: { string: ColumnMeta };
+ theme: SupersetTheme;
+}
+
+function DndColumnSelectLabel(props: LabelProps) {
+ const { value, options } = props;
+ const optionSelector = new OptionSelector(options, value);
+ const [groupByOptions, setGroupByOptions] = useState<ColumnMeta[]>(
+ optionSelector.groupByOptions,
+ );
+
+ const [, datasourcePanelDrop] = useDrop({
+ accept: DatasourcePanelDndType.COLUMN,
+
+ drop: (item: DatasourcePanelDndItem) => {
+ optionSelector.add(item.metricOrColumnName);
+ setGroupByOptions(optionSelector.groupByOptions);
+ props.onChange(optionSelector.getValues());
+ },
+
+ canDrop: (item: DatasourcePanelDndItem) =>
+ !optionSelector.has(item.metricOrColumnName),
+
+ collect: monitor => ({
+ isOver: monitor.isOver(),
+ canDrop: monitor.canDrop(),
+ }),
+ });
+
+ function onClickClose(index: number) {
+ optionSelector.del(index);
+ setGroupByOptions(optionSelector.groupByOptions);
+ props.onChange(optionSelector.getValues());
+ }
+
+ function onShiftOptions(dragIndex: number, hoverIndex: number) {
+ optionSelector.swap(dragIndex, hoverIndex);
+ setGroupByOptions(optionSelector.groupByOptions);
+ props.onChange(optionSelector.getValues());
+ }
+
+ function placeHolderRenderer() {
+ return (
+ <AddControlLabel cancelHover>
Review comment:
I personally feel it's better to offer the users the option of using the
traditional approach, especially as long there is a sensible control which you
can click. While e.g. Tableau AFAIK only supports dnd interaction, in that UI
it makes more sense, but in Superset I feel it's still a perfectly valid path
to adding filters/metrics/columns.
##########
File path:
superset-frontend/src/explore/components/controls/DndColumnSelectControl/utils/optionSelector.ts
##########
@@ -0,0 +1,86 @@
+/**
+ * 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 { ColumnMeta } from '@superset-ui/chart-controls';
+
+export class OptionSelector {
+ groupByOptions: ColumnMeta[];
+
+ options: { string: ColumnMeta };
+
+ isScalar: boolean;
+
+ constructor(
+ options: { string: ColumnMeta },
+ values: string[] | string | null,
+ ) {
+ this.options = options;
+ let groupByValues: string[];
+ if (Array.isArray(values)) {
+ groupByValues = values;
+ this.isScalar = false;
+ } else {
+ groupByValues = values ? [values] : [];
+ this.isScalar = true;
+ }
Review comment:
This might just be me, but I feel the term `scalar` can cause confusion
here (in mathematics a scalar is a real number, which in the context of JS
would be `number`). I'd rather use `isArray` to highlight that this refers to
distinguishing between a arrays and non-arrays.
----------------------------------------------------------------
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]