Skip to content

Conversation

@taylor-steve
Copy link
Contributor

@taylor-steve taylor-steve commented Sep 19, 2025

Fixes #3533

I believe these these two tests represent incompatible notions of page parent relationships:

it 'updates the translated child pages with the correct parent association' do
expect(child_page_es.parent_page).to eq parent_page
parent_page_es.save
expect(child_page_es.reload.parent_page).to eq parent_page_es
end

it 'removes the parent page id when the child page is set to an as-yet-untranslated parent page' do
child_page.update(parent_page: another_page)
expect(child_page_es.reload.parent_page).to be_nil
end

The first test suggests that a translated child page can and should point its parent_page at the default locale parent page when there is no translated parent page available.

The second test suggests that translated children should have a nil parent relationship when the translated parent is missing.

I think this all might be somewhat awkwardly modeled, but nil parent relationships make more sense for our existing code.

This bug was caused by a discrepancy with the parent handling between:

def clone_for_locale(locale)
dup.tap do |np|
np.locale = locale
np.default_locale_page = self
np.published = false
np.slug = slug
if !top_level_page? && (parent_translation = parent_page.translated_page_for(locale)).present?
np.parent_page = parent_translation
end
child_pages.for_locale(locale).update(parent_page: np) if top_level_page? && respond_to?(:child_pages)
end
end

and:

def update_translated_pages_weights_and_parent_page
return unless locale.to_sym == I18n.default_locale
if saved_change_to_parent_page_id?
translated_pages.find_each do |translated_page|
parent_translation = parent_page&.translated_page_for(translated_page.locale)
translated_page.update(parent_page_id: parent_translation&.id)
end
end
translated_pages.update(weight:) if saved_change_to_weight?
end

This PR would effectively mean you'd use locale to shift laterally between fully independent trees of feature pages

Checking if you have translated pages that would be impacted

In a Rails console in your Spotlight app:

translated_pages = Spotlight::Page.where.not(locale: I18n.default_locale).where.not(parent_page_id: nil)

pages_with_the_bug = translated_pages.select { |page| page.parent_page&.locale&.to_sym == I18n.default_locale }

If you have impacted pages (pages_with_the_bug.length > 0) you have two choices:

  • add translations for all the parent pages of the pages_with_the_bug pages
  • set the parent_page relationship to nil for all pages_with_the_bug pages

Potential Future Work

This PR only serves to establish consistency in how we treat page parent relationships, it does not address the somewhat odd behavior than can arise from how they are currently modeled. Take this example, where all pages with the exception of FP 3 have French translations:
Screenshot 2025-09-19 at 4 47 37 PM

When viewing the exhibit in French the ordering can differ significantly from the default locale because of the mismatch between the page trees and the weights being considered.
Screenshot 2025-09-19 at 4 47 44 PM

The Spotlight community may want to revisit if this current page translation approach is meeting their needs or if moving to a more simple approach would suffice.

@taylor-steve taylor-steve force-pushed the 3533-translations-can-have-nil-parent-page branch 6 times, most recently from b49f497 to 39ada1d Compare September 19, 2025 22:26
@taylor-steve taylor-steve force-pushed the 3533-translations-can-have-nil-parent-page branch from 39ada1d to e5d4be9 Compare September 19, 2025 23:08
@taylor-steve taylor-steve marked this pull request as ready for review September 19, 2025 23:59
@corylown corylown merged commit bdde8d1 into main Sep 24, 2025
6 checks passed
@corylown corylown deleted the 3533-translations-can-have-nil-parent-page branch September 24, 2025 19:42
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.

Bug: adding translated pages causes the feature page layout/order editing UI to not save changes.

3 participants