mdelobelle / metadatamenu

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

Metadata is not being updated by inserted at the beginning (over Dataview query) #612

Open niceszett opened 7 months ago

niceszett commented 7 months ago

Hi there,

I have this very weird issue that when I update any type of metadata field inside a Dataview query, the metadata is most of the times not being updated in its correct position (which it should) but rather a new piece of YAML metadata gets inserted right at the beginning of the file. Please have a look at these two screenshots, 'status' is the metadata in this case:

1 before updating the 'status':

grafik

2 what happens when 'status' gets updated using Metadata menu:

grafik

This destroys all other metadata in this file and excludes it from my Dataview query which is really annoying.. Any tips on how I could solve this?

Thank you for this otherwise outstanding plugin!

Greetings Nic

mdelobelle commented 7 months ago

Hi, I can't reproduce. Can you please paste here:

niceszett commented 7 months ago

Here's the query:

const source = '"Index/01 Practical notes"';
const filter = p => p.tags === "tasks" && p.status !== "closed" && p.status !== "done" && p.due !== null;
const sortBy1 = "due";
const sortBy2 = "categ";
const sortOrder = "asc";
const colorBy = "due";
const color0 = "black";
const color1 = "red";
const color2 = "orange";
const color3 = "green";
const timespan0 = p => p.due === null;
const timespan1 = p => p.due <= dv.date("today").plus({days: 9});
const timespan2 = p => p.due >= dv.date("today").plus({days: 10}) && p.due <= dv.date("today").plus({days: 28});
const timespan3 = p => p.due >= dv.date("today").plus({days: 29});

const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api;

let tableHeadings;
if (colorBy === "due") {
        tableHeadings = ["", "name", "categ", "field", "scope", "comp", "status", "due"];
} else if (colorBy === "priority") {
        tableHeadings = ["", "name", "categ", "field", "scope", "comp", "status", "priority"];
}

dv.table(tableHeadings,
    await Promise.all(dv.pages(source)
        .filter(filter)
        .sort(p => [p[sortBy1], p[sortBy2]], sortOrder)
        .map(async p => {
            let cellClass = "";
            if (colorBy === "due") {
                if (timespan0(p)) {
                    cellClass = color0;
                } else if (timespan1(p)) {
                    cellClass = color1;
                } else if (timespan2(p)) {
                    cellClass = color2;
                } else if (timespan3(p)) {
                    cellClass = color3;
                }
                return [
                    `<span class='${cellClass}'> </span>`,
                    p.file.link,
                    await f(dv, p, "categ"),
                    await f(dv, p, "field"),
                    await f(dv, p, "scope"),
                    await f(dv, p, "comp"),
                    await f(dv, p, "status"),
                    await f(dv, p, "due")
                ];
            } else if (colorBy === "priority") {
                if (p.priority == 0) {
                    cellClass = color0;
                } else if (p.priority == 1) {
                    cellClass = color1;
                } else if (p.priority == 2) {
                    cellClass = color2;
                } else if (p.priority == 3) {
                    cellClass = color3;
                }
                return [
                    `<span class='${cellClass}'> </span>`,
                    p.file.link,
                    await f(dv, p, "categ"),
                    await f(dv, p, "field"),
                    await f(dv, p, "scope"),
                    await f(dv, p, "comp"),
                    await f(dv, p, "status"),
                    await f(dv, p, "priority")
                ];
            }
        })
    )
);

I haven't touched the fileClass definition though, I just added the fields I'd like to change in the 'Preset Field settings' (plugin settings) - here's a screenshot of this:

grafik

niceszett commented 7 months ago

Hey @mdelobelle! I don't know for sure if you changed anything in the latest release but it seems to work properly now! Will close the issue after a week of testing.

Thanks already :)

niceszett commented 6 months ago

I thought the issue might be resolved since I didn't experience any of the described issues for a few weeks. However, since the last update they re-appeared.. some behaviour as before.