* Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Initial work to change navigate to UI * Remove console.logs * Adjust default parameters and getters/setters for page dropdown field * change url field getter so page names are not showm * Remove ../ from the imports Remove unnecessary todo * Add check for undefined fields * Add validations for url/page name, add error message * Make height auto to accommodate the flexible size of query param text box * Update dropdown list of pages when page names are updated * Set tab to url when a url has been entered, else default to page * Add feature tests * Add check on null value in isValueValidURL to ensure it does not crash the app * Remove unused ref * Fix bug when switch is selected and a new page addition let to page crash * Fix types and imports * Update the tests * Add ref back to the code Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
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 "";
|
|
}
|
|
}
|
|
|
|
export function isValidURL(url: string): boolean {
|
|
return (
|
|
url.match(
|
|
/\(?(?:(http|https|ftp|mailto|tel):\/\/)?(?:((?:[^\W\s]|\.|-|[:]{1})+)@{1})?((?:www.)?(?:[^\W\s]|\.|-)+[\.][^\W\s]{2,4}|localhost(?=\/)|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(?::(\d*))?([\/]?[^\s\?]*[\/]{1})*(?:\/?([^\s\n\?\[\]\{\}\#]*(?:(?=\.)){1}|[^\s\n\?\[\]\{\}\.\#]*)?([\.]{1}[^\s\?\#]*)?)?(?:\?{1}([^\s\n\#\[\]]*))?([\#][^\s\n]*)?\)?/g,
|
|
) !== null
|
|
);
|
|
}
|