Skip to content

Navigation spike - combo [WHIT-3342]#4076

Closed
ChrisBAshton wants to merge 16 commits into
mainfrom
navigation-spike--three
Closed

Navigation spike - combo [WHIT-3342]#4076
ChrisBAshton wants to merge 16 commits into
mainfrom
navigation-spike--three

Conversation

@ChrisBAshton

@ChrisBAshton ChrisBAshton commented May 29, 2026

Copy link
Copy Markdown
Contributor

Cherry-picking the best of #4074 and #4075

Jira: https://gov-uk.atlassian.net/browse/WHIT-3342


This application is owned by the Content APIs team. Please let us know in #govuk-content-apis when you raise any PRs.

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

@lauraghiorghisor-tw lauraghiorghisor-tw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but a bit difficult to wrap my head around some bits - left some comments.

It would be nice to have in the spike output (Jira card or even better, an outcome section on the confluence decision log):

  • A little flow/diagram/stickies/something outlining the exact interaction with pub api, the payloads in whitehall, and the eventual representation in content store after link expansion; using the last version of the terminology (I think your card comment has the latest?)
  • Tag Sally about the terminology - I am sure she'd have thoughts.
  • A more detailed explanation/ the why of some of the decisions around the new expansion rule and why current rules are insufficient.

)
end

it "expands all member documents under the collection" do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I am reading this test correctly. Can I check my understanding?

We want to expand the links on a parent or child document, so we show smth like:

{
  details: {},
  links: {
    shared_navigation: [
        {
            content_id: <>,
            links: {
              documents: [
                {
                  content_id: <self/this LP>,
                  title: <>,
                  base_path: <>  
                },
                { <some other doc in nav> }
              ]#end documents
            }#end shared navigation links
        }#end shared navigation item -> can we have multiple?
    ]#end shared navigation array
  }# end links
}

Is that right? The test feels like we are expanding the links on the navigation (collection) itself.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other bit I am struggling with, and maybe it's worth writing this out explicitly in the spike output - is on whose publication/put-content/both call we are doing the expansion work - a landing page's or the navigation's?

@lauraghiorghisor-tw lauraghiorghisor-tw Jun 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here, if we need to support non-child documents in the nav, and a document can be added to multiple navs, this shared_navigation link on the doc page would actually be an array of more than one - that would be terribly confusing for figuring out what nav to render. If we ever wanted to inject some nav on non-lp (read: semantic) content types - which honestly, let's not 😅 but I may have read somewhere on some doc that we would consider that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this is clearer in the revamped spike and PR description over at #4085 😅

As for the shared_navigation being an array - yes, that's a bit uncomfortable. Publishing API convention seems to be that these links are always arrays.

We could consider adding a maxItems: 1 rule, as is done for primary_publishing_organisation?

@lauraghiorghisor-tw lauraghiorghisor-tw Jun 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it now about the behaviour we had on collections vs this.

  • Test still reads weird to me 😅
  • I like the maxItems idea 👌

On the point about the array actually having multiple navs for a linked page that is not a landing page (child) type - I am thinking we wouldn't enable rendering of any nav in the FE for our old types, so we simply wouldn't consume that expanded links information. We could just use the parent link solution for breadcrumbs if we have to include such pages in nav (end of Q2 concern).

Comment thread lib/link_expansion.rb Outdated
end
end

def document_collection_member_links(collection_content_id)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's just a spike - would be nice to write this in a more readable way when we implement, the code duplication between this and the logic in the method that calls it, is a bit dizzying.

Comment thread lib/link_expansion.rb
return {}
end

reverse_link_type = node.link_types_path.first

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we need to support multiple nesting, do we mix in the recursive logic as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - as the links are flat. The nesting (if we do ever do that) would be in the details.menu_items JSON structure, which isn't touched by link expansion / dependency resolution.

Comment thread lib/expansion_rules.rb

# These expand every member of the reciprocal direct link type from
# the source link set, instead of only mirroring the edition being expanded.
REVERSE_LINKS_WITH_MEMBER_EXPANSION = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need this because if we used the normal rule, the expanded nav links in a LP content item would include that single LP content item rather than all?

Just looking at a typical collection https://www.integration.publishing.service.gov.uk/api/content/government/statistics/dcms-economic-estimates-gva-2024-provisional.

Can this also be articulated in a bit more detail in the spike output in layman's terms?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attempted to explain this in the cleaned up spike at #4085.

Comment thread lib/expansion_rules.rb
# These expand every member of the reciprocal direct link type from
# the source link set, instead of only mirroring the edition being expanded.
REVERSE_LINKS_WITH_MEMBER_EXPANSION = {
document_collections: :documents,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the order of the key and the value reversed here - compared to the old collections? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question 🤔 Only a spike. But agree for the real implementation it would be nice for this to be consistent with everywhere else in the file.

@lauraghiorghisor-tw lauraghiorghisor-tw Jun 2, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought maybe the key implies some precedence like doing the expansion for a content item containing links like the key, or something.

But I guess the expansion applies both ways for reverse links? In practice, you wouldn't send those payloads both ways as that would defy the point of the reverse link?

@ChrisBAshton

Copy link
Copy Markdown
Contributor Author

Superseded by #4085

@ChrisBAshton ChrisBAshton deleted the navigation-spike--three branch June 2, 2026 15:22
@TonyGDS

TonyGDS commented Jun 2, 2026

Copy link
Copy Markdown

LGTM, I assume we'd need a new link type like navigations -> navigation_documents for the actual implemenation

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.

3 participants