ktmud commented on a change in pull request #11435: URL: https://github.com/apache/incubator-superset/pull/11435#discussion_r516262148
########## File path: superset-frontend/src/explore/components/controls/withAsyncVerification.tsx ########## @@ -0,0 +1,224 @@ +/** + * 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, { + ComponentType, + useCallback, + useEffect, + useRef, + useState, +} from 'react'; +import sharedControlComponents from '@superset-ui/chart-controls/lib/shared-controls/components'; +import { ExtraControlProps } from '@superset-ui/chart-controls'; +import { JsonArray, JsonValue, t } from '@superset-ui/core'; +import { ControlProps } from 'src/explore/components/Control'; +import builtInControlComponents from 'src/explore/components/controls'; + +/** + * Full control component map. + */ +const controlComponentMap = { + ...builtInControlComponents, + ...sharedControlComponents, +}; + +export type SharedControlComponent = keyof typeof controlComponentMap; + +/** + * The actual props passed to the control component itself + * (not src/explore/components/Control.tsx). + */ +export type ControlPropsWithExtras = Omit<ControlProps, 'type'> & + ExtraControlProps; + +/** + * The full props passed to control component. Including withAsyncVerification + * related props and `onChange` event + `hovered` state from Control.tsx. + */ +export type FullControlProps = ControlPropsWithExtras & { + onChange?: (value: JsonValue) => void; + hovered?: boolean; + /** + * An extra flag for triggering async verification. Set it in mapStateToProps. + */ + needAsyncVerification?: boolean; Review comment: It's possible not all charts or datasources or a combination of control values need async verification. This flag allows users to skip calling the async verifier so the `withAsyncVerification` HOC doesn't have to set and reset loading state (which triggers two unnecessary re-renderings). ########## File path: superset-frontend/src/explore/components/controls/withAsyncVerification.tsx ########## @@ -0,0 +1,224 @@ +/** + * 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, { + ComponentType, + useCallback, + useEffect, + useRef, + useState, +} from 'react'; +import sharedControlComponents from '@superset-ui/chart-controls/lib/shared-controls/components'; +import { ExtraControlProps } from '@superset-ui/chart-controls'; +import { JsonArray, JsonValue, t } from '@superset-ui/core'; +import { ControlProps } from 'src/explore/components/Control'; +import builtInControlComponents from 'src/explore/components/controls'; + +/** + * Full control component map. + */ +const controlComponentMap = { + ...builtInControlComponents, + ...sharedControlComponents, +}; + +export type SharedControlComponent = keyof typeof controlComponentMap; + +/** + * The actual props passed to the control component itself + * (not src/explore/components/Control.tsx). + */ +export type ControlPropsWithExtras = Omit<ControlProps, 'type'> & + ExtraControlProps; + +/** + * The full props passed to control component. Including withAsyncVerification + * related props and `onChange` event + `hovered` state from Control.tsx. + */ +export type FullControlProps = ControlPropsWithExtras & { + onChange?: (value: JsonValue) => void; + hovered?: boolean; + /** + * An extra flag for triggering async verification. Set it in mapStateToProps. + */ + needAsyncVerification?: boolean; + /** + * Whether to show loading state when verification is still loading. + */ + showLoadingState?: boolean; + verify?: AsyncVerify; +}; + +/** + * The async verification function that accepts control props and returns a + * promise resolving to extra props if overrides are needed. + */ +export type AsyncVerify = ( + props: ControlPropsWithExtras, +) => Promise<ExtraControlProps | undefined | null>; + +/** + * Whether the extra props will update the original props. + */ +function hasUpdates( + props: ControlPropsWithExtras, + newProps: ExtraControlProps, +) { + return ( + props !== newProps && + Object.entries(newProps).some(([key, value]) => { + if (Array.isArray(props[key]) && Array.isArray(value)) { + const sourceValue: JsonArray = props[key]; + return ( + sourceValue.length !== value.length || + sourceValue.some((x, i) => x !== value[i]) Review comment: Yes, if the order changed, then the array should be considered changed. ########## File path: superset-frontend/src/messageToasts/actions/index.ts ########## @@ -19,6 +19,8 @@ import shortid from 'shortid'; import { ToastType, ToastMeta } from '../types'; +type ToastOptions = Partial<Omit<ToastMeta, 'id' | 'toastType' | 'text'>>; Review comment: A new `noDuplicate` option was added in case the same verification endpoint returns the same error message. We could extract this change to a new PR but that PR would miss some context. Plus I'm also lazy. ---------------------------------------------------------------- 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]
