Skip to content

Commit

Permalink
Merge pull request #6110 from keithjgrant/qs-empty-strings
Browse files Browse the repository at this point in the history
Remove "Manual" option from search filters

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Feb 28, 2020
2 parents 7fe5726 + 5574cf0 commit fe046b4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function InventorySourcesList({
name: i18n._(t`Source`),
key: 'source',
options: [
[``, i18n._(t`Manual`)],
[`file`, i18n._(t`File, Directory or Script`)],
[`scm`, i18n._(t`Sourced from a Project`)],
[`ec2`, i18n._(t`Amazon EC2`)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ function ProjectsList({ history, i18n, nodeResource, onUpdateNodeResource }) {
name: i18n._(t`Type`),
key: 'type',
options: [
[``, i18n._(t`Manual`)],
[`git`, i18n._(t`Git`)],
[`hg`, i18n._(t`Mercurial`)],
[`svn`, i18n._(t`Subversion`)],
Expand Down
4 changes: 2 additions & 2 deletions awx/ui_next/src/util/qs.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function removeParams(config, oldParams, paramsToRemove) {
};
Object.keys(oldParams).forEach(key => {
const value = removeParam(oldParams[key], paramsToRemove[key]);
if (value) {
if (value !== null) {
updated[key] = value;
}
});
Expand Down Expand Up @@ -205,7 +205,7 @@ export function mergeParams(oldParams, newParams) {
}

function mergeParam(oldVal, newVal) {
if (!newVal) {
if (!newVal && newVal !== '') {
return oldVal;
}
if (!oldVal) {
Expand Down
30 changes: 30 additions & 0 deletions awx/ui_next/src/util/qs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ describe('qs (qs.js)', () => {
page_size: 15,
});
});

test('should parse empty string values', () => {
const config = {
namespace: 'bee',
defaultParams: { page: 1, page_size: 15 },
integerFields: ['page', 'page_size'],
};
const query = '?bee.baz=bar&bee.or__source=';
expect(parseQueryString(config, query)).toEqual({
baz: 'bar',
page: 1,
page_size: 15,
or__source: '',
});
});
});

describe('removeParams', () => {
Expand Down Expand Up @@ -532,6 +547,21 @@ describe('qs (qs.js)', () => {
page_size: 15,
});
});

test('should retain empty string', () => {
const config = {
namespace: null,
defaultParams: { page: 1, page_size: 15 },
integerFields: ['page', 'page_size'],
};
const oldParams = { baz: '', page: 3, bag: 'boom', page_size: 15 };
const toRemove = { bag: 'boom' };
expect(removeParams(config, oldParams, toRemove)).toEqual({
baz: '',
page: 3,
page_size: 15,
});
});
});

describe('_stringToObject', () => {
Expand Down

0 comments on commit fe046b4

Please sign in to comment.