github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/components/exportToFlamegraphDotCom.hook.ts (about)

     1  import { Profile } from '@pyroscope/models/src';
     2  import { shareWithFlamegraphDotcom } from '@webapp/services/share';
     3  import { useAppDispatch } from '@webapp/redux/hooks';
     4  import handleError from '@webapp/util/handleError';
     5  
     6  export default function useExportToFlamegraphDotCom(
     7    flamebearer?: Profile,
     8    groupByTag?: string,
     9    groupByTagValue?: string
    10  ) {
    11    const dispatch = useAppDispatch();
    12  
    13    return async (name?: string) => {
    14      if (!flamebearer) {
    15        return '';
    16      }
    17  
    18      const res = await shareWithFlamegraphDotcom({
    19        flamebearer,
    20        name,
    21        // or we should add this to name ?
    22        groupByTag,
    23        groupByTagValue,
    24      });
    25  
    26      if (res.isErr) {
    27        handleError(dispatch, 'Failed to export to flamegraph.com', res.error);
    28        return null;
    29      }
    30  
    31      return res.value.url;
    32    };
    33  }