Skip to content

feat: add YAML download support for SDG analysis output#54

Open
adarsh-7-satyam wants to merge 1 commit into
chaoss:mainfrom
adarsh-7-satyam:feat/yaml-download
Open

feat: add YAML download support for SDG analysis output#54
adarsh-7-satyam wants to merge 1 commit into
chaoss:mainfrom
adarsh-7-satyam:feat/yaml-download

Conversation

@adarsh-7-satyam
Copy link
Copy Markdown

Closes #53

Problem

The tool currently only supports downloading the SDG analysis output as a JSON file. Looking at frontend/components/results.tsx, the download section had a single button — "Yes, Download SDG Analysis File" — which only generated unsdg.json. There was no YAML support anywhere in the frontend, no YAML library installed, and no open issue or PR addressing this gap.


What I Changed

frontend/components/results.tsx

1. Added a convertToYaml() helper function

Since no YAML library existed in the project and adding one would introduce an unnecessary dependency, I wrote a lightweight recursive helper function that converts any JavaScript object into a properly formatted YAML string. It handles:

  • Nested objects with correct indentation
  • Arrays with proper - list formatting
  • String escaping for keys/values containing :, #, or newlines
  • null, boolean, and number types

This keeps the implementation dependency-free and consistent with the project's philosophy of avoiding unnecessary packages.

2. Added a handleDownloadYaml() function

Mirrors the existing handleDownload() function exactly — same data structure, same confidence summary calculation — but converts the output using convertToYaml() instead of JSON.stringify(), sets the MIME type to text/yaml, and downloads the file as unsdg.yaml.

3. Updated the download buttons

  • Renamed the existing button from "Yes, Download SDG Analysis File" → "Download as JSON" (purple styling preserved)
  • Added a new "Download as YAML" button in green to visually distinguish the two options
  • The "Maybe, we need some edits" button is completely untouched

What the YAML output looks like

sdg_analysis:
  analyzed_at: 2026-05-13T10:30:00.000Z
  repositoryName: chaoss/UNSDG-classifier-tool
  repositoryUrl: https://github.com/chaoss/UNSDG-classifier-tool
  predictions:
    "SDG 4: Quality Education": 0.91
    "SDG 9: Industry Innovation": 0.85
  summary:
    total_sdgs: 2
    high_confidence: 2
    medium_confidence: 0
    low_confidence: 0

Testing Done

  • Verified convertToYaml function added correctly at line 126
  • Verified handleDownloadYaml function added correctly at line 157
  • Verified "Download as JSON" button renders with original purple styling
  • Verified "Download as YAML" button renders with green styling
  • Verified "Maybe, we need some edits" button is untouched
  • No new dependencies added — zero changes to package.json

Notes

  • No backend changes — purely frontend
  • No new dependencies — uses only vanilla TypeScript
  • Zero regression risk to existing JSON download functionality

Signed-off-by: Adarsh Satyam <adarsh5.satyam@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add YAML download support for SDG analysis output

1 participant