Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query sort by journal date with nlp-date would broken when clicking label for sort #7210

Open
danilofaria opened this issue Nov 3, 2022 · 10 comments

Comments

@danilofaria
Copy link

What happened?

Let's say I have a [[Journal]] page I always use as a header in journal entries. If I do a query {{query [[Journal]]}} it will show the blocks in the order of journal dates. But if I switch Table view, then the order is completely random.

Reproduce the Bug

  1. Go to Journals

Add

- [[Journal]]
    - my note

On multiple dates.

  1. Go to some page and insert the query {{query [[Journal]]}}
  2. turn on Table view

Expected Behavior

I would expect the rows in the table to be in the same order as when shown as blocks, i.e sorted by appearance in journals by date. However the order in table mode is totally random.

Screenshots

No response

Desktop Platform Information

No response

Mobile Platform Information

No response

Additional Context

No response

@guypursey
Copy link
Contributor

Possibly related to more fundamental sorting issue in query table view?

#7679

(I also had an issue with dates in query table view, but did some more testing to find there was an issue with sorting in general.)

@danilofaria
Copy link
Author

I am currently using the following :result-transform to get around the issue:

 :result-transform (fn [result] 
  (reverse (sort-by (fn [h] (get-in h [:block/page :block/journal-day])) 
           (map (fn [m] 
                  (update m :block/properties (fn [u] 
                                                (assoc u :date 
                                                       (hash-set (get-in m [:block/page :block/original-name])))))) result)
           )))

This will reverse sort results by journal date (such that more recent ones are on top) and will add a property to the table showing the journal page.

Of course it would be nice if this was built-in, but this will do it for now.

@guypursey
Copy link
Contributor

Thanks @danilofaria

Do you use that code within an advanced query within the Logseq Markdown file itself? Or is it a piece of external script?

Would be great to see how this looks too (assuming it looks different to a normal table) if you have time to take a screenshot.

@danilofaria
Copy link
Author

@guypursey :result-transform is part of advanced queries.
See an example query:

#+BEGIN_QUERY
{ :query [:find (pull ?b [*])
       :where
          (block-content ?b "[[Journal]]")
       ]
 :result-transform (fn [result] 
  (reverse (sort-by (fn [h] (get-in h [:block/page :block/journal-day])) 
           (map (fn [m] 
                  (update m :block/properties (fn [u] 
                                                (assoc u :date 
                                                       (hash-set (get-in m [:block/page :block/original-name])))))) result)
           )))
}
#+END_QUERY

Screen Shot 2022-12-24 at 11 31 59 AM

@guypursey
Copy link
Contributor

guypursey commented Dec 27, 2022

@danilofaria Thanks for taking the time to add the further explanation and screenshot. Really appreciated. Hoping to look at this at fixing the underlying issue at some point, unless someone gets there before I do.

@logseq-cldwalker logseq-cldwalker added query-table Table view for query and removed query labels Apr 6, 2023
@stdword
Copy link
Contributor

stdword commented Apr 11, 2023

Hi, guys! I want to up this bug. It was created at November 2022 and today in Logseq v0.9.1 it is still actual, unfortunately =(
Details:

In demo I've used this instruction from Query Table section.

@Bad3r, does Backlog project on issue mean it won't be fixed in next release?

@logseq-cldwalker logseq-cldwalker added the :type/enhancement Enhancement to product. Does not affect the overall basic use. label Apr 19, 2023
@cnrpman cnrpman added :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section. and removed :type/enhancement Enhancement to product. Does not affect the overall basic use. labels May 23, 2023
@cnrpman
Copy link
Collaborator

cnrpman commented May 23, 2023

@stdword Sorry for the late reply. I just redo a pass on this ticket today.

Does enabling nlp-date help the sorting?
https://docs.logseq.com/#/page/query%20table?anchor=ls-block-646c1baf-cc3c-444d-bd6a-f394ccb41e56

@cnrpman cnrpman added the awaiting-response Issue will be closed if a reply is not received label May 23, 2023
@stdword
Copy link
Contributor

stdword commented May 23, 2023

@cnrpman It works now!! 🚀 for v0.9.8 and my iso-date formats (can't recognize is it sorted by dates or by strings)

But, I still can't use logseq.query/nlp-date:: true because the namespace is omitting by editor:

@cnrpman
Copy link
Collaborator

cnrpman commented May 24, 2023

Seems clicking the label for sort would break the namespace. It's not that cool.

Also need some E2E coverage following #7708

@cnrpman cnrpman added :type/regression can-be-reproduced and removed awaiting-response Issue will be closed if a reply is not received :type/question Not bug, closed at will. Frequently asked ones would be collected in Logseq Forum's FAQ section. labels May 24, 2023
@cnrpman cnrpman changed the title Query for pages within journal does not sort by journal date when in table mode Query sort by journal date with nlp-date would broken when clicking label for sort May 24, 2023
@cnrpman cnrpman added the estimate: medium Medium effort required label May 24, 2023
@lef-est
Copy link

lef-est commented Jun 5, 2023

it's also not consistent with tables v2 which is using . instead of namespace for property hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🗄 Backlog
Development

No branches or pull requests

6 participants