Skip to content

Commit 8cd4ffe

Browse files
committed
Add database chooser options
1 parent 423b945 commit 8cd4ffe

File tree

9 files changed

+84
-28
lines changed

9 files changed

+84
-28
lines changed

assets/js/bundle.js

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

layouts/shortcodes/choosable.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515

1616

1717
<div>
18-
<pulumi-choosable type="{{ $type }}" values="{{ $values }}" mode="{{ $mode }}">{{ .Inner }}</pulumi-choosable>
18+
<pulumi-choosable type="{{ $type }}" values="{{ $values }}" mode="{{ $mode }}">{{ .Inner | markdownify }}</pulumi-choosable>
1919
</div>

theme/stencil/src/components/choosable/choosable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Choosable {
7272
// @ts-ignore-next-line
7373
this.storeUnsubscribe = store.mapStateToProps(this, (state: AppState) => {
7474
const {
75-
preferences: { language, k8sLanguage, os, cloud, persona, backend },
75+
preferences: { language, k8sLanguage, os, cloud, persona, backend, database },
7676
} = state;
7777

7878
switch (this.type) {
@@ -88,6 +88,8 @@ export class Choosable {
8888
return { selection: persona };
8989
case "backend":
9090
return { selection: backend };
91+
case "database":
92+
return { selection: database };
9193
}
9294
});
9395
}

theme/stencil/src/components/chooser/chooser.tsx

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, Element, Host, h, Listen, Prop, State } from "@stencil/core";
22
import { store, Unsubscribe } from "@stencil/redux";
33
import { AppState } from "../../store/state";
4-
import { setLanguage, setK8sLanguage, setOS, setCloud, setPersona, setBackEnd } from "../../store/actions/preferences";
4+
import { setLanguage, setK8sLanguage, setOS, setCloud, setPersona, setBackEnd, setDatabase } from "../../store/actions/preferences";
55

66
export type LanguageKey = "javascript" | "typescript" | "python" | "go" | "csharp" | "fsharp" | "visualbasic" | "java" | "yaml";
77
export type K8sLanguageKey = "typescript" | "yaml" | "typescript-kx";
@@ -12,9 +12,10 @@ export type BackEndKey = "service" | "self-managed";
1212

1313
export type ChooserMode = "local" | "global";
1414
export type ChooserOptionStyle = "tabbed" | "none";
15-
export type ChooserType = "language" | "k8s-language" | "os" | "cloud" | "persona" | "backend";
16-
export type ChooserKey = LanguageKey | K8sLanguageKey | OSKey | CloudKey | PersonaKey | BackEndKey;
17-
export type ChooserOption = SupportedLanguage | SupportedK8sLanguage | SupportedOS | SupportedCloud | SupportedPersona | SupportedBackEnd;
15+
export type DatabaseKey = "mysql" | "postgresql" | "snowflake";
16+
export type ChooserType = "language" | "k8s-language" | "os" | "cloud" | "persona" | "backend" | "database";
17+
export type ChooserKey = LanguageKey | K8sLanguageKey | OSKey | CloudKey | PersonaKey | BackEndKey | DatabaseKey;
18+
export type ChooserOption = SupportedLanguage | SupportedK8sLanguage | SupportedOS | SupportedCloud | SupportedPersona | SupportedBackEnd | SupportedDatabase;
1819

