Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Issues
  • #2290
Closed
Open
Issue created Nov 25, 2022 by Alfonso Mancilla@ammancilla

Render custom partials for a Field without overriding the default ones

What would you like to be able to do? Can you provide some examples?

As a developer I can render custom partials for a Field without overriding its default ones

For example, I have a dashboard with three Field::HasMany attributes. For two of them I want to render the default partials but for the third one I want to render custom show and index pages.

How could we go about implementing that?

Introducing a new option (partials or so) to allow developers to provide path(s) to custom(s) partials(s) to be used when rendering the field in the context of the dashboard. If no custom partial is given for a page then the default one is used.

i.e

  • Dashboard
  # app/dashboards/book_dashboard.rb

  ATTRIBUTE_TYPES = {
    pages: Field::HasMany,
    authors: Field::HasMany.with_options(partials: { index: '/path/to/custom/partial'}),
    publishers: Field::HasMany.with_options(partials: { show: '/path/to/custom/partial'})
  }
  • Aministrate Base field
# administrate/lib/administrate/field/base.rb

def to_partial_path
  options.dig(:partials, page) || "/fields/#{self.class.field_type}/#{page}"
end

Can you think of other approaches to the problem?

Edit: https://github.com/thoughtbot/administrate/issues/2290#issuecomment-1327363377


At the moment I can't think of another approach to be taken from within Administrate but I have been doing the following to cover the described use case:

Create a custom field type (without any custom behavior), that inherit from the respective administrate field type. Use the custom field in the dashboard where you want to have custom partials rendered.

For example:

def HasManyExtendedView < Field::HasMany; end

def HasManySimpleView < Field::HashMany; end

This approach doesn't scale and results in having a lot of unnecessary files/code (a bunch of custom fields without custom behaviour)

Assignee
Assign to
Time tracking