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

     1  import * as annotationsService from '@webapp/services/annotations';
     2  import { addNotification } from '../notifications';
     3  import { createAsyncThunk } from '../../async-thunk';
     4  
     5  // TODO(eh-am): support different views
     6  export const addAnnotation = createAsyncThunk(
     7    'continuous/addAnnotation',
     8    async (newAnnotation: annotationsService.NewAnnotation, thunkAPI) => {
     9      const res = await annotationsService.addAnnotation(newAnnotation);
    10  
    11      if (res.isOk) {
    12        return Promise.resolve({
    13          annotation: res.value,
    14        });
    15      }
    16  
    17      thunkAPI.dispatch(
    18        addNotification({
    19          type: 'danger',
    20          title: 'Failed to add annotation',
    21          message: res.error.message,
    22        })
    23      );
    24  
    25      return Promise.reject(res.error);
    26    }
    27  );