-
Notifications
You must be signed in to change notification settings - Fork 4
Combine all fertilizer addition routes into a single route #337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9541d9f
Use returnUrl in the fertilizers/new route to get rid of all the othe…
BoraIneviNMI 1feffff
Add changeset
BoraIneviNMI dafcac4
Gray out sidebar when coming to fertilizer management from the create…
BoraIneviNMI e4a08e5
Add url parsing utility and resolve some nitpicks
BoraIneviNMI d209ed6
Resolve open redirect vulnerability
BoraIneviNMI a62f18b
Redirect in new fertilizer route in case of cross origin return url
BoraIneviNMI b193ebc
Use same header content for all fertilizer application pages
BoraIneviNMI 63785be
Remove loader code that was added to accomodate the varying header
BoraIneviNMI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@svenvw/fdm-app": patch | ||
| --- | ||
|
|
||
| The code for fertilizer management is made more maintainable by using only one route for all fertilizer application routes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * Applies a function on the search params from a relative or absolute path, | ||
| * or a full URL, then returns the modified value. | ||
| * | ||
| * Note that it will treat input like `example.com/about` as | ||
| * `/example.com/about` since it looks for a http:// or https:// at the | ||
| * beginning to determine full URLs | ||
| * | ||
| * @param href relative or absolute path, or a full URL | ||
| * @param modifier function to be applied on the search params | ||
| * @returns a relative or absolute path, or a full URL, whichever format was | ||
| * provided | ||
| */ | ||
| export function modifySearchParams( | ||
| href: string, | ||
| modifier: (searchParams: URLSearchParams) => void, | ||
| ): string { | ||
| const hasProtocol = | ||
| href.startsWith("http://") || href.startsWith("https://") | ||
| const hasSlash = href.startsWith("/") | ||
| const url = new URL( | ||
| hasProtocol | ||
| ? href | ||
| : hasSlash | ||
| ? `http://localhost${href}` | ||
| : `http://localhost/${href}`, | ||
| ) | ||
| modifier(url.searchParams) | ||
| const relativeToOrigin = `${url.pathname}${url.search}${url.hash}` | ||
| return hasProtocol | ||
| ? url.href | ||
| : hasSlash | ||
| ? relativeToOrigin | ||
| : relativeToOrigin.substring(1) | ||
| } | ||
|
|
||
| /** | ||
| * Gets the search params from a relative or absolute path, or a full URL. | ||
| * | ||
| * Note that it will treat input like `example.com/about` as | ||
| * `/example.com/about` since it looks for a http:// or https:// at the | ||
| * beginning to determine full URLs | ||
| * | ||
| * @param href relative or absolute path, or a full URL | ||
| * @returns the search parameters, or empty search parameters if none was found | ||
| */ | ||
| export function getSearchParams(href: string) { | ||
| let searchParams: URLSearchParams | undefined | ||
| if (href.length > 0) { | ||
| modifySearchParams(href, (p) => { | ||
| searchParams = p | ||
| }) | ||
| } | ||
| return searchParams ?? new URLSearchParams() | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the given URL-like might be a full URL, and if so, if it is of the | ||
| * origin given. No checks are performed if no protocol in the URL is detected. | ||
| * | ||
| * @param href URL-like | ||
| * @param origin origin, like `example.com` to check if full URL is detected | ||
| * @returns the validation result for full URLs, true if no full URL is found | ||
| */ | ||
| export function isOfOrigin(href: string, origin: string) { | ||
| try { | ||
| return !href.includes("://") || new URL(href).origin === origin | ||
| } catch { | ||
| return false | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.