Optimise code editor renders (#15405)
This commit is contained in:
parent
7624b91026
commit
4e5b21600d
|
|
@ -249,7 +249,7 @@ describe("MultiSelect Widget Functionality", function() {
|
|||
|
||||
cy.openPropertyPane("multiselectwidgetv2");
|
||||
// set options
|
||||
propPane.UpdatePropertyFieldValue("Options", JSON.stringify(options))
|
||||
propPane.UpdatePropertyFieldValue("Options", JSON.stringify(options));
|
||||
agHelper.Escape();
|
||||
// set default value
|
||||
propPane.UpdatePropertyFieldValue(
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ describe("Datasource form OAuth2 client credentials related tests", function() {
|
|||
});
|
||||
|
||||
it("3. Create an API with app url and save as Datasource for Authorization code details test", function() {
|
||||
apiPage.CreateAndFillApi(testdata.appUrl, "TestOAuth")
|
||||
apiPage.CreateAndFillApi(testdata.appUrl, "TestOAuth");
|
||||
agHelper.GetNClick(apiPage._saveAsDS);
|
||||
agHelper.ValidateToastMessage("datasource created"); //verifying there is no error toast, Bug 14566
|
||||
});
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ Cypress.Commands.add("updateCodeInput", ($selector, value) => {
|
|||
input.focus();
|
||||
cy.wait(200);
|
||||
input.setValue(value);
|
||||
cy.wait(200); //time for value to set
|
||||
cy.wait(1000); //time for value to set
|
||||
//input.focus();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
||||
import { REQUEST_TIMEOUT_MS } from "@appsmith/constants/ApiConstants";
|
||||
import { convertObjectToQueryParams } from "utils/AppsmithUtils";
|
||||
import { convertObjectToQueryParams } from "utils/URLUtils";
|
||||
import {
|
||||
apiFailureResponseInterceptor,
|
||||
apiRequestInterceptor,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import {
|
|||
ReduxActionErrorTypes,
|
||||
ReduxActionTypes,
|
||||
} from "@appsmith/constants/ReduxActionConstants";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
|
||||
export const initialState: SettingsReduxState = {
|
||||
isLoading: false,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import PerformanceTracker, {
|
|||
PerformanceTransactionName,
|
||||
} from "utils/PerformanceTracker";
|
||||
import { INTEGRATION_TABS } from "constants/routes";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
|
||||
import {
|
||||
builderURL,
|
||||
|
|
|
|||
|
|
@ -102,8 +102,8 @@ import { interactionAnalyticsEvent } from "utils/AppsmithUtils";
|
|||
import { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator";
|
||||
|
||||
interface ReduxStateProps {
|
||||
dynamicData: DataTree;
|
||||
datasources: any;
|
||||
dynamicData: DataTree;
|
||||
pluginIdToImageLocation: Record<string, string>;
|
||||
recentEntities: string[];
|
||||
}
|
||||
|
|
@ -353,37 +353,35 @@ class CodeEditor extends Component<Props, State> {
|
|||
window.addEventListener("keydown", this.handleKeydown);
|
||||
}
|
||||
|
||||
shouldComponentUpdate(nextProps: Props, nextState: State) {
|
||||
if (this.props.dynamicData !== nextProps.dynamicData)
|
||||
return nextState.isFocused || !!nextProps.isJSObject;
|
||||
return true;
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Props): void {
|
||||
this.editor.operation(() => {
|
||||
if (!this.state.isFocused) {
|
||||
// const currentMode = this.editor.getOption("mode");
|
||||
const editorValue = this.editor.getValue();
|
||||
// Safe update of value of the editor when value updated outside the editor
|
||||
const inputValue = getInputValue(this.props.input.value);
|
||||
const previousInputValue = getInputValue(prevProps.input.value);
|
||||
if (this.state.isFocused) return;
|
||||
// const currentMode = this.editor.getOption("mode");
|
||||
const editorValue = this.editor.getValue();
|
||||
// Safe update of value of the editor when value updated outside the editor
|
||||
const inputValue = getInputValue(this.props.input.value);
|
||||
const previousInputValue = getInputValue(prevProps.input.value);
|
||||
|
||||
if (!!inputValue || inputValue === "") {
|
||||
if (inputValue !== editorValue && isString(inputValue)) {
|
||||
this.editor.setValue(inputValue);
|
||||
this.editor.clearHistory(); // when input gets updated on focus out clear undo/redo from codeMirror History
|
||||
} else if (prevProps.isEditorHidden && !this.props.isEditorHidden) {
|
||||
// Even if Editor is updated with new value, it cannot update without layour calcs.
|
||||
//So, if it is hidden it does not reflect in UI, this code is to refresh editor if it was just made visible.
|
||||
this.editor.refresh();
|
||||
}
|
||||
} else if (previousInputValue !== inputValue) {
|
||||
// handles case when inputValue changes from a truthy to a falsy value
|
||||
this.editor.setValue("");
|
||||
}
|
||||
CodeEditor.updateMarkings(this.editor, this.props.marking);
|
||||
} else {
|
||||
// Update the dynamic bindings for autocomplete
|
||||
if (prevProps.dynamicData !== this.props.dynamicData) {
|
||||
this.hinters.forEach(
|
||||
(hinter) => hinter.update && hinter.update(this.props.dynamicData),
|
||||
);
|
||||
if (!!inputValue || inputValue === "") {
|
||||
if (inputValue !== editorValue && isString(inputValue)) {
|
||||
this.editor.setValue(inputValue);
|
||||
this.editor.clearHistory(); // when input gets updated on focus out clear undo/redo from codeMirror History
|
||||
} else if (prevProps.isEditorHidden && !this.props.isEditorHidden) {
|
||||
// Even if Editor is updated with new value, it cannot update without layour calcs.
|
||||
//So, if it is hidden it does not reflect in UI, this code is to refresh editor if it was just made visible.
|
||||
this.editor.refresh();
|
||||
}
|
||||
} else if (previousInputValue !== inputValue) {
|
||||
// handles case when inputValue changes from a truthy to a falsy value
|
||||
this.editor.setValue("");
|
||||
}
|
||||
CodeEditor.updateMarkings(this.editor, this.props.marking);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -757,7 +755,6 @@ class CodeEditor extends Component<Props, State> {
|
|||
}
|
||||
|
||||
getPropertyValidation = (
|
||||
dataTree: DataTree,
|
||||
dataTreePath?: string,
|
||||
): {
|
||||
isInvalid: boolean;
|
||||
|
|
@ -773,7 +770,7 @@ class CodeEditor extends Component<Props, State> {
|
|||
}
|
||||
|
||||
const errors = _.get(
|
||||
dataTree,
|
||||
this.props.dynamicData,
|
||||
getEvalErrorPath(dataTreePath),
|
||||
[],
|
||||
) as EvaluationError[];
|
||||
|
|
@ -792,7 +789,10 @@ class CodeEditor extends Component<Props, State> {
|
|||
this.state.hasLintError && this.setState({ hasLintError: false });
|
||||
}
|
||||
|
||||
const pathEvaluatedValue = _.get(dataTree, getEvalValuePath(dataTreePath));
|
||||
const pathEvaluatedValue = _.get(
|
||||
this.props.dynamicData,
|
||||
getEvalValuePath(dataTreePath),
|
||||
);
|
||||
|
||||
return {
|
||||
isInvalid: filteredLintErrors.length > 0,
|
||||
|
|
@ -809,7 +809,6 @@ class CodeEditor extends Component<Props, State> {
|
|||
codeEditorVisibleOverflow,
|
||||
dataTreePath,
|
||||
disabled,
|
||||
dynamicData,
|
||||
evaluatedValue,
|
||||
evaluationSubstitutionType,
|
||||
expected,
|
||||
|
|
@ -823,14 +822,14 @@ class CodeEditor extends Component<Props, State> {
|
|||
theme,
|
||||
useValidationMessage,
|
||||
} = this.props;
|
||||
const validations = this.getPropertyValidation(dynamicData, dataTreePath);
|
||||
|
||||
const validations = this.getPropertyValidation(dataTreePath);
|
||||
let { errors, isInvalid } = validations;
|
||||
const { pathEvaluatedValue } = validations;
|
||||
let evaluated = evaluatedValue;
|
||||
if (dataTreePath) {
|
||||
evaluated = pathEvaluatedValue;
|
||||
}
|
||||
|
||||
const entityInformation = this.getEntityInformation();
|
||||
/* Evaluation results for snippet arguments. The props below can be used to set the validation errors when computed from parent component */
|
||||
if (this.props.errors) {
|
||||
|
|
@ -840,7 +839,6 @@ class CodeEditor extends Component<Props, State> {
|
|||
isInvalid = Boolean(this.props.isInvalid);
|
||||
}
|
||||
/* Evaluation results for snippet snippets */
|
||||
|
||||
this.lintCode(this.editor);
|
||||
|
||||
const showEvaluatedValue =
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
import { getSelectedWidget } from "selectors/ui";
|
||||
import AnalyticsUtil from "utils/AnalyticsUtil";
|
||||
import history from "utils/history";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { datasourcesEditorIdURL, jsCollectionIdURL } from "RouteBuilder";
|
||||
|
||||
function ActionLink(props: EntityLinkProps) {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ import AnalyticsUtil from "utils/AnalyticsUtil";
|
|||
import useRecentEntities from "./useRecentEntities";
|
||||
import { get, noop } from "lodash";
|
||||
import { getCurrentPageId } from "selectors/editorSelectors";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import SnippetsFilter from "./SnippetsFilter";
|
||||
import SnippetRefinements from "./SnippetRefinements";
|
||||
import { Configure, Index } from "react-instantsearch-dom";
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { CurlIconV2, JsFileIconV2 } from "pages/Editor/Explorer/ExplorerIcons";
|
|||
import { createNewApiAction } from "actions/apiPaneActions";
|
||||
import { createNewJSCollection } from "actions/jsPaneActions";
|
||||
import { EventLocation } from "utils/AnalyticsUtil";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import history from "utils/history";
|
||||
import { curlImportPageURL } from "RouteBuilder";
|
||||
import { isMacOrIOS, modText, shiftText } from "utils/helpers";
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ import { Text, FontWeight, TextType } from "design-system";
|
|||
import history from "utils/history";
|
||||
import { getDatasourceInfo } from "pages/Editor/APIEditor/ApiRightPane";
|
||||
import * as FontFamilies from "constants/Fonts";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { AuthType } from "entities/Datasource/RestAPIForm";
|
||||
import { setDatsourceEditorMode } from "actions/datasourceActions";
|
||||
|
||||
|
|
|
|||
|
|
@ -16,10 +16,7 @@ import TemplateMenu from "pages/Editor/QueryEditor/TemplateMenu";
|
|||
import { QUERY_BODY_FIELD } from "constants/QueryEditorConstants";
|
||||
import { getPluginResponseTypes } from "selectors/entitiesSelector";
|
||||
import history from "utils/history";
|
||||
import {
|
||||
convertObjectToQueryParams,
|
||||
getQueryParams,
|
||||
} from "utils/AppsmithUtils";
|
||||
import { convertObjectToQueryParams, getQueryParams } from "utils/URLUtils";
|
||||
import { actionPathFromName } from "components/formControls/utils";
|
||||
import { EvaluationSubstitutionType } from "entities/DataTree/dataTreeFactory";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
export * from "ce/reducers/settingsReducer";
|
||||
import { handlers, initialState } from "ce/reducers/settingsReducer";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
|
||||
export default createReducer(initialState, handlers);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import ReactDOM from "react-dom";
|
|||
import { Provider } from "react-redux";
|
||||
import "./index.css";
|
||||
import { ThemeProvider } from "constants/DefaultTheme";
|
||||
import { appInitializer } from "utils/AppsmithUtils";
|
||||
import { appInitializer } from "utils/AppUtils";
|
||||
import { Slide } from "react-toastify";
|
||||
import store from "./store";
|
||||
import { LayersContext, Layers } from "constants/Layers";
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
storeAsDatasource,
|
||||
} from "actions/datasourceActions";
|
||||
import history from "utils/history";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { Text, TextType } from "design-system";
|
||||
import { AuthType } from "entities/Datasource/RestAPIForm";
|
||||
import { API_EDITOR_FORM_NAME } from "constants/forms";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { TabComponent } from "components/ads/Tabs";
|
|||
import { Text, FontWeight, TextType } from "design-system";
|
||||
import { TabbedViewContainer } from "./Form";
|
||||
import get from "lodash/get";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import ActionRightPane, {
|
||||
useEntityDependencies,
|
||||
} from "components/editorComponents/ActionRightPane";
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import { useDispatch, useSelector } from "react-redux";
|
|||
import { AppState } from "reducers";
|
||||
import { DatasourceStructureContainer } from "./DatasourceStructureContainer";
|
||||
import { isStoredDatasource, PluginType } from "entities/Action";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getAction } from "selectors/entitiesSelector";
|
||||
import {
|
||||
datasourcesEditorIdURL,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { useParams, useLocation } from "react-router";
|
|||
import { ExplorerURLParams } from "../../../Explorer/helpers";
|
||||
import { INTEGRATION_TABS } from "constants/routes";
|
||||
import history from "utils/history";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getIsGeneratingTemplatePage } from "selectors/pageListSelectors";
|
||||
import DataSourceOption from "../DataSourceOption";
|
||||
import { getQueryStringfromObject } from "RouteBuilder";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
getPostWelcomeTourState,
|
||||
setPostWelcomeTourState,
|
||||
} from "utils/storage";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { showPostCompletionMessage } from "actions/onboardingActions";
|
||||
import AnalyticsUtil from "utils/AnalyticsUtil";
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import { Position } from "@blueprintjs/core/lib/esm/common/position";
|
|||
|
||||
import { renderDatasourceSection } from "pages/Editor/DataSourceEditor/DatasourceSection";
|
||||
import { setDatsourceEditorMode } from "actions/datasourceActions";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import Menu from "components/ads/Menu";
|
||||
import Icon, { IconSize } from "components/ads/Icon";
|
||||
import MenuItem from "components/ads/MenuItem";
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import AnalyticsUtil from "utils/AnalyticsUtil";
|
|||
import { getCurrentApplication } from "selectors/applicationSelectors";
|
||||
import { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
|
||||
import { Colors } from "constants/Colors";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getGenerateCRUDEnabledPluginMap } from "selectors/entitiesSelector";
|
||||
import { GenerateCRUDEnabledPluginMap } from "api/PluginApi";
|
||||
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import { INTEGRATION_TABS, INTEGRATION_EDITOR_MODES } from "constants/routes";
|
|||
import { thinScrollbar } from "constants/DefaultTheme";
|
||||
import BackButton from "../DataSourceEditor/BackButton";
|
||||
import UnsupportedPluginDialog from "./UnsupportedPluginDialog";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
|
||||
import { getCurrentApplicationId } from "selectors/editorSelectors";
|
||||
import { integrationEditorURL } from "RouteBuilder";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { getPluginImages } from "selectors/entitiesSelector";
|
|||
import { Colors } from "constants/Colors";
|
||||
import { addMockDatasourceToWorkspace } from "actions/datasourceActions";
|
||||
import { getCurrentWorkspaceId } from "@appsmith/selectors/workspaceSelectors";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { AppState } from "reducers";
|
||||
import AnalyticsUtil from "utils/AnalyticsUtil";
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import AnalyticsUtil, { EventLocation } from "utils/AnalyticsUtil";
|
|||
import { CURL } from "constants/AppsmithActionConstants/ActionConstants";
|
||||
import { PluginType } from "entities/Action";
|
||||
import { Spinner } from "@blueprintjs/core";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { GenerateCRUDEnabledPluginMap } from "api/PluginApi";
|
||||
import { getGenerateCRUDEnabledPluginMap } from "selectors/entitiesSelector";
|
||||
import { useSelector } from "react-redux";
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import {
|
|||
} from "actions/datasourceActions";
|
||||
import AnalyticsUtil from "utils/AnalyticsUtil";
|
||||
import { redirectToNewIntegrations } from "actions/apiPaneActions";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getCurrentApplicationId } from "selectors/editorSelectors";
|
||||
import { useParams, useLocation } from "react-router";
|
||||
import { ExplorerURLParams } from "pages/Editor/Explorer/helpers";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
UpdateCanvasPayload,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import { JSAction, JSCollection } from "entities/JSCollection";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionErrorTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { set } from "lodash";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
UpdateWidgetMetaPropertyPayload,
|
||||
ResetWidgetMetaPayload,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import {
|
|||
ClonePageSuccessPayload,
|
||||
ReduxActionErrorTypes,
|
||||
} from "@appsmith/constants/ReduxActionConstants";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import { GenerateCRUDSuccess } from "actions/pageActions";
|
||||
|
||||
const initialState: PageListReduxState = {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import {
|
|||
} from "@appsmith/constants/ReduxActionConstants";
|
||||
import { applyChange, Diff } from "deep-diff";
|
||||
import { DataTree } from "entities/DataTree/dataTreeFactory";
|
||||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import * as Sentry from "@sentry/react";
|
||||
|
||||
export type EvaluatedTreeState = DataTree;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {
|
|||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
} from "@appsmith/constants/ReduxActionConstants";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import { User } from "entities/AppCollab/CollabInterfaces";
|
||||
import { cloneDeep } from "lodash";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { AppTheme } from "entities/AppTheming";
|
||||
import { AppThemingMode } from "selectors/appThemingSelectors";
|
||||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import { Log } from "entities/AppsmithConsole";
|
||||
import {
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
UpdateCanvasPayload,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import {
|
|||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
} from "@appsmith/constants/ReduxActionConstants";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
|
||||
const initialState: OnboardingState = {
|
||||
// Signposting
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReflowReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxActionTypes,
|
||||
ReduxAction,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionErrorTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import _ from "lodash";
|
||||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createReducer } from "utils/AppsmithUtils";
|
||||
import { createReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createImmerReducer } from "utils/AppsmithUtils";
|
||||
import { createImmerReducer } from "utils/ReducerUtils";
|
||||
import {
|
||||
ReduxAction,
|
||||
ReduxActionTypes,
|
||||
|
|
|
|||
|
|
@ -86,11 +86,8 @@ import AppsmithConsole from "utils/AppsmithConsole";
|
|||
import { ENTITY_TYPE } from "entities/AppsmithConsole";
|
||||
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
||||
import { createNewApiAction } from "actions/apiPaneActions";
|
||||
import {
|
||||
createNewApiName,
|
||||
createNewQueryName,
|
||||
getQueryParams,
|
||||
} from "utils/AppsmithUtils";
|
||||
import { createNewApiName, createNewQueryName } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { DEFAULT_API_ACTION_CONFIG } from "constants/ApiEditorConstants";
|
||||
import {
|
||||
setGlobalSearchCategory,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ import history from "utils/history";
|
|||
import { INTEGRATION_EDITOR_MODES, INTEGRATION_TABS } from "constants/routes";
|
||||
import { initialize, autofill, change } from "redux-form";
|
||||
import { Property } from "api/ActionAPI";
|
||||
import { createNewApiName, getQueryParams } from "utils/AppsmithUtils";
|
||||
import { createNewApiName } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { getPluginIdOfPackageName } from "sagas/selectors";
|
||||
import { getAction, getActions, getPlugin } from "selectors/entitiesSelector";
|
||||
import {
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ import { checkAndGetPluginFormConfigsSaga } from "sagas/PluginSagas";
|
|||
import { PluginType } from "entities/Action";
|
||||
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
||||
import { isDynamicValue } from "utils/DynamicBindingUtils";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { GenerateCRUDEnabledPluginMap } from "api/PluginApi";
|
||||
import { getIsGeneratePageInitiator } from "utils/GenerateCrudUtil";
|
||||
import { shouldBeDefined, trimQueryString } from "utils/helpers";
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ import {
|
|||
JSCollectionData,
|
||||
JSCollectionDataState,
|
||||
} from "reducers/entityReducers/jsActionsReducer";
|
||||
import { createNewJSFunctionName, getQueryParams } from "utils/AppsmithUtils";
|
||||
import { createNewJSFunctionName } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { JSCollection, JSAction } from "entities/JSCollection";
|
||||
import { createJSCollectionRequest } from "actions/jsActionActions";
|
||||
import history from "utils/history";
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ import {
|
|||
import { UrlDataState } from "reducers/entityReducers/appReducer";
|
||||
import { APP_MODE } from "entities/App";
|
||||
import { clearEvalCache } from "./EvaluationsSaga";
|
||||
import { getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import PerformanceTracker, {
|
||||
PerformanceTransactionName,
|
||||
} from "utils/PerformanceTracker";
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ import {
|
|||
createActionRequest,
|
||||
setActionProperty,
|
||||
} from "actions/pluginActionActions";
|
||||
import { getNextEntityName, getQueryParams } from "utils/AppsmithUtils";
|
||||
import { getNextEntityName } from "utils/AppsmithUtils";
|
||||
import { getQueryParams } from "utils/URLUtils";
|
||||
import { isEmpty, merge } from "lodash";
|
||||
import { getConfigInitialValues } from "components/formControls/utils";
|
||||
import { Variant } from "components/ads/common";
|
||||
|
|
|
|||
22
app/client/src/utils/AppUtils.ts
Normal file
22
app/client/src/utils/AppUtils.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { getAppsmithConfigs } from "ce/configs";
|
||||
import FormControlRegistry from "./formControl/FormControlRegistry";
|
||||
import { LogLevelDesc } from "loglevel";
|
||||
import localStorage from "utils/localStorage";
|
||||
import * as log from "loglevel";
|
||||
|
||||
export const appInitializer = () => {
|
||||
FormControlRegistry.registerFormControlBuilders();
|
||||
const appsmithConfigs = getAppsmithConfigs();
|
||||
log.setLevel(getEnvLogLevel(appsmithConfigs.logLevel));
|
||||
};
|
||||
|
||||
const getEnvLogLevel = (configLevel: LogLevelDesc): LogLevelDesc => {
|
||||
let logLevel = configLevel;
|
||||
if (localStorage && localStorage.getItem) {
|
||||
const localStorageLevel = localStorage.getItem(
|
||||
"logLevelOverride",
|
||||
) as LogLevelDesc;
|
||||
if (localStorageLevel) logLevel = localStorageLevel;
|
||||
}
|
||||
return logLevel;
|
||||
};
|
||||
|
|
@ -1,53 +1,16 @@
|
|||
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
||||
import { getAppsmithConfigs } from "@appsmith/configs";
|
||||
import * as Sentry from "@sentry/react";
|
||||
import AnalyticsUtil from "./AnalyticsUtil";
|
||||
import FormControlRegistry from "./formControl/FormControlRegistry";
|
||||
import { Property } from "api/ActionAPI";
|
||||
import _ from "lodash";
|
||||
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
|
||||
import * as log from "loglevel";
|
||||
import { LogLevelDesc } from "loglevel";
|
||||
import produce from "immer";
|
||||
import { AppIconCollection, AppIconName } from "components/ads/AppIcon";
|
||||
import { ERROR_CODES } from "@appsmith/constants/ApiConstants";
|
||||
import { createMessage, ERROR_500 } from "@appsmith/constants/messages";
|
||||
import localStorage from "utils/localStorage";
|
||||
import { JSCollectionData } from "reducers/entityReducers/jsActionsReducer";
|
||||
import { osName } from "react-device-detect";
|
||||
|
||||
export const createReducer = (
|
||||
initialState: any,
|
||||
handlers: { [type: string]: (state: any, action: any) => any },
|
||||
) => {
|
||||
return function reducer(state = initialState, action: ReduxAction<any>) {
|
||||
if (handlers.hasOwnProperty(action.type)) {
|
||||
return handlers[action.type](state, action);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const createImmerReducer = (
|
||||
initialState: any,
|
||||
handlers: { [type: string]: any },
|
||||
) => {
|
||||
return function reducer(state = initialState, action: ReduxAction<any>) {
|
||||
if (handlers.hasOwnProperty(action.type)) {
|
||||
return produce(handlers[action.type])(state, action);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const appInitializer = () => {
|
||||
FormControlRegistry.registerFormControlBuilders();
|
||||
const appsmithConfigs = getAppsmithConfigs();
|
||||
log.setLevel(getEnvLogLevel(appsmithConfigs.logLevel));
|
||||
};
|
||||
|
||||
export const initializeAnalyticsAndTrackers = () => {
|
||||
const appsmithConfigs = getAppsmithConfigs();
|
||||
|
||||
|
|
@ -255,17 +218,6 @@ export const convertToString = (value: any): string => {
|
|||
return value.toString();
|
||||
};
|
||||
|
||||
const getEnvLogLevel = (configLevel: LogLevelDesc): LogLevelDesc => {
|
||||
let logLevel = configLevel;
|
||||
if (localStorage && localStorage.getItem) {
|
||||
const localStorageLevel = localStorage.getItem(
|
||||
"logLevelOverride",
|
||||
) as LogLevelDesc;
|
||||
if (localStorageLevel) logLevel = localStorageLevel;
|
||||
}
|
||||
return logLevel;
|
||||
};
|
||||
|
||||
export const getInitialsAndColorCode = (
|
||||
fullName: any,
|
||||
colorPalette: string[],
|
||||
|
|
@ -329,29 +281,6 @@ export function hexToRgb(
|
|||
};
|
||||
}
|
||||
|
||||
export function getQueryParams() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const keys = urlParams.keys();
|
||||
let key = keys.next().value;
|
||||
const queryParams: Record<string, string> = {};
|
||||
while (key) {
|
||||
queryParams[key] = urlParams.get(key) as string;
|
||||
key = keys.next().value;
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
export function convertObjectToQueryParams(object: any): string {
|
||||
if (!_.isNil(object)) {
|
||||
const paramArray: string[] = _.map(_.keys(object), (key) => {
|
||||
return encodeURIComponent(key) + "=" + encodeURIComponent(object[key]);
|
||||
});
|
||||
return "?" + _.join(paramArray, "&");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export const retryPromise = (
|
||||
fn: () => Promise<any>,
|
||||
retriesLeft = 5,
|
||||
|
|
|
|||
28
app/client/src/utils/ReducerUtils.ts
Normal file
28
app/client/src/utils/ReducerUtils.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
||||
import produce from "immer";
|
||||
|
||||
export const createReducer = (
|
||||
initialState: any,
|
||||
handlers: { [type: string]: (state: any, action: any) => any },
|
||||
) => {
|
||||
return function reducer(state = initialState, action: ReduxAction<any>) {
|
||||
if (handlers.hasOwnProperty(action.type)) {
|
||||
return handlers[action.type](state, action);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const createImmerReducer = (
|
||||
initialState: any,
|
||||
handlers: { [type: string]: any },
|
||||
) => {
|
||||
return function reducer(state = initialState, action: ReduxAction<any>) {
|
||||
if (handlers.hasOwnProperty(action.type)) {
|
||||
return produce(handlers[action.type])(state, action);
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
24
app/client/src/utils/URLUtils.ts
Normal file
24
app/client/src/utils/URLUtils.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import _ from "lodash";
|
||||
|
||||
export function getQueryParams() {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const keys = urlParams.keys();
|
||||
let key = keys.next().value;
|
||||
const queryParams: Record<string, string> = {};
|
||||
while (key) {
|
||||
queryParams[key] = urlParams.get(key) as string;
|
||||
key = keys.next().value;
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
|
||||
export function convertObjectToQueryParams(object: any): string {
|
||||
if (!_.isNil(object)) {
|
||||
const paramArray: string[] = _.map(_.keys(object), (key) => {
|
||||
return encodeURIComponent(key) + "=" + encodeURIComponent(object[key]);
|
||||
});
|
||||
return "?" + _.join(paramArray, "&");
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user