2019-11-25 12:22:05 +00:00
|
|
|
import { ReduxAction } from "../constants/ReduxActionConstants";
|
|
|
|
|
import { getAppsmithConfigs } from "configs";
|
2019-09-09 09:08:54 +00:00
|
|
|
import * as Sentry from "@sentry/browser";
|
|
|
|
|
import AnalyticsUtil from "./AnalyticsUtil";
|
2019-09-13 11:59:45 +00:00
|
|
|
import FontFaceObserver from "fontfaceobserver";
|
2019-09-18 10:19:50 +00:00
|
|
|
import PropertyControlRegistry from "./PropertyControlRegistry";
|
|
|
|
|
import WidgetBuilderRegistry from "./WidgetRegistry";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { Property } from "api/ActionAPI";
|
2019-09-18 14:10:57 +00:00
|
|
|
import _ from "lodash";
|
2019-11-06 12:12:41 +00:00
|
|
|
import moment from "moment-timezone";
|
2019-11-19 12:44:58 +00:00
|
|
|
import ValidationRegistry from "./ValidationRegistry";
|
2019-08-30 10:33:49 +00:00
|
|
|
|
|
|
|
|
export const createReducer = (
|
|
|
|
|
initialState: any,
|
2019-09-09 09:08:54 +00:00
|
|
|
handlers: { [type: string]: Function },
|
2019-08-30 10:33:49 +00:00
|
|
|
) => {
|
|
|
|
|
return function reducer(state = initialState, action: ReduxAction<any>) {
|
|
|
|
|
if (handlers.hasOwnProperty(action.type)) {
|
2019-09-09 09:08:54 +00:00
|
|
|
return handlers[action.type](state, action);
|
2019-08-30 10:33:49 +00:00
|
|
|
} else {
|
2019-09-09 09:08:54 +00:00
|
|
|
return state;
|
2019-08-30 10:33:49 +00:00
|
|
|
}
|
2019-09-09 09:08:54 +00:00
|
|
|
};
|
|
|
|
|
};
|
2019-08-30 10:33:49 +00:00
|
|
|
|
|
|
|
|
export const appInitializer = () => {
|
2019-09-18 10:19:50 +00:00
|
|
|
WidgetBuilderRegistry.registerWidgetBuilders();
|
|
|
|
|
PropertyControlRegistry.registerPropertyControlBuilders();
|
2019-11-19 12:44:58 +00:00
|
|
|
ValidationRegistry.registerInternalValidators();
|
2019-11-06 12:12:41 +00:00
|
|
|
moment.tz.setDefault(moment.tz.guess());
|
2019-11-25 12:22:05 +00:00
|
|
|
const appsmithConfigs = getAppsmithConfigs();
|
|
|
|
|
if (appsmithConfigs.sentry.enabled && appsmithConfigs.sentry.config) {
|
|
|
|
|
Sentry.init(appsmithConfigs.sentry.config);
|
|
|
|
|
}
|
|
|
|
|
if (appsmithConfigs.hotjar.enabled && appsmithConfigs.hotjar.config) {
|
|
|
|
|
const { id, sv } = appsmithConfigs.hotjar.config;
|
|
|
|
|
AnalyticsUtil.initializeHotjar(id, sv);
|
|
|
|
|
}
|
|
|
|
|
if (appsmithConfigs.segment.enabled) {
|
|
|
|
|
AnalyticsUtil.initializeSegment();
|
2019-08-30 10:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 11:40:00 +00:00
|
|
|
const textFont = new FontFaceObserver("DM Sans");
|
2019-09-09 09:08:54 +00:00
|
|
|
textFont
|
|
|
|
|
.load()
|
|
|
|
|
.then(() => {
|
|
|
|
|
document.body.className += "fontLoaded";
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-09-18 14:10:57 +00:00
|
|
|
|
|
|
|
|
export const mapToPropList = (map: Record<string, string>): Property[] => {
|
|
|
|
|
return _.map(map, (value, key) => {
|
|
|
|
|
return { key: key, value: value };
|
|
|
|
|
});
|
|
|
|
|
};
|
2019-10-02 18:13:04 +00:00
|
|
|
|
2020-01-24 09:54:40 +00:00
|
|
|
export const getNextEntityName = (prefix: string, existingNames: string[]) => {
|
2019-10-03 17:06:44 +00:00
|
|
|
const regex = new RegExp(`^${prefix}(\\d+)$`);
|
2020-01-24 09:54:40 +00:00
|
|
|
const usedIndices: number[] = existingNames.map(name => {
|
|
|
|
|
if (name && regex.test(name)) {
|
2019-10-03 17:06:44 +00:00
|
|
|
const matches = name.match(regex);
|
|
|
|
|
const ind =
|
|
|
|
|
matches && Array.isArray(matches) ? parseInt(matches[1], 10) : 0;
|
2019-10-02 18:13:04 +00:00
|
|
|
return Number.isNaN(ind) ? 0 : ind;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}) as number[];
|
|
|
|
|
|
2020-01-24 09:54:40 +00:00
|
|
|
const lastIndex = Math.max(...usedIndices, ...[0]);
|
2019-10-02 18:13:04 +00:00
|
|
|
|
|
|
|
|
return prefix + (lastIndex + 1);
|
|
|
|
|
};
|
2019-11-07 11:17:53 +00:00
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
export const noop = () => {
|
|
|
|
|
console.log("noop");
|
|
|
|
|
};
|