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

Add a toggleable sidebar to view records #103

Merged
merged 20 commits into from
Oct 12, 2024
Merged

Add a toggleable sidebar to view records #103

merged 20 commits into from
Oct 12, 2024

Conversation

jorgerojas26
Copy link
Owner

image

The main idea here is to have that toggleable sidebar that shows the table results in a vertical manner, so it is easy to see all the columns.

Comment on lines 206 to 216
switch stateChange.Key {
case "Editing":
editing := stateChange.Value.(bool)
table.SetIsEditing(editing)
case "Unfocusing":
App.SetFocus(table)
App.ForceDraw()
case "Toggling":
table.ShowSidebar(false)
App.ForceDraw()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing, Unfocusing, and Toggling should be constants

if repeatCount <= 0 {
repeatCount = 1
}
title += "[gray]" + strings.Repeat("-", repeatCount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't gray be a constant you define somewhere to provide a consistent theming

func (sidebar *Sidebar) FocusNextField() {
newIndex := sidebar.GetCurrentFieldIndex() + 1

if newIndex < sidebar.Flex.GetItemCount() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert the test to simplify

Suggested change
if newIndex < sidebar.Flex.GetItemCount() {
if newIndex >= sidebar.Flex.GetItemCount() {
return
}

func (sidebar *Sidebar) FocusPreviousField() {
newIndex := sidebar.GetCurrentFieldIndex() - 1

if newIndex >= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same check for < 0 and return

if newIndex >= 0 {
item := sidebar.Fields[newIndex]

if item != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If item == nil, then return

case commands.UnfocusSidebar:
sidebar.Publish(models.StateChange{Key: "Unfocusing", Value: nil})
case commands.ToggleSidebar:
sidebar.Publish(models.StateChange{Key: "Toggling", Value: nil})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case commands.GotoEnd:
sidebar.FocusLastField()
case commands.Edit:
sidebar.Publish(models.StateChange{Key: "Editing", Value: true})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case commands.CommitEdit:
sidebar.SetInputCapture(sidebar.inputCapture)
sidebar.SetDisabledStyles(item)
sidebar.Publish(models.StateChange{Key: "Editing", Value: false})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sidebar.SetInputCapture(sidebar.inputCapture)
sidebar.SetDisabledStyles(item)
item.SetText(text, true)
sidebar.Publish(models.StateChange{Key: "Editing", Value: false})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 8 to 10
EditorTabName string = "Editor"
HelpPageName string = "Help"
SidebarPageName string = "Sidebar"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you think your constant are reused externally, they should be unexported.

So this would be better

Suggested change
EditorTabName string = "Editor"
HelpPageName string = "Help"
SidebarPageName string = "Sidebar"
editorTabName string = "Editor"
helpPageName string = "Help"
sidebarPageName string = "Sidebar"

also usually constant of the same kind share a common prefix, not suffix. this way you can use the first letter to find them all in your IDE

So this would be what I would use

Suggested change
EditorTabName string = "Editor"
HelpPageName string = "Help"
SidebarPageName string = "Sidebar"
tabNameEditor string = "Editor"
pageNameHelp string = "Help"
pageNameSidebar string = "Sidebar"

@ccoVeille
Copy link
Contributor

I'm glad you accepted my suggestion 👍

@jorgerojas26
Copy link
Owner Author

I'm glad you accepted my suggestion 👍

Good suggestions. :) I addressed them all. Thanks for taking the time.

@ccoVeille
Copy link
Contributor

Unless I'm wrong, you didn't apply these suggestions

#103 (comment)

#103 (comment)

#103 (comment)

#103 (comment)

@jorgerojas26
Copy link
Owner Author

Unless I'm wrong, you didn't apply these suggestions

#103 (comment)

#103 (comment)

#103 (comment)

#103 (comment)

You are right haha i missed them.

Copy link
Contributor

@ccoVeille ccoVeille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor remark, but OK 👍

hidingFieldIndex := 0
fieldCount := sidebar.Flex.GetItemCount()

for i := 0; i < fieldCount; i++ {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a candidate for for range loop, I think

Suggested change
for i := 0; i < fieldCount; i++ {
for i := range fieldCount {

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will need to upgrade go version in go.mod from 1.20 to 1.22. I don't know how much of it is a problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are providing a tool, not a lib.

So upgrading to 1.23 directly should be fine.

You will have to upgrade a lot of thing such as golangci-lint in the CI

While it's a thing to do, there is no need to do it in this PR, just to use for range

So, yes, you could upgrade, but not necessarily now

@jorgerojas26 jorgerojas26 changed the title [WIP] Add a toggleable sidebar to view records Add a toggleable sidebar to view records Oct 12, 2024
@jorgerojas26 jorgerojas26 merged commit c4ac8f1 into main Oct 12, 2024
2 checks passed
@jorgerojas26 jorgerojas26 deleted the results-sidebar branch October 12, 2024 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants