Skip to content

Anonymous declarations on Actions, Cards, Scopes, etc.. #3702

@Paul-Bob

Description

@Paul-Bob

Feature

Currently when we want to register an action, card, filter, scope, etc.. we need to create a new class first.

Let's make it possible to register them anonymously, directly in the resource file.

Something like this:

class Avo::Resources::User < Avo::BaseResource
  def actions
    action title: "Toggle inactive",
      icon: "heroicons/outline/globe",
      visible: -> { record.active? },
      handler: -> { records.update_all(active: !record.active) }
  end
end

This will register an action with the given options and make it available in the resource.

Something similar can be done for cards, filters, scopes, etc..

class Avo::Resources::User < Avo::BaseResource
  def scopes
    scope name: "Even", description: "Only even numbers", query: -> { ... }
    scope name: "Odd", description: "Only odd numbers", query: -> { ... }
  end
end

This will register two scopes with the given options and make them available in the resource.

Approach

To be explored

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions