Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for , non presence of consul-version meta #18464

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Changes from 1 commit
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
42 changes: 22 additions & 20 deletions ui/packages/consul-ui/app/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,36 +227,38 @@ export default class ApplicationSerializer extends Serializer {
// create a Set and add version with only major.minor : ex-1.24.6 as 1.24
let versionSet = new Set();
payload.forEach(function (item) {
if (item.Meta && item.Meta['consul-version'] !== '') {
if (item.Meta && item.Meta['consul-version'] && item.Meta['consul-version'] !== '') {
vijayraghav-io marked this conversation as resolved.
Show resolved Hide resolved
const split = item.Meta['consul-version'].split('.');
versionSet.add(split[0] + '.' + split[1]);
}
});

const versionArray = Array.from(versionSet);

// Sort the array in descending order using a custom comparison function
versionArray.sort((a, b) => {
// Split the versions into arrays of numbers
const versionA = a.split('.').map((part) => {
const number = Number(part);
return isNaN(number) ? 0 : number;
});
const versionB = b.split('.').map((part) => {
const number = Number(part);
return isNaN(number) ? 0 : number;
});
if (versionArray.length > 0) {
vijayraghav-io marked this conversation as resolved.
Show resolved Hide resolved
// Sort the array in descending order using a custom comparison function
versionArray.sort((a, b) => {
// Split the versions into arrays of numbers
const versionA = a.split('.').map((part) => {
const number = Number(part);
return isNaN(number) ? 0 : number;
});
const versionB = b.split('.').map((part) => {
const number = Number(part);
return isNaN(number) ? 0 : number;
});

const minLength = Math.min(versionA.length, versionB.length);
const minLength = Math.min(versionA.length, versionB.length);

// start with comparing major version num, if equal then compare minor
for (let i = 0; i < minLength; i++) {
if (versionA[i] !== versionB[i]) {
return versionB[i] - versionA[i];
// start with comparing major version num, if equal then compare minor
for (let i = 0; i < minLength; i++) {
if (versionA[i] !== versionB[i]) {
return versionB[i] - versionA[i];
}
}
}
return versionB.length - versionA.length;
});
return versionB.length - versionA.length;
});
}

return versionArray; //sorted array
}
Expand Down