-
Notifications
You must be signed in to change notification settings - Fork 2
/
DialogRedirectionVisitor.ts
100 lines (82 loc) · 3.71 KB
/
DialogRedirectionVisitor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import {Base64} from "../util/Base64";
import {DialogProxyTools} from "./DialogProxyTools";
import {RedirectionVisitor} from "./RedirectionVisitor";
/**
*
*/
export class DialogRedirectionVisitor extends RedirectionVisitor {
constructor(value: string | object) {
super(value);
}
// --- State Management Helpers --- //
public static propagateDialogId(dialogRedirection: object, dialogId: string) {
(new DialogRedirectionVisitor(dialogRedirection)).propagateDialogId(dialogId);
}
public static propagateTenantIdAndSessionId(dialogRedirection: object, tenantId: string, sessionId: string) {
(new DialogRedirectionVisitor(dialogRedirection)).propagateTenantIdAndSessionId(tenantId, sessionId);
}
public static visitId(dialogRedirection: object): string {
return (new DialogRedirectionVisitor(dialogRedirection)).visitId();
}
// --- State Management --- //
public deriveDialogIdsFromDialogNameAndRecordId() {
let derivedDialogId = this.enclosedJsonObject()['dialogName'];
if (!derivedDialogId) {
throw new Error("Cannot propagate dialog name -- dialog name not found")
}
const referringObject = this.visitReferringObject();
if (DialogProxyTools.isReferringDialogModel(referringObject)) {
const referringDialogName = referringObject['dialogName'];
if (referringDialogName) {
referringObject['dialogId'] = referringDialogName;
}
// WARNING: Although this code sets the id on the dialog redirection, it is conditioned on the
// referring object being a dialog redirection. This is because workbench redirections have a
// synthetic record id that we do NOT want to include as part of the redirection id.
const recordId = this.visitRecordId();
// TODO: Fix the error in Dialog Service that returns null record ids as a string literal of "null"
if (recordId && recordId !== 'null') {
const recordIdEncoded = Base64.encodeUrlSafeString(recordId);
derivedDialogId = `${derivedDialogId}@${recordIdEncoded}`;
}
}
this.propagateDialogId(derivedDialogId);
}
public deriveDialogIdsFromDialogNameAndSuffix(suffix: string) {
// NOTE: If it's ever needed, this suffix scheme could also append the record id using an '@' sign
let derivedDialogId = this.enclosedJsonObject()['dialogName'];
if (!derivedDialogId) {
throw new Error("Cannot propagate dialog name -- dialog name not found")
}
if (suffix) {
derivedDialogId = derivedDialogId + '$' + suffix;
}
this.propagateDialogId(derivedDialogId);
}
public propagateDialogId(dialogId: string) {
this.enclosedJsonObject()['id'] = dialogId;
this.enclosedJsonObject()['dialogId'] = dialogId;
}
public propagateTenantIdAndSessionId(tenantId: string, sessionId: string) {
this.enclosedJsonObject()['tenantId'] = tenantId;
this.enclosedJsonObject()['sessionId'] = sessionId;
}
public visitDialogId(): string {
return this.enclosedJsonObject().dialogId;
}
public visitAndSetDialogId(dialogId: string) {
this.enclosedJsonObject().dialogId = dialogId;
}
public visitDialogName(): string {
return this.enclosedJsonObject().dialogName;
}
public visitAndSetDialogName(dialogName: string) {
this.enclosedJsonObject().dialogName = dialogName;
}
public visitRecordId(): string {
return this.enclosedJsonObject().recordId;
}
public visitAndSetRecordId(recordId: string) {
this.enclosedJsonObject().recordId = recordId;
}
}