mdelobelle / metadatamenu

For data management enthusiasts : type and manage the metadata of your notes.
https://mdelobelle.github.io/metadatamenu
MIT License
478 stars 27 forks source link

Adding fields to object from parent fileClass throws Impossible to restore field hierarchy and breaks fileClass. #600

Open ChristinWhite opened 4 months ago

ChristinWhite commented 4 months ago

Issue

I'm running into an issue adding fields to a inherited object from a parent fileClass.

As soon as I create a field and specify that I want a new field to have the parent object from created in the parent fileClass Obsidian shows an error that it's Impossible to restore field hierarchy, check your fileclass configuration. It also breaks the fileClass quite a bit. While it remembers the other fields specified it looks like all of the values for the properties under Fileclass settings seem to get erased and set back to defaults. Some properties file Flieclass settings sometimes stop being editable though somewhat inconsistently. Changing the field order in Fileclass fields also stops working.

Actually using Metadata Menu you insert and modify fields on a note with that class works flawlessly.

Setup

My default fileClass is simply Class, one of it's fields is an Object named Links

I then have a subclass, in this case, Visual Studio Code Extensions that extends Class. I then have another object called Extension, it has two input fields named Marketplace and Repo.

So we have this basically:

fileClass: Class
  object: Links

fileClass: Visual Studio Code Extension
  *Class.Links*
  ↳ object: Extension
    ↳ input: Marketplace
    ↳ input: Repo

Here's the full fileClass files

Full console errors:

CleanShot 2024-02-21 at 16 43 22@2x

Environment

Obsidian: 1.5.7 Metadata Menu: 0.7.7

Workaround

I suspect you may never have intended for people to extend inherited objects this way but when I had the idea while playing with Metadata Menu objects I was thrilled! It seemed like one the last couple of pieces I needed to achieve a Tana-like workflow in Obsidian.

I will likely just use multiple link objects like Links and Extension Links without nesting them but it's definitely going to be a bit more complicated to have Dataview loop through them.

I would love for the original idea to be possible though.

mdelobelle commented 4 months ago

I see that you run 0.7.7: can you try with 0.8.3? I have fixed fileclasses with whitespaces in their name breaking some ui (the fileclass name is used in some css class that don't like white spaces, hence the console error)

ChristinWhite commented 4 months ago

Thanks for looking into this! I'm now running 0.8.3 and I'm seeing the same behavior.

mdelobelle commented 4 months ago

Ok I can reproduce this. To be honest I never thought about this usage for inherited fields 😅. It will require some work to expose the hierarchy "inherited" from the parent because the "parent-class's field's parent field" (🤯) doesn't exist in the child fileclass

First I have to deal with the fact that the path of the child field refers to an id that belongs to the parent fileclass and not the current fileclass itself (will be tricky)

Then I'll have to deal with the display within the fields settings view and the modals (also challenging)

I can see the benefit of defining objects à the top level so as not to recreate them in each class, still it will require quite some coding and testing to make it work, so I'm not sure I can ship this feature in the near future. But I will try

ChristinWhite commented 4 months ago

I suspected this wasn't really what you had in mind, I somehow manage to find the weird bugs and obscure edge cases wherever I go. I do think it's a kind of cool use case though so I appreciate you working on that functionality. That said, this isn't a critical issue that prevents me from using your fantastic plugin and I have a decent workaround that will be pretty easy to switch back to the original idea when you finish the changes. Please don't feel like you have to kill yourself over this, especially since I'm the only user who's apparently tried to use inheritance in this manor.

While it's on the learn list, I unfortunately don't a very strong working knowledge of Obsidian's APIs and the underlying technologies but if there's anything I can do to help with testing please let me know!

nikorado commented 3 months ago

I assume there are others interested in this feature also. Because the parent class parent field can be used as an aggregator of other classfile fields (some cases exist). That data can then be accessed in other queries under the same key, and if you have for example multiple child number fields you can do bulk operations on them using basic "for (key in parent field)" loops. Example:

"for (let key in yourObject) { sum+=(key, yourObject[key]); }"

or other stuff similar to this.