You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "rickychen-infinirc (via GitHub)" <gi...@apache.org> on 2025/11/27 06:37:22 UTC
[PR] fix Preserve variable value formatting in edit dialog (#58648) [airflow]
rickychen-infinirc opened a new pull request, #58757:
URL: https://github.com/apache/airflow/pull/58757
**Description**
This PR fixes the variable editor to preserve JSON formatting when editing variables in the Airflow UI.
**Problem:**
In Airflow 3.x, variable values are displayed as minified single-line strings in the edit dialog, making it difficult to read and edit structured data like JSON and YAML.
**Solution:**
Added a `formatValue` function in `EditVariableButton.tsx` that formats JSON values with proper indentation (2 spaces) when the edit dialog is opened. Non-JSON values are preserved as-is.
**Changes:**
- Modified `EditVariableButton.tsx` to add `formatValue` function
- JSON values are formatted using `JSON.stringify(parsed, null, 2)`
- Non-JSON values are displayed unchanged
**Testing:**
1. Created test variable with formatted JSON
2. Verified formatting is preserved in edit dialog
3. Tested with YAML values - preserved as-is
**Screenshots:**
**Before:**
Value field shows: `{"key": "val", "key2": "val2"}`
<img width="788" height="376" alt="截圖 2025-11-27 下午2 28 11" src="https://github.com/user-attachments/assets/bce8baf9-8763-4686-a7bb-1f00d0eec85d" />
**After:**
Value field shows:
```
{
"key": "val",
"key2": "val2"
}
```
<img width="886" height="461" alt="截圖 2025-11-27 下午2 29 14" src="https://github.com/user-attachments/assets/3b982871-77b4-4e8a-b442-b7b50153b700" />
**Related Issue(s):**
Closes #58648
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog [airflow]
Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on PR #58757:
URL: https://github.com/apache/airflow/pull/58757#issuecomment-3592494075
Thanks @Lee-W for the review and merge.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog (#58648) [airflow]
Posted by "choo121600 (via GitHub)" <gi...@apache.org>.
choo121600 commented on code in PR #58757:
URL: https://github.com/apache/airflow/pull/58757#discussion_r2567597986
##########
airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/EditVariableButton.tsx:
##########
@@ -36,6 +36,14 @@ type Props = {
const EditVariableButton = ({ disabled, variable }: Props) => {
const { t: translate } = useTranslation("admin");
const { onClose, onOpen, open } = useDisclosure();
+ const formatValue = (value: string): string => {
+ try {
+ const parsed = JSON.parse(value);
+ return JSON.stringify(parsed, null, 2);
+ } catch {
Review Comment:
The formatting is incorrect. Please adjust the spacing properly.
```
try {
const parsed = JSON.parse(value);
return JSON.stringify(parsed, null, 2);
} catch {
return value;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog [airflow]
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #58757:
URL: https://github.com/apache/airflow/pull/58757#issuecomment-3590934221
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #58757:
URL: https://github.com/apache/airflow/pull/58757
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on PR #58757:
URL: https://github.com/apache/airflow/pull/58757#issuecomment-3942509802
looks like a valid backport. just create a backport PR here https://github.com/apache/airflow/pull/62339
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog [airflow]
Posted by "ctolon (via GitHub)" <gi...@apache.org>.
ctolon commented on PR #58757:
URL: https://github.com/apache/airflow/pull/58757#issuecomment-3909295753
Hi, Is this addressed in PR for Apache Airflow 3.2? It's a significant update from a developer UX perspective
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix Preserve variable value formatting in edit dialog (#58648) [airflow]
Posted by "rickychen-infinirc (via GitHub)" <gi...@apache.org>.
rickychen-infinirc commented on code in PR #58757:
URL: https://github.com/apache/airflow/pull/58757#discussion_r2567652638
##########
airflow-core/src/airflow/ui/src/pages/Variables/ManageVariable/EditVariableButton.tsx:
##########
@@ -36,6 +36,14 @@ type Props = {
const EditVariableButton = ({ disabled, variable }: Props) => {
const { t: translate } = useTranslation("admin");
const { onClose, onOpen, open } = useDisclosure();
+ const formatValue = (value: string): string => {
+ try {
+ const parsed = JSON.parse(value);
+ return JSON.stringify(parsed, null, 2);
+ } catch {
Review Comment:
Thanks for the review! I've already fixed this in the latest commit. The formatValue function now:
- Is moved to outer scope
- Has proper type annotation (const parsed: unknown)
- Uses undefined instead of null
Please check the updated code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org