Skip to content

Commit 53e6c96

Browse files
committed
fix: #5 when stream is null page error
1 parent 52cf124 commit 53e6c96

File tree

10 files changed

+72
-37
lines changed

10 files changed

+72
-37
lines changed

api/connection_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ func (sut *ConnectionSuite) TestOpen() {
3030
sut.NotEqual(connection._client, nil)
3131
}
3232

33+
func (sut *ConnectionSuite) TestConnection() {
34+
id := strconv.FormatInt(time.Now().UnixNano(), 10)
35+
connection := &Connection{
36+
ID: id,
37+
Host: "localhost",
38+
Port: 6379,
39+
}
40+
err := connection.Open()
41+
sut.ErrorIs(err, nil)
42+
commands := [][]interface{}{
43+
{"SELECT", "1"},
44+
{"HSET", "hash1", "name3", nil},
45+
}
46+
_, err = connection.Command(commands)
47+
sut.ErrorIs(err, nil)
48+
}
49+
3350
func (sut *ConnectionSuite) TestScripting() {
3451
id := strconv.FormatInt(time.Now().UnixNano(), 10)
3552
connection := &Connection{

web/src/components/HashKey.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const HashKey = (props: IHashKeyProps) => {
7171
});
7272
});
7373
setKeyProps(kp => {
74-
var scanned = vs.length > search.count ? vs.length : search.count * 1;
74+
let scanned = vs.length > search.count ? vs.length : search.count * 1;
7575
if (search.cursor !== 0) {
7676
scanned += kp.scanned * 1;
7777
}

web/src/components/SetKey.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const SetKey = (props: ISetKeyProps) => {
8686
});
8787
});
8888
setKeyProps(kp => {
89-
var scanned = vs.length > search.count ? vs.length : search.count * 1;
89+
let scanned = vs.length > search.count ? vs.length : search.count * 1;
9090
if (search.cursor !== 0) {
9191
scanned += kp.scanned * 1;
9292
}

web/src/components/StreamKey.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface IStreamKey {
3838
length: number
3939
values: Array<IStreamKeyItem>
4040
memoryUsage: number
41-
firstTimestamp: number
42-
lastTimestamp: number
41+
firstTimestamp: number | null
42+
lastTimestamp: number | null
4343
}
4444

4545
const defaultStreamKey: IStreamKey = {
@@ -95,9 +95,13 @@ export const StreamKey = (props: IStreamKeyProps) => {
9595
const streamInfo = parseArrayToObject(ret[2]);
9696
setKeyProps(kp => {
9797
return {
98-
...kp, keyName: keyProps.keyName, TTL: ret[1], length: streamInfo.length, values: vs,
99-
firstTimestamp: Number(Object.keys(streamInfo['first-entry'])[0].split("-")[0]),
100-
lastTimestamp: Number(Object.keys(streamInfo['last-entry'])[0].split("-")[0])
98+
...kp,
99+
keyName: keyProps.keyName,
100+
TTL: ret[1],
101+
length: streamInfo.length,
102+
values: vs,
103+
firstTimestamp: streamInfo['first-entry'] ? Number(Object.keys(streamInfo['first-entry'])[0].split("-")[0]) : null,
104+
lastTimestamp: streamInfo['last-entry'] ? Number(Object.keys(streamInfo['last-entry'])[0].split("-")[0]) : null
101105
};
102106
})
103107
})

web/src/components/StreamKeySearch.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ export interface IStreamKeySearch {
77
id: string
88
onSearch: (start: string | number, end: string | number, count: number) => void
99
length: number
10-
firstTimestamp: number
11-
lastTimestamp: number
12-
defaultCount: number
10+
firstTimestamp: number | null
11+
lastTimestamp: number | null
12+
defaultCount: number | null
1313
}
1414

1515
export interface IStreamKeySearchCondition {
1616
start: string | number
1717
end: string | number
1818
count: number
19-
firstTimestamp: number
20-
lastTimestamp: number
19+
firstTimestamp: number | null
20+
lastTimestamp: number | null
2121
length: number
2222
}
2323

@@ -32,7 +32,7 @@ export const StreamKeySearch = (props: IStreamKeySearch) => {
3232
};
3333

3434
const [searchVisible, setSearchVisible] = useState(false),
35-
[condition, setCondition] = useState<IStreamKeySearchCondition>({ start: '-', end: '+', count: defaultCount, length, firstTimestamp, lastTimestamp });
35+
[condition, setCondition] = useState<IStreamKeySearchCondition>({ start: '-', end: '+', count: defaultCount || 0, length, firstTimestamp, lastTimestamp });
3636

3737
useEffect(() => {
3838
setCondition(condition => {
@@ -60,11 +60,11 @@ export const StreamKeySearch = (props: IStreamKeySearch) => {
6060
<Stack tokens={{ childrenGap: 10, padding: 10 }} style={{ minWidth: 300 }}>
6161

6262
<Slider ranged
63-
min={condition.firstTimestamp}
64-
max={condition.lastTimestamp}
65-
defaultLowerValue={condition.firstTimestamp}
66-
lowerValue={condition.start === '-' ? condition.firstTimestamp : Number(condition.start)}
67-
value={condition.end === '+' ? condition.lastTimestamp : Number(condition.end)}
63+
min={condition.firstTimestamp || 0}
64+
max={condition.lastTimestamp || 0}
65+
defaultLowerValue={condition.firstTimestamp || 0}
66+
lowerValue={condition.start === '-' ? (condition.firstTimestamp || 0) : Number(condition.start)}
67+
value={condition.end === '+' ? (condition.lastTimestamp || 0) : Number(condition.end)}
6868
onChange={handleRangeChange}
6969
showValue={false}
7070
step={100} />

web/src/components/panel/StreamKeyPanel.tsx

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ export const StreamKeyPanel = (props: IStreamKeyPanelProps) => {
5050
const handleSave = (refresh = false) => {
5151
setError(undefined);
5252
setLoading(true);
53-
54-
const values = JSON.parse(keyItem.value);
53+
const values = JSON.parse(keyItem.value);;
5554
const kvs = Object.keys(values).map(k => { return [k, values[k]]; }).reduce((p, c) => p.concat(c))
5655
const commands = [['SELECT', db]];
5756
commands.push(['XADD', keyItem.name, keyItem.id, ...kvs]);
@@ -65,6 +64,27 @@ export const StreamKeyPanel = (props: IStreamKeyPanelProps) => {
6564
.finally(() => setLoading(false));
6665
}
6766

67+
const validValue = () => {
68+
if (!keyItem.value) {
69+
setValueError(t('Incorrect format'))
70+
return;
71+
}
72+
try {
73+
const v = JSON.parse(keyItem.value);
74+
if (Array.isArray(v) || typeof v !== 'object') {
75+
setValueError(t('Incorrect format'));
76+
return;
77+
}
78+
if (Object.keys(v).length <= 0) {
79+
setValueError(t('Incorrect format'));
80+
return;
81+
}
82+
} catch (error) {
83+
setValueError(t('Incorrect format'));
84+
return;
85+
}
86+
}
87+
6888
return (
6989
<Panel
7090
styles={{ content: { paddingBottom: 0, height: '100%' } }}
@@ -76,7 +96,7 @@ export const StreamKeyPanel = (props: IStreamKeyPanelProps) => {
7696
onRenderFooterContent={() => {
7797
if (onlyView) return (<></>);
7898

79-
var disabled: boolean = !!!keyItem.name || !keyItem.id || !!valueError;
99+
let disabled: boolean = !keyItem.name || !keyItem.id || !!valueError;
80100
return (
81101
<Stack tokens={{ childrenGap: 10 }} horizontal horizontalAlign="space-evenly">
82102
<Stack.Item grow={1}><span></span></Stack.Item>
@@ -109,19 +129,10 @@ export const StreamKeyPanel = (props: IStreamKeyPanelProps) => {
109129
}} />
110130

111131
<Stack.Item grow={1}>
112-
<FormatTextField label={t('Value (JSON object)')} multiline rows={10} value={keyItem.value} errorMessage={valueError} onChange={(e, v) => {
113-
if (!v) return;
114-
setKeyItem({ ...keyItem, value: v });
132+
<FormatTextField autoFocus onFocus={validValue} label={t('Value (JSON object)')} multiline rows={10} value={keyItem.value} errorMessage={valueError} onChange={(e, v) => {
133+
setKeyItem({ ...keyItem, value: v || '' });
115134
setValueError("");
116-
try {
117-
if (Array.isArray(JSON.parse(v))) {
118-
setValueError(t('Incorrect format'));
119-
return;
120-
}
121-
} catch (error) {
122-
setValueError(t('Incorrect format'));
123-
return;
124-
}
135+
validValue();
125136
}} />
126137
</Stack.Item>
127138

web/src/components/settings/AppSettings.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const AppSettings = (props: IAppSettings) => {
4747
},
4848
},
4949
{
50-
key: 'localeLanguage', text: t('Lanaguage'), iconProps: { iconName: 'LocaleLanguage', style: { lineHeight: '14px' } }, subMenuProps: {
50+
key: 'localeLanguage', text: t('Language'), iconProps: { iconName: 'LocaleLanguage', style: { lineHeight: '14px' } }, subMenuProps: {
5151
items: Object.keys(supportedLanguages).map(v => {
5252
return { key: v, text: supportedLanguages[v], onClick: () => handleChangeLanguage(v) }
5353
}),

web/src/locales/en_US.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"Theme-Light": "Default",
1111
"Theme-Word": "Word",
1212
"Theme-Teams": "Teams",
13-
"Lanaguage": "Lanaguage",
13+
"Language": "Language",
1414
"About": "About",
1515
"The test connection to the Redis server is successful!": "The test connection to the Redis server is successful!",
1616
"The connection to the Redis server is successful!": "The connection to the Redis server is successful!",
@@ -49,6 +49,7 @@
4949
"Refresh": "Refresh",
5050
"Disconnect": "Disconnect",
5151
"Add key": "Add key",
52+
"Remove keys": "Remove keys",
5253
"Delete this key?": "Delete this key?",
5354
"Filter": "Filter",
5455
"Size": "Size",

web/src/locales/zh-Hans.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"Theme-Light": "默认",
1111
"Theme-Word": "Word",
1212
"Theme-Teams": "Teams",
13-
"Lanaguage": "语言",
13+
"Language": "语言",
1414
"About": "关于",
1515
"The test connection to the Redis server is successful!": "测试连接 Redis 服务成功!",
1616
"The connection to the Redis server is successful!": "连接 Reids 服务器成功!",
@@ -49,6 +49,7 @@
4949
"Refresh": "刷新",
5050
"Disconnect": "断开连接",
5151
"Add key": "添加键",
52+
"Remove keys": "删除选中键",
5253
"Delete this key?": "删除该键?",
5354
"Filter": "过滤",
5455
"Size": "大小",

web/src/locales/zh-Hant.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"Theme-Light": "亮色主題",
1111
"Theme-Word": "Word",
1212
"Theme-Teams": "Teams",
13-
"Lanaguage": "語言",
13+
"Language": "語言",
1414
"About": "關於",
1515
"The test connection to the Redis server is successful!": "與Redis服務器的測試連接成功!",
1616
"The connection to the Redis server is successful!": "與Redis服務器的連接成功!",
@@ -49,6 +49,7 @@
4949
"Refresh": "刷新",
5050
"Disconnect": "斷開連接",
5151
"Add key": "添加鍵",
52+
"Remove keys": "删除選中鍵",
5253
"Delete this key?": "刪除此鍵嗎?",
5354
"Filter": "過濾",
5455
"Size": "大小",

0 commit comments

Comments
 (0)