コード例 #1
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
  return async (dispatch, getState) => {
    // TODO: How to handle a failed creation and display it to a user?
    // Maybe RestfulRequest.trigger should throw an exception
    // that the React component calling createAlert could catch ...?
    await dispatch(createAlertRequest.trigger(alert));

    dispatch(
      addUndo(
        createUndo({
          type: "create-alert",
          // eslint-disable-next-line react/display-name
          message: () => (
            <div className="flex align-center text-bold">
              <Icon
                name="alertConfirm"
                size="19"
                className="mr2 text-success"
              />
              {t`Your alert is all set up.`}
            </div>
          ),
          action: null, // alert creation is not undoable
        }),
      ),
    );

    dispatch.action(CREATE_ALERT);
  };
コード例 #2
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
  return async (dispatch, getState) => {
    await dispatch(updateAlertRequest.trigger(alert));

    dispatch(
      addUndo(
        createUndo({
          type: "update-alert",
          // eslint-disable-next-line react/display-name
          message: () => (
            <div className="flex align-center text-bold">
              <Icon
                name="alertConfirm"
                size="19"
                className="mr2 text-success"
              />
              {t`Your alert was updated.`}
            </div>
          ),
          action: null, // alert updating is not undoable
        }),
      ),
    );

    dispatch.action(UPDATE_ALERT);
  };
コード例 #3
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
  return async (dispatch, getState) => {
    await dispatch(unsubscribeFromAlertRequest.trigger(alert));
    dispatch.action(UNSUBSCRIBE_FROM_ALERT);

    // This delay lets us to show "You're unsubscribed" text in place of an
    // alert list item for a while before removing the list item completely
    setTimeout(
      () => dispatch.action(UNSUBSCRIBE_FROM_ALERT_CLEANUP, alert.id),
      5000,
    );
  };
コード例 #4
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
  return async (dispatch, getState) => {
    await dispatch(deleteAlertRequest.trigger({ id: alertId }));

    dispatch(
      addUndo(
        createUndo({
          type: "delete-alert",
          // eslint-disable-next-line react/display-name
          message: () => (
            <div className="flex align-center text-bold">
              <Icon
                name="alertConfirm"
                size="19"
                className="mr2 text-success"
              />
              {t`The alert was successfully deleted.`}
            </div>
          ),
          action: null, // alert deletion is not undoable
        }),
      ),
    );
    dispatch.action(DELETE_ALERT, alertId);
  };
コード例 #5
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
 return async (dispatch, getState) => {
   dispatch.action(FETCH_ALERTS_FOR_QUESTION_CLEAR_OLD_ALERTS, questionId);
   await dispatch(fetchAlertsForQuestionRequest.trigger({ questionId }));
   dispatch.action(FETCH_ALERTS_FOR_QUESTION);
 };
コード例 #6
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
 return async (dispatch, getState) => {
   await dispatch(fetchAllAlertsRequest.trigger());
   dispatch.action(FETCH_ALL_ALERTS);
 };
コード例 #7
0
ファイル: alert.js プロジェクト: aplusphilic/metabase
import React from "react";
import _ from "underscore";
import { handleActions } from "redux-actions";
import { combineReducers } from "redux";
import { addUndo, createUndo } from "metabase/redux/undo";
import { t } from "c-3po";
import { AlertApi } from "metabase/services";
import { RestfulRequest } from "metabase/lib/request";
import Icon from "metabase/components/Icon.jsx";

export const FETCH_ALL_ALERTS = "metabase/alerts/FETCH_ALL_ALERTS";
const fetchAllAlertsRequest = new RestfulRequest({
  endpoint: AlertApi.list,
  actionPrefix: FETCH_ALL_ALERTS,
  storeAsDictionary: true,
});
export const fetchAllAlerts = () => {
  return async (dispatch, getState) => {
    await dispatch(fetchAllAlertsRequest.trigger());
    dispatch.action(FETCH_ALL_ALERTS);
  };
};

export const FETCH_ALERTS_FOR_QUESTION_CLEAR_OLD_ALERTS =
  "metabase/alerts/FETCH_ALERTS_FOR_QUESTION_CLEAR_OLD_ALERTS";
export const FETCH_ALERTS_FOR_QUESTION =
  "metabase/alerts/FETCH_ALERTS_FOR_QUESTION";
const fetchAlertsForQuestionRequest = new RestfulRequest({
  endpoint: AlertApi.list_for_question,
  actionPrefix: FETCH_ALERTS_FOR_QUESTION,
  storeAsDictionary: true,