1920
export interface SupportedLanguage {
2021
key: LanguageKey;
@@ -53,6 +54,12 @@ interface SupportedBackEnd {
5354
preview: boolean;
5455
}
5556

57+
interface SupportedDatabase {
58+
key: DatabaseKey;
59+
name: string;
60+
preview: boolean;
61+
}
62+
5663
export interface Choice {
5764
type: ChooserType;
5865
value: ChooserOption;
@@ -123,6 +130,7 @@ export class Chooser {
123130
setCloud: typeof setCloud;
124131
setPersona: typeof setPersona;
125132
setBackEnd: typeof setBackEnd;
133+
setDatabase: typeof setDatabase;
126134

127135
componentWillLoad() {
128136
// Translate the set of options provided into choices.
@@ -158,12 +166,13 @@ export class Chooser {
158166
setCloud,
159167
setPersona,
160168
setBackEnd,
169+
setDatabase,
161170
});
162171

163172
// Map currently selected values from the store, so we can use them in this component.
164173
this.storeUnsubscribe = store.mapStateToProps(this, (state: AppState) => {
165174
const {
166-
preferences: { language, k8sLanguage, os, cloud, persona, backend },
175+
preferences: { language, k8sLanguage, os, cloud, persona, backend, database },
167176
} = state;
168177

169178
// In some cases, the user's preferred (i.e., most recently selected) choice
@@ -208,6 +217,8 @@ export class Chooser {
208217
return preferredOrDefault(persona);
209218
case "backend":
210219
return preferredOrDefault(backend);
220+
case "database":
221+
return preferredOrDefault(database);
211222
default:
212223
return {};
213224
}
@@ -284,6 +295,9 @@ export class Chooser {
284295
case "backend":
285296
options = this.supportedBackEnds;
286297
break;
298+
case "database":
299+
options = this.supportedDatabases;
300+
break;
287301
}
288302

289303
this.currentOptions = options.filter(opt => keys.includes(opt.key));
@@ -322,6 +336,7 @@ export class Chooser {
322336
private setChoice(type: ChooserType, choice: ChooserOption) {
323337
const key = choice.key;
324338
this.selection = key;
339+
console.log(`Setting choice: type=${type}, key=${key}`);
325340

326341
if (this.mode !== "local") {
327342
switch (type) {
@@ -343,6 +358,9 @@ export class Chooser {
343358
case "backend":
344359
this.setBackEnd(key as BackEndKey);
345360
break;
361+
case "database":
362+
this.setDatabase(key as DatabaseKey);
363+
break;
346364
}
347365
}
348366
}
@@ -529,4 +547,23 @@ export class Chooser {
529547
preview: false,
530548
},
531549
];
550+
551+
// The list of supported databases.
552+
private supportedDatabases: SupportedDatabase[] = [
553+
{
554+
key: "mysql",
555+
name: "MySQL",
556+
preview: false,
557+
},
558+
{
559+
key: "postgresql",
560+
name: "PostgreSQL",
561+
preview: false,
562+
},
563+
{
564+
key: "snowflake",
565+
name: "Snowflake",
566+
preview: false,
567+
},
568+
];
532569
}

theme/stencil/src/store/actions/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SetLanguage, SetK8sLanguage, SetOS, SetCloud, SetPersona, SetBackEnd } from "./preferences";
1+
import { SetLanguage, SetK8sLanguage, SetOS, SetCloud, SetPersona, SetBackEnd, SetDatabase } from "./preferences";
22
import { DismissBanner } from "./banners";
33
import { GetUser } from "./user";
44

@@ -11,6 +11,7 @@ export enum TypeKeys {
1111
SET_CLOUD = "SET_CLOUD",
1212
SET_PERSONA = "SET_PERSONA",
1313
SET_BACKEND = "SET_BACKEND",
14+
SET_DATABASE = "SET_DATABASE",
1415

1516
// Banner-related action types.
1617
DISMISS_BANNER = "DISMISS_BANNER",
@@ -19,6 +20,6 @@ export enum TypeKeys {
1920
GET_USER_INFO = "GET_USER_INFO",
2021
}
2122

22-
export type PreferencesAction = SetLanguage | SetK8sLanguage | SetOS | SetCloud | SetPersona | SetBackEnd;
23+
export type PreferencesAction = SetLanguage | SetK8sLanguage | SetOS | SetCloud | SetPersona | SetBackEnd | SetDatabase;
2324
export type BannersAction = DismissBanner;
2425
export type UserAction = GetUser;

theme/stencil/src/store/actions/preferences.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TypeKeys } from "./index";
2-
import { LanguageKey, K8sLanguageKey, OSKey, CloudKey, PersonaKey, BackEndKey } from "../../components/chooser/chooser";
2+
import { LanguageKey, K8sLanguageKey, OSKey, CloudKey, PersonaKey, BackEndKey, DatabaseKey } from "../../components/chooser/chooser";
33

44
export interface SetLanguage {
55
type: TypeKeys.SET_LANGUAGE;
@@ -31,6 +31,11 @@ export interface SetBackEnd {
3131
key: BackEndKey;
3232
}
3333

34+
export interface SetDatabase {
35+
type: TypeKeys.SET_DATABASE;
36+
key: DatabaseKey;
37+
}
38+
3439
const dispatchAction = <T>(action: T) => (dispatch, _getState) => dispatch(action);
3540

3641
// Set the currently selected language.
@@ -68,3 +73,9 @@ export const setBackEnd = (key: BackEndKey) => dispatchAction<SetBackEnd>({
6873
key,
6974
type: TypeKeys.SET_BACKEND,
7075
});
76+
77+
// Set the currently selected database type.
78+
export const setDatabase = (key: DatabaseKey) => dispatchAction<SetDatabase>({
79+
key,
80+
type: TypeKeys.SET_DATABASE,
81+
});

theme/stencil/src/store/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ export function normalizeState(persistedState: any): Partial<AppState> {
8383
cloud: persistedState.preferences.cloud || "aws",
8484
k8sLanguage: persistedState.preferences.k8sLanguage || "typescript",
8585
persona: persistedState.preferences.persona || "developer",
86-
backend: persistedState.backend || "service",
86+
backend: persistedState.preferences.backend || "service",
87+
database: persistedState.preferences.database || "mysql",
8788
};
8889
}
8990
} catch (e) {

theme/stencil/src/store/reducers/preferences.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const getInitialState = (): PreferencesState => {
1111
os: guessOS(),
1212
cloud: "aws",
1313
backend: "service",
14+
database: "mysql",
1415
};
1516
};
1617

@@ -45,6 +46,8 @@ export const preferences = (currentState = getInitialState(), action: Preference
4546
return { ...currentState, persona: action.key };
4647
case TypeKeys.SET_BACKEND:
4748
return { ...currentState, backend: action.key };
49+
case TypeKeys.SET_DATABASE:
50+
return { ...currentState, database: action.key };
4851
default:
4952
return currentState;
5053
}

theme/stencil/src/store/state.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LanguageKey, K8sLanguageKey, OSKey, CloudKey, PersonaKey, BackEndKey } from "../components/chooser/chooser";
1+
import { LanguageKey, K8sLanguageKey, OSKey, CloudKey, PersonaKey, BackEndKey, DatabaseKey } from "../components/chooser/chooser";
22

33
// PreferencesState tracks settings like preferred language, cloud and operating system.
44
// Values tracked in this state slice persist between pages and reloads.
@@ -9,6 +9,7 @@ export interface PreferencesState {
99
cloud: CloudKey;
1010
persona: PersonaKey;
1111
backend: BackEndKey;
12+
database: DatabaseKey;
1213
}
1314

1415
export interface Banner {

0 commit comments

Comments
 (0)