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/03/10 09:18:46 UTC

[GitHub] [superset] ktmud commented on a change in pull request #19085: feat(select): keep options order when not in async mode

ktmud commented on a change in pull request #19085:
URL: https://github.com/apache/superset/pull/19085#discussion_r823313432



##########
File path: superset-frontend/src/components/TimezoneSelector/index.tsx
##########
@@ -92,6 +92,16 @@ const TIMEZONE_OPTIONS = TIMEZONES.map(zone => ({
   timezoneName: zone.name,
 }));
 
+const TIMEZONE_OPTIONS_SORT_COMPARTOR = (
+  a: typeof TIMEZONE_OPTIONS[number],
+  b: typeof TIMEZONE_OPTIONS[number],
+) =>
+  moment.tz(currentDate, a.timezoneName).utcOffset() -
+  moment.tz(currentDate, b.timezoneName).utcOffset();
+
+// pre-sort timezone options
+TIMEZONE_OPTIONS.sort(TIMEZONE_OPTIONS_SORT_COMPARTOR);

Review comment:
       Select control now expects `options` to be pre-sorted.

##########
File path: superset-frontend/packages/superset-ui-core/src/utils/isEqualArray.test.ts
##########
@@ -0,0 +1,31 @@
+/**
+ * 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 isEqualArray from './isEqualArray';

Review comment:
       Basically a faster version of `lodash.isEqual` where we only compare items in arrays shallowly. Also used in Table chart.

##########
File path: superset-frontend/src/explore/components/controls/SelectControl.jsx
##########
@@ -94,8 +94,8 @@ export default class SelectControl extends React.PureComponent {
 
   UNSAFE_componentWillReceiveProps(nextProps) {
     if (
-      nextProps.choices !== this.props.choices ||
-      nextProps.options !== this.props.options
+      !isEqualArray(nextProps.choices, this.props.choices) ||
+      !isEqualArray(nextProps.options, this.props.options)

Review comment:
       Had to run this deeper check because mapStateToProps may create columns list with a new array but same content. We may need to dig deeper to those excessive rerendering and check whether they are actually necessary.

##########
File path: superset-frontend/src/explore/components/controls/SelectControl.test.jsx
##########
@@ -37,9 +37,9 @@ const defaultProps = {
 };
 
 const options = [
-  { value: '1 year ago', label: '1 year ago', order: 0 },
-  { value: '1 week ago', label: '1 week ago', order: 1 },
-  { value: 'today', label: 'today', order: 2 },

Review comment:
       May do a bigger sweep in other components to clean up similar `order` props later.

##########
File path: superset-frontend/packages/superset-ui-core/src/utils/isEqualArray.ts
##########
@@ -23,9 +23,11 @@ export default function isEqualArray<T extends unknown[] | undefined | null>(
   return (
     arrA === arrB ||
     (!arrA && !arrB) ||
-    (arrA &&
+    !!(

Review comment:
       Making sure return result is always boolean




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