Skip to content

Commit

Permalink
Fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
invaders-xx committed Apr 23, 2024
1 parent 5e01b0e commit f85d874
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Filament Nested List

Filament Nested List is a plugin for Filament Admin that creates a model management page with a heritage tree structure
Filament Nested List is a plugin for Filament Admin that creates a model management page with a heritage nested list
structure
view.
This plugin can be used to create menus and more.

This plugin creates model management page with heritage tree structure view for Filament Admin. It could be used to
This plugin creates model management page with heritage nested list structure view for Filament Admin. It could be used
to
create menu, etc.

## Installation
Expand Down Expand Up @@ -70,7 +72,7 @@ return [

### Prepare the database and model

To use Filament Tree, follow these table structure conventions:
To use Filament Nested List, follow these table structure conventions:

> **Tip: The `parent_id` field must always default to -1!!!**
Expand All @@ -85,8 +87,7 @@ Schema::create('product_categories', function (Blueprint $table) {
```

This plugin provides a convenient method called `nestedListColumns()` that you can use to add the required columns for
the
tree structure to your table more easily. Here's an example:
the nested list structure to your table more easily. Here's an example:

```
Schema::create('product_categories', function (Blueprint $table) {
Expand All @@ -96,7 +97,7 @@ Schema::create('product_categories', function (Blueprint $table) {
});
```

This will automatically add the required columns for the tree structure to your table.
This will automatically add the required columns for the nested list structure to your table.

The above table structure contains three required fields: `parent_id`, `order`, `title`, and other fields do not have
any requirements.
Expand Down Expand Up @@ -175,7 +176,7 @@ class ProductCategory extends Model
Filament provides a powerful feature that allows you to display widgets inside pages, below the header and above the
footer. This can be useful for adding additional functionality to your resource pages.

To create a Tree Widget and apply it to a resource page, you can follow these steps:
To create a Nested List Widget and apply it to a resource page, you can follow these steps:

#### 1. Creating a Filament Resource Page

Expand All @@ -187,7 +188,7 @@ php artisan make:filament-resource ProductCategory

#### 2. Create Tree Widget

Prepare the filament-tree Widget and show it in Resource page.
Prepare the filament-nested-list Widget and show it in Resource page.

```php
php artisan make:filament-nested-list-widget ProductCategoryWidget
Expand Down Expand Up @@ -228,7 +229,7 @@ class ProductCategoryWidget extends BaseWidget
#### 3. Displaying a widget on a resource page

Once you have created the widget, modify the `getHeaderWidgets()` or `getFooterWidgets()` methods of the resource page
to show the tree view:
to show the nested list view:

```php
<?php
Expand Down Expand Up @@ -262,20 +263,21 @@ class ListProductCategories extends ListRecords

### Resources

Filament allows you to create a custom pages for resources, you also can create a tree page that display hierarchical
Filament allows you to create a custom pages for resources, you also can create a nested list page that display
hierarchical
data.

#### Create a Page

To create a tree page for resource, you can use:
To create a nested list page for resource, you can use:

```
php artisan make:filament-nested-list-page ProductCategoryNestedList --resource=ProductCategory
```

#### Register a Page to the resource

You must register the tree page to a route in the static `getPages()` methods of your resource. For example:
You must register the nested list page to a route in the static `getPages()` methods of your resource. For example:

``` php
public static function getPages(): array
Expand All @@ -289,7 +291,8 @@ public static function getPages(): array

#### Actions

Define the available "actions" for the tree page using the `getActions()` and `getTreeActions()` methods of your page
Define the available "actions" for the nested list page using the `getActions()` and `getTreeActions()` methods of your
page
class.

The `getActions()` method defines actions that are displayed next to the page's heading:
Expand All @@ -307,7 +310,7 @@ The `getActions()` method defines actions that are displayed next to the page's
}
```

The `getTreeActions()` method defines the actions that are displayed for each record in the tree. For example:
The `getTreeActions()` method defines the actions that are displayed for each record in the nested list. For example:

```php
use Filament\Pages\Actions\Action;
Expand Down Expand Up @@ -345,21 +348,24 @@ protected function hasViewAction(): bool

### Pages

This plugin enables you to create tree pages in the admin panel. To create a tree page for a model, use
the `make:filament-nested-list-page` command. For example, to create a tree page for the ProductCategory model, you can
This plugin enables you to create tree pages in the admin panel. To create a nested list page for a model, use
the `make:filament-nested-list-page` command. For example, to create a nested list page for the ProductCategory model,
you can
run:

#### Create a Page

> **Tip: Note that you should make sure the model contains the required columns or already uses the `ModelTree` trait**
> **Tip: Note that you should make sure the model contains the required columns or already uses the `ModelNestedList`
trait**

```php
php artisan make:filament-nested-list-page ProductCategory --model=ProductCategory
```

#### Actions, Widgets and Icon for each record

Once you've created the tree page, you can customize the available actions, widgets, and icon for each record. You can
Once you've created the nested list page, you can customize the available actions, widgets, and icon for each record.
You can
use the same methods as for resource pages. See the [Resource Page](#resources) for more information on how to
customize actions, widgets, and icons.

Expand Down
14 changes: 7 additions & 7 deletions src/Concern/HasHeading.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@

trait HasHeading
{
protected ?string $title = null;
protected ?string $nestedListTitle = null;

protected bool $enableTitle = false;
protected bool $enableNestedListTitle = false;

public function nestedListTitle(string $title): static
public function nestedListTitle(string $nestedListTitle): static
{
$this->title = $title;
$this->nestedListTitle = $nestedListTitle;

return $this;
}

public function enableNestedListTitle(bool $condition): static
{
$this->enableTitle = $condition;
$this->enableNestedListTitle = $condition;

return $this;
}

public function getNestedListTitle(): ?string
{
return $this->title;
return $this->nestedListTitle;
}

public function displayNestedListTitle(): bool
{
return $this->enableTitle;
return $this->enableNestedListTitle;
}
}
12 changes: 6 additions & 6 deletions src/Forms/Components/NestedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NestedList extends Field

protected ?Closure $modifyRelationshipQueryUsing = null;

public function getState()
public function getState(): mixed
{
$state = parent::getState();

Expand Down Expand Up @@ -68,6 +68,11 @@ public function getNodeLabel(string $uuid): ?string
return data_get($this->getChildComponentContainer($uuid)->getRawState(), $this->getTitleColumn() ?? 'title');
}

public function getTitleColumn(): ?string
{
return $this->evaluate($this->titleColumn);
}

public function nodes(array|Arrayable $nodes): static
{
if ($nodes instanceof Arrayable) {
Expand Down Expand Up @@ -276,11 +281,6 @@ public function getKeyColumn(): ?string
return $this->evaluate($this->keyColumn);
}

public function getTitleColumn(): ?string
{
return $this->evaluate($this->titleColumn);
}

public function getChildrenColumn(): ?string
{
return $this->evaluate($this->childrenColumn);
Expand Down

0 comments on commit f85d874

Please sign in to comment.