fix: fixed issue while deleting empty query params (#93)

This commit is contained in:
Anoop M D 2023-02-22 02:42:59 +05:30
parent 8044286b80
commit f22858219b
5 changed files with 43 additions and 4 deletions

View File

@ -50,7 +50,6 @@
"react-redux": "^7.2.6", "react-redux": "^7.2.6",
"react-tooltip": "^5.5.2", "react-tooltip": "^5.5.2",
"sass": "^1.46.0", "sass": "^1.46.0",
"split-on-first": "^3.0.0",
"styled-components": "^5.3.3", "styled-components": "^5.3.3",
"tailwindcss": "^2.2.19", "tailwindcss": "^2.2.19",
"yup": "^0.32.11" "yup": "^0.32.11"

View File

@ -102,7 +102,7 @@ class SingleLineEditor extends Component {
} }
if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue && this.editor) { if (this.props.value !== prevProps.value && this.props.value !== this.cachedValue && this.editor) {
this.cachedValue = this.props.value; this.cachedValue = this.props.value;
this.editor.setValue(this.props.value); this.editor.setValue(this.props.value || '');
} }
this.ignoreChangeEvent = false; this.ignoreChangeEvent = false;
} }

View File

@ -8,7 +8,7 @@ import filter from 'lodash/filter';
import each from 'lodash/each'; import each from 'lodash/each';
import cloneDeep from 'lodash/cloneDeep'; import cloneDeep from 'lodash/cloneDeep';
import { createSlice } from '@reduxjs/toolkit'; import { createSlice } from '@reduxjs/toolkit';
import splitOnFirst from 'split-on-first'; import { splitOnFirst } from 'utils/url';
import { import {
findCollectionByUid, findCollectionByUid,
findCollectionByPathname, findCollectionByPathname,

View File

@ -40,3 +40,16 @@ export const stringifyQueryParams = (params) => {
return queryString.join('&'); return queryString.join('&');
}; };
export const splitOnFirst = (str, char) => {
if(!str || !str.length) {
return [str];
}
let index = str.indexOf(char);
if (index === -1) {
return [str];
}
return [str.slice(0, index), str.slice(index + 1)];
};

View File

@ -1,4 +1,4 @@
import { parseQueryParams } from './index'; import { parseQueryParams, splitOnFirst } from './index';
describe('Url Utils - parseQueryParams', () => { describe('Url Utils - parseQueryParams', () => {
it('should parse query - case 1', () => { it('should parse query - case 1', () => {
@ -41,3 +41,30 @@ describe('Url Utils - parseQueryParams', () => {
expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: '2'}]); expect(params).toEqual([{name: 'a', value: '1'}, {name: 'b', value: '2'}]);
}); });
}); });
describe('Url Utils - splitOnFirst', () => {
it('should split on first - case 1', () => {
const params = splitOnFirst("a", "=");
expect(params).toEqual(['a']);
});
it('should split on first - case 2', () => {
const params = splitOnFirst("a=", "=");
expect(params).toEqual(['a', '']);
});
it('should split on first - case 3', () => {
const params = splitOnFirst("a=1", "=");
expect(params).toEqual(['a', '1']);
});
it('should split on first - case 4', () => {
const params = splitOnFirst("a=1&b=2", "=");
expect(params).toEqual(['a', '1&b=2']);
});
it('should split on first - case 5', () => {
const params = splitOnFirst("a=1&b=2", "&");
expect(params).toEqual(['a=1', 'b=2']);
});
});