Repository: apache/superset
File: superset-frontend/src/features/alerts/AlertReportModal.tsx (TypeScript)

Code before:
        }).then(response => {
          const list = response.json.result.map(
            (item: { value: number; text: string }) => ({
              value: item.value,
              label: item.text,
            }),
          );
          setSourceOptions(list);
          return { data: list, totalCount: response.json.count };
        });
      },
    [],
  );

  const dashboard = currentAlert?.dashboard;
  useEffect(() => {
    if (!tabsEnabled) return;

    if (dashboard?.value) {
      SupersetClient.get({
        endpoint: `/api/v1/dashboard/${dashboard.value}/tabs`,
      }).then(response => {
        const { tab_tree: tabTree, all_tabs: allTabs } = response.json.result;
        setTabOptions(tabTree);
        if (currentAlert?.extra?.dashboard?.anchor) {
          if (!(currentAlert?.extra?.dashboard?.anchor in allTabs)) {
            updateAnchorState(undefined);
          }
        }
      });
    }
  }, [dashboard, tabsEnabled, currentAlert?.extra]);

  const databaseLabel = currentAlert?.database && !currentAlert.database.label;
  useEffect(() => {
    // Find source if current alert has one set
    if (databaseLabel) {
      updateAlertState('database', getSourceData());
    }
  }, [databaseLabel, getSourceData]);

  const loadDashboardOptions = useMemo(
    () =>
      (input = '', page: number, pageSize: number) => {
        const query = rison.encode_uri({
          filter: input,
          page,
          page_size: pageSize,
        });
        return SupersetClient.get({
          endpoint: `/api/v1/report/related/dashboard?q=${query}`,

Review comment (suggestion):
You are already checking above if this exists. Maybe it would help readability to move it inside a const.

```
const anchor = currentAlert?.extra?.dashboard?.anchor
if (anchor && !anchor in allTabs)...
```

Code after:
          page,
          page_size: pageSize,
        });
        return SupersetClient.get({
          endpoint: `/api/v1/report/related/database?q=${query}`,
        }).then(response => {
          const list = response.json.result.map(
            (item: { value: number; text: string }) => ({
              value: item.value,
              label: item.text,
            }),
          );
          setSourceOptions(list);
          return { data: list, totalCount: response.json.count };
        });
      },
    [],
  );

  const dashboard = currentAlert?.dashboard;
  useEffect(() => {
    if (!tabsEnabled) return;

    if (dashboard?.value) {
      SupersetClient.get({
        endpoint: `/api/v1/dashboard/${dashboard.value}/tabs`,
      })
        .then(response => {
          const { tab_tree: tabTree, all_tabs: allTabs } = response.json.result;
          setTabOptions(tabTree);
          const anchor = currentAlert?.extra?.dashboard?.anchor;
          if (anchor && !(anchor in allTabs)) {
            updateAnchorState(undefined);
          }
        })
        .catch(() => {
          addDangerToast(t('There was an error retrieving dashboard tabs.'));
        });
    }
  }, [dashboard, tabsEnabled, currentAlert?.extra, addDangerToast]);

  const databaseLabel = currentAlert?.database && !currentAlert.database.label;
  useEffect(() => {
    // Find source if current alert has one set
    if (databaseLabel) {
      updateAlertState('database', getSourceData());
    }
  }, [databaseLabel, getSourceData]);

  const loadDashboardOptions = useMemo(
    () =>