ktmud commented on code in PR #19979:
URL: https://github.com/apache/superset/pull/19979#discussion_r867247847


##########
superset-frontend/src/explore/components/controls/SelectControl.jsx:
##########
@@ -160,6 +164,17 @@ export default class SelectControl extends 
React.PureComponent {
     return filterOption({ data: option }, text);
   }
 
+  handleSelectAll() {
+    /**
+     * Function to handle select all button.
+     * Adds all options to the selected values.
+     */

Review Comment:
   ```suggestion
     /**
      * Function to handle select all button.
      * Adds all options to the selected values.
      */
     handleSelectAll() {
   ```
   
   Nit: normally we put function doc string above the function name.



##########
superset-frontend/src/explore/components/SelectAllButton/index.tsx:
##########
@@ -0,0 +1,49 @@
+/**
+ * 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 { t, css, SupersetTheme } from '@superset-ui/core';
+import Button, { OnClickHandler } from 'src/components/Button';
+
+export type SelectAllButtonProps = {
+  onSelectAll: OnClickHandler;
+  selectMode: () => boolean;
+  deselectEnabled: boolean;
+};
+
+export const SelectAllButton = ({
+  onSelectAll,
+  selectMode = () => true,
+  deselectEnabled = false,
+  }: SelectAllButtonProps) =>
+  (
+    <Button
+      buttonStyle={'link'}
+      disabled={deselectEnabled ? false : !selectMode()}
+      css={(theme: SupersetTheme) =>
+        css`
+          padding: 0;
+        `
+      }
+      onClick={onSelectAll}
+    >
+      {deselectEnabled && !selectMode()? t('Deselect All'): t('Select All')}

Review Comment:
   ```suggestion
         {deselectEnabled && !selectMode()? t('Deselect all'): t('Select all')}
   ```
   
   We use sentence case for control buttons. Although in this case it doesn't 
matter since it's all capitalized by CSS.



##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndColumnSelect.tsx:
##########
@@ -229,6 +271,7 @@ export function DndColumnSelect(props: 
DndColumnSelectProps) {
             ? openPopover
             : undefined
         }
+        selectAllButton={showSelectAllButton ? <SelectAllButton 
{...selectAllButtonProps} /> : null}

Review Comment:
   ```suggestion
           selectAllButton={
             showSelectAllButton ? (
               <Button
                 buttonStyle="link" 
                 disabled={hasSelectedAll}
                 onClick={
                   hasSelectedAll
                    ? undefined
                    : () => hasSelectedSome ? deselectAll() : selectAll()
                  }
               >
                 {hasSelectedSome ? t('Deselect all') : t('Select all')}
               </Button>
             ) : null
           }
   ```
   
   I think it's possible to directly render the button without all the "mode" 
conversion. This should make things easier to understand.



##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndSelectLabel.tsx:
##########
@@ -43,11 +43,17 @@ export type DndSelectLabelProps = {
   valuesRenderer: () => ReactNode;
   displayGhostButton?: boolean;
   onClickGhostButton?: () => void;
+  /**
+   * Adds a select all button next to the header, allowing the user to 
+   * select all options in one click. Can only be a SelectAllButton or null.  
+   */
+  selectAllButton?: ReactNode;

Review Comment:
   ```suggestion
     headerAfter?: ReactNode;
   ```
   
   I think it's okay to make this node more generic. You never know if you want 
to add a different type of control here. For example, in non-DnD mode adhoc 
metrics control, this is a plus button.



##########
superset-frontend/src/explore/components/SelectAllButton/index.tsx:
##########
@@ -0,0 +1,49 @@
+/**
+ * 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 { t, css, SupersetTheme } from '@superset-ui/core';
+import Button, { OnClickHandler } from 'src/components/Button';
+
+export type SelectAllButtonProps = {
+  onSelectAll: OnClickHandler;
+  selectMode: () => boolean;
+  deselectEnabled: boolean;
+};
+
+export const SelectAllButton = ({
+  onSelectAll,
+  selectMode = () => true,
+  deselectEnabled = false,
+  }: SelectAllButtonProps) =>
+  (
+    <Button
+      buttonStyle={'link'}
+      disabled={deselectEnabled ? false : !selectMode()}
+      css={(theme: SupersetTheme) =>
+        css`
+          padding: 0;
+        `
+      }

Review Comment:
   ```suggestion
         css={{ padding: 0 }}
   ```
   
   Since `theme` is not used, this should be good enough.



##########
superset-frontend/plugins/plugin-chart-table/src/controlPanel.tsx:
##########
@@ -118,6 +118,7 @@ const all_columns: typeof sharedControls.groupby = {
   }),
   visibility: isRawMode,
   resetOnHide: false,
+  showSelectAllButton: true,

Review Comment:
   ```suggestion
     showSelectAll: true,
   ```
   
   I think it's okay to call this prop `showSelectAll` in case we want to 
change how the "select all" trigger looks like.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to