1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Load name from url (#323)

* fix: changed loadNameFromHash to loadNameFromUrl

Co-authored-by: Shane A. Stillwell <shane@northernv.com>
This commit is contained in:
Fredrik Strand Oseberg 2021-08-11 11:43:31 +02:00 committed by GitHub
parent 1dbf74f6d8
commit cad5e1a01b
4 changed files with 9 additions and 14 deletions

View File

@ -85,14 +85,9 @@ export function updateWeight(variants, totalWeight) {
});
}
export function loadNameFromHash() {
let field = '';
try {
[, field] = document.location.hash.match(/name=([a-z0-9-_.]+)/i);
} catch (e) {
// nothing
}
return field;
export function loadNameFromUrl() {
const params = new URLSearchParams(document.location.search);
return params.get('name') || '';
}
export const modalStyles = {

View File

@ -77,7 +77,7 @@ exports[`renders correctly with one feature 1`] = `
dateTime="2018-02-04T20:27:52.127Z"
title="2018-02-04T20:27:52.127Z"
>
3 years ago
4 years ago
</time>
</small>
<div>
@ -178,7 +178,7 @@ exports[`renders correctly with one feature without permission 1`] = `
dateTime="2018-02-04T20:27:52.127Z"
title="2018-02-04T20:27:52.127Z"
>
3 years ago
4 years ago
</time>
</small>
<div>

View File

@ -6,7 +6,7 @@ import {
validateName,
} from '../../../../store/feature-toggle/actions';
import CreateFeature from './CreateFeature';
import { loadNameFromHash, showPnpsFeedback } from '../../../common/util';
import { loadNameFromUrl, showPnpsFeedback } from '../../../common/util';
import { showFeedback } from '../../../../store/feedback/actions';
const defaultStrategy = {
@ -27,7 +27,7 @@ function resolveCurrentProjectId(settings) {
class WrapperComponent extends Component {
constructor(props) {
super();
const name = loadNameFromHash();
const name = loadNameFromUrl();
this.state = {
featureToggle: {
name,

View File

@ -9,7 +9,7 @@ import {
} from '../../../store/strategy/actions';
import CreateStrategy from './CreateStrategy';
import { loadNameFromHash } from '../../common/util';
import { loadNameFromUrl } from '../../common/util';
const STRATEGY_EXIST_ERROR = 'Error: Strategy with name';
@ -141,7 +141,7 @@ const mapStateToProps = (state, props) => {
return {
strategy: strategy
? strategy
: { name: loadNameFromHash(), description: '', parameters: [] },
: { name: loadNameFromUrl(), description: '', parameters: [] },
editMode,
};
};