mirror of
https://github.com/zulip/zulip.git
synced 2026-07-12 21:04:41 +08:00
narrow-state: Return undefined for a channel ID that would be NaN.
When the channel operand would return NaN for the ID value, we now return undefined, so that there is only one invalid value being returned by narrow_state.stream_id.
This commit is contained in:
parent
edc9853a3e
commit
61fa5ccbf1
@ -130,7 +130,10 @@ export let stream_id = (current_filter: Filter | undefined = filter()): number |
|
||||
}
|
||||
const stream_operands = current_filter.operands("channel");
|
||||
if (stream_operands.length === 1 && stream_operands[0] !== undefined) {
|
||||
return Number.parseInt(stream_operands[0], 10);
|
||||
const id = Number.parseInt(stream_operands[0], 10);
|
||||
if (!Number.isNaN(id)) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
@ -40,6 +40,15 @@ test("stream", () => {
|
||||
assert.ok(!narrow_state.filter());
|
||||
assert.equal(narrow_state.stream_id(), undefined);
|
||||
|
||||
// hash_util.decode_operand returns an empty string when
|
||||
// stream_data.slug_to_stream_id returns undefined, e.g., the
|
||||
// stream name in the URL no longer exists or is inaccessible.
|
||||
set_filter([["channel", ""]]);
|
||||
assert.ok(narrow_state.filter());
|
||||
assert.equal(narrow_state.stream_name(), undefined);
|
||||
assert.equal(narrow_state.stream_id(), undefined);
|
||||
assert.equal(narrow_state.stream_sub(), undefined);
|
||||
|
||||
const test_stream_id = 15;
|
||||
const test_stream = {name: "Test", stream_id: test_stream_id};
|
||||
stream_data.add_sub(test_stream);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user