mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SignIn button - use correct url (#26239)
* SignIn button - use correct url * Fix SignIn test (#26266) * Don't use absolute URL * post review * Fix snap Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com>
This commit is contained in:
parent
54ad5b869e
commit
187612ca8d
@ -2,13 +2,9 @@ import React from 'react';
|
|||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import { SignIn } from './SignIn';
|
import { SignIn } from './SignIn';
|
||||||
|
|
||||||
jest.mock('../../config', () => ({
|
|
||||||
appUrl: 'http://localhost:3000/',
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('Render', () => {
|
describe('Render', () => {
|
||||||
it('should render component', () => {
|
it('should render component', () => {
|
||||||
const wrapper = shallow(<SignIn url="/" />);
|
const wrapper = shallow(<SignIn url="/whatever" />);
|
||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
@ -1,18 +1,13 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import config from 'app/core/config';
|
|
||||||
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
||||||
import { StoreState } from 'app/types';
|
import { StoreState } from 'app/types';
|
||||||
import { Icon } from '@grafana/ui';
|
import { Icon } from '@grafana/ui';
|
||||||
|
import { getForcedLoginUrl } from './utils';
|
||||||
const getForcedLoginUrl = (url: string) => {
|
|
||||||
const urlObj = new URL(url, config.appUrl);
|
|
||||||
let params = urlObj.searchParams;
|
|
||||||
params.set('forceLogin', 'true');
|
|
||||||
return urlObj.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SignIn: FC<any> = ({ url }) => {
|
export const SignIn: FC<any> = ({ url }) => {
|
||||||
const forcedLoginUrl = getForcedLoginUrl(url);
|
const forcedLoginUrl = getForcedLoginUrl(url);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="sidemenu-item">
|
<div className="sidemenu-item">
|
||||||
<a href={forcedLoginUrl} className="sidemenu-link" target="_self">
|
<a href={forcedLoginUrl} className="sidemenu-link" target="_self">
|
||||||
|
@ -6,7 +6,7 @@ exports[`Render should render component 1`] = `
|
|||||||
>
|
>
|
||||||
<a
|
<a
|
||||||
className="sidemenu-link"
|
className="sidemenu-link"
|
||||||
href="http://localhost:3000/?forceLogin=true"
|
href="/whatever?forceLogin=true"
|
||||||
target="_self"
|
target="_self"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@ -19,7 +19,7 @@ exports[`Render should render component 1`] = `
|
|||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href="http://localhost:3000/?forceLogin=true"
|
href="/whatever?forceLogin=true"
|
||||||
target="_self"
|
target="_self"
|
||||||
>
|
>
|
||||||
<ul
|
<ul
|
||||||
|
25
public/app/core/components/sidemenu/utils.test.ts
Normal file
25
public/app/core/components/sidemenu/utils.test.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { updateConfig } from '../../config';
|
||||||
|
import { getForcedLoginUrl } from './utils';
|
||||||
|
|
||||||
|
describe('getForcedLoginUrl', () => {
|
||||||
|
it.each`
|
||||||
|
appSubUrl | url | expected
|
||||||
|
${''} | ${'/whatever?a=1&b=2'} | ${'/whatever?a=1&b=2&forceLogin=true'}
|
||||||
|
${'/grafana'} | ${'/whatever?a=1&b=2'} | ${'/grafana/whatever?a=1&b=2&forceLogin=true'}
|
||||||
|
${'/grafana/test'} | ${'/whatever?a=1&b=2'} | ${'/grafana/test/whatever?a=1&b=2&forceLogin=true'}
|
||||||
|
${'/grafana'} | ${''} | ${'/grafana?forceLogin=true'}
|
||||||
|
${'/grafana'} | ${'/whatever'} | ${'/grafana/whatever?forceLogin=true'}
|
||||||
|
${'/grafana'} | ${'/whatever/'} | ${'/grafana/whatever/?forceLogin=true'}
|
||||||
|
`(
|
||||||
|
"when appUrl set to '$appUrl' and appSubUrl set to '$appSubUrl' then result should be '$expected'",
|
||||||
|
({ appSubUrl, url, expected }) => {
|
||||||
|
updateConfig({
|
||||||
|
appSubUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = getForcedLoginUrl(url);
|
||||||
|
|
||||||
|
expect(result).toBe(expected);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
8
public/app/core/components/sidemenu/utils.ts
Normal file
8
public/app/core/components/sidemenu/utils.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { getConfig } from 'app/core/config';
|
||||||
|
|
||||||
|
export const getForcedLoginUrl = (url: string) => {
|
||||||
|
const queryParams = new URLSearchParams(url.split('?')[1]);
|
||||||
|
queryParams.append('forceLogin', 'true');
|
||||||
|
|
||||||
|
return `${getConfig().appSubUrl}${url.split('?')[0]}?${queryParams.toString()}`;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user