Skip to content

Commit e96d7ba

Browse files
committed
Read a navigate-back action without a destination
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0147gqWiq3xoEdAGwWSpq9JK
1 parent b2cca3e commit e96d7ba

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Unreleased
22

3+
- A navigate-back (`pop`) action reads from JSON without `destinationId`,
4+
which it has no use for. It is still written, as `''`, for readers that
5+
require it.
36
- `SignatureNode` (`signature`): a box to sign in. Its `value` is a list of
47
strokes, each a list of `[x, y]` points normalized to the box; `inkColor`,
58
`strokeWidth` and `readOnly` are in `SignatureProperties`.

‎lib/src/api/models/action/navigation_action.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ enum NavigationType {
3232
}
3333
}
3434

35+
Object? _readDestinationId(Map json, String key) => json[key] ?? '';
36+
3537
/// An action that navigates to a new page.
3638
@JsonSerializable()
3739
class NavigationAction extends ActionModel with Equatable, SerializableMixin {
3840
/// Defines how the navigation should be performed.
3941
final NavigationType navigationType;
4042

41-
/// Destination canvas node's ID.
43+
/// Destination canvas node's ID. Empty for [NavigationType.pop], which
44+
/// has no destination, and still written so older readers, which require
45+
/// it, can read the action.
46+
@JsonKey(readValue: _readDestinationId)
4247
final String destinationId;
4348

4449
/// Parameters to pass to the destination page.

‎lib/src/api/models/action/navigation_action.g.dart‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎test/navigation_pop_json_test.dart‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import 'package:codelessly_api/codelessly_api.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
test('a navigate back action reads without a destination', () {
6+
final action = NavigationAction.fromJson({
7+
'type': 'navigation',
8+
'navigationType': 'pop',
9+
});
10+
expect(action.navigationType, NavigationType.pop);
11+
expect(action.destinationId, '');
12+
// Still written, for readers that require it.
13+
expect(action.toJson()['destinationId'], '');
14+
});
15+
}

0 commit comments

Comments
 (0)