rusackas commented on a change in pull request #11814:
URL: 
https://github.com/apache/incubator-superset/pull/11814#discussion_r544836682



##########
File path: superset-frontend/src/components/SupersetResourceSelect.tsx
##########
@@ -0,0 +1,106 @@
+/**
+ * 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, { useEffect } from 'react';
+import rison from 'rison';
+import { SupersetClient } from '@superset-ui/core';
+import { AsyncSelect } from 'src/components/Select';
+import {
+  ClientErrorObject,
+  getClientErrorObject,
+} from 'src/utils/getClientErrorObject';
+
+export type Value<V> = { value: V; label: string };
+
+export interface SupersetResourceSelectProps<T = unknown, V = string> {
+  value?: Value<V> | null;
+  initialId?: number | string;
+  onChange?: (value: Value<V>) => void;
+  isMulti?: boolean;
+  searchColumn?: string;
+  resource?: string; // e.g. "dataset", "dashboard/related/owners"
+  transformItem?: (item: T) => Value<V>;
+  onError: (error: ClientErrorObject) => void;
+}
+
+/**
+ * This is a special-purpose select component for when you're selecting
+ * items from one of the standard Superset resource APIs.
+ * Such as selecting a datasource, a chart, or users.
+ *
+ * If you're selecting a "related" resource (such as dashboard/related/owners),
+ * leave the searchColumn prop unset.
+ * The api doesn't do columns on related resources for some reason.
+ *
+ * If you're doing anything more complex than selecting a standard resource,
+ * we'll all be better off if you use AsyncSelect directly instead.
+ */
+export default function SupersetResourceSelect<T, V>({
+  value,
+  initialId,
+  onChange,
+  isMulti,
+  resource,
+  searchColumn,
+  transformItem,
+  onError,
+}: SupersetResourceSelectProps<T, V>) {
+  useEffect(() => {
+    if (initialId == null) return;
+    SupersetClient.get({
+      endpoint: `/api/v1/${resource}/${initialId}`,
+    }).then(response => {
+      const { result } = response.json;
+      const value = transformItem ? transformItem(result) : result;
+      if (onChange) onChange(value);

Review comment:
       I thought I added a lint rule requiring curlies... wonder if you got 
through that somehow...




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

Reply via email to