Skip to content

Commit 6a3ead1

Browse files
authored
Merge branch 'master' into enableSOC2Check
2 parents 92d9ee8 + e61a551 commit 6a3ead1

File tree

12 files changed

+336
-81
lines changed

12 files changed

+336
-81
lines changed

dashboard/package-lock.json

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

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"@babel/preset-typescript": "^7.15.0",
103103
"@ianvs/prettier-plugin-sort-imports": "^4.1.1",
104104
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
105-
"@porter-dev/api-contracts": "^0.2.71",
105+
"@porter-dev/api-contracts": "^0.2.81",
106106
"@testing-library/jest-dom": "^4.2.4",
107107
"@testing-library/react": "^9.3.2",
108108
"@testing-library/user-event": "^7.1.2",

dashboard/src/assets/redis.svg

Lines changed: 2 additions & 0 deletions
Loading

dashboard/src/lib/addons/index.ts

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import { z } from "zod";
88
import { serviceStringValidator } from "lib/porter-apps/values";
99

1010
import { defaultPostgresAddon, postgresConfigValidator } from "./postgres";
11+
import { redisConfigValidator } from "./redis";
1112

1213
export const clientAddonValidator = z.object({
13-
expanded: z.boolean().default(true),
14+
expanded: z.boolean().default(false),
1415
canDelete: z.boolean().default(true),
1516
name: z.object({
1617
readOnly: z.boolean(),
@@ -23,20 +24,40 @@ export const clientAddonValidator = z.object({
2324
}),
2425
}),
2526
envGroups: z.array(serviceStringValidator).default([]),
26-
config: z.discriminatedUnion("type", [postgresConfigValidator]),
27+
config: z.discriminatedUnion("type", [
28+
postgresConfigValidator,
29+
redisConfigValidator,
30+
]),
2731
});
2832
export type ClientAddon = z.infer<typeof clientAddonValidator>;
2933

30-
export function defaultClientAddon(): ClientAddon {
31-
return clientAddonValidator.parse({
32-
name: { readOnly: false, value: "addon" },
33-
config: defaultPostgresAddon(),
34-
});
34+
export function defaultClientAddon(
35+
type: ClientAddon["config"]["type"]
36+
): ClientAddon {
37+
return match(type)
38+
.with("postgres", () =>
39+
clientAddonValidator.parse({
40+
expanded: true,
41+
name: { readOnly: false, value: "addon" },
42+
config: defaultPostgresAddon(),
43+
})
44+
)
45+
.with("redis", () =>
46+
clientAddonValidator.parse({
47+
expanded: true,
48+
name: { readOnly: false, value: "addon" },
49+
config: redisConfigValidator.parse({
50+
type: "redis",
51+
}),
52+
})
53+
)
54+
.exhaustive();
3555
}
3656

3757
function addonTypeEnumProto(type: ClientAddon["config"]["type"]): AddonType {
3858
return match(type)
3959
.with("postgres", () => AddonType.POSTGRES)
60+
.with("redis", () => AddonType.REDIS)
4061
.exhaustive();
4162
}
4263

@@ -50,6 +71,14 @@ export function clientAddonToProto(addon: ClientAddon): Addon {
5071
},
5172
case: "postgres" as const,
5273
}))
74+
.with({ type: "redis" }, (data) => ({
75+
value: {
76+
cpuCores: data.cpuCores.value,
77+
ramMegabytes: data.ramMegabytes.value,
78+
storageGigabytes: data.storageGigabytes.value,
79+
},
80+
case: "redis" as const,
81+
}))
5382
.exhaustive();
5483

