Skip to content

Commit d242f47

Browse files
cpcloudcursoragent
andcommitted
fix(ui): refine mag mode formatting and skip IDs
- Format: `$ 🠡3` (space after unit, number flush with arrow) - Skip cellReadonly (IDs, ages, counts) -- only transform money and drilldown cells Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 98ce5b0 commit d242f47

File tree

2 files changed

+47
-34
lines changed

2 files changed

+47
-34
lines changed

internal/app/mag.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ func magValue(c cell) string {
2222
return value
2323
}
2424

25-
// Only transform kinds that carry numeric data.
25+
// Only transform kinds that carry meaningful numeric data.
26+
// Skip cellReadonly (IDs, ages, counts) and non-numeric kinds.
2627
switch c.Kind {
27-
case cellText, cellMoney, cellReadonly, cellDrilldown:
28+
case cellText, cellMoney, cellDrilldown:
2829
// Potentially numeric; continue to parsing below.
29-
case cellDate, cellWarranty, cellUrgency, cellNotes, cellStatus:
30+
case cellReadonly, cellDate, cellWarranty, cellUrgency, cellNotes, cellStatus:
3031
return value
3132
}
3233

@@ -35,10 +36,10 @@ func magValue(c cell) string {
3536

3637
// Handle negative money: "-$123.45"
3738
if strings.HasPrefix(numStr, "-$") {
38-
prefix = "-$"
39+
prefix = "-$ "
3940
numStr = numStr[2:]
4041
} else if strings.HasPrefix(numStr, "$") {
41-
prefix = "$"
42+
prefix = "$ "
4243
numStr = numStr[1:]
4344
}
4445

@@ -50,11 +51,11 @@ func magValue(c cell) string {
5051
}
5152

5253
if f == 0 {
53-
return prefix + magArrow + " 0"
54+
return prefix + magArrow + "0"
5455
}
5556

5657
mag := int(math.Floor(math.Log10(math.Abs(f))))
57-
return fmt.Sprintf("%s%s %d", prefix, magArrow, mag)
58+
return fmt.Sprintf("%s%s%d", prefix, magArrow, mag)
5859
}
5960

6061
// magCents converts a cent amount to magnitude notation (e.g. 523423 → "$🠡 3").

