-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚸 Automatically create variables when pasting groups to a new typebot
Closes #1587
- Loading branch information
1 parent
67f37c0
commit 4ab1803
Showing
7 changed files
with
148 additions
and
20 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Variable } from './types' | ||
|
||
const variableNameRegex = /\{\{([^{}]+)\}\}/g | ||
|
||
export const extractVariableIdReferencesInObject = ( | ||
obj: any, | ||
existingVariables: Variable[] | ||
): string[] => | ||
[...(JSON.stringify(obj).match(variableNameRegex) ?? [])].reduce<string[]>( | ||
(acc, match) => { | ||
const varName = match.slice(2, -2) | ||
const id = existingVariables.find((v) => v.name === varName)?.id | ||
if (!id || acc.find((accId) => accId === id)) return acc | ||
return acc.concat(id) | ||
}, | ||
[] | ||
) | ||
|
||
const variableIdRegex = /"\w*variableid":"([^"]+)"/gi | ||
|
||
export const extractVariableIdsFromObject = (obj: any): string[] => | ||
[...(JSON.stringify(obj).match(variableIdRegex) ?? [])].reduce<string[]>( | ||
(acc, match) => { | ||
const id = variableIdRegex.exec(match)?.[1] | ||
if (!id || acc.find((accId) => accId === id)) return acc | ||
return acc.concat(id) | ||
}, | ||
[] | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.