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:
commit
517f4b7ce0
|
|
@ -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(",");
|
||||||
|
if (isDynamicValue(changeValue)) {
|
||||||
|
args[0] = `${changeValue.substring(2, changeValue.length - 2)}`;
|
||||||
|
} else {
|
||||||
args[0] = `'${changeValue}'`;
|
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];
|
||||||
|
if (IS_URL_OR_MODAL.test(modalName) || modalName === "") {
|
||||||
name = modalName.substring(1, modalName.length - 1);
|
name = modalName.substring(1, modalName.length - 1);
|
||||||
|
} else {
|
||||||
|
name = `{{${modalName}}}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -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,8 +349,14 @@ 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);
|
||||||
|
if (dataTree) {
|
||||||
|
if (isDynamicValue(pageNameOrUrl)) {
|
||||||
|
return {
|
||||||
|
isValid: true,
|
||||||
|
parsed: value,
|
||||||
|
};
|
||||||
|
}
|
||||||
const isPage =
|
const isPage =
|
||||||
dataTree &&
|
|
||||||
(dataTree.pageList as PageListPayload).findIndex(
|
(dataTree.pageList as PageListPayload).findIndex(
|
||||||
page => page.pageName === pageNameOrUrl,
|
page => page.pageName === pageNameOrUrl,
|
||||||
) !== -1;
|
) !== -1;
|
||||||
|
|
@ -363,6 +370,7 @@ export const VALIDATORS: Record<ValidationType, Validator> = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
isValid: true,
|
isValid: true,
|
||||||
parsed: value,
|
parsed: value,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user