github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/snackbarReducer.ts (about)

     1  import {
     2    CLOSE_SNACKBAR,
     3    SnackbarActionTypes,
     4  } from "../actions/snackbarActions";
     5  import {
     6    BATCH_CANCEL_ACTIVE_TASKS_SUCCESS,
     7    BATCH_DELETE_ARCHIVED_TASKS_SUCCESS,
     8    BATCH_DELETE_RETRY_TASKS_SUCCESS,
     9    BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
    10    BATCH_ARCHIVE_RETRY_TASKS_SUCCESS,
    11    BATCH_ARCHIVE_SCHEDULED_TASKS_SUCCESS,
    12    BATCH_RUN_ARCHIVED_TASKS_SUCCESS,
    13    BATCH_RUN_RETRY_TASKS_SUCCESS,
    14    BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
    15    CANCEL_ALL_ACTIVE_TASKS_SUCCESS,
    16    DELETE_ALL_ARCHIVED_TASKS_SUCCESS,
    17    DELETE_ALL_RETRY_TASKS_SUCCESS,
    18    DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
    19    DELETE_ARCHIVED_TASK_SUCCESS,
    20    DELETE_RETRY_TASK_SUCCESS,
    21    DELETE_SCHEDULED_TASK_SUCCESS,
    22    ARCHIVE_ALL_RETRY_TASKS_SUCCESS,
    23    ARCHIVE_ALL_SCHEDULED_TASKS_SUCCESS,
    24    ARCHIVE_RETRY_TASK_SUCCESS,
    25    ARCHIVE_SCHEDULED_TASK_SUCCESS,
    26    RUN_ALL_ARCHIVED_TASKS_SUCCESS,
    27    RUN_ALL_RETRY_TASKS_SUCCESS,
    28    RUN_ALL_SCHEDULED_TASKS_SUCCESS,
    29    RUN_ARCHIVED_TASK_SUCCESS,
    30    RUN_RETRY_TASK_SUCCESS,
    31    RUN_SCHEDULED_TASK_SUCCESS,
    32    TasksActionTypes,
    33    ARCHIVE_PENDING_TASK_SUCCESS,
    34    DELETE_PENDING_TASK_SUCCESS,
    35    BATCH_ARCHIVE_PENDING_TASKS_SUCCESS,
    36    BATCH_DELETE_PENDING_TASKS_SUCCESS,
    37    ARCHIVE_ALL_PENDING_TASKS_SUCCESS,
    38    DELETE_ALL_PENDING_TASKS_SUCCESS,
    39    DELETE_COMPLETED_TASK_SUCCESS,
    40    DELETE_ALL_COMPLETED_TASKS_SUCCESS,
    41    BATCH_DELETE_COMPLETED_TASKS_SUCCESS,
    42    RUN_AGGREGATING_TASK_SUCCESS,
    43    ARCHIVE_AGGREGATING_TASK_SUCCESS,
    44    DELETE_AGGREGATING_TASK_SUCCESS,
    45    BATCH_RUN_AGGREGATING_TASKS_SUCCESS,
    46    BATCH_ARCHIVE_AGGREGATING_TASKS_SUCCESS,
    47    BATCH_DELETE_AGGREGATING_TASKS_SUCCESS,
    48    RUN_ALL_AGGREGATING_TASKS_SUCCESS,
    49    ARCHIVE_ALL_AGGREGATING_TASKS_SUCCESS,
    50    DELETE_ALL_AGGREGATING_TASKS_SUCCESS,
    51  } from "../actions/tasksActions";
    52  
    53  interface SnackbarState {
    54    isOpen: boolean;
    55    message: string;
    56  }
    57  
    58  const initialState: SnackbarState = {
    59    isOpen: false,
    60    message: "",
    61  };
    62  
    63  function snackbarReducer(
    64    state = initialState,
    65    action: TasksActionTypes | SnackbarActionTypes
    66  ): SnackbarState {
    67    switch (action.type) {
    68      case CLOSE_SNACKBAR:
    69        return {
    70          // Note: We keep the message state unchanged for
    71          // smoother transition animation.
    72          ...state,
    73          isOpen: false,
    74        };
    75  
    76      case BATCH_CANCEL_ACTIVE_TASKS_SUCCESS: {
    77        const n = action.payload.canceled_ids.length;
    78        return {
    79          isOpen: true,
    80          message: `Cancelation signal sent to ${n} ${
    81            n === 1 ? "task" : "tasks"
    82          }`,
    83        };
    84      }
    85  
    86      case CANCEL_ALL_ACTIVE_TASKS_SUCCESS:
    87        return {
    88          isOpen: true,
    89          message: `Cancelation signal sent to all tasks in ${action.queue} queue`,
    90        };
    91  
    92      case RUN_SCHEDULED_TASK_SUCCESS:
    93        return {
    94          isOpen: true,
    95          message: `Scheduled task is now pending`,
    96        };
    97  
    98      case RUN_RETRY_TASK_SUCCESS:
    99        return {
   100          isOpen: true,
   101          message: `Retry task is now pending`,
   102        };
   103  
   104      case RUN_ARCHIVED_TASK_SUCCESS:
   105        return {
   106          isOpen: true,
   107          message: `Archived task is now pending`,
   108        };
   109  
   110      case RUN_AGGREGATING_TASK_SUCCESS:
   111        return {
   112          isOpen: true,
   113          message: `Aggregating task is now pending`,
   114        };
   115  
   116      case ARCHIVE_PENDING_TASK_SUCCESS:
   117        return {
   118          isOpen: true,
   119          message: `Pending task is now archived`,
   120        };
   121  
   122      case ARCHIVE_SCHEDULED_TASK_SUCCESS:
   123        return {
   124          isOpen: true,
   125          message: `Scheduled task is now archived`,
   126        };
   127  
   128      case ARCHIVE_RETRY_TASK_SUCCESS:
   129        return {
   130          isOpen: true,
   131          message: `Retry task is now archived`,
   132        };
   133  
   134      case ARCHIVE_AGGREGATING_TASK_SUCCESS:
   135        return {
   136          isOpen: true,
   137          message: `Aggregating task is now archived`,
   138        };
   139  
   140      case DELETE_PENDING_TASK_SUCCESS:
   141        return {
   142          isOpen: true,
   143          message: `Pending task deleted`,
   144        };
   145  
   146      case DELETE_SCHEDULED_TASK_SUCCESS:
   147        return {
   148          isOpen: true,
   149          message: `Scheduled task deleted`,
   150        };
   151  
   152      case DELETE_AGGREGATING_TASK_SUCCESS:
   153        return {
   154          isOpen: true,
   155          message: `Aggregating task deleted`,
   156        };
   157  
   158      case BATCH_RUN_SCHEDULED_TASKS_SUCCESS: {
   159        const n = action.payload.pending_ids.length;
   160        return {
   161          isOpen: true,
   162          message: `${n} scheduled ${
   163            n === 1 ? "task is" : "tasks are"
   164          } now pending`,
   165        };
   166      }
   167  
   168      case BATCH_RUN_AGGREGATING_TASKS_SUCCESS: {
   169        const n = action.payload.pending_ids.length;
   170        return {
   171          isOpen: true,
   172          message: `${n} aggregating ${
   173            n === 1 ? "task is" : "tasks are"
   174          } now pending`,
   175        };
   176      }
   177  
   178      case BATCH_ARCHIVE_AGGREGATING_TASKS_SUCCESS: {
   179        const n = action.payload.archived_ids.length;
   180        return {
   181          isOpen: true,
   182          message: `${n} aggregating ${
   183            n === 1 ? "task is" : "tasks are"
   184          } now archived`,
   185        };
   186      }
   187  
   188      case BATCH_DELETE_AGGREGATING_TASKS_SUCCESS: {
   189        const n = action.payload.deleted_ids.length;
   190        return {
   191          isOpen: true,
   192          message: `${n} aggregating ${n === 1 ? "task" : "tasks"} deleted`,
   193        };
   194      }
   195  
   196      case BATCH_ARCHIVE_PENDING_TASKS_SUCCESS: {
   197        const n = action.payload.archived_ids.length;
   198        return {
   199          isOpen: true,
   200          message: `${n} pending ${
   201            n === 1 ? "task is" : "tasks are"
   202          } now archived`,
   203        };
   204      }
   205  
   206      case BATCH_DELETE_PENDING_TASKS_SUCCESS: {
   207        const n = action.payload.deleted_ids.length;
   208        return {
   209          isOpen: true,
   210          message: `${n} pending ${n === 1 ? "task" : "tasks"} deleted`,
   211        };
   212      }
   213  
   214      case BATCH_ARCHIVE_SCHEDULED_TASKS_SUCCESS: {
   215        const n = action.payload.archived_ids.length;
   216        return {
   217          isOpen: true,
   218          message: `${n} scheduled ${
   219            n === 1 ? "task is" : "tasks are"
   220          } now archived`,
   221        };
   222      }
   223  
   224      case BATCH_DELETE_SCHEDULED_TASKS_SUCCESS: {
   225        const n = action.payload.deleted_ids.length;
   226        return {
   227          isOpen: true,
   228          message: `${n} scheduled ${n === 1 ? "task" : "tasks"} deleted`,
   229        };
   230      }
   231  
   232      case ARCHIVE_ALL_PENDING_TASKS_SUCCESS:
   233        return {
   234          isOpen: true,
   235          message: "All pending tasks are now archived",
   236        };
   237  
   238      case DELETE_ALL_PENDING_TASKS_SUCCESS:
   239        return {
   240          isOpen: true,
   241          message: "All pending tasks deleted",
   242        };
   243  
   244      case RUN_ALL_AGGREGATING_TASKS_SUCCESS:
   245        return {
   246          isOpen: true,
   247          message: `All tasks in group ${action.group}  are now pending`,
   248        };
   249  
   250      case ARCHIVE_ALL_AGGREGATING_TASKS_SUCCESS:
   251        return {
   252          isOpen: true,
   253          message: `All tasks in group ${action.group} are now archived`,
   254        };
   255  
   256      case DELETE_ALL_AGGREGATING_TASKS_SUCCESS:
   257        return {
   258          isOpen: true,
   259          message: `All tasks in group ${action.group} deleted`,
   260        };
   261  
   262      case RUN_ALL_SCHEDULED_TASKS_SUCCESS:
   263        return {
   264          isOpen: true,
   265          message: "All scheduled tasks are now pending",
   266        };
   267  
   268      case ARCHIVE_ALL_SCHEDULED_TASKS_SUCCESS:
   269        return {
   270          isOpen: true,
   271          message: "All scheduled tasks are now archived",
   272        };
   273  
   274      case DELETE_ALL_SCHEDULED_TASKS_SUCCESS:
   275        return {
   276          isOpen: true,
   277          message: "All scheduled tasks deleted",
   278        };
   279  
   280      case DELETE_RETRY_TASK_SUCCESS:
   281        return {
   282          isOpen: true,
   283          message: `Retry task deleted`,
   284        };
   285  
   286      case BATCH_RUN_RETRY_TASKS_SUCCESS: {
   287        const n = action.payload.pending_ids.length;
   288        return {
   289          isOpen: true,
   290          message: `${n} retry ${n === 1 ? "task is" : "tasks are"} now pending`,
   291        };
   292      }
   293  
   294      case BATCH_ARCHIVE_RETRY_TASKS_SUCCESS: {
   295        const n = action.payload.archived_ids.length;
   296        return {
   297          isOpen: true,
   298          message: `${n} retry ${n === 1 ? "task is" : "tasks are"} now archived`,
   299        };
   300      }
   301  
   302      case BATCH_DELETE_RETRY_TASKS_SUCCESS: {
   303        const n = action.payload.deleted_ids.length;
   304        return {
   305          isOpen: true,
   306          message: `${n} retry ${n === 1 ? "task" : "tasks"} deleted`,
   307        };
   308      }
   309  
   310      case RUN_ALL_RETRY_TASKS_SUCCESS:
   311        return {
   312          isOpen: true,
   313          message: "All retry tasks are now pending",
   314        };
   315  
   316      case ARCHIVE_ALL_RETRY_TASKS_SUCCESS:
   317        return {
   318          isOpen: true,
   319          message: "All retry tasks are now archived",
   320        };
   321  
   322      case DELETE_ALL_RETRY_TASKS_SUCCESS:
   323        return {
   324          isOpen: true,
   325          message: "All retry tasks deleted",
   326        };
   327  
   328      case DELETE_ARCHIVED_TASK_SUCCESS:
   329        return {
   330          isOpen: true,
   331          message: `Archived task deleted`,
   332        };
   333  
   334      case BATCH_RUN_ARCHIVED_TASKS_SUCCESS: {
   335        const n = action.payload.pending_ids.length;
   336        return {
   337          isOpen: true,
   338          message: `${n} archived ${
   339            n === 1 ? "task is" : "tasks are"
   340          } now pending`,
   341        };
   342      }
   343  
   344      case BATCH_DELETE_ARCHIVED_TASKS_SUCCESS: {
   345        const n = action.payload.deleted_ids.length;
   346        return {
   347          isOpen: true,
   348          message: `${n} archived ${n === 1 ? "task" : "tasks"} deleted`,
   349        };
   350      }
   351  
   352      case RUN_ALL_ARCHIVED_TASKS_SUCCESS:
   353        return {
   354          isOpen: true,
   355          message: "All archived tasks are now pending",
   356        };
   357  
   358      case DELETE_ALL_ARCHIVED_TASKS_SUCCESS:
   359        return {
   360          isOpen: true,
   361          message: "All archived tasks deleted",
   362        };
   363  
   364      case DELETE_COMPLETED_TASK_SUCCESS:
   365        return {
   366          isOpen: true,
   367          message: `Completed task deleted`,
   368        };
   369  
   370      case DELETE_ALL_COMPLETED_TASKS_SUCCESS:
   371        return {
   372          isOpen: true,
   373          message: "All completed tasks deleted",
   374        };
   375  
   376      case BATCH_DELETE_COMPLETED_TASKS_SUCCESS:
   377        const n = action.payload.deleted_ids.length;
   378        return {
   379          isOpen: true,
   380          message: `${n} completed ${n === 1 ? "task" : "tasks"} deleted`,
   381        };
   382  
   383      default:
   384        return state;
   385    }
   386  }
   387  
   388  export default snackbarReducer;