Skip to content

Commit ec4bccb

Browse files
committed
minor: edits
2 parents d66a989 + 2c280fa commit ec4bccb

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
lines changed

RedisCommon/redis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func (r Rule) AsRow(rowId int) table.Row {
574574
}
575575

576576
if r.Regex != nil {
577-
rd["Matches"] = r.Regex
577+
rd["Matches"] = *r.Regex
578578
}
579579

580580
rd["RowId"] = rowId
@@ -638,7 +638,7 @@ func GetRules(rdb *redis.Client, applicationName string) ([]Rule, error) {
638638
rule.QueryIds = make([]string, 0)
639639
}
640640
rule.QueryIds = append(rule.QueryIds, value.(string))
641-
case "Regex":
641+
case "regex":
642642
r := value.(string)
643643
rule.Regex = &r
644644
case "ttl":

RuleDialog/RuleDialog.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ type Model struct {
7474
ttl string
7575
match string
7676
textInput textinput.Model
77+
wasPreset bool
7778
}
7879

79-
func New(parentModel tea.Model, rdb *redis.Client, rule *RedisCommon.Rule, confirm bool, applicationName string) Model {
80+
func New(parentModel tea.Model, rdb *redis.Client, rule *RedisCommon.Rule, confirm bool, applicationName string, ruleType RedisCommon.RuleType) Model {
8081
items := []list.Item{
81-
item{RedisCommon.QueryIds},
8282
item{RedisCommon.Tables},
8383
item{RedisCommon.TablesAll},
8484
item{RedisCommon.TablesAny},
@@ -93,6 +93,7 @@ func New(parentModel tea.Model, rdb *redis.Client, rule *RedisCommon.Rule, confi
9393
ti.Focus()
9494
ti.CharLimit = 30
9595
ti.Width = 30
96+
wasPreset := ruleType != RedisCommon.Unknown
9697

9798
m := Model{
9899
parentModel: parentModel,
@@ -101,9 +102,10 @@ func New(parentModel tea.Model, rdb *redis.Client, rule *RedisCommon.Rule, confi
101102
isNew: rule == nil,
102103
applicationName: applicationName,
103104
typeSelectorList: typeSelectList,
104-
ruleType: RedisCommon.Unknown,
105+
ruleType: ruleType,
105106
textInput: ti,
106107
ttl: "",
108+
wasPreset: wasPreset,
107109
}
108110

109111
return m
@@ -166,7 +168,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
166168
if m.match != "" {
167169
m.match = ""
168170
return m, nil
169-
} else if m.ruleType != RedisCommon.Unknown {
171+
} else if m.ruleType != RedisCommon.Unknown && !m.wasPreset {
170172
m.ruleType = RedisCommon.Unknown
171173
return m, nil
172174
}
@@ -241,16 +243,22 @@ func (m Model) View() string {
241243
var b strings.Builder
242244

243245
if m.ruleType == RedisCommon.Unknown {
244-
b.WriteString("Select the type of rule you want to create.\nPress [CTRL+B] to return to the previous screen.\n")
246+
b.WriteString(" == Create rule menu ==\n\n Select the type of rule you want to create.\n Press [CTRL+B] to return to the previous screen.\n\n")
245247
b.WriteString(m.typeSelectorList.View())
246248
return b.String()
247249
} else if m.match == "" && m.ruleType != RedisCommon.All {
248250
b.WriteString(m.ruleSoFar())
249-
b.WriteString("Enter the string to match against (e.g., table names, regular expression, etc.): ")
251+
if m.ruleType == RedisCommon.Regex {
252+
b.WriteString("Enter a regular expression to match against:")
253+
} else if m.ruleType == RedisCommon.QueryIds {
254+
b.WriteString("Enter a comma-separated list of Query IDs to match against:")
255+
} else {
256+
b.WriteString("Enter a comma-separated list of tables to match against:")
257+
}
250258
b.WriteString(m.textInput.View())
251259
} else {
252260
b.WriteString(m.ruleSoFar())
253-
b.WriteString("Enter a TTL in the form of a duration (e.g. 1h, 300s, 5m): ")
261+
b.WriteString("Enter a TTL in the form of a duration (e.g. 1h, 300s, 5m):")
254262
b.WriteString(m.textInput.View())
255263
}
256264

RuleList/RuleList.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8686
m.parentModel, _ = m.parentModel.Update(ConfirmationDialog.ConfirmationMessage{ConfirmedUpdate: true})
8787
return m.parentModel, nil
8888
case "n":
89-
return RuleDialog.New(m, m.rdb, nil, false, m.applicationName), nil
89+
return RuleDialog.New(m, m.rdb, nil, false, m.applicationName, RedisCommon.Unknown), nil
9090
case "r":
9191
idxInDelete := indexOf(rowId, m.indexesWithPendingDeletes)
9292
if idxInDelete >= 0 {
@@ -130,7 +130,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
130130
if rowId >= 0 {
131131
// pop open editor
132132
rule := m.rules[rowId]
133-
return RuleDialog.New(m, m.rdb, &rule, false, m.applicationName), nil
133+
return RuleDialog.New(m, m.rdb, &rule, false, m.applicationName, rule.GetType()), nil
134134
}
135135
}
136136
case BulkUpdateConfirmation.BulkConfirmationMessage:
@@ -192,6 +192,7 @@ func (m Model) View() string {
192192
body.WriteString("press 'b' to go back\n")
193193
body.WriteString("press [ENTER] to edit a rule\n")
194194
body.WriteString("press 'n' to create a rule\n")
195+
body.WriteString("press 'd' to delete a rule\n")
195196
body.WriteString("press 'c' to commit rule updates\n")
196197
body.WriteString(m.table.View())
197198

TableList/TableList.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (m Model) View() string {
9393
body := strings.Builder{}
9494
body.WriteString("Press [ENTER] to update the TTL for a table\n")
9595
body.WriteString("Press 'b' to go back\n")
96-
body.WriteString("Press 's' to change sorting\n")
96+
body.WriteString("Press 's' to change sorting\n\n")
9797
body.WriteString(m.table.View())
9898

9999
return body.String()

mainMenu/mainMenu.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"smart-cache-cli/ConfirmationDialog"
7+
"smart-cache-cli/RedisCommon"
78
"smart-cache-cli/RuleDialog"
89
"smart-cache-cli/RuleList"
910
"smart-cache-cli/TableList"
@@ -99,7 +100,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
99100
if string(i) == listQueries {
100101
return queryList.InitialModel(m, m.rdb, m.applicationName, m.width), nil
101102
} else if string(i) == createRule {
102-
return RuleDialog.New(m, m.rdb, nil, true, m.applicationName), nil
103+
return RuleDialog.New(m, m.rdb, nil, true, m.applicationName, RedisCommon.Unknown), nil
103104
} else if string(i) == listRules {
104105
return RuleList.New(m, m.rdb, m.applicationName), nil
105106
} else if string(i) == listTables {
@@ -143,7 +144,7 @@ func InitialModel(rdb *redis.Client, applicationName string, connectionInfo stri
143144
const defaultWidth = 20
144145

145146
l := list.New(items, itemDelegate{}, defaultWidth, listHeight)
146-
l.Title = "-- Main menu --"
147+
l.Title = "== Main menu =="
147148
l.SetShowStatusBar(false)
148149
l.SetFilteringEnabled(false)
149150
l.Styles.Title = titleStyle

0 commit comments

Comments
 (0)