PromucFlow_constructor/app/client/src/utils/URLUtils.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-08-04 05:40:44 +00:00
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;
}
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2022-08-04 05:40:44 +00:00
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 "";
}
}
feat: Change navigate to UI (#14856) * 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>
2022-09-16 04:30:16 +00:00
export function isValidURL(url: string): boolean {
fix: fixed URL validation to not restrict navigateTo URLs to limited protocols (#27399) ## Description Currently, we check to see if the URL that is passed to the `navigateTo` method starts with http(s), mailTo or tel. This limits the capability to load/navigate to other URLs that do not conform to these protocols. This PR remove this crude protocol check and only checks to see if the navigateTo argument is a valid URL. > > Links to Notion, Figma or any other documents that might be relevant to the PR > > #### PR fixes following issue(s) Fixes #4878 > > #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) > > > ## Testing > #### How Has This Been Tested? - [x] Manual > > #### Test Plan 1. Verify NavigateTo() for https:// mailTo ftp urls 2. Verify NavigateTo for above protocol from jsobject and from Action selector 3. Verify NavigateTo for same and NewWindow with above URLs #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-09-21 01:32:37 +00:00
try {
new URL(url);
return true;
} catch (e) {
return false;
}
}
export function matchesURLPattern(url: string) {
feat: Change navigate to UI (#14856) * 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>
2022-09-16 04:30:16 +00:00
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
);
}
fix: Overflow list new UI restore (#34658) ## Description Overflow list view changes was reverted because of Anvil failures in EE. This PR add the changes back. Fixes #33432 ## Automation /ok-to-test tags="@tag.All" ### :mag: Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!CAUTION] > 🔴 🔴 🔴 Some tests have failed. > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/9802067318> > Commit: 18b7a5780abca4e5813d9089c31a01a31f1d348a > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9802067318&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail" target="_blank">Cypress dashboard</a>. > Tags: @tag.All > The following are new failures, please fix them before merging the PR: <ol> > <li>cypress/e2e/Regression/ClientSide/PartialImportExport/PartialExport_spec.ts</ol> > <a href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master" target="_blank">List of identified flaky tests</a>. > <hr>Fri, 05 Jul 2024 03:11:20 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced several new React components (`FileTab`, `AddTab`, `List`, `ScreenModeToggle`, `EditorTabs`) to enhance the IDE tab management and user interaction. - **Bug Fixes** - Improved drag-and-drop (DnD) simulation logic by using `realMouseMove` method. - **Refactor** - Simplified and refactored the `FileTabs` component, improving its encapsulation and rendering logic. - Enhanced state and props handling across various tab components and hooks. - **Tests** - Updated test IDs and test logic to ensure consistency and correctness for tab interactions and states. - **Style** - Updated styled components, replacing tab-related styles with list-related styles to improve UI consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-07-05 06:25:29 +00:00
export const sanitizeString = (str: string): string => {
return str.toLowerCase().replace(/[^a-z0-9]/g, "_");
};