nytai commented on a change in pull request #10510:
URL: 
https://github.com/apache/incubator-superset/pull/10510#discussion_r465365535



##########
File path: superset-frontend/src/views/CRUD/utils.tsx
##########
@@ -59,3 +59,56 @@ export function createErrorHandler(handleErrorFunc: 
(errMsg?: string) => void) {
     handleErrorFunc(parsedError.message);
   };
 }
+
+export function createFaveStarHandlers(
+  baseURL: string,
+  context: any,
+  handleErrorFunc: (message: string) => void,
+) {
+  const fetchFaveStar = (id: number) => {
+    SupersetClient.get({
+      endpoint: `${baseURL}/${id}/count/`,
+    })
+      .then(({ json }) => {
+        const faves = {
+          ...context.state.favoriteStatus,
+        };
+
+        faves[id] = json.count > 0;
+
+        context.setState({
+          favoriteStatus: faves,
+        });
+      })
+      .catch(() =>
+        handleErrorFunc('There was an error fetching the favorite status'),

Review comment:
       let's wrap this in a `t` string for i18n. 

##########
File path: superset-frontend/src/views/CRUD/utils.tsx
##########
@@ -59,3 +59,56 @@ export function createErrorHandler(handleErrorFunc: 
(errMsg?: string) => void) {
     handleErrorFunc(parsedError.message);
   };
 }
+
+export function createFaveStarHandlers(
+  baseURL: string,
+  context: any,
+  handleErrorFunc: (message: string) => void,
+) {
+  const fetchFaveStar = (id: number) => {
+    SupersetClient.get({
+      endpoint: `${baseURL}/${id}/count/`,
+    })
+      .then(({ json }) => {
+        const faves = {
+          ...context.state.favoriteStatus,
+        };
+
+        faves[id] = json.count > 0;
+
+        context.setState({
+          favoriteStatus: faves,
+        });
+      })
+      .catch(() =>
+        handleErrorFunc('There was an error fetching the favorite status'),
+      );
+  };
+
+  const saveFaveStar = (id: number, isStarred: boolean) => {
+    const urlSuffix = isStarred ? 'unselect' : 'select';
+
+    SupersetClient.get({
+      endpoint: `${baseURL}/${id}/${urlSuffix}/`,
+    })
+      .then(() => {
+        const faves = {
+          ...context.state.favoriteStatus,
+        };
+
+        faves[id] = !isStarred;
+
+        context.setState({
+          favoriteStatus: faves,
+        });
+      })
+      .catch(() =>
+        handleErrorFunc('There was an error saving the favorite status'),

Review comment:
       same here




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