internal/app/mag_test.go

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ func TestMagValueMoney(t *testing.T) {
1515
value string
1616
want string
1717
}{
18-
{"thousands", "$5,234.23", "$\U0001F821 3"},
19-
{"hundreds", "$500.00", "$\U0001F821 2"},
20-
{"millions", "$1,000,000.00", "$\U0001F821 6"},
21-
{"tens", "$42.00", "$\U0001F821 1"},
22-
{"single digit", "$7.50", "$\U0001F821 0"},
23-
{"sub-dollar", "$0.50", "$\U0001F821 -1"},
24-
{"zero", "$0.00", "$\U0001F821 0"},
25-
{"negative", "-$5.00", "-$\U0001F821 0"},
26-
{"negative large", "-$12,345.00", "-$\U0001F821 4"},
18+
{"thousands", "$5,234.23", "$ \U0001F8213"},
19+
{"hundreds", "$500.00", "$ \U0001F8212"},
20+
{"millions", "$1,000,000.00", "$ \U0001F8216"},
21+
{"tens", "$42.00", "$ \U0001F8211"},
22+
{"single digit", "$7.50", "$ \U0001F8210"},
23+
{"sub-dollar", "$0.50", "$ \U0001F821-1"},
24+
{"zero", "$0.00", "$ \U0001F8210"},
25+
{"negative", "-$5.00", "-$ \U0001F8210"},
26+
{"negative large", "-$12,345.00", "-$ \U0001F8214"},
2727
}
2828
for _, tt := range tests {
2929
t.Run(tt.name, func(t *testing.T) {
@@ -33,25 +33,30 @@ func TestMagValueMoney(t *testing.T) {
3333
}
3434
}
3535

36-
func TestMagValuePlainNumbers(t *testing.T) {
36+
func TestMagValueDrilldown(t *testing.T) {
3737
tests := []struct {
3838
name string
3939
value string
4040
want string
4141
}{
42-
{"integer", "42", "\U0001F821 1"},
43-
{"zero", "0", "\U0001F821 0"},
44-
{"large", "1000000", "\U0001F821 6"},
45-
{"decimal", "3.14", "\U0001F821 0"},
42+
{"count", "42", "\U0001F8211"},
43+
{"zero", "0", "\U0001F8210"},
44+
{"large", "1000", "\U0001F8213"},
4645
}
4746
for _, tt := range tests {
4847
t.Run(tt.name, func(t *testing.T) {
49-
c := cell{Value: tt.value, Kind: cellReadonly}
48+
c := cell{Value: tt.value, Kind: cellDrilldown}
5049
assert.Equal(t, tt.want, magValue(c))
5150
})
5251
}
5352
}
5453

54+
func TestMagValueSkipsReadonly(t *testing.T) {
55+
// IDs and other readonly cells should not be transformed.
56+
c := cell{Value: "42", Kind: cellReadonly}
57+
assert.Equal(t, "42", magValue(c))
58+
}
59+
5560
func TestMagValueSkipsNonNumeric(t *testing.T) {
5661
tests := []struct {
5762
name string
@@ -66,44 +71,51 @@ func TestMagValueSkipsNonNumeric(t *testing.T) {
6671
{"notes", "Some long note", cellNotes},
6772
{"empty", "", cellText},
6873
{"dash", "\u2014", cellMoney},
74+
{"readonly id", "7", cellReadonly},
6975
}
7076
for _, tt := range tests {
7177
t.Run(tt.name, func(t *testing.T) {
7278
c := cell{Value: tt.value, Kind: tt.kind}
73-
assert.Equal(t, tt.value, magValue(c), "non-numeric value should be unchanged")
79+
assert.Equal(t, tt.value, magValue(c), "value should be unchanged")
7480
})
7581
}
7682
}
7783

7884
func TestMagTransformCells(t *testing.T) {
7985
rows := [][]cell{
8086
{
87+
{Value: "1", Kind: cellReadonly},
8188
{Value: "Kitchen Remodel", Kind: cellText},
8289
{Value: "$5,234.23", Kind: cellMoney},
8390
{Value: "3", Kind: cellDrilldown},
8491
},
8592
{
93+
{Value: "2", Kind: cellReadonly},
8694
{Value: "Deck", Kind: cellText},
8795
{Value: "$100.00", Kind: cellMoney},
8896
{Value: "0", Kind: cellDrilldown},
8997
},
9098
}
9199
out := magTransformCells(rows)
92100

101+
// ID cells unchanged.
102+
assert.Equal(t, "1", out[0][0].Value)
103+
assert.Equal(t, "2", out[1][0].Value)
104+
93105
// Text cells unchanged.
94-
assert.Equal(t, "Kitchen Remodel", out[0][0].Value)
95-
assert.Equal(t, "Deck", out[1][0].Value)
106+
assert.Equal(t, "Kitchen Remodel", out[0][1].Value)
107+
assert.Equal(t, "Deck", out[1][1].Value)
96108

97109
// Money cells transformed.
98-
assert.Equal(t, "$\U0001F821 3", out[0][1].Value)
99-
assert.Equal(t, "$\U0001F821 2", out[1][1].Value)
110+
assert.Equal(t, "$ \U0001F8213", out[0][2].Value)
111+
assert.Equal(t, "$ \U0001F8212", out[1][2].Value)
100112

101113
// Drilldown counts transformed.
102-
assert.Equal(t, "\U0001F821 0", out[0][2].Value)
103-
assert.Equal(t, "\U0001F821 0", out[1][2].Value)
114+
assert.Equal(t, "\U0001F8210", out[0][3].Value)
115+
assert.Equal(t, "\U0001F8210", out[1][3].Value)
104116

105117
// Original rows are not modified.
106-
assert.Equal(t, "$5,234.23", rows[0][1].Value)
118+
assert.Equal(t, "$5,234.23", rows[0][2].Value)
107119
}
108120

109121
func TestMagModeToggle(t *testing.T) {
@@ -124,9 +136,9 @@ func TestMagModeWorksInEditMode(t *testing.T) {
124136
}
125137

126138
func TestMagCents(t *testing.T) {
127-
assert.Equal(t, "$\U0001F821 3", magCents(523423))
128-
assert.Equal(t, "$\U0001F821 2", magCents(50000))
129-
assert.Equal(t, "$\U0001F821 0", magCents(100))
139+
assert.Equal(t, "$ \U0001F8213", magCents(523423))
140+
assert.Equal(t, "$ \U0001F8212", magCents(50000))
141+
assert.Equal(t, "$ \U0001F8210", magCents(100))
130142
}
131143

132144
func TestMagOptionalCentsNil(t *testing.T) {
@@ -135,5 +147,5 @@ func TestMagOptionalCentsNil(t *testing.T) {
135147

136148
func TestMagOptionalCentsPresent(t *testing.T) {
137149
cents := int64(100000)
138-
assert.Equal(t, "$\U0001F821 3", magOptionalCents(&cents))
150+
assert.Equal(t, "$ \U0001F8213", magOptionalCents(&cents))
139151
}

0 commit comments

Comments
 (0)