django-unicorn icon indicating copy to clipboard operation
django-unicorn copied to clipboard

Feature request: remove component

Open nerdoc opened this issue 2 years ago • 3 comments

Hi Adam, a feature that could be easily integrated and would greatly enhance Unicorn is a client side "remove component" action. In many cases unicorn components are list elements or table rows that include action buttons like "Delete". You have examples for that using parent components that remove that row and rerender the whole list. This unnecessarily over-complicates the situation, as in IMHO many cases no parent component is needed - just a <ul> or <table> element. What e.g. the Tetra framework does, is to provide a self.client._remove_component() method, that just removes the whole element from the DOM at the client side. So a simple component delete action would just be:

class MyComponentView(UnicornView)
    def delete():
        self.client._remove_component()

and the template:

<tr>
  <td>...</td>
  <td>
      <button ... u:click="delete()">Delete</button>
  </td>
</tr>

Adding client side Js functions that can be called from the backend would be generally a huge benefit. (already there) But the delete() action is the most important.

nerdoc avatar Oct 26 '22 08:10 nerdoc

Maybe just the client side must be implemented here, as self.call() in the backend is already there.

nerdoc avatar Oct 26 '22 10:10 nerdoc

0.58.0 of Unicorn adds a Unicorn.deleteComponent method to remove a component from internal component store. I could extend this to remove the actual DOM element as well if that would be useful.

adamghill avatar Dec 26 '23 15:12 adamghill

I think this is what would be expected then, yes.

nerdoc avatar Jan 08 '24 21:01 nerdoc