ryangjchandler / filament-navigation

Build structured navigation menus in Filament.
MIT License
168 stars 64 forks source link

Differing schemas state persisted #81

Closed freshleafmedia closed 10 months ago

freshleafmedia commented 1 year ago

When the schema changes between different item types the data of the previous item type is still persisted.

Give the following item types:

FilamentNavigation::addItemType('TypeA', [
    Select::make('url'),
    TextInput::make('label'),
]);

FilamentNavigation::addItemType('Type B', [
    Select::make('url'),
]);
  1. create a nav item of Type A
  2. edit it, changing the type to Type B
  3. save

You will see the saved JSON contains a label property even though Type B doesn't have this field.

I believe the offending code is this block: https://github.com/ryangjchandler/filament-navigation/blob/7221e37aae3f3afc953923ac7fb052a90533726d/src/Filament/Resources/NavigationResource/Pages/Concerns/HandlesNavigationBuilder.php#L104-L108

I think it fills the previous state into the new form even though there are aren't fields to contain some of the state.

ryangjchandler commented 10 months ago

Please try to reproduce in Filament v3 with the latest version of this plugin.