Skip to content

Conversation

@momo3404
Copy link
Collaborator

@momo3404 momo3404 commented Sep 29, 2025

Fixes #1196 .

Changes proposed in this PR:

  • Change the ordering of templates in the template dropdown menu from alphabetical to all organizational templates first, followed by the Alliance Simplified Template, Alliance Template, and all remaining templates.
  • Simplified template loading logic by removing explicit Template.default handling.
  • Template.latest_customizable.where(org_id: funder.id) and Template.published.publicly_visible.where(org_id: funder.id, customization_of: nil) now fetch the default template as well
  • Removed manual insertion and filtering of the default template; sort_templates() now determines ordering.

@momo3404 momo3404 force-pushed the momo/issues/1196-dropdown branch from f2311b0 to cbb80dc Compare October 1, 2025 18:08
@momo3404 momo3404 marked this pull request as ready for review October 1, 2025 21:09
@aaronskiba
Copy link
Collaborator

The ordering seems to be off in the dropdown when I select Digital Research Alliance of Canada as the Organisation.

# Assign the order of templates in the dropdown menu
def sort_templates(templates, org) # rubocop:disable Metrics/AbcSize
# Get all templates belonging to the selected organization
org_templates = templates.select { |template| template.org_id == org&.id && template.customization_of.nil? }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you using template.customization_of.nil??

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seemed to fix this bug that occurs with some orgs (like McMaster for example) where the order would be Alliance Simplified Template -> Org templates -> Alliance Template

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this query result might reveal a bit:
Screenshot from 2025-10-02 12-13-15

Non-Alliance orgs may have their own customisation of the "Alliance Simplified Template". If an org does have that customisation, then it will be included in org_templates. And further, I'm thinking the .uniq execution at the end would remove the alliance_template = templates.find { |t| t.title == 'Alliance Template' } duplicate.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@CeriMacMillan, what to do in the following scenario?

An org has customised the Alliance Simplified Template (Funding Application Stage) template but the title remains identical. Should this be grouped with the org templates? Or should it be grouped below that in the (Alliance Simplified Template (Funding Application Stage) / Alliance Template) section?

Maybe that same question can be asked of any org customisation of an Alliance template the retains the exact same title.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@aaronskiba That's a really good question, I would lean towards putting it with the org templates as they have taken the time to add local content/context. Maybe they can come after any or templates named as 'org template' but before the Alliance templates.

Can double check this with @closenma though to be sure.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree, if it has customization then let's count it at organizational and sort it above the other Alliance templates.

@momo3404
Copy link
Collaborator Author

momo3404 commented Oct 2, 2025

The ordering seems to be off in the dropdown when I select Digital Research Alliance of Canada as the Organisation.

I'm guessing that's because the Alliance templates get included in org_templates. Just to confirm, the order you're seeing is Alliance Template -> Two other Alliance templates -> Alliance Simplified Template?

@aaronskiba
Copy link
Collaborator

The ordering seems to be off in the dropdown when I select Digital Research Alliance of Canada as the Organisation.

I'm guessing that's because the Alliance templates get included in org_templates. Just to confirm, the order you're seeing is Alliance Template -> Two other Alliance templates -> Alliance Simplified Template?

That's right. Basically, Alliance Template, and then all of the others in alphabetical order.

Copy link
Collaborator

@aaronskiba aaronskiba left a comment

Choose a reason for hiding this comment

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

This snippet mutates @templates by removing default/customization and then prepending it:

      @templates.select! { |t| t.id != Template.default.id && t.id != customization.id }
      # We want the default template to appear at the beggining of the list
      @templates.unshift(customization)
    end

That snippet was used for the prior ordering of the templates. Since sort_templates is now fully responsible for the ordering, maybe we should address/remove the old ordering code.

@momo3404
Copy link
Collaborator Author

momo3404 commented Oct 3, 2025

This snippet mutates @templates by removing default/customization and then prepending it:

      @templates.select! { |t| t.id != Template.default.id && t.id != customization.id }
      # We want the default template to appear at the beggining of the list
      @templates.unshift(customization)
    end

That snippet was used for the prior ordering of the templates. Since sort_templates is now fully responsible for the ordering, maybe we should address/remove the old ordering code.

I think that code might still be necessary. I tried removing it, but with that change the Alliance Template now never shows up in the dropdown.

I also am not sure how much we should meddle with the existing code, since it seems there's a lot going on with customizations and default templates.

@aaronskiba
Copy link
Collaborator

This snippet mutates @templates by removing default/customization and then prepending it:

      @templates.select! { |t| t.id != Template.default.id && t.id != customization.id }
      # We want the default template to appear at the beggining of the list
      @templates.unshift(customization)
    end

That snippet was used for the prior ordering of the templates. Since sort_templates is now fully responsible for the ordering, maybe we should address/remove the old ordering code.

I think that code might still be necessary. I tried removing it, but with that change the Alliance Template now never shows up in the dropdown.

I also am not sure how much we should meddle with the existing code, since it seems there's a lot going on with customizations and default templates.

Yes, this controller is looking pretty fragile. I might take a shot at that change though, just to help a bit with future maintainability.

@momo3404 momo3404 changed the title Reorganize template dropdown menu Reorganize template dropdown menu and refactor TemplateOptionsController Oct 7, 2025
@momo3404 momo3404 force-pushed the momo/issues/1196-dropdown branch from 7273b10 to b7fe417 Compare October 7, 2025 21:33
momo3404 and others added 9 commits October 8, 2025 13:34
- With these changes, if the chosen org is the Alliance, now the first two displayed templates are the Alliance Simplified and Alliance main templates
- The previous code incorrectly excluded org templates that were customizations of other templates. Now those templates are included at the top of the dropdown menu along with other org templates.
Simplified template loading logic by removing explicit default template handling.
- `Template.latest_customizable.where(org_id: funder.id)` and `Template.published.publicly_visible.where(org_id: funder.id, customization_of: nil)` now fetch the default template as well
- Removed manual insertion and filtering of the default template; `sort_templates()` now determines ordering.
The changes in a4fc95e require that the default template belong to the default org.
@momo3404 momo3404 force-pushed the momo/issues/1196-dropdown branch from 27ac43c to 40c0299 Compare October 8, 2025 19:34
aaronskiba
aaronskiba previously approved these changes Oct 8, 2025
Copy link
Collaborator

@aaronskiba aaronskiba left a comment

Choose a reason for hiding this comment

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

Looks good. Sorting looks in order and I'm liking the simpler handling of the default template throughout this controller now.

@momo3404 momo3404 merged commit 8f96d63 into integration Oct 8, 2025
10 checks passed
@momo3404 momo3404 deleted the momo/issues/1196-dropdown branch October 8, 2025 20:01
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.

5 participants