Skip to content

Commit

Permalink
Fix presets (#1461)
Browse files Browse the repository at this point in the history
* Fix stream presets

* Preset Fixes
  • Loading branch information
ia3andy authored Aug 14, 2024
1 parent 5a655e3 commit dfa1ddb
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class AcceptanceTestApp implements QuarkusApplication {
private static final Logger LOG = LoggerFactory.getLogger(AcceptanceTestApp.class);

private static final String GENERATE_YOUR_APPLICATION_TEXT = "generate your application";
public static final String LABEL_TOGGLE_FULL_LIST = "[aria-label='Toggle full list of extensions']";
public static final String LABEL_DOWNLOAD_THE_ZIP = "[aria-label='Download the zip']";
private static final int DEFAULT_MIN_EXTENSIONS = 50;
private static final int DEFAULT_MIN_STREAMS = 1;
Expand Down Expand Up @@ -80,7 +81,7 @@ public int run(String... args) throws Exception {
} else {
LOG.info("{} streams found", streams.size());
}

page.waitForSelector(LABEL_TOGGLE_FULL_LIST).click();
page.waitForSelector(".extensions-picker .extension-row");
final List<ElementHandle> extensions = page.querySelectorAll(".extensions-picker .extension-row");
final Integer minExtensions = testConfig.getMinExtensions().orElse(DEFAULT_MIN_EXTENSIONS);
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
23 changes: 16 additions & 7 deletions base/src/main/java/io/quarkus/code/rest/CodeQuarkusResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -154,23 +155,31 @@ public Uni<Response> extensionsForStream(
@Tag(name = "Presets", description = "Preset related endpoints")
@APIResponse(responseCode = "200", description = "List of Presets", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Preset.class, type = SchemaType.ARRAY)))
public Uni<Response> presets() {
String lastUpdated = platformService.cacheLastUpdated().format(FORMATTER);
Response response = Response.ok(PRESETS)
.header(LAST_MODIFIED_HEADER, lastUpdated)
.build();
return Uni.createFrom().item(response);
return presets(platformService.recommendedPlatformInfo().extensionsById());
}

@GET
@Path("/extensions/presets/{streamKey}")
@Path("/presets/stream/{streamKey}")
@Produces(MediaType.APPLICATION_JSON)
@NoCache
@Operation(operationId = "presetsForStream", summary = "Get the Quarkus Launcher list of Presets")
@Tag(name = "Presets", description = "Preset related endpoints")
@APIResponse(responseCode = "200", description = "List of Presets for a certain stream", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = Preset.class, type = SchemaType.ARRAY)))
public Uni<Response> presetsForStream(
@PathParam("streamKey") String streamKey) {
return presets();

final Map<String, ExtensionRef> extensionsById = platformService.platformInfo(streamKey).extensionsById();
return presets(extensionsById);
}

private Uni<Response> presets(Map<String, ExtensionRef> extensionsById) {
String lastUpdated = platformService.cacheLastUpdated().format(FORMATTER);
final List<Preset> presets = PRESETS.stream().filter(p -> p.extensions().stream().allMatch(extensionsById::containsKey))
.toList();
Response response = Response.ok(presets)
.header(LAST_MODIFIED_HEADER, lastUpdated)
.build();
return Uni.createFrom().item(response);
}

private Uni<Response> extensions(
Expand Down
29 changes: 23 additions & 6 deletions base/src/main/java/io/quarkus/code/service/PlatformService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,34 @@
public class PlatformService {

public static final List<Preset> PRESETS = List.of(
new Preset("db-service", "Microservice with database", "/static/media/presets/db-service.svg",
new Preset("db-service-reactive", "Microservice with database",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/db-service.svg",
List.of("io.quarkus:quarkus-resteasy-reactive", "io.quarkus:quarkus-resteasy-reactive-jackson",
"io.quarkus:quarkus-hibernate-reactive-panache", "io.quarkus:quarkus-jdbc-postgresql")),
new Preset("webapp-npm-reactive", "Web app with NPM UI",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/webapp-npm.svg",
List.of("io.quarkus:quarkus-resteasy-reactive", "io.quarkus:quarkus-resteasy-reactive-jackson",
"io.quarkiverse.quinoa:quarkus-quinoa")),
new Preset("event-driven-reactive-kafka", "Event driven service with Kafka",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/event-driven-kafka.svg",
List.of("io.quarkus:quarkus-smallrye-reactive-messaging-kafka")),
new Preset("db-service", "Microservice with database",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/db-service.svg",
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
"io.quarkus:quarkus-hibernate-orm-panache", "io.quarkus:quarkus-jdbc-postgresql")),
new Preset("event-driven-kafka", "Event driven service with Kafka", "/static/media/presets/event-driven-kafka.svg",
new Preset("event-driven-kafka", "Event driven service with Kafka",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/event-driven-kafka.svg",
List.of("io.quarkus:quarkus-messaging-kafka")),
new Preset("cli", "Command-line tool", "/static/media/presets/cli.svg",
new Preset("cli", "Command-line tool",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/cli.svg",
List.of("io.quarkus:quarkus-picocli")),
new Preset("webapp-mvc", "Web app with Model-View-Controller", "/static/media/presets/webapp-mvc.svg",
new Preset("webapp-mvc", "Web app with Model-View-Controller",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/webapp-mvc.svg",
List.of("io.quarkiverse.renarde:quarkus-renarde", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
new Preset("webapp-npm", "Web app with NPM UI", "/static/media/presets/webapp-npm.svg",
List.of("io.quarkus:quarkus-rest", "io.quarkiverse.quinoa:quarkus-quinoa")),
new Preset("webapp-npm", "Web app with NPM UI",
"https://raw.githubusercontent.com/quarkusio/code.quarkus.io/main/base/assets/icons/presets/webapp-npm.svg",
List.of("io.quarkus:quarkus-rest", "io.quarkus:quarkus-rest-jackson",
"io.quarkiverse.quinoa:quarkus-quinoa")),
new Preset("webapp-qute", "Web app with ServerSide Rendering", "static/media/presets/webapp-qute.svg",
List.of("io.quarkiverse.qute.web:quarkus-qute-web", "io.quarkiverse.web-bundler:quarkus-web-bundler")),
new Preset("ai-infused", "AI Infused service", "static/media/presets/ai-infused.svg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import styled from 'styled-components';
import {TagEntry} from "./extensions-picker";
import {Platform, Preset} from "../api/model";
import _ from "lodash";
import {useAnalytics} from "../../core/analytics";

interface PresetsProps {
platform: Platform,
Expand All @@ -15,7 +16,7 @@ const PresetsPanelDiv = styled.div`
.panel-title {
font-weight: bold;
color: var(--extensionsPickerCategoryTextColor);
font-size: 1.1rem;
font-size: 1.3rem;
margin: 10px 0 10px 0;
height: 30px;
}
Expand All @@ -39,16 +40,16 @@ const PresetsPanelDiv = styled.div`
.preset-title {
color: var(--presetsCardTextColor);
font-size: 1.2rem;
font-size: 1.1rem;
text-align: center;
}
.preset-icon {
flex-basis: 130px;
flex-basis: 110px;
}
.preset-icon img {
width: 100px;
width: 90px;
}
`;
Expand All @@ -63,12 +64,15 @@ export const PresetCard = (props: { preset: Preset, tagsDef: TagEntry[], onClick
}

export const PresetsPanel = (props: PresetsProps) => {
let analytics = useAnalytics();
const context = {element: 'preset-picker'};
const byId = _.keyBy(props.platform.extensions, ({id}) => id);
const presets = props.platform.presets.map(p => ({
...p, resolvedExtensions: p.extensions.filter(e => byId[e]).map(e => byId[e])
} as Preset))

const selectPreset = (preset: Preset) => {
analytics.event('Select preset', {preset: preset.key, ...context});
preset.extensions.forEach(e => props.select(e, "presets"));
};
return (
Expand Down

0 comments on commit dfa1ddb

Please sign in to comment.