<commit_before>
import { createAction } from "redux-actions";
import { AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
import { normalize, Schema, arrayOf } from "normalizr";

const card = new Schema('card');
const pulse = new Schema('pulse');
const user = new Schema('user');
// pulse.define({
//   cards: arrayOf(card)
// });

const Pulse = new AngularResourceProxy("Pulse", ["list", "get", "create", "update", "delete", "test", "form_input", "preview_card"]);
const Card = new AngularResourceProxy("Card", ["list"]);
const User = new AngularResourceProxy("User", ["list"]);

export const FETCH_PULSES = 'FETCH_PULSES';
export const SET_EDITING_PULSE = 'SET_EDITING_PULSE';
export const UPDATE_EDITING_PULSE = 'UPDATE_EDITING_PULSE';
export const SAVE_PULSE = 'SAVE_PULSE';
export const SAVE_EDITING_PULSE = 'SAVE_EDITING_PULSE';
export const DELETE_PULSE = 'DELETE_PULSE';
export const TEST_PULSE = 'TEST_PULSE';

export const FETCH_CARDS = 'FETCH_CARDS';
export const FETCH_USERS = 'FETCH_USERS';
export const FETCH_PULSE_FORM_INPUT = 'FETCH_PULSE_FORM_INPUT';
export const FETCH_PULSE_CARD_PREVIEW = 'FETCH_PULSE_CARD_PREVIEW';

export const fetchPulses = createThunkAction(FETCH_PULSES, function() {
    return async function(dispatch, getState) {
        let pulses = await Pulse.list();
        return normalize(pulses, arrayOf(pulse));
    };
});

export const setEditingPulse = createThunkAction(SET_EDITING_PULSE, function(id) {
    return async function(dispatch, getState) {
        if (id != null) {
            try {
                return await Pulse.get({ pulseId: id });
            } catch (e) {
            }
        }
        return {
            name: null,
            cards: [],
            channels: []
        }
    };
});

export const updateEditingPulse = createAction(UPDATE_EDITING_PULSE);

export const savePulse = createThunkAction(SAVE_PULSE, function(pulse) {
    return async function(dispatch, getState) {
        return await Pulse.update(pulse);
    };
});

export const saveEditingPulse = createThunkAction(SAVE_EDITING_PULSE, function() {
    return async function(dispatch, getState) {
        let { editingPulse } = getState();
        if (editingPulse.id != null) {
            return await Pulse.update(editingPulse);<commit_msg>Fix pulse saving, broke when centralizing Redux<commit_after>
import { createAction } from "redux-actions";
import { AngularResourceProxy, createThunkAction } from "metabase/lib/redux";
import { normalize, Schema, arrayOf } from "normalizr";

const card = new Schema('card');
const pulse = new Schema('pulse');
const user = new Schema('user');
// pulse.define({
//   cards: arrayOf(card)
// });

const Pulse = new AngularResourceProxy("Pulse", ["list", "get", "create", "update", "delete", "test", "form_input", "preview_card"]);
const Card = new AngularResourceProxy("Card", ["list"]);
const User = new AngularResourceProxy("User", ["list"]);

export const FETCH_PULSES = 'FETCH_PULSES';
export const SET_EDITING_PULSE = 'SET_EDITING_PULSE';
export const UPDATE_EDITING_PULSE = 'UPDATE_EDITING_PULSE';
export const SAVE_PULSE = 'SAVE_PULSE';
export const SAVE_EDITING_PULSE = 'SAVE_EDITING_PULSE';
export const DELETE_PULSE = 'DELETE_PULSE';
export const TEST_PULSE = 'TEST_PULSE';

export const FETCH_CARDS = 'FETCH_CARDS';
export const FETCH_USERS = 'FETCH_USERS';
export const FETCH_PULSE_FORM_INPUT = 'FETCH_PULSE_FORM_INPUT';
export const FETCH_PULSE_CARD_PREVIEW = 'FETCH_PULSE_CARD_PREVIEW';

export const fetchPulses = createThunkAction(FETCH_PULSES, function() {
    return async function(dispatch, getState) {
        let pulses = await Pulse.list();
        return normalize(pulses, arrayOf(pulse));
    };
});

export const setEditingPulse = createThunkAction(SET_EDITING_PULSE, function(id) {
    return async function(dispatch, getState) {
        if (id != null) {
            try {
                return await Pulse.get({ pulseId: id });
            } catch (e) {
            }
        }
        return {
            name: null,
            cards: [],
            channels: []
        }
    };
});

export const updateEditingPulse = createAction(UPDATE_EDITING_PULSE);

export const savePulse = createThunkAction(SAVE_PULSE, function(pulse) {
    return async function(dispatch, getState) {
        return await Pulse.update(pulse);
    };
});

export const saveEditingPulse = createThunkAction(SAVE_EDITING_PULSE, function() {
    return async function(dispatch, getState) {
        let { pulse: { editingPulse } } = getState();
        if (editingPulse.id != null) {
            return await Pulse.update(editingPulse);
{'fraction_non_alphanumeric': 0.1195769479818692, 'fraction_numerical': 0.0, 'mean_word_length': 3.9721030042918457, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6872961', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1499, 'n_words': 350}