Skip to content

Commit 4d8fc78

Browse files
authored
Merge pull request #236 from docker/cm/tidyup
Tidyup extension for 5/5
2 parents e32b40d + 5a0b178 commit 4d8fc78

File tree

13 files changed

+489
-401
lines changed

13 files changed

+489
-401
lines changed

src/extension/ui/src/FileUtils.ts

Lines changed: 0 additions & 69 deletions
This file was deleted.

src/extension/ui/src/Registry.ts

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,91 @@
11
import { v1 } from "@docker/extension-api-client-types";
22
import { parse, stringify } from "yaml";
33
import { REGISTRY_YAML } from "./Constants";
4-
import { readFileInPromptsVolume, writeToPromptsVolume } from "./FileUtils";
4+
import { readFileInPromptsVolume, writeToPromptsVolume } from "./utils/Files";
55
import { mergeDeep } from "./MergeDeep";
66
import { ParsedParameters } from "./types/config";
77

88
export const getRegistry = async (client: v1.DockerDesktopClient) => {
9-
const parseRegistry = async () => {
10-
const registry = await readFileInPromptsVolume(client, REGISTRY_YAML)
11-
if (registry) {
12-
const value = parse(registry)['registry'] as { [key: string]: { ref: string, config: any } }
13-
if (!value) {
14-
client.desktopUI.toast.error('Failed to parse registry.yaml: ' + registry)
15-
}
16-
return value;
17-
}
18-
return {};
9+
const parseRegistry = async () => {
10+
const registry = await readFileInPromptsVolume(client, REGISTRY_YAML);
11+
if (registry) {
12+
const value = parse(registry)["registry"] as {
13+
[key: string]: { ref: string; config: any };
14+
};
15+
if (!value) {
16+
client.desktopUI.toast.error(
17+
"Failed to parse registry.yaml: " + registry
18+
);
19+
}
20+
return value;
1921
}
20-
const writeRegistryIfNotExists = async () => {
21-
const registry = await readFileInPromptsVolume(client, REGISTRY_YAML)
22-
if (!registry) {
23-
await writeToPromptsVolume(client, REGISTRY_YAML, 'registry: {}')
24-
}
22+
return {};
23+
};
24+
const writeRegistryIfNotExists = async () => {
25+
const registry = await readFileInPromptsVolume(client, REGISTRY_YAML);
26+
if (!registry) {
27+
await writeToPromptsVolume(client, REGISTRY_YAML, "registry: {}");
2528
}
26-
try {
27-
await writeRegistryIfNotExists()
28-
return await parseRegistry()
29-
}
30-
catch (error) {
31-
client.desktopUI.toast.error('Failed to get prompt registry: ' + error)
32-
return {};
33-
}
34-
}
29+
};
30+
try {
31+
await writeRegistryIfNotExists();
32+
return await parseRegistry();
33+
} catch (error) {
34+
client.desktopUI.toast.error("Failed to get prompt registry: " + error);
35+
return {};
36+
}
37+
};
3538

3639
export const getStoredConfig = async (client: v1.DockerDesktopClient) => {
37-
const parseConfig = async () => {
38-
const config = await readFileInPromptsVolume(client, 'config.yaml')
39-
if (config) {
40-
return parse(config) as Promise<{ [key: string]: { [key: string]: ParsedParameters } }>;
41-
}
42-
return {};
43-
}
44-
const writeConfigIfNotExists = async () => {
45-
const config = await readFileInPromptsVolume(client, 'config.yaml')
46-
if (!config) {
47-
await writeToPromptsVolume(client, 'config.yaml', '{}')
48-
}
49-
}
50-
try {
51-
await writeConfigIfNotExists()
52-
return await parseConfig()
40+
const parseConfig = async () => {
41+
const config = await readFileInPromptsVolume(client, "config.yaml");
42+
if (config) {
43+
return parse(config) as Promise<{
44+
[key: string]: { [key: string]: ParsedParameters };
45+
}>;
5346
}
54-
catch (error) {
55-
client.desktopUI.toast.error('Failed to get stored configs: ' + error)
56-
return {};
47+
return {};
48+
};
49+
const writeConfigIfNotExists = async () => {
50+
const config = await readFileInPromptsVolume(client, "config.yaml");
51+
if (!config) {
52+
await writeToPromptsVolume(client, "config.yaml", "{}");
5753
}
58-
}
54+
};
55+
try {
56+
await writeConfigIfNotExists();
57+
return await parseConfig();
58+
} catch (error) {
59+
client.desktopUI.toast.error("Failed to get stored configs: " + error);
60+
return {};
61+
}
62+
};
5963

6064
// if registry.yaml has a config, it must be the same as what you have stored
6165
// if that’s not true and the registry.yaml value is valid then you should sync with it
6266
// if it’s not true and the registry.yaml is invalid then the catalog item needs user assistance because the catalog has probably been updated with a breaking change
6367

6468
// Replace conflicting registry values with config values
65-
export const syncRegistryWithConfig = async (client: v1.DockerDesktopClient, registry: { [key: string]: { ref: string, config: any } }, config: { [key: string]: { [key: string]: ParsedParameters } }) => {
66-
if (Object.keys(config).length === 0) {
67-
return;
68-
}
69-
if (Object.keys(registry).length === 0) {
70-
return;
71-
}
72-
const oldRegString = JSON.stringify(registry)
73-
for (const [itemName, itemConfig] of Object.entries(config)) {
74-
if (registry[itemName]) {
75-
registry[itemName].config = { [itemName]: itemConfig }
76-
}
77-
}
78-
const newRegString = JSON.stringify(registry)
79-
if (oldRegString !== newRegString) {
80-
await writeToPromptsVolume(client, REGISTRY_YAML, stringify({ registry }))
69+
export const syncRegistryWithConfig = async (
70+
client: v1.DockerDesktopClient,
71+
registry: { [key: string]: { ref: string; config: any } },
72+
config: { [key: string]: { [key: string]: ParsedParameters } }
73+
) => {
74+
if (Object.keys(config).length === 0) {
75+
return;
76+
}
77+
if (Object.keys(registry).length === 0) {
78+
return;
79+
}
80+
const oldRegString = JSON.stringify(registry);
81+
for (const [itemName, itemConfig] of Object.entries(config)) {
82+
if (registry[itemName]) {
83+
registry[itemName].config = { [itemName]: itemConfig };
8184
}
82-
return registry
83-
}
85+
}
86+
const newRegString = JSON.stringify(registry);
87+
if (oldRegString !== newRegString) {
88+
await writeToPromptsVolume(client, REGISTRY_YAML, stringify({ registry }));
89+
}
90+
return registry;
91+
};

src/extension/ui/src/components/CatalogGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const CatalogGrid: React.FC<CatalogGridProps> = ({ appProps }) => {
122122
>
123123
<Tab label="MCP Servers" />
124124
<Tab label="MCP Clients" />
125-
<Tab label="OAuth Providers" />
125+
{/* <Tab label="OAuth Providers" /> */}
126126
</Tabs>
127127
{tab === 0 && (
128128
<Stack

0 commit comments

Comments
 (0)