-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: trigger creation bug #2151
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
680f645
fix bug
liweitian d35b07b
save tmp code
liweitian 3baabd1
add regex intent back
liweitian f3bb301
update
liweitian 3d09dee
update label text
liweitian 22ea9bc
rename onMessageActivity to onMessageReceivedMessage
alanlong9278 11303bc
update trigger type validation function
liweitian 0a5aee8
remove commented code
liweitian d584c7d
rename onMessageActivity to onMessageReceivedMessage & update trigger…
alanlong9278 80056dd
Merge branch 'trggerCreationBugFix' of https://github.com/liweitian/B…
liweitian 7b10482
update regex field
liweitian e395e6b
remove commented code
liweitian b720921
remove commented code
liweitian 1ef1aa0
revert auto-saved file
liweitian 6007691
Merge branch 'trggerCreationBugFix' of https://github.com/liweitian/B…
liweitian 7b8f29a
Merge branch 'triggerCreationStep2' into trggerCreationBugFix
liweitian 5e54b19
update label text
liweitian 713438d
fix bug
liweitian e8170f5
save tmp code
liweitian db898b5
add regex intent back
liweitian ef20191
update
liweitian b78b9d6
update label text
liweitian 7f1aba7
rename onMessageActivity to onMessageReceivedMessage
alanlong9278 f94ba2c
update trigger type validation function
liweitian 48182b6
remove commented code
liweitian eb56714
update regex field
liweitian 539c2a1
remove commented code
liweitian 08f9779
remove commented code
liweitian 95200ef
revert auto-saved file
liweitian b36db10
update label text
liweitian 63fecad
Merge branch 'master' into trggerCreationBugFix
alanlong9278 d7938ec
Merge branch 'trggerCreationBugFix' of https://github.com/liweitian/B…
liweitian 233f2ec
update label text
liweitian c8467fb
update regEx api
liweitian b624da1
add shellapi updateRegExIntentHandler
liweitian 5f5a313
shell api
alanlong9278 0f31ae5
inline regex in form editor
alanlong9278 89afc58
create new inline regex intent when no intent
alanlong9278 348be66
Merge branch 'master' into trggerCreationBugFix
liweitian 4309287
Merge branch 'master' into trggerCreationBugFix
cwhitten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,13 +24,15 @@ export interface TriggerFormData { | |
specifiedType: string; | ||
intent: string; | ||
triggerPhrases: string; | ||
regexEx: string; | ||
} | ||
|
||
export interface TriggerFormDataErrors { | ||
$type?: string; | ||
intent?: string; | ||
specifiedType?: string; | ||
triggerPhrases?: string; | ||
regexEx?: string; | ||
} | ||
|
||
export function getDialog(dialogs: DialogInfo[], dialogId: string) { | ||
|
@@ -60,8 +62,15 @@ export function getFriendlyName(data) { | |
return data.$type; | ||
} | ||
|
||
export function insert(content, path: string, position: number | undefined, data: TriggerFormData) { | ||
export function insert(content, path: string, position: number | undefined, data: any) { | ||
const current = get(content, path, []); | ||
const insertAt = typeof position === 'undefined' ? current.length : position; | ||
current.splice(insertAt, 0, data); | ||
set(content, path, current); | ||
return content; | ||
} | ||
|
||
export function generateNewTrigger(data: TriggerFormData) { | ||
const optionalAttributes: { intent?: string; event?: string } = {}; | ||
if (data.specifiedType) { | ||
data.$type = data.specifiedType; | ||
|
@@ -73,23 +82,52 @@ export function insert(content, path: string, position: number | undefined, data | |
$type: data.$type, | ||
...seedNewDialog(data.$type, {}, optionalAttributes), | ||
}; | ||
return newStep; | ||
} | ||
|
||
const insertAt = typeof position === 'undefined' ? current.length : position; | ||
|
||
current.splice(insertAt, 0, newStep); | ||
export function generateRegexExpression(intent: string, pattern: string) { | ||
return { intent, pattern }; | ||
} | ||
|
||
set(content, path, current); | ||
export function createNewTrigger(dialog: DialogInfo, data: TriggerFormData): DialogInfo { | ||
const dialogCopy = cloneDeep(dialog); | ||
const trigger = generateNewTrigger(data); | ||
insert(dialogCopy.content, 'triggers', undefined, trigger); | ||
return dialogCopy; | ||
} | ||
|
||
return content; | ||
export function createRegExIntent(dialog: DialogInfo, intent: string, pattern: string): DialogInfo { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above. |
||
const regex = generateRegexExpression(intent, pattern); | ||
const dialogCopy = cloneDeep(dialog); | ||
insert(dialogCopy.content, 'recognizer.intents', undefined, regex); | ||
return dialogCopy; | ||
} | ||
|
||
export function addNewTrigger(dialogs: DialogInfo[], dialogId: string, data: TriggerFormData): DialogInfo { | ||
const dialogCopy = getDialog(dialogs, dialogId); | ||
if (!dialogCopy) throw new Error(`dialog ${dialogId} does not exist`); | ||
insert(dialogCopy.content, 'triggers', undefined, data); | ||
export function updateRegExIntent(dialog: DialogInfo, intent: string, pattern: string): DialogInfo { | ||
let dialogCopy = cloneDeep(dialog); | ||
const regexIntents = get(dialogCopy, 'content.recognizer.intents', []); | ||
const targetIntent = regexIntents.find(ri => ri.intent === intent); | ||
if (!targetIntent) { | ||
dialogCopy = createRegExIntent(dialog, intent, pattern); | ||
} else { | ||
targetIntent.pattern = pattern; | ||
} | ||
return dialogCopy; | ||
} | ||
|
||
export function generateNewDialog(dialogs: DialogInfo[], dialogId: string, data: TriggerFormData): DialogInfo { | ||
//add new trigger | ||
const dialog = dialogs.find(dialog => dialog.id === dialogId); | ||
if (!dialog) throw new Error(`dialog ${dialogId} does not exist`); | ||
let updatedDialog = createNewTrigger(dialog, data); | ||
|
||
//add regex expression | ||
if (data.regexEx) { | ||
updatedDialog = createRegExIntent(updatedDialog, data.intent, data.regexEx); | ||
} | ||
return updatedDialog; | ||
} | ||
|
||
export function createSelectedPath(selected: number) { | ||
return `triggers[${selected}]`; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type
DialogInfo
I believe is an indexed dialog type, but here you didn'treindex it, and seems no need to reindex it. So I would suggest return
content: string
.