-
Notifications
You must be signed in to change notification settings - Fork 6k
fix(ui): preserve pending env vars in Add Extension form #9285
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ export default function ExtensionModal({ | |
| const [submitAttempted, setSubmitAttempted] = useState(false); | ||
| const [showCloseConfirmation, setShowCloseConfirmation] = useState(false); | ||
| const [hasPendingEnvVars, setHasPendingEnvVars] = useState(false); | ||
| const [pendingEnvVar, setPendingEnvVar] = useState<{ key: string; value: string } | null>(null); | ||
| const [hasPendingHeaders, setHasPendingHeaders] = useState(false); | ||
| const [pendingHeader, setPendingHeader] = useState<{ key: string; value: string } | null>(null); | ||
|
|
||
|
|
@@ -232,6 +233,14 @@ export default function ExtensionModal({ | |
| [] | ||
| ); | ||
|
|
||
| const handlePendingEnvVarChange = useCallback( | ||
| (hasPending: boolean, envVar: { key: string; value: string } | null) => { | ||
| setHasPendingEnvVars(hasPending); | ||
| setPendingEnvVar(envVar); | ||
| }, | ||
| [] | ||
| ); | ||
|
|
||
| // Function to store a secret value | ||
| const storeSecret = async (key: string, value: string) => { | ||
| try { | ||
|
|
@@ -289,6 +298,19 @@ export default function ExtensionModal({ | |
| return finalHeaders; | ||
| }; | ||
|
|
||
| const getFinalEnvVars = () => { | ||
| const finalEnvVars = [...formData.envVars]; | ||
| if ( | ||
| pendingEnvVar && | ||
| pendingEnvVar.key.trim() !== '' && | ||
| pendingEnvVar.value.trim() !== '' && | ||
| !pendingEnvVar.key.includes(' ') | ||
| ) { | ||
| finalEnvVars.push({ ...pendingEnvVar, isEdited: true }); | ||
| } | ||
| return finalEnvVars; | ||
| }; | ||
|
|
||
| const isHeadersValid = () => { | ||
| return getFinalHeaders().every( | ||
| ({ key, value }) => (key === '' && value === '') || (key !== '' && value !== '') | ||
|
|
@@ -323,6 +345,7 @@ export default function ExtensionModal({ | |
| if (isFormValid()) { | ||
| const finalFormData = { | ||
| ...formData, | ||
| envVars: getFinalEnvVars(), | ||
|
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.
Guard the pending-env merge by Useful? React with 👍 / 👎. |
||
| headers: getFinalHeaders(), | ||
| }; | ||
|
|
||
|
|
@@ -437,7 +460,7 @@ export default function ExtensionModal({ | |
| onRemove={handleRemoveEnvVar} | ||
| onChange={handleEnvVarChange} | ||
| submitAttempted={submitAttempted} | ||
| onPendingInputChange={setHasPendingEnvVars} | ||
| onPendingInputChange={handlePendingEnvVarChange} | ||
| /> | ||
| </div> | ||
| </> | ||
|
|
||
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.
getFinalEnvVars()always appendspendingEnvVarwhen it is non-empty, even if the env var section has been unmounted after switchingformData.typeaway fromstdio/streamable_http. In that flow, a user can type a pending env var, change type tosse, and submit; the hidden pending value is still sent tostoreSecreteven thoughcreateExtensionConfigforssedrops env keys, so the UI silently persists an orphaned secret that is not part of the saved extension config.Useful? React with 👍 / 👎.