Skip to content

Commit fc5df01

Browse files
authored
Merge pull request #886 from amvanbaren/admin-version-targetplatforms-order
Display ordered list of extension versions in admin dashboard
2 parents 4e2cac5 + 8cff3b1 commit fc5df01

File tree

8 files changed

+67
-21
lines changed

8 files changed

+67
-21
lines changed

server/src/main/java/org/eclipse/openvsx/admin/AdminAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public ResponseEntity<ExtensionJson> getExtension(@PathVariable String namespace
189189
json.namespace = extension.getNamespace().getName();
190190
json.name = extension.getName();
191191
json.allVersions = Collections.emptyMap();
192-
json.allTargetPlatformVersions = Collections.emptyMap();
192+
json.allTargetPlatformVersions = Collections.emptyList();
193193
} else {
194194
json = local.toExtensionVersionJson(latest, null, false);
195195
json.allTargetPlatformVersions = repositories.findTargetPlatformsGroupedByVersion(extension);

server/src/main/java/org/eclipse/openvsx/json/ExtensionJson.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public static ExtensionJson error(String message) {
177177
public Map<String, String> downloads;
178178

179179
@Schema(description = "Map of target platforms by extension version")
180-
public Map<String, List<String>> allTargetPlatformVersions;
180+
public List<VersionTargetPlatformsJson> allTargetPlatformVersions;
181181

182182
@Schema(description = "version metadata URL")
183183
public String url;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** ******************************************************************************
2+
* Copyright (c) 2024 Precies. Software Ltd and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
* ****************************************************************************** */
10+
package org.eclipse.openvsx.json;
11+
12+
import java.util.List;
13+
14+
public record VersionTargetPlatformsJson(String version, String[] targetPlatforms) {}

server/src/main/java/org/eclipse/openvsx/repositories/ExtensionVersionJooqRepository.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.commons.lang3.StringUtils;
1414
import org.eclipse.openvsx.entities.*;
1515
import org.eclipse.openvsx.json.QueryRequest;
16+
import org.eclipse.openvsx.json.VersionTargetPlatformsJson;
1617
import org.eclipse.openvsx.util.TargetPlatform;
1718
import org.eclipse.openvsx.util.VersionAlias;
1819
import org.jooq.Record;
@@ -542,16 +543,41 @@ private List<String> toList(String raw, ListOfStringConverter converter) {
542543
return converter.convertToEntityAttribute(raw);
543544
}
544545

545-
public Map<String, List<String>> findTargetPlatformsGroupedByVersion(Extension extension) {
546-
var TARGET_PLATFORMS = DSL.arrayAgg(EXTENSION_VERSION.TARGET_PLATFORM);
547-
return dsl.select(EXTENSION_VERSION.VERSION, TARGET_PLATFORMS)
546+
public List<VersionTargetPlatformsJson> findTargetPlatformsGroupedByVersion(Extension extension) {
547+
var targetPlatforms = DSL.arrayAgg(EXTENSION_VERSION.TARGET_PLATFORM)
548+
.orderBy(
549+
EXTENSION_VERSION.UNIVERSAL_TARGET_PLATFORM.desc(),
550+
EXTENSION_VERSION.TARGET_PLATFORM.asc()
551+
);
552+
553+
return dsl.select(
554+
EXTENSION_VERSION.SEMVER_MAJOR,
555+
EXTENSION_VERSION.SEMVER_MINOR,
556+
EXTENSION_VERSION.SEMVER_PATCH,
557+
EXTENSION_VERSION.SEMVER_IS_PRE_RELEASE,
558+
EXTENSION_VERSION.VERSION,
559+
targetPlatforms
560+
)
548561
.from(EXTENSION_VERSION)
549562
.where(EXTENSION_VERSION.EXTENSION_ID.eq(extension.getId()))
550-
.groupBy(EXTENSION_VERSION.VERSION)
563+
.groupBy(
564+
EXTENSION_VERSION.SEMVER_MAJOR,
565+
EXTENSION_VERSION.SEMVER_MINOR,
566+
EXTENSION_VERSION.SEMVER_PATCH,
567+
EXTENSION_VERSION.SEMVER_IS_PRE_RELEASE,
568+
EXTENSION_VERSION.VERSION
569+
)
570+
.orderBy(
571+
EXTENSION_VERSION.SEMVER_MAJOR.desc(),
572+
EXTENSION_VERSION.SEMVER_MINOR.desc(),
573+
EXTENSION_VERSION.SEMVER_PATCH.desc(),
574+
EXTENSION_VERSION.SEMVER_IS_PRE_RELEASE.asc(),
575+
EXTENSION_VERSION.VERSION.asc()
576+
)
551577
.fetch()
552-
.collect(Collectors.toMap(
553-
r -> r.get(EXTENSION_VERSION.VERSION),
554-
r -> List.of(r.get(TARGET_PLATFORMS))
578+
.map(record -> new VersionTargetPlatformsJson(
579+
record.get(EXTENSION_VERSION.VERSION),
580+
record.get(targetPlatforms)
555581
));
556582
}
557583

server/src/main/java/org/eclipse/openvsx/repositories/RepositoryService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.micrometer.observation.annotation.Observed;
1313
import org.eclipse.openvsx.entities.*;
1414
import org.eclipse.openvsx.json.QueryRequest;
15+
import org.eclipse.openvsx.json.VersionTargetPlatformsJson;
1516
import org.eclipse.openvsx.util.NamingUtil;
1617
import org.eclipse.openvsx.web.SitemapRow;
1718
import org.springframework.beans.factory.annotation.Autowired;
@@ -528,7 +529,7 @@ public List<SitemapRow> fetchSitemapRows() {
528529
return extensionJooqRepo.fetchSitemapRows();
529530
}
530531

531-
public Map<String, List<String>> findTargetPlatformsGroupedByVersion(Extension extension) {
532+
public List<VersionTargetPlatformsJson> findTargetPlatformsGroupedByVersion(Extension extension) {
532533
return extensionVersionJooqRepo.findTargetPlatformsGroupedByVersion(extension);
533534
}
534535

webui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "openvsx-webui",
3-
"version": "0.11.4",
3+
"version": "0.11.5",
44
"description": "User interface for Eclipse Open VSX",
55
"keywords": [
66
"react",

webui/src/extension-registry-types.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ export interface Extension {
107107

108108
// key: target platform, value: download link
109109
downloads: { [targetPlatform: string]: UrlString };
110-
111-
// key: version, value: target platforms
112-
allTargetPlatformVersions: { [version: string]: string[] };
110+
allTargetPlatformVersions?: VersionTargetPlatforms[];
113111
}
114112

115113
export interface Badge {
@@ -124,6 +122,11 @@ export interface ExtensionReference {
124122
version?: string;
125123
}
126124

125+
export interface VersionTargetPlatforms {
126+
version: string;
127+
targetPlatforms: string[];
128+
}
129+
127130
export type StarRating = 1 | 2 | 3 | 4 | 5;
128131
export interface NewReview {
129132
rating: StarRating;

webui/src/pages/admin-dashboard/extension-version-container.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ export const ExtensionVersionContainer: FunctionComponent<ExtensionVersionContai
2323
const getTargetPlatformVersions = () => {
2424
const versionMap: TargetPlatformVersion[] = [];
2525
versionMap.push({ targetPlatform: WILDCARD, version: WILDCARD, checked: false });
26-
Object.keys(extension.allTargetPlatformVersions)
27-
.filter(version => VERSION_ALIASES.indexOf(version) < 0)
28-
.forEach(version => {
29-
versionMap.push({ targetPlatform: WILDCARD, version: version, checked: false });
30-
const targetPlatforms = extension.allTargetPlatformVersions[version];
31-
targetPlatforms.forEach(targetPlatform => versionMap.push({ targetPlatform: targetPlatform, version: version, checked: false }));
32-
});
26+
if (extension.allTargetPlatformVersions != null) {
27+
extension.allTargetPlatformVersions
28+
.filter(i => VERSION_ALIASES.indexOf(i.version) < 0)
29+
.forEach(i => {
30+
const { version, targetPlatforms } = i;
31+
versionMap.push({ targetPlatform: WILDCARD, version, checked: false });
32+
targetPlatforms.forEach(targetPlatform => versionMap.push({ targetPlatform, version, checked: false }));
33+
});
34+
}
3335

3436
return versionMap;
3537
};

0 commit comments

Comments
 (0)