lyndsiWilliams commented on code in PR #22043:
URL: https://github.com/apache/superset/pull/22043#discussion_r1072727729


##########
superset-frontend/src/views/CRUD/data/hooks.ts:
##########
@@ -75,11 +76,36 @@ export function useQueryPreviewState<D extends 
BaseQueryObject = any>({
   };
 }
 
-export const UseGetDatasetsList = (queryParams: string | undefined) =>
-  SupersetClient.get({
-    endpoint: `/api/v1/dataset/?q=${queryParams}`,
-  })
-    .then(({ json }) => json)
-    .catch(error =>
-      logging.error('There was an error fetching dataset', error),
-    );
+export const useGetDatasetsList = (queryParams: string | undefined) => {
+  const [datasets, setDatasets] = useState<DatasetObject[]>([]);
+
+  const getDatasetsList = () =>
+    SupersetClient.get({
+      endpoint: `/api/v1/dataset/?q=${queryParams}`,
+    })
+      .then(({ json }) => {
+        setDatasets(json?.result);
+      })
+      .catch(error =>
+        logging.error('There was an error fetching dataset', error),
+      );
+
+  const datasetNames = datasets?.map(dataset => dataset.table_name);
+
+  return { getDatasetsList, datasets, datasetNames };
+};
+
+export const useGetDatasetRelatedObjects = (id: string) => {
+  const [usageCount, setUsageCount] = useState(0);
+
+  const getDatasetRelatedObjects = () =>
+    SupersetClient.get({
+      endpoint: `/api/v1/dataset/${id}/related_objects`,
+    })
+      .then(({ json }) => {
+        setUsageCount(json?.charts.count);
+      })
+      .catch(error => logging.error(error));

Review Comment:
   #22610 changes all the errors to use toasts, once it's merged I will be 
bringing those changes into this PR.



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