Skip to content

Commit e32b40d

Browse files
authored
Merge pull request #237 from docker/cm/better-type
OAuthProvider -> OAuthClient
2 parents 5b57be9 + f812c4d commit e32b40d

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

src/extension/ui/src/components/tabs/OAuthProviders.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v1 } from "@docker/extension-api-client-types";
22
import useOAuthProvider from "../../queries/useOAuthProvider";
33
import { Alert, Box, Button, Card, CardContent, CardHeader, Chip, CircularProgress, Collapse, Link, Stack, Typography } from "@mui/material";
44
import { useState } from "react";
5-
import { OAuthProvider } from "../../types/oauth/Provider";
5+
import { OAuthClient } from "../../types/oauth/Client";
66

77
const OAuthProviders = ({ client }: { client: v1.DockerDesktopClient }) => {
88
const { data, isLoading, error, authorizeOAuthProvider, unauthorizeOAuthProvider } = useOAuthProvider(client);
@@ -25,7 +25,7 @@ const OAuthProviders = ({ client }: { client: v1.DockerDesktopClient }) => {
2525
}
2626
if (data.length > 0) {
2727
return <>
28-
{data.map((provider: OAuthProvider) => {
28+
{data.map((provider: OAuthClient) => {
2929
return <Card>
3030
<CardHeader title={provider.app} action={provider.authorized ? <Button variant="contained" color="error" onClick={() => {
3131
unauthorizeOAuthProvider.mutateAsync(provider.app);

src/extension/ui/src/components/tile/ConfigEditor.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const ConfigEditor = ({
2929
catalogItem: CatalogItemRichened;
3030
client: v1.DockerDesktopClient;
3131
}) => {
32+
33+
if (!catalogItem.config?.[0]) {
34+
return null;
35+
}
36+
3237
const configSchema = catalogItem.configSchema;
3338

3439
const {
@@ -160,6 +165,9 @@ const ConfigEditor = ({
160165
};
161166

162167
function sanitizeConfig(config: { [key: string]: any; }, catalogItem: CatalogItemRichened) {
168+
if (!catalogItem.config?.[0]) {
169+
return config;
170+
}
163171
const newConfig = buildObjectFromFlattenedObject(config);
164172

165173
// Remove all attributes which are optional and which have the defautl value

src/extension/ui/src/queries/useCatalog.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function useCatalog(client: v1.DockerDesktopClient) {
4646
...item,
4747
secrets: secretsWithAssignment,
4848
configValue: itemConfigValue,
49-
configSchema: item.config,
49+
configSchema: item.config || {},
5050
configTemplate,
5151
missingConfig: unConfigured,
5252
missingSecrets: missingASecret,
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
import { ReactNode } from "react";
2-
import { Secret } from "../secrets";
1+
import { JsonSchema } from "json-schema-library";
32

43
/**
54
* Interface for a catalog item
65
*/
76
export interface CatalogItem {
8-
description?: string;
9-
title?: string;
10-
source?: string;
11-
icon?: string;
12-
secrets?: { name: string }[];
13-
ref: string;
14-
prompts: number;
15-
resources: object[];
16-
tools: { name: string }[];
17-
config?: any; // Configuration type
7+
description?: string;
8+
title?: string;
9+
source?: string;
10+
icon?: string;
11+
secrets?: { name: string }[];
12+
ref: string;
13+
prompts: number;
14+
resources: object[];
15+
tools: { name: string }[];
16+
config?: JsonSchema;
1817
}
1918

19+
// Base Catalog
20+
export interface CatalogYaml {
21+
[itemName: string]: CatalogItem;
22+
}
23+
24+
// End result when mapping out the catalog keys into a list
2025
export interface CatalogItemWithName extends CatalogItem {
21-
name: string;
26+
name: string;
2227
}
2328

24-
/**
25-
* Interface for a catalog item with a name
26-
*/
29+
// Catalog item enrichened with all of the runtime information
2730
export interface CatalogItemRichened extends CatalogItem {
28-
name: string;
29-
readme?: string;
30-
secrets: { name: string, assigned: boolean }[];
31-
configValue: { [key: string]: any };
32-
configSchema: any;
33-
registered: boolean;
34-
canRegister: boolean;
35-
missingConfig: boolean;
36-
missingSecrets: boolean;
37-
configTemplate: { [key: string]: any };
31+
name: string;
32+
readme?: string;
33+
secrets: { name: string; assigned: boolean }[];
34+
configValue: { [key: string]: any };
35+
configSchema: JsonSchema;
36+
config?: JsonSchema;
37+
registered: boolean;
38+
canRegister: boolean;
39+
missingConfig: boolean;
40+
missingSecrets: boolean;
41+
configTemplate: { [key: string]: any };
3842
}

src/extension/ui/src/types/oauth/Provider.ts renamed to src/extension/ui/src/types/oauth/Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface OAuthProvider {
1+
export interface OAuthClient {
22
app: string;
33
authorized: boolean;
44
provider: string;

src/extension/ui/src/utils/OAuth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { v1 } from "@docker/extension-api-client-types";
2-
import { OAuthProvider } from "../types/oauth/Provider";
2+
import { OAuthClient } from "../types/oauth/Client";
3+
34
export const listOAuthApps = async (client: v1.DockerDesktopClient) => {
45
const output = await client.extension.host?.cli.exec("host-binary", [
56
"list-oauth-apps",
67
]);
7-
return JSON.parse(output?.stdout || "[]") as OAuthProvider[];
8+
return JSON.parse(output?.stdout || "[]") as OAuthClient[];
89
};
910

1011
export const authorizeOAuthApp = async (

0 commit comments

Comments
 (0)