-
Notifications
You must be signed in to change notification settings - Fork 56
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: custom validation refactor #11
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4d3340
wip
c83de86
wip
3e66757
Customization refactor.
001d0b9
Restricted custom url to paypalobjects. Added error handling.
6fe990f
Updated custom banner demo functionality.
e0bab9e
Updated error logging for custom banners.
9dd6a42
removing console log
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import objectEntries from 'core-js-pure/stable/object/entries'; | |
import { ZalgoPromise } from 'zalgo-promise'; | ||
|
||
import { memoizeOnProps, objectGet, objectMerge, objectFlattenToArray } from '../../utils'; | ||
import { logger, EVENTS } from '../logger'; | ||
import { logger, EVENTS, ERRORS } from '../logger'; | ||
import getCustomTemplate from './customTemplate'; | ||
|
||
// Specific dimensions tied to JSON banners in Campaign Studio | ||
|
@@ -87,7 +87,12 @@ function fetcher(options) { | |
function getBannerOptions(markup) { | ||
const annotationsString = markup.match(/^<!--([\s\S]+?)-->/); | ||
if (annotationsString) { | ||
return JSON.parse(annotationsString[1]); | ||
try { | ||
const bannerOptions = JSON.parse(annotationsString[1]); | ||
return bannerOptions; | ||
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. Can't we just 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. Yup - remnant of some previous code. |
||
} catch (err) { | ||
throw new Error(ERRORS.INVALID_CUSTOM_BANNER_JSON); | ||
} | ||
} | ||
return {}; | ||
} | ||
|
@@ -104,8 +109,14 @@ export default function getBannerMarkup(options) { | |
data.markup.template = template; | ||
|
||
const bannerOptions = getBannerOptions(template); | ||
options = objectMerge(options, { ...bannerOptions }); | ||
options.style._flattened = objectFlattenToArray(options.style); | ||
if (!bannerOptions) { | ||
return null; | ||
} | ||
|
||
const mergedOptions = objectMerge(options, bannerOptions); | ||
mergedOptions.style._flattened = objectFlattenToArray(mergedOptions.style); | ||
|
||
return { markup: data.markup, options: mergedOptions }; | ||
} | ||
return { markup: data.markup, options }; | ||
}); | ||
|
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
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.
Is it feasible to use
String.prototype.startsWith()
instead of a regex for this scenario? And for__DEMO__
we can just accept anything since it's for internal use only?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.
Also, have we considered how this will work with the customization app since everything is now some form of URL?