-
Notifications
You must be signed in to change notification settings - Fork 71
fix: trim whitespace for secrete name and file paths in UI #628
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
Open
srikanth-s2003
wants to merge
5
commits into
semaphoreio:main
Choose a base branch
from
srikanth-s2003:srikanth/trim-secrete-whitespace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5bffc4f
fix: trim whitespace for secrete name and file paths in UI; determini…
srikanth-s2003 5c7add0
Merge branch 'main' into srikanth/trim-secrete-whitespace
srikanth-s2003 caf97bf
Merge branch 'main' into srikanth/trim-secrete-whitespace
srikanth-s2003 df539cb
fix: apply reviewer feedback - correct file path trimming and remove …
srikanth-s2003 d5602da
refactor: remove duration formatter changes from trimming PR
srikanth-s2003 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -111,7 +111,7 @@ export var ManageSecret = { | |||||
| </div> | ||||||
| </div>` | ||||||
|
|
||||||
| return [element, secretUploadLinkId, secretUploadId, fileContentId, fileDivId, secretInputId, fileDeleteLink, fileMd5Id, fileMd5PresentId, fileImageId]; | ||||||
| return [element, secretUploadLinkId, secretUploadId, fileContentId, fileDivId, secretInputId, fileDeleteLink, fileMd5Id, fileMd5PresentId, fileImageId, filePathId]; | ||||||
| }, | ||||||
|
|
||||||
| showEnvVars: function() { | ||||||
|
|
@@ -134,14 +134,16 @@ export var ManageSecret = { | |||||
| document.getElementById("files-input").innerHTML = ""; | ||||||
|
|
||||||
| this.files.forEach(function(file, index) { | ||||||
| let [element, fileUploadLink, fileUpload, fileContent, fileDiv, fileInput, fileDeleteLink, md5Id, fileMd5PresentId, fileImageId] = | ||||||
| let [element, fileUploadLink, fileUpload, fileContent, fileDiv, fileInputContainer, fileDeleteLink, md5Id, fileMd5PresentId, fileImageId, filePathInput] = | ||||||
| secretEditor.fileElement(file, index); | ||||||
|
|
||||||
| document.getElementById("files-input").insertAdjacentHTML("beforeend", element); | ||||||
|
|
||||||
| secretEditor.browseFilesOnClick(fileUploadLink, fileUpload); | ||||||
| secretEditor.formatUploadedFile(fileUpload, fileContent, fileDiv, fileInput, fileDeleteLink, fileMd5PresentId, fileImageId); | ||||||
| secretEditor.activateFilesDeleteLink(fileDeleteLink, fileDiv, fileInput, fileContent, md5Id); | ||||||
| secretEditor.formatUploadedFile(fileUpload, fileContent, fileDiv, fileInputContainer, fileDeleteLink, fileMd5PresentId, fileImageId); | ||||||
| secretEditor.activateFilesDeleteLink(fileDeleteLink, fileDiv, fileInputContainer, fileContent, md5Id); | ||||||
| // Attach trimming handler for the file path input | ||||||
| secretEditor.attachFilePathTrimmer(filePathInput); | ||||||
| }); | ||||||
| }, | ||||||
|
|
||||||
|
|
@@ -152,12 +154,16 @@ export var ManageSecret = { | |||||
|
|
||||||
| let envVarIndex = secretEditor.envVars.length - 1; | ||||||
| let envVar = secretEditor.envVars[envVarIndex]; | ||||||
| let [element, envVarDiv, envVarDeleteLink, envVarInput, md5Id] = | ||||||
| // envVarElement returns [element, envVarNameId, envVarDivId, envVarDeleteLink, envVarValueId, envVarMd5Id] | ||||||
| let [element, envVarNameId, envVarDiv, envVarDeleteLink, envVarInput, md5Id] = | ||||||
| secretEditor.envVarElement(envVar, envVarIndex); | ||||||
|
|
||||||
| document.getElementById("env-vars-input").insertAdjacentHTML("beforeend", element); | ||||||
| secretEditor.activateEnvVarDeleteLink(envVarDeleteLink, envVarDiv, envVarInput, md5Id); | ||||||
|
|
||||||
| // ensure validation/trim is attached for the newly created input | ||||||
| secretEditor.activateEnvVarValidation(envVarNameId); | ||||||
|
|
||||||
| return false; | ||||||
| }); | ||||||
| }, | ||||||
|
|
@@ -169,31 +175,53 @@ export var ManageSecret = { | |||||
|
|
||||||
| let fileIndex = secretEditor.files.length - 1; | ||||||
| let file = secretEditor.files[fileIndex]; | ||||||
| let [element, fileUploadLink, fileUpload, fileContent, fileDiv, fileInput, fileDeleteLink, md5Id, fileMd5PresentId, fileImageId] = | ||||||
| let [element, fileUploadLink, fileUpload, fileContent, fileDiv, fileInputContainer, fileDeleteLink, md5Id, fileMd5PresentId, fileImageId, filePathInput] = | ||||||
| secretEditor.fileElement(file, fileIndex); | ||||||
|
|
||||||
| document.getElementById("files-input").insertAdjacentHTML("beforeend", element); | ||||||
|
|
||||||
| secretEditor.browseFilesOnClick(fileUploadLink, fileUpload); | ||||||
| secretEditor.formatUploadedFile(fileUpload, fileContent, fileDiv, fileInput, fileDeleteLink, fileMd5PresentId, fileImageId); | ||||||
| secretEditor.activateFilesDeleteLink(fileDeleteLink, fileDiv, fileInput, fileContent, md5Id); | ||||||
| secretEditor.formatUploadedFile(fileUpload, fileContent, fileDiv, fileInputContainer, fileDeleteLink, fileMd5PresentId, fileImageId); | ||||||
| secretEditor.activateFilesDeleteLink(fileDeleteLink, fileDiv, fileInputContainer, fileContent, md5Id); | ||||||
| // Attach trimming handler for newly cloned file path input | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Pass
Suggested change
|
||||||
| secretEditor.attachFilePathTrimmer(filePathInput); | ||||||
|
|
||||||
| return false; | ||||||
| }); | ||||||
| }, | ||||||
|
|
||||||
| attachFilePathTrimmer: function(fileInputId) { | ||||||
| // fileInputId is the id of the visible text input for the file path (e.g. files_0_path) | ||||||
| $("body").on("change input", "#" + fileInputId, function() { | ||||||
| let raw = $(this).val(); | ||||||
| let trimmed = raw !== undefined && raw !== null ? raw.trim() : raw; | ||||||
| if (raw !== trimmed) { | ||||||
| $(this).val(trimmed); | ||||||
| } | ||||||
| }); | ||||||
| }, | ||||||
|
|
||||||
| activateEnvVarValidation: function (selector) { | ||||||
| let secretEditor = this; | ||||||
| // Validate on input and change, but always validate the trimmed value. | ||||||
| $("body").on("change textInput input", "#" + selector, function () { | ||||||
| valid_name_regex = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||||||
| let name = $(this).val(); | ||||||
| const valid_name_regex = /^[a-zA-Z_][a-zA-Z0-9_]*$/; | ||||||
| // Trim whitespace from the input value (leading/trailing) and update the field on blur/change | ||||||
| let raw = $(this).val(); | ||||||
| let name = raw !== undefined && raw !== null ? raw.trim() : raw; | ||||||
|
|
||||||
| if (name.match(valid_name_regex)) { | ||||||
| $(this).next(".error-message").remove(); // removes existing error message | ||||||
| } | ||||||
| else { | ||||||
| $(this).next(".error-message").remove(); // removes existing error message | ||||||
| $(this).after('<p class="f6 fw5 mt1 mb0 red error-message">Invalid variable name!</p>'); | ||||||
| } | ||||||
|
|
||||||
| // If the visible value differs from trimmed, update it on blur/change | ||||||
| if (raw !== name) { | ||||||
| $(this).val(name); | ||||||
| } | ||||||
| }); | ||||||
| }, | ||||||
|
|
||||||
|
|
||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Pass
filePathInput(the actual input field ID) instead offileInput(the container):