json-log-viewer icon indicating copy to clipboard operation
json-log-viewer copied to clipboard

feat: support sorting by field

Open hedhyw opened this issue 1 year ago • 7 comments

Add an ability to sort by field:

  • Descending
  • Ascending

hedhyw avatar Jul 25 '23 02:07 hedhyw

Hi I want to work on it. Can you please explain what do you mean by Show the list of fields to sort by ?

arsalankone avatar Nov 29 '23 16:11 arsalankone

Hi I want to work on it.

Hi! Thank you.

Can you please explain what do you mean by Show the list of fields to sort by ?

The idea was to show a list of fields from which we can select a field to sort by, but of course, it's not a requirement. Feel free to describe how you see it at its best.

hedhyw avatar Nov 29 '23 17:11 hedhyw

He @hedhyw assign it to me on this account, @arsalankone is my work account and I had mistakenly commented from that account.

I might need some help also in understanding the flow of code properly. Also like in sorting by fields, what criterion should be used for sorting mechanism. Sorting by value in case of timestamps and lexicographical sorting in message makes sense, but for level fields, what should be an appropriate parameter?

SpoonBuoy avatar Dec 02 '23 15:12 SpoonBuoy

I might need some help also in understanding the flow of code properly.

  • Clicking hotkeys ("O"/"F6") on StateLoaded, StateFiltered should open a dialogue to select a field to sort by:
    • We need to create a new state (=bubble tea model) for the window that configures the sort order. https://github.com/hedhyw/json-log-viewer/blob/c65754ff6ef294d9d1d9653c105c8cda3e86dc80/internal/app/state.go#L9

      There are many examples: StateError, StateInitial, StateFiltering, etc.

    • Possible widgets to use: https://github.com/charmbracelet/bubbles#list or https://github.com/charmbracelet/bubbles#table.
    • It would be nice to be able to reset the sorting to defaults (unsorted, as lines appear in the file).
    • Submitting: [Enter] -> configure and sort in descending order, [A] -> configure and sort in ascending order.
    • Make sure hotkeys do not influence StateFiltering.
  • Possible sorting fields can be taken from the config: https://github.com/hedhyw/json-log-viewer/blob/c65754ff6ef294d9d1d9653c105c8cda3e86dc80/internal/pkg/config/config.go#L21
  • The current sorting order can be stored in the persistent application state (available in all models, note: each local state clones it). StateLoaded and StateFiltered will sort considering sorting configuration from the persistent state: https://github.com/hedhyw/json-log-viewer/blob/c65754ff6ef294d9d1d9653c105c8cda3e86dc80/internal/app/app.go#L11

Sorting by value in case of timestamps and lexicographical sorting in message makes sense, but for level fields, what should be an appropriate parameter?

  • Numbers/Timestamps -> by value.
  • Any other value -> lexicographical.

hedhyw avatar Dec 03 '23 04:12 hedhyw

Can you take a look at it and see if I am following the right approach? https://github.com/SpoonBuoy/json-log-viewer/tree/spoon

SpoonBuoy avatar Dec 10 '23 18:12 SpoonBuoy

Can you take a look at it and see if I am following the right approach? https://github.com/SpoonBuoy/json-log-viewer/tree/spoon

looks right, but I'm not sure we need StateSorted, we can save the order in the application state, and use it in StateLoaded/StateFiltered

hedhyw avatar Dec 11 '23 17:12 hedhyw

@SpoonBuoy do you still need this feature?

hedhyw avatar May 27 '24 14:05 hedhyw