Coder Social home page Coder Social logo

awcodes / filament-quick-create Goto Github PK

View Code? Open in Web Editor NEW
147.0 4.0 22.0 414 KB

Plugin for Filament Panels that adds a dropdown menu to the header to quickly create new items.

License: MIT License

Blade 11.59% PHP 88.41%
filament filament-plugin

filament-quick-create's Introduction

Quick Create for Filament

Plugin for Filament Admin Panel that adds a dropdown menu to the header to quickly create new items from anywhere in your app.

quick-create-og

Installation

Install the package via composer

composer require awcodes/filament-quick-create

In an effort to align with Filament's theming methodology you will need to use a custom theme to use this plugin.

Note If you have not set up a custom theme and are using a Panel follow the instructions in the Filament Docs first. The following applies to both the Panels Package and the standalone Forms package.

Add the plugin's views to your tailwind.config.js file.

content: [
    '<path-to-vendor>/awcodes/filament-quick-create/resources/**/*.blade.php',
]

Usage

By default, Quick Create will use all resources that are registered with current Filament context. All resources will follow the authorization used by Filament, meaning that if a user doesn't have permission to create a record it will not be listed in the dropdown.

Registering the plugin

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make(),
        ])
}

Warning Excludes and includes are not meant to work together. You should use one or the other, but not both.

Excluding Resources

Excluding resources will filter them out of the registered resources to prevent them from displaying in the dropdown.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->excludes([
                    \App\Filament\Resources\UserResource::class,
                ]),
        ])
}

Including Resources

Sometimes, it might be easier to only include some resources instead of filtering them out. For instance, you have 30 resources but only want to display 3 to 4 in the dropdown.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->includes([
                    \App\Filament\Resources\UserResource::class,
                ]),
        ])
}

Sorting

By default, Quick Create will sort all the displayed options in descending order by Label. This can be disabled should you choose. In which case they will be displayed in the order they are registered with Filament.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->sort(false),
        ])
}

Sorting by resource navigation

By default, Quick Create will sort all the displayed options by Label. This can be changed to resource navigation sort should you choose. In which case they will be displayed in the order they are displayed in the navigation.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->sortBy('navigation'),
        ])
}

Appearance

Rounded

By default, the Quick Create button will be fully rounded if you would like to have a more square button you can disable the rounding with the rounded() method.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->rounded(false),
        ])
}

Hiding Icons

If you prefer to not show icons for the items in the menu you can disable them with the hiddenIcons() method.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->hiddenIcons(),
        ])
}

Setting a label

If you prefer to show a label with the plus icon you can set it using the label() method and passing your label to it.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->label('New'),
        ])
}

Slide Overs

By default, Quick Create will render simple resources in a standard modal. If you would like to render them in a slide over instead you may use the slideOver() modifier to do so.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->slideOver(),
        ])
}

Hiding Quick Create

By default, Quick Create is visible if there are registered resources. If you would like to hide it you may use the hidden() modifier to do so.

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->hidden(fn() => Filament::getTenant()->requiresOnboarding()),
        ])
}

Render Plugin on a Custom Panel Hook

By default, Quick Create plugin renders using 'panels::user-menu.before' Filament Panel Render Hook. If you would like to customize this to render at a different render hook, you may use the renderUsingHook(string $panelHook) modifier to do so. You may read about the available Render Hooks in Filament PHP here

use Awcodes\FilamentQuickCreate\QuickCreatePlugin;
use Filament\View\PanelsRenderHook;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            QuickCreatePlugin::make()
                ->renderUsingHook(PanelsRenderHook::SIDEBAR_NAV_END),
        ])
}

filament-quick-create's People

Contributors

abishekrsrikaanth avatar alperenersoy avatar artmin96 avatar awcodes avatar dependabot[bot] avatar fdt2k avatar github-actions[bot] avatar nicko170 avatar sitenzo avatar tanthammar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

filament-quick-create's Issues

SPA + Tenancy gives wrong URLs

Filament Version

v3

Plugin Version

3.3.2

PHP Version

8.2

Problem description

When we enable SPA mode + multi tenancy and you switch your team, the items on the quick create action do not get resetted. So when you click on an item, it takes you back to the other tenant. (See video)

Screen.Recording.2024-05-10.at.08.42.04.mov

Expected behavior

The URLs on the navigation should get refreshed upon team change and it should link to correct team.

Steps to reproduce

  1. Enable SPA
  2. Add multiple teams
  3. Switch from team
  4. Use quick create -> you'll be redirected to the wrong team

Reproduction repository

No response

Relevant log output

No response

Does not fill tenant id for tenant resources

Filament Version

v3

Plugin Version

v3.4

PHP Version

PHP 8.3.7

Problem description

In a multi-tenant applicaiton, Filament automatically handles populating the tenant id when creating new resources. This plugin does not, resulting in database error when trying to create new entry and the tenant ID is set to NOT NULL.

Screencast:

filament-quick-create.mov

Expected behavior

When a new model is created that has tenancy, it should auto-populat the tenant id like Filament does

Steps to reproduce

  • add tenancy to a filament project
  • make the tenant_id not null
  • add quick create to the project
  • try and use quick create to create new record
  • see database error similar to below:

image

Reproduction repository

No response

Relevant log output

No response

Feature Request: Include only option

i have over 20 resources and new ones are added often. I would really love to only have in my quick create menu the 4-5 resources I actually want there versus having to exclude everything i dont want.

option enabled without create page.

is there any way to hide this option if users do not have rides to create any resources?

I mean it works fine if the user has 3 access from 6 resources it shows 3 of them but it isn't hiding when the user has 0 from 6 resources it shows a blank drop-down.

it may be done by checking the item count in the blade component.

image

Native Filament v3 profile page doesn't work with Multi-Tenancy + this plugin

Filament Version

v3

Plugin Version

v3.1.0

PHP Version

PHP 8.2.8

Problem description

The profile page doesn't render with this plugin installed, as the plugin is trying to render the quick create button without the tenant parameter available.

Expected behavior

The page works correctly & renders.

Steps to reproduce

  • Setup multi-tenancy
  • Activate the native v3 profile page
  • Install quick create plugin
  • List at least one resource on the quick create button
  • Try to access the profile page

Reproduction repository

No response

Relevant log output

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.