fix: Improve evaluated url experience (#24301)
This PR improves the evaluated value experience to be able to accommodate more edge cases and also process different url input types that a user can provide especially in the case of query parameters.
This commit is contained in:
parent
e6612037d0
commit
bf588ad20f
|
|
@ -26,10 +26,7 @@ import { bindingMarker } from "components/editorComponents/CodeEditor/MarkHelper
|
|||
import { entityMarker } from "components/editorComponents/CodeEditor/MarkHelpers/entityMarker";
|
||||
import { bindingHint } from "components/editorComponents/CodeEditor/hintHelpers";
|
||||
import StoreAsDatasource from "components/editorComponents/StoreAsDatasource";
|
||||
import {
|
||||
DATASOURCE_PATH_EXACT_MATCH_REGEX,
|
||||
DATASOURCE_PATH_PARTIAL_MATCH_REGEX,
|
||||
} from "constants/AppsmithActionConstants/ActionConstants";
|
||||
import { DATASOURCE_URL_EXACT_MATCH_REGEX } from "constants/AppsmithActionConstants/ActionConstants";
|
||||
import styled from "styled-components";
|
||||
import { getDatasourceInfo } from "pages/Editor/APIEditor/ApiRightPane";
|
||||
import * as FontFamilies from "constants/Fonts";
|
||||
|
|
@ -258,18 +255,9 @@ class EmbeddedDatasourcePathComponent extends React.Component<
|
|||
|
||||
let datasourceUrl = "";
|
||||
let path = "";
|
||||
const isCorrectFullPath = DATASOURCE_PATH_EXACT_MATCH_REGEX.test(value);
|
||||
const isSlightlyIncorrectFullPath =
|
||||
DATASOURCE_PATH_PARTIAL_MATCH_REGEX.test(value);
|
||||
|
||||
if (isCorrectFullPath) {
|
||||
const matches = value.match(DATASOURCE_PATH_EXACT_MATCH_REGEX);
|
||||
if (matches && matches.length) {
|
||||
datasourceUrl = matches[1];
|
||||
path = `${matches[2] || ""}${matches[3] || ""}`;
|
||||
}
|
||||
} else if (isSlightlyIncorrectFullPath && !isCorrectFullPath) {
|
||||
const matches = value.match(DATASOURCE_PATH_PARTIAL_MATCH_REGEX);
|
||||
const isCorrectFullURL = DATASOURCE_URL_EXACT_MATCH_REGEX.test(value);
|
||||
if (isCorrectFullURL) {
|
||||
const matches = value.match(DATASOURCE_URL_EXACT_MATCH_REGEX);
|
||||
if (matches && matches.length) {
|
||||
datasourceUrl = matches[1];
|
||||
path = `${matches[2] || ""}${matches[3] || ""}`;
|
||||
|
|
|
|||
|
|
@ -148,15 +148,9 @@ export interface LayoutOnLoadActionErrors {
|
|||
// Group 1 = datasource (https://www.domain.com)
|
||||
// Group 2 = path (/nested/path)
|
||||
// Group 3 = params (?param=123¶m2=12)
|
||||
export const DATASOURCE_PATH_EXACT_MATCH_REGEX =
|
||||
export const DATASOURCE_URL_EXACT_MATCH_REGEX =
|
||||
/^(https?:\/{2}\S+?)(\/[\s\S]*?)?(\?(?![^{]*})[\s\S]*)?$/;
|
||||
|
||||
// this regex is for matching patterns that does not conform with our standards.
|
||||
// Group 1 = datasource (https:/www.domain.com) or (https:/www.domain.com) or (htt/www.domain.com)
|
||||
// Group 2 = path (/nested/path)
|
||||
// Group 3 = params (?param=123¶m2=12)
|
||||
export const DATASOURCE_PATH_PARTIAL_MATCH_REGEX = /^(.*?)\/(.*?)$/;
|
||||
|
||||
export const EXECUTION_PARAM_KEY = "executionParams";
|
||||
export const EXECUTION_PARAM_REFERENCE_REGEX = /this.params|this\?.params/g;
|
||||
export const THIS_DOT_PARAMS_KEY = "$params";
|
||||
|
|
|
|||
|
|
@ -60,20 +60,32 @@ export function parseUrlForQueryParams(url: string) {
|
|||
});
|
||||
|
||||
params = paramsWithDynamicValues.map((queryParam) => {
|
||||
if (queryParam.value.includes("~")) {
|
||||
const newVal = queryParam?.value?.replace(
|
||||
/~/,
|
||||
dynamicValuesDetected[0],
|
||||
);
|
||||
// this time around we check for both key and values.
|
||||
if (queryParam.value.includes("~") || queryParam.key.includes("~")) {
|
||||
let newVal = queryParam.value;
|
||||
let newKey = queryParam.key;
|
||||
|
||||
// remove the first index from detected dynamic values.
|
||||
dynamicValuesDetected.shift();
|
||||
return { key: queryParam.key, value: newVal };
|
||||
if (queryParam.key.includes("~")) {
|
||||
newKey = queryParam?.key?.replace(/~/, dynamicValuesDetected[0]);
|
||||
// remove the first index from detected dynamic values.
|
||||
dynamicValuesDetected.shift();
|
||||
}
|
||||
|
||||
if (queryParam.value.includes("~")) {
|
||||
newVal = queryParam?.value?.replace(/~/, dynamicValuesDetected[0]);
|
||||
|
||||
// remove the first index from detected dynamic values.
|
||||
dynamicValuesDetected.shift();
|
||||
}
|
||||
|
||||
// dynamicValuesDetected.shift();
|
||||
return { key: newKey, value: newVal };
|
||||
}
|
||||
|
||||
return queryParam;
|
||||
});
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user