Skip to content

Commit

Permalink
Simplify docs string base generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mabashian committed Sep 19, 2023
1 parent 7b846e1 commit d1267e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
13 changes: 3 additions & 10 deletions awx/ui/src/util/getDocsBaseUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,9 @@ export default function getDocsBaseUrl(config) {
let version = 'latest';
const licenseType = config?.license_info?.license_type;

if (licenseType && licenseType !== 'open') {
if (config?.version) {
if (parseFloat(config?.version.split('-')[0]) >= 4.3) {
version = parseFloat(config?.version.split('-')[0]);
} else {
version = config?.version.split('-')[0];
}
}
} else {
version = 'latest';
if (licenseType && licenseType !== 'open' && config?.version) {
version = parseFloat(config?.version.split('-')[0]).toFixed(1);
}

return `https://docs.ansible.com/automation-controller/${version}`;
}
12 changes: 6 additions & 6 deletions awx/ui/src/util/getDocsBaseUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('getDocsBaseUrl', () => {
license_info: {
license_type: 'open',
},
version: '18.0.0',
version: '18.4.4',
});

expect(result).toEqual(
Expand All @@ -19,11 +19,11 @@ describe('getDocsBaseUrl', () => {
license_info: {
license_type: 'enterprise',
},
version: '4.0.0',
version: '18.4.4',
});

expect(result).toEqual(
'https://docs.ansible.com/automation-controller/4.0.0'
'https://docs.ansible.com/automation-controller/18.4'
);
});

Expand All @@ -32,17 +32,17 @@ describe('getDocsBaseUrl', () => {
license_info: {
license_type: 'enterprise',
},
version: '4.0.0-beta',
version: '7.0.0-beta',
});

expect(result).toEqual(
'https://docs.ansible.com/automation-controller/4.0.0'
'https://docs.ansible.com/automation-controller/7.0'
);
});

it('should return latest version if license info missing', () => {
const result = getDocsBaseUrl({
version: '18.0.0',
version: '18.4.4',
});

expect(result).toEqual(
Expand Down

0 comments on commit d1267e2

Please sign in to comment.