github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/redux/reducers/continuous/diffView.thunks.ts (about)

     1  import { renderDiff, RenderDiffResponse } from '@webapp/services/render';
     2  import { RequestAbortedError } from '@webapp/services/base';
     3  import { addNotification } from '../notifications';
     4  import { createAsyncThunk } from '../../async-thunk';
     5  import { ContinuousState } from './state';
     6  
     7  let diffViewAbortController: AbortController | undefined;
     8  
     9  export const fetchDiffView = createAsyncThunk<
    10    { profile: RenderDiffResponse },
    11    {
    12      leftQuery: string;
    13      leftFrom: string;
    14      leftUntil: string;
    15      rightQuery: string;
    16      rightFrom: string;
    17      rightUntil: string;
    18    },
    19    { state: { continuous: ContinuousState } }
    20  >('continuous/diffView', async (params, thunkAPI) => {
    21    if (diffViewAbortController) {
    22      diffViewAbortController.abort();
    23    }
    24  
    25    diffViewAbortController = new AbortController();
    26    thunkAPI.signal = diffViewAbortController.signal;
    27  
    28    const state = thunkAPI.getState();
    29    const res = await renderDiff(
    30      {
    31        ...params,
    32        maxNodes: state.continuous.maxNodes,
    33      },
    34      diffViewAbortController
    35    );
    36  
    37    if (res.isOk) {
    38      return Promise.resolve({ profile: res.value });
    39    }
    40  
    41    if (res.isErr && res.error instanceof RequestAbortedError) {
    42      return thunkAPI.rejectWithValue({ rejectedWithValue: 'reloading' });
    43    }
    44  
    45    thunkAPI.dispatch(
    46      addNotification({
    47        type: 'danger',
    48        title: 'Failed to load diff view',
    49        message: res.error.message,
    50      })
    51    );
    52  
    53    return Promise.reject(res.error);
    54  });