json-log-viewer
json-log-viewer copied to clipboard
feat: support sorting by field
Add an ability to sort by field:
- Descending
- Ascending
Hi I want to work on it. Can you please explain what do you mean by Show the list of fields to sort by ?
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.
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?
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
.
- 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
- 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
andStateFiltered
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.
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
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
@SpoonBuoy do you still need this feature?