Skip to content

Commit

Permalink
wip: nkey component
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed May 28, 2024
1 parent 514bcb2 commit bdca132
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 62 deletions.
14 changes: 14 additions & 0 deletions internal/utils/strings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package utils

// FirstN returns the first n characters of a string.
func FirstN(s string, n int) string {
i := 0
for j := range s {
if i == n {
return s[:j]
}
i++
}

return s
}
9 changes: 8 additions & 1 deletion internal/web/adapters/db/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ func (db *database) CreateAccount(ctx context.Context, account *models.Account)

// GetAccount ...
func (db *database) GetAccount(ctx context.Context, account *models.Account) error {
return db.conn.WithContext(ctx).Preload("SigningKeyGroups").Preload("SigningKeyGroups.Key").Preload("Key").Preload("Token").First(account).Error
return db.conn.WithContext(ctx).
Preload("SigningKeyGroups").
Preload("SigningKeyGroups.Key").
Preload("Key").
Preload("Token").
Preload("Operator").
Preload("Operator.Key").
First(account).Error
}

// UpdateAccount ...
Expand Down
57 changes: 57 additions & 0 deletions internal/web/components/nkeys/nkey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package nkeys

import (
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/tooltips"
"github.com/zeiss/typhoon/internal/utils"
)

// NKeyProps are the properties of the NKey display component.
type NKeyProps struct {
ClassNames htmx.ClassNames
PublicKey string
Title string
}

// NKey renders the NKey display component.
func NKey(props NKeyProps, children ...htmx.Node) htmx.Node {
return htmx.Div(
htmx.Merge(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
},
props.ClassNames,
),
htmx.H4(
htmx.ClassNames{
"text-neutral-content": true,
"flex": true,
"items-center": true,
},
htmx.Text(props.Title),
tooltips.Tooltip(
tooltips.TooltipProps{
ClassNames: htmx.ClassNames{},
DataTip: "Public NKey is the public key of the operator",
},
icons.InformationCircleOutline(
icons.IconProps{},
),
),
),
htmx.H3(
tooltips.Tooltip(
tooltips.TooltipProps{
ClassNames: htmx.ClassNames{},
DataTip: props.PublicKey,
},
htmx.Text(
utils.FirstN(props.PublicKey, 8),
),
),
),
)
}
50 changes: 17 additions & 33 deletions internal/web/controllers/accounts/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package accounts
import (
"fmt"

"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/utils"
"github.com/zeiss/typhoon/internal/web/components"
"github.com/zeiss/typhoon/internal/web/components/accounts"
"github.com/zeiss/typhoon/internal/web/components/nkeys"
"github.com/zeiss/typhoon/internal/web/ports"

"github.com/google/uuid"
htmx "github.com/zeiss/fiber-htmx"
"github.com/zeiss/fiber-htmx/components/buttons"
"github.com/zeiss/fiber-htmx/components/cards"
"github.com/zeiss/fiber-htmx/components/dropdowns"
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/tooltips"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/utils"
"github.com/zeiss/typhoon/internal/web/components"
"github.com/zeiss/typhoon/internal/web/components/accounts"
"github.com/zeiss/typhoon/internal/web/ports"
)

// ShowAccountControllerImpl ...
Expand Down Expand Up @@ -159,34 +160,17 @@ func (l *ShowAccountControllerImpl) Get() error {
cards.TitleProps{},
htmx.Text("Details"),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
nkeys.NKey(
nkeys.NKeyProps{
Title: "ID",
PublicKey: acc.Key.ID,
},
),
nkeys.NKey(
nkeys.NKeyProps{
Title: "Issuer",
PublicKey: acc.Operator.Key.ID,
},
htmx.H4(
htmx.ClassNames{
"text-gray-500": true,
},
htmx.Text("Public NKey"),
tooltips.Tooltip(
tooltips.TooltipProps{
ClassNames: htmx.ClassNames{
"tooltip-right": true,
},
DataTip: "Public NKey is the public key of the account",
},
icons.InformationCircleOutline(
icons.IconProps{},
),
),
),
htmx.H3(
htmx.Text(
acc.Key.ID,
),
),
),
),
),
Expand Down
33 changes: 5 additions & 28 deletions internal/web/controllers/operators/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/utils"
"github.com/zeiss/typhoon/internal/web/components"
"github.com/zeiss/typhoon/internal/web/components/nkeys"
"github.com/zeiss/typhoon/internal/web/components/operators"
"github.com/zeiss/typhoon/internal/web/ports"

Expand All @@ -15,7 +16,6 @@ import (
"github.com/zeiss/fiber-htmx/components/dropdowns"
"github.com/zeiss/fiber-htmx/components/forms"
"github.com/zeiss/fiber-htmx/components/icons"
"github.com/zeiss/fiber-htmx/components/tooltips"
)

// ShowOperatorControllerImpl ...
Expand Down Expand Up @@ -210,34 +210,11 @@ func (l *ShowOperatorControllerImpl) Get() error {
cards.TitleProps{},
htmx.Text("Details"),
),
htmx.Div(
htmx.ClassNames{
"flex": true,
"flex-col": true,
"py-2": true,
nkeys.NKey(
nkeys.NKeyProps{
Title: "ID",
PublicKey: op.Key.ID,
},
htmx.H4(
htmx.ClassNames{
"text-gray-500": true,
},
htmx.Text("Public NKey"),
tooltips.Tooltip(
tooltips.TooltipProps{
ClassNames: htmx.ClassNames{
"tooltip-right": true,
},
DataTip: "Public NKey is the public key of the operator",
},
icons.InformationCircleOutline(
icons.IconProps{},
),
),
),
htmx.H3(
htmx.Text(
op.Key.ID,
),
),
),
),
),
Expand Down

0 comments on commit bdca132

Please sign in to comment.