Fix Bug 1506594 - Open snippet links in same window (#4563)

This commit is contained in:
Andrei Oprea 2018-11-15 08:54:00 +00:00 коммит произвёл GitHub
Родитель 78c4062812
Коммит 4cec5cd2f1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 20 добавлений и 10 удалений

Просмотреть файл

@ -17,7 +17,7 @@ const ALLOWED_TAGS = {
* Transform an object (tag name: {url}) into (tag name: anchor) where the url
* is used as href, in order to render links inside a Fluent.Localized component.
*/
export function convertLinks(links, sendClick, doNotAutoBlock) {
export function convertLinks(links, sendClick, doNotAutoBlock, openNewWindow = false) {
if (links) {
return Object.keys(links).reduce((acc, linkTag) => {
const {action} = links[linkTag];
@ -25,7 +25,7 @@ export function convertLinks(links, sendClick, doNotAutoBlock) {
const url = action ? false : safeURI(links[linkTag].url);
acc[linkTag] = (<a href={url}
target={doNotAutoBlock ? "_blank" : ""}
target={openNewWindow ? "_blank" : ""}
data-metric={links[linkTag].metric}
data-action={action}
data-args={links[linkTag].args}
@ -46,7 +46,7 @@ export function RichText(props) {
throw new Error(`ASRouter: ${props.localization_id} is not a valid rich text property. If you want it to be processed, you need to add it to asrouter/rich-text-strings.js`);
}
return (
<Localized id={props.localization_id} {...ALLOWED_TAGS} {...props.customElements} {...convertLinks(props.links, props.sendClick, props.doNotAutoBlock)}>
<Localized id={props.localization_id} {...ALLOWED_TAGS} {...props.customElements} {...convertLinks(props.links, props.sendClick, props.doNotAutoBlock, props.openNewWindow)}>
<span>{props.text}</span>
</Localized>
);

Просмотреть файл

@ -89,6 +89,7 @@ export class SubmitFormSnippet extends React.PureComponent {
localization_id="disclaimer_html"
links={content.links}
doNotAutoBlock={true}
openNewWindow={true}
sendClick={this.props.sendClick} />
</p>);
}
@ -105,6 +106,7 @@ export class SubmitFormSnippet extends React.PureComponent {
localization_id="privacy_html"
links={content.links}
doNotAutoBlock={true}
openNewWindow={true}
sendClick={this.props.sendClick} />
</span>
</p>

Просмотреть файл

@ -928,7 +928,7 @@ class _ASRouter {
target.browser.ownerGlobal.OpenBrowserWindow({private: true});
break;
case ra.OPEN_URL:
target.browser.ownerGlobal.openLinkIn(action.data.args, "tabshifted", {
target.browser.ownerGlobal.openLinkIn(action.data.args, action.data.where || "current", {
private: false,
triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
});
@ -948,7 +948,7 @@ class _ASRouter {
case ra.SHOW_FIREFOX_ACCOUNTS:
const url = await FxAccounts.config.promiseSignUpURI("snippets");
// We want to replace the current tab.
target.browser.ownerGlobal.openLinkIn(url, "tabshifted", {
target.browser.ownerGlobal.openLinkIn(url, "current", {
private: false,
triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
});

Просмотреть файл

@ -38,7 +38,7 @@ const ONBOARDING_MESSAGES = async () => ([
button_label: {string_id: "onboarding-button-label-try-now"},
button_action: {
type: "OPEN_URL",
data: {args: "https://screenshots.firefox.com/#tour"},
data: {args: "https://screenshots.firefox.com/#tour", where: "tabshifted"},
},
},
trigger: {id: "firstRun"},
@ -73,7 +73,7 @@ const ONBOARDING_MESSAGES = async () => ([
button_label: {string_id: "onboarding-button-label-try-now"},
button_action: {
type: "OPEN_URL",
data: {args: "https://addons.mozilla.org/en-US/firefox/addon/ghostery/"},
data: {args: "https://addons.mozilla.org/en-US/firefox/addon/ghostery/", where: "tabshifted"},
},
},
targeting: "providerCohorts.onboarding == 'ghostery'",
@ -91,7 +91,7 @@ const ONBOARDING_MESSAGES = async () => ([
button_label: {string_id: "onboarding-button-label-get-started"},
button_action: {
type: "OPEN_URL",
data: {args: await FxAccountsConfig.promiseEmailFirstURI("onboarding")},
data: {args: await FxAccountsConfig.promiseEmailFirstURI("onboarding"), where: "tabshifted"},
},
},
targeting: "attributionData.campaign == 'non-fx-button' && attributionData.source == 'addons.mozilla.org'",

Просмотреть файл

@ -840,7 +840,7 @@ describe("ASRouter", () => {
});
it("should call openLinkIn with the correct params on OPEN_URL", async () => {
let [testMessage] = Router.state.messages;
testMessage.button_action = {type: "OPEN_URL", data: {args: "some/url.com"}};
testMessage.button_action = {type: "OPEN_URL", data: {args: "some/url.com", where: "tabshifted"}};
const msg = fakeExecuteUserAction(testMessage.button_action);
await Router.onMessage(msg);
@ -873,7 +873,7 @@ describe("ASRouter", () => {
assert.calledOnce(msg.target.browser.ownerGlobal.openLinkIn);
assert.calledWith(msg.target.browser.ownerGlobal.openLinkIn,
"some/url", "tabshifted", {"private": false, "triggeringPrincipal": undefined});
"some/url", "current", {"private": false, "triggeringPrincipal": undefined});
});
});

Просмотреть файл

@ -43,6 +43,14 @@ describe("convertLinks", () => {
assert.propertyVal(result.cta.props, "data-args", cta.args);
assert.propertyVal(result.cta.props, "onClick", stub);
});
it("should follow openNewWindow prop", () => {
const cta = {url: "https://foo.com"};
const newWindow = convertLinks({cta}, sandbox.stub(), false, true);
const sameWindow = convertLinks({cta}, sandbox.stub(), false);
assert.propertyVal(newWindow.cta.props, "target", "_blank");
assert.propertyVal(sameWindow.cta.props, "target", "");
});
it("should allow for custom elements & styles", () => {
const wrapper = mount(<RichText customElements={{em: <em style={{color: "#f05"}} />}} text="<em>foo</em>" localization_id="text" />);