5584
const proto = new Addon({
@@ -95,6 +124,22 @@ export function clientAddonFromProto({
95124
username: variables.POSTGRESQL_USERNAME,
96125
password: secrets.POSTGRESQL_PASSWORD,
97126
}))
127+
.with({ case: "redis" }, (data) => ({
128+
type: "redis" as const,
129+
cpuCores: {
130+
readOnly: false,
131+
value: data.value.cpuCores,
132+
},
133+
ramMegabytes: {
134+
readOnly: false,
135+
value: data.value.ramMegabytes,
136+
},
137+
storageGigabytes: {
138+
readOnly: false,
139+
value: data.value.storageGigabytes,
140+
},
141+
password: secrets.REDIS_PASSWORD,
142+
}))
98143
.exhaustive();
99144

100145
const clientAddon = clientAddonValidator.parse({

dashboard/src/lib/addons/redis.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { z } from "zod";
2+
3+
import { serviceNumberValidator } from "lib/porter-apps/values";
4+
5+
export const redisConfigValidator = z.object({
6+
type: z.literal("redis"),
7+
cpuCores: serviceNumberValidator.default({
8+
value: 0.5,
9+
readOnly: false,
10+
}),
11+
ramMegabytes: serviceNumberValidator.default({
12+
value: 512,
13+
readOnly: false,
14+
}),
15+
storageGigabytes: serviceNumberValidator.default({
16+
value: 1,
17+
readOnly: false,
18+
}),
19+
password: z.string().default("redis"),
20+
});
21+
export type RedisConfig = z.infer<typeof redisConfigValidator>;
22+
23+
export function defaultRedisAddon(): RedisConfig {
24+
return redisConfigValidator.parse({
25+
type: "redis",
26+
});
27+
}

dashboard/src/main/home/app-dashboard/apps/Addon.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { type ClientAddon } from "lib/addons";
1212
import { useDeploymentTarget } from "shared/DeploymentTargetContext";
1313
import copy from "assets/copy-left.svg";
1414
import postgresql from "assets/postgresql.svg";
15+
import redis from "assets/redis.svg";
1516

1617
import { Block, Row } from "./AppGrid";
1718

@@ -27,15 +28,26 @@ export const Addon: React.FC<AddonProps> = ({ addon, view }) => {
2728
if (!currentDeploymentTarget) return "";
2829
if (!addon.name.value) return "";
2930

30-
return `${addon.name.value}-postgres.${currentDeploymentTarget.namespace}.svc.cluster.local:5432`;
31+
const port = match(addon.config.type)
32+
.with("postgres", () => 5432)
33+
.with("redis", () => 6379)
34+
.exhaustive();
35+
36+
return `${addon.name.value}-${addon.config.type}.${currentDeploymentTarget.namespace}.svc.cluster.local:${port}`;
3137
}, [currentDeploymentTarget, addon.name.value]);
3238

39+
const renderIcon = (type: ClientAddon["config"]["type"]): JSX.Element =>
40+
match(type)
41+
.with("postgres", () => <Icon height="16px" src={postgresql} />)
42+
.with("redis", () => <Icon height="16px" src={redis} />)
43+
.exhaustive();
44+
3345
return match(view)
3446
.with("grid", () => (
3547
<Block locked>
3648
<Container row>
3749
<Spacer inline width="1px" />
38-
<Icon height="16px" src={postgresql} />
50+
{renderIcon(addon.config.type)}
3951
<Spacer inline width="12px" />
4052
<Text size={14}>{addon.name.value}</Text>
4153
<Spacer inline x={2} />
@@ -60,7 +72,7 @@ export const Addon: React.FC<AddonProps> = ({ addon, view }) => {
6072
<Row locked>
6173
<Container row>
6274
<Spacer inline width="1px" />
63-
<Icon height="16px" src={postgresql} />
75+
{renderIcon(addon.config.type)}
6476
<Spacer inline width="12px" />
6577
<Text size={14}>{addon.name.value}</Text>
6678
<Spacer inline x={1} />

dashboard/src/main/home/cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,22 @@ export const PreviewAppDataContainer: React.FC<Props> = ({
189189
setValidatedAppProto(proto);
190190

191191
const addons = data.addons.map((addon) => {
192-
const variables = match(addon.config.type)
193-
.with("postgres", () => ({
194-
POSTGRESQL_USERNAME: addon.config.username,
192+
const variables = match(addon.config)
193+
.with({ type: "postgres" }, (conf) => ({
194+
POSTGRESQL_USERNAME: conf.username,
195195
}))
196-
.otherwise(() => ({}));
197-
const secrets = match(addon.config.type)
198-
.with("postgres", () => ({
199-
POSTGRESQL_PASSWORD: addon.config.password,
196+
.with({ type: "redis" }, (conf) => ({
197+
REDIS_PASSWORD: conf.password,
200198
}))
201-
.otherwise(() => ({}));
199+
.exhaustive();
200+
const secrets = match(addon.config)
201+
.with({ type: "postgres" }, (conf) => ({
202+
POSTGRESQL_PASSWORD: conf.password,
203+
}))
204+
.with({ type: "redis" }, (conf) => ({
205+
REDIS_PASSWORD: conf.password,
206+
}))
207+
.exhaustive();
202208

203209
const proto = clientAddonToProto(addon);
204210

dashboard/src/main/home/managed-addons/AddonListRow.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { type UseFieldArrayUpdate } from "react-hook-form";
44
import styled from "styled-components";
55
import { match } from "ts-pattern";
66

7+
import Spacer from "components/porter/Spacer";
78
import { type ClientAddon } from "lib/addons";
89

910
import postgresql from "assets/postgresql.svg";
11+
import redis from "assets/redis.svg";
1012

1113
import { type AppTemplateFormData } from "../cluster-dashboard/preview-environments/v2/setup-app/PreviewAppDataContainer";
1214
import { PostgresTabs } from "./tabs/PostgresTabs";
15+
import { RedisTabs } from "./tabs/RedisTabs";
1316

1417
type AddonRowProps = {
1518
index: number;
@@ -24,7 +27,11 @@ export const AddonListRow: React.FC<AddonRowProps> = ({
2427
update,
2528
remove,
2629
}) => {
27-
const renderIcon = (): JSX.Element => <Icon src={postgresql} />;
30+
const renderIcon = (type: ClientAddon["config"]["type"]): JSX.Element =>
31+
match(type)
32+
.with("postgres", () => <Icon src={postgresql} />)
33+
.with("redis", () => <Icon src={redis} />)
34+
.exhaustive();
2835

2936
return (
3037
<>
@@ -42,7 +49,7 @@ export const AddonListRow: React.FC<AddonRowProps> = ({
4249
<ActionButton>
4350
<span className="material-icons dropdown">arrow_drop_down</span>
4451
</ActionButton>
45-
{renderIcon()}
52+
{renderIcon(addon.config.type)}
4653
{addon.name.value.trim().length > 0 ? addon.name.value : "New Addon"}
4754
</AddonTitle>
4855

@@ -84,15 +91,19 @@ export const AddonListRow: React.FC<AddonRowProps> = ({
8491
border: "1px solid #494b4f",
8592
}}
8693
>
87-
{match(addon.config.type)
88-
.with("postgres", () => (
89-
<PostgresTabs index={index} addon={addon} />
94+
{match(addon)
95+
.with({ config: { type: "postgres" } }, (ao) => (
96+
<PostgresTabs index={index} addon={ao} />
97+
))
98+
.with({ config: { type: "redis" } }, (ao) => (
99+
<RedisTabs index={index} addon={ao} />
90100
))
91101
.exhaustive()}
92102
</div>
93103
</StyledSourceBox>
94104
)}
95105
</AnimatePresence>
106+
<Spacer y={0.5} />
96107
</>
97108
);
98109
};

dashboard/src/main/home/managed-addons/AddonsList.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { type AppTemplateFormData } from "main/home/cluster-dashboard/preview-en
2121
import { defaultClientAddon } from "lib/addons";
2222

2323
import postgresql from "assets/postgresql.svg";
24+
import redis from "assets/redis.svg";
2425

2526
import { AddonListRow } from "./AddonListRow";
2627

@@ -32,7 +33,7 @@ const addAddonFormValidator = z.object({
3233
.regex(/^[a-z0-9-]+$/, {
3334
message: 'Lowercase letters, numbers, and " - " only.',
3435
}),
35-
type: z.enum(["postgres"]),
36+
type: z.enum(["postgres", "redis"]),
3637
});
3738
type AddAddonFormValues = z.infer<typeof addAddonFormValidator>;
3839

@@ -80,7 +81,7 @@ export const AddonsList: React.FC = () => {
8081
}, [fields]);
8182

8283
const onSubmit = handleSubmit((data) => {
83-
const baseAddon = defaultClientAddon();
84+
const baseAddon = defaultClientAddon(data.type);
8485
append({
8586
...baseAddon,
8687
name: {
@@ -106,19 +107,15 @@ export const AddonsList: React.FC = () => {
106107
/>
107108
))}
108109
</AddonsContainer>
109-
{fields.length === 0 && (
110-
<>
111-
<AddAddonButton
112-
onClick={() => {
113-
setShowAddAddonModal(true);
114-
}}
115-
>
116-
<I className="material-icons add-icon">add</I>
117-
Include add-on in preview environments
118-
</AddAddonButton>
119-
<Spacer y={0.5} />
120-
</>
121-
)}
110+
<AddAddonButton
111+
onClick={() => {
112+
setShowAddAddonModal(true);
113+
}}
114+
>
115+
<I className="material-icons add-icon">add</I>
116+
Include add-on in preview environments
117+
</AddAddonButton>
118+
<Spacer y={0.5} />
122119
{showAddAddonModal && (
123120
<Modal
124121
closeModal={() => {
@@ -134,6 +131,7 @@ export const AddonsList: React.FC = () => {
134131
<AddonIcon>
135132
{match(addonType)
136133
.with("postgres", () => <img src={postgresql} />)
134+
.with("redis", () => <img src={redis} />)
137135
.exhaustive()}
138136
</AddonIcon>
139137
<Controller
@@ -146,7 +144,10 @@ export const AddonsList: React.FC = () => {
146144
setValue={(value: string) => {
147145
onChange(value);
148146
}}
149-
options={[{ label: "Postgres", value: "postgres" }]}
147+
options={[
148+
{ label: "Postgres", value: "postgres" },
149+
{ label: "Redis", value: "redis" },
150+
]}
150151
/>
151152
)}
152153
/>

0 commit comments

Comments
 (0)