diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c28d95c9..1f2cc1cec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ changes. ### Fixed +- Fix blank page on dRep details when link or identity references contain objects: { @value: ... } not strings [Issue 3733](https://github.com/IntersectMBO/govtool/issues/3733) - Fix missing off chain references in DRep details [Issue 3490](https://github.com/IntersectMBO/govtool/issues/3490) - Fix blank screen and type error on linkReferences when navigating to edit dRep page that has no links [Issue 3714](https://github.com/IntersectMBO/govtool/issues/3714) - Fix adding two link input fields when editing the dRep form when no links are present initially [Issue 3709](https://github.com/IntersectMBO/govtool/issues/3709) diff --git a/govtool/backend/sql/list-dreps.sql b/govtool/backend/sql/list-dreps.sql index 3062c9f48..cb27c527c 100644 --- a/govtool/backend/sql/list-dreps.sql +++ b/govtool/backend/sql/list-dreps.sql @@ -95,7 +95,7 @@ HasNonDeregisterVotingAnchor AS ( EXISTS ( SELECT 1 FROM drep_registration dr_sub - WHERE + WHERE dr_sub.drep_hash_id = dr.drep_hash_id AND dr_sub.voting_anchor_id IS NULL AND COALESCE(dr_sub.deposit, 0) >= 0 @@ -129,12 +129,24 @@ DRepData AS ( off_chain_vote_drep_data.image_hash, COALESCE( ( - SELECT jsonb_agg(ref) + SELECT jsonb_agg( + jsonb_build_object( + 'uri', COALESCE( + CASE WHEN jsonb_typeof(ref->'uri') = 'string' THEN ref->>'uri' END, + ref->'uri'->>'@value' + ), + '@type', ref->>'@type', + 'label', COALESCE( + CASE WHEN jsonb_typeof(ref->'label') = 'string' THEN ref->>'label' END, + ref->'label'->>'@value' + ) + ) + ) FROM jsonb_array_elements( - CASE - WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL - THEN (ocvd.json::jsonb)->'body'->'references' - ELSE '[]'::jsonb + CASE + WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL + THEN (ocvd.json::jsonb)->'body'->'references' + ELSE '[]'::jsonb END ) AS ref WHERE ref->>'@type' = 'Identity' @@ -143,12 +155,24 @@ DRepData AS ( ) AS identity_references, COALESCE( ( - SELECT jsonb_agg(ref) + SELECT jsonb_agg( + jsonb_build_object( + 'uri', COALESCE( + CASE WHEN jsonb_typeof(ref->'uri') = 'string' THEN ref->>'uri' END, + ref->'uri'->>'@value' + ), + '@type', ref->>'@type', + 'label', COALESCE( + CASE WHEN jsonb_typeof(ref->'label') = 'string' THEN ref->>'label' END, + ref->'label'->>'@value' + ) + ) + ) FROM jsonb_array_elements( - CASE - WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL - THEN (ocvd.json::jsonb)->'body'->'references' - ELSE '[]'::jsonb + CASE + WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL + THEN (ocvd.json::jsonb)->'body'->'references' + ELSE '[]'::jsonb END ) AS ref WHERE ref->>'@type' = 'Link' @@ -185,7 +209,7 @@ DRepData AS ( LEFT JOIN FetchError fetch_error ON fetch_error.voting_anchor_id = leva.voting_anchor_id LEFT JOIN HasNonDeregisterVotingAnchor hndva ON hndva.drep_hash_id = dh.id LEFT JOIN off_chain_vote_data ocvd ON ocvd.voting_anchor_id = leva.voting_anchor_id - LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = ocvd.id + LEFT JOIN off_chain_vote_drep_data ON off_chain_vote_drep_data.off_chain_vote_data_id = ocvd.id LEFT JOIN voting_procedure ON voting_procedure.drep_voter = dh.id LEFT JOIN tx voting_procedure_transaction ON voting_procedure_transaction.id = voting_procedure.tx_id LEFT JOIN block voting_procedure_block ON voting_procedure_block.id = voting_procedure_transaction.block_id @@ -244,10 +268,10 @@ DRepData AS ( ( SELECT jsonb_agg(ref) FROM jsonb_array_elements( - CASE - WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL - THEN (ocvd.json::jsonb)->'body'->'references' - ELSE '[]'::jsonb + CASE + WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL + THEN (ocvd.json::jsonb)->'body'->'references' + ELSE '[]'::jsonb END ) AS ref WHERE ref->>'@type' = 'Identity' @@ -255,10 +279,10 @@ DRepData AS ( ( SELECT jsonb_agg(ref) FROM jsonb_array_elements( - CASE - WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL - THEN (ocvd.json::jsonb)->'body'->'references' - ELSE '[]'::jsonb + CASE + WHEN (ocvd.json::jsonb)->'body'->'references' IS NOT NULL + THEN (ocvd.json::jsonb)->'body'->'references' + ELSE '[]'::jsonb END ) AS ref WHERE ref->>'@type' = 'Link' @@ -275,4 +299,4 @@ WHERE objectives ILIKE ? OR motivations ILIKE ? OR qualifications ILIKE ? - ) \ No newline at end of file + )