Merge branch 'feature/nav-dyn-bind' into 'release'

NavigateTo dynamic binding support

See merge request theappsmith/internal-tools-client!498
This commit is contained in:
Satbir Singh 2020-04-29 05:35:02 +00:00
commit 517f4b7ce0
2 changed files with 32 additions and 16 deletions

View File

@ -17,6 +17,7 @@ import { createModalAction } from "actions/widgetActions";
import { createActionRequest } from "actions/actionActions"; import { createActionRequest } from "actions/actionActions";
import { DEFAULT_API_ACTION } from "constants/ApiEditorConstants"; import { DEFAULT_API_ACTION } from "constants/ApiEditorConstants";
import { createNewApiName } from "utils/AppsmithUtils"; import { createNewApiName } from "utils/AppsmithUtils";
import { isDynamicValue } from "utils/DynamicBindingUtils";
const ALERT_STYLE_OPTIONS = [ const ALERT_STYLE_OPTIONS = [
{ label: "Info", value: "'info'", id: "info" }, { label: "Info", value: "'info'", id: "info" },
@ -26,12 +27,15 @@ const ALERT_STYLE_OPTIONS = [
]; ];
const ACTION_TRIGGER_REGEX = /^{{([\s\S]*?)\(([\s\S]*?)\)}}$/g; const ACTION_TRIGGER_REGEX = /^{{([\s\S]*?)\(([\s\S]*?)\)}}$/g;
const ACTION_ANONYMOUS_FUNC_REGEX = /\(\) => ([\s\S]*?)(\([\s\S]*?\))/g; const ACTION_ANONYMOUS_FUNC_REGEX = /\(\) => ([\s\S]*?)(\([\s\S]*?\))/g;
const IS_URL_OR_MODAL = /^'.*'$/;
const modalSetter = (changeValue: any, currentValue: string) => { const modalSetter = (changeValue: any, currentValue: string) => {
const matches = [...currentValue.matchAll(ACTION_TRIGGER_REGEX)]; const matches = [...currentValue.matchAll(ACTION_TRIGGER_REGEX)];
const args = matches[0][2].split(","); const args = matches[0][2].split(",");
args[0] = `'${changeValue}'`; if (isDynamicValue(changeValue)) {
args[0] = `${changeValue.substring(2, changeValue.length - 2)}`;
} else {
args[0] = `'${changeValue}'`;
}
return currentValue.replace( return currentValue.replace(
ACTION_TRIGGER_REGEX, ACTION_TRIGGER_REGEX,
`{{$1(${args.join(",")})}}`, `{{$1(${args.join(",")})}}`,
@ -43,7 +47,11 @@ export const modalGetter = (value: string) => {
let name = "none"; let name = "none";
if (matches.length) { if (matches.length) {
const modalName = matches[0][2].split(",")[0]; const modalName = matches[0][2].split(",")[0];
name = modalName.substring(1, modalName.length - 1); if (IS_URL_OR_MODAL.test(modalName) || modalName === "") {
name = modalName.substring(1, modalName.length - 1);
} else {
name = `{{${modalName}}}`;
}
} }
return name; return name;
}; };

View File

@ -14,6 +14,7 @@ import { modalGetter } from "components/editorComponents/actioncreator/ActionCre
import { WidgetProps } from "widgets/BaseWidget"; import { WidgetProps } from "widgets/BaseWidget";
import { DataTree } from "entities/DataTree/dataTreeFactory"; import { DataTree } from "entities/DataTree/dataTreeFactory";
import { PageListPayload } from "constants/ReduxActionConstants"; import { PageListPayload } from "constants/ReduxActionConstants";
import { isDynamicValue } from "./DynamicBindingUtils";
const URL_REGEX = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/; const URL_REGEX = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/;
export const VALIDATORS: Record<ValidationType, Validator> = { export const VALIDATORS: Record<ValidationType, Validator> = {
@ -348,18 +349,25 @@ export const VALIDATORS: Record<ValidationType, Validator> = {
if (_.isString(value)) { if (_.isString(value)) {
if (value.indexOf("navigateTo") !== -1) { if (value.indexOf("navigateTo") !== -1) {
const pageNameOrUrl = modalGetter(value); const pageNameOrUrl = modalGetter(value);
const isPage = if (dataTree) {
dataTree && if (isDynamicValue(pageNameOrUrl)) {
(dataTree.pageList as PageListPayload).findIndex( return {
page => page.pageName === pageNameOrUrl, isValid: true,
) !== -1; parsed: value,
const isValidUrl = URL_REGEX.test(pageNameOrUrl); };
if (!(isValidUrl || isPage)) { }
return { const isPage =
isValid: false, (dataTree.pageList as PageListPayload).findIndex(
parsed: value, page => page.pageName === pageNameOrUrl,
message: `${NAVIGATE_TO_VALIDATION_ERROR}`, ) !== -1;
}; const isValidUrl = URL_REGEX.test(pageNameOrUrl);
if (!(isValidUrl || isPage)) {
return {
isValid: false,
parsed: value,
message: `${NAVIGATE_TO_VALIDATION_ERROR}`,
};
}
} }
} }
} }