Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ module.exports = {
transformIgnorePatterns: [
'<rootDir>/node_modules/(?!(@patternfly/react-core/|@patternfly/react-icons/|@redhat-cloud-services|@openshift|lodash-es|@patternfly/react-table|@patternfly/react-tokens|p-all)).*$',
],
maxWorkers: 4,
Comment thread
xbhouse marked this conversation as resolved.
};
36 changes: 30 additions & 6 deletions src/Utilities/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,18 +703,40 @@ export const isRHAdvisory = (name) => /^(RHEA|RHBA|RHSA)/.test(name);
export const buildTagString = (tag) =>
`${tag.category}/${tag.values?.tagKey}=${tag.value?.tagValue}`;

/**
* Build one `tags=…` query fragment with a single URI encode pass. Inventory / insights-chrome
* sometimes passes tag strings that are already `tags=` segments or percent-encoded and encoding
* again turns `%2F` into `%252F` and breaks the patch API.
*/
const buildTagsQuerySegment = (rawTagInput) => {
if (rawTagInput === undefined || rawTagInput === null) {
return '';
}
let inner = String(rawTagInput).trim();
if (inner.startsWith('tags=')) {
inner = inner.slice(5);
}
let decoded = inner;
try {
decoded = decodeURIComponent(inner);
} catch {
decoded = inner;
}
return `tags=${encodeURIComponent(decoded)}`;
};

export const mapGlobalFilters = (tags, workloads = {}) => {
let tagsInUrlFormat = [];
tags &&
tags.forEach((tag, index) => {
let tagGruop = tag;
if (typeof tag === 'object') {
tagGruop = tag?.values.map(
(value) => `tags=${encodeURIComponent(`${tag.category}/${value.tagKey}=${value.value}`)}`,
if (typeof tag === 'object' && tag !== null) {
tagGruop = tag?.values.map((value) =>
buildTagsQuerySegment(`${tag.category}/${value.tagKey}=${value.value}`),
);
tagsInUrlFormat[index] = (Array.isArray(tagGruop) && flatten(tagGruop)) || tagGruop;
} else {
tagsInUrlFormat[index] = `tags=${encodeURIComponent(tagGruop)}`;
} else if (typeof tag === 'string') {
tagsInUrlFormat[index] = buildTagsQuerySegment(tagGruop);
}
});

Expand All @@ -730,7 +752,9 @@ export const mapGlobalFilters = (tags, workloads = {}) => {
}),
};

tagsInUrlFormat && (globalFilterConfig.selectedTags = tagsInUrlFormat);
if (tagsInUrlFormat?.length) {
globalFilterConfig.selectedTags = flatten(tagsInUrlFormat).filter(Boolean);
}

return globalFilterConfig;
};
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/hooks/Hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('Custom hooks tests', () => {
os: 'RHEL 8.8',
},
filters: params.filters,
selectedTags: ['tags=owner%2Fteam%3Dplatform', ['tags=env%2Fstage%3Dprod']],
selectedTags: ['tags=owner%2Fteam%3Dplatform', 'tags=env%2Fstage%3Dprod'],
systemProfile: { ansible: { controller_version: 'not_nil' } },
});
expect(applyInventorySnapshot.mock.invocationCallOrder[0]).toBeLessThan(
Expand Down
Loading