Skip to content

Commit 4760d6e

Browse files
refactor(explore): rename filter→view, remove dead StandardModel code
- Remove unused StandardModel/loadStandardModel and resources/focuses/ - Rename src/views/localstack → src/views/explore to match the view name - Migrate internal "filter" terminology to "view" (cloud-profile views): SavedView/ViewScope, getProfileViews, saveProfileView, removeProfileView, ProfileViewTreeItem, resolveRegionViewFocus, command IDs localstack.{add,edit,remove}ProfileView, contextValue localstackProfileView, and config key cloudProfiles.views Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 56db232 commit 4760d6e

14 files changed

Lines changed: 198 additions & 329 deletions

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"type": "string"
6666
}
6767
},
68-
"localstack.cloudProfiles.filters": {
68+
"localstack.cloudProfiles.views": {
6969
"type": "object",
7070
"default": {},
7171
"markdownDescription": "User-defined resource views per AWS profile. Managed via the view's \"Add View...\" / \"Edit View...\" / \"Remove View\" actions.",
@@ -229,19 +229,19 @@
229229
"icon": "$(settings-gear)"
230230
},
231231
{
232-
"command": "localstack.addFilter",
232+
"command": "localstack.addProfileView",
233233
"title": "Add View...",
234234
"category": "LocalStack",
235235
"icon": "$(add)"
236236
},
237237
{
238-
"command": "localstack.editFilter",
238+
"command": "localstack.editProfileView",
239239
"title": "Edit View...",
240240
"category": "LocalStack",
241241
"icon": "$(settings-gear)"
242242
},
243243
{
244-
"command": "localstack.removeFilter",
244+
"command": "localstack.removeProfileView",
245245
"title": "Remove View",
246246
"category": "LocalStack",
247247
"icon": "$(trash)"
@@ -310,12 +310,12 @@
310310
"group": "inline"
311311
},
312312
{
313-
"command": "localstack.addFilter",
313+
"command": "localstack.addProfileView",
314314
"when": "view == localstack.instances && (viewItem == localstackDefaultRegion || viewItem == localstackUserRegion)",
315315
"group": "1_region@1"
316316
},
317317
{
318-
"command": "localstack.addFilter",
318+
"command": "localstack.addProfileView",
319319
"when": "view == localstack.instances && (viewItem == localstackDefaultRegion || viewItem == localstackUserRegion)",
320320
"group": "inline@1"
321321
},
@@ -330,23 +330,23 @@
330330
"group": "inline@2"
331331
},
332332
{
333-
"command": "localstack.editFilter",
334-
"when": "view == localstack.instances && viewItem == localstackFilter",
333+
"command": "localstack.editProfileView",
334+
"when": "view == localstack.instances && viewItem == localstackProfileView",
335335
"group": "1_modify@1"
336336
},
337337
{
338-
"command": "localstack.editFilter",
339-
"when": "view == localstack.instances && viewItem == localstackFilter",
338+
"command": "localstack.editProfileView",
339+
"when": "view == localstack.instances && viewItem == localstackProfileView",
340340
"group": "inline@1"
341341
},
342342
{
343-
"command": "localstack.removeFilter",
344-
"when": "view == localstack.instances && viewItem == localstackFilter",
343+
"command": "localstack.removeProfileView",
344+
"when": "view == localstack.instances && viewItem == localstackProfileView",
345345
"group": "1_modify@2"
346346
},
347347
{
348-
"command": "localstack.removeFilter",
349-
"when": "view == localstack.instances && viewItem == localstackFilter",
348+
"command": "localstack.removeProfileView",
349+
"when": "view == localstack.instances && viewItem == localstackProfileView",
350350
"group": "inline@2"
351351
},
352352
{
@@ -393,15 +393,15 @@
393393
"when": "false"
394394
},
395395
{
396-
"command": "localstack.addFilter",
396+
"command": "localstack.addProfileView",
397397
"when": "false"
398398
},
399399
{
400-
"command": "localstack.editFilter",
400+
"command": "localstack.editProfileView",
401401
"when": "false"
402402
},
403403
{
404-
"command": "localstack.removeFilter",
404+
"command": "localstack.removeProfileView",
405405
"when": "false"
406406
},
407407
{

resources/focuses/everything-in-all-profiles.focus.json

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

resources/focuses/everything-in-default-profile.focus.json

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

resources/focuses/everything-in-default-region.focus.json

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

src/models/focus.ts

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44
* and resources should be shown in the UI. The model is platform-neutral: AWS
55
* (and future emulators) populate it via their own code under src/platforms/.
66
*/
7-
import * as fs from "node:fs";
8-
import path from "node:path";
9-
107
import * as z from "zod";
118

12-
import { InternalError } from "../utils/errors.ts";
13-
import { memoize } from "../utils/memoize.ts";
14-
159
const ResourceTypeFocus = z.object({
1610
id: z.string(),
1711
get arns() {
@@ -53,72 +47,6 @@ export type RegionFocus = z.infer<typeof RegionFocus>;
5347
export type ServiceFocus = z.infer<typeof ServiceFocus>;
5448
export type ResourceTypeFocus = z.infer<typeof ResourceTypeFocus>;
5549

56-
/**
57-
* Standard focuses that are always available by default,
58-
* and can never be modified.
59-
*/
60-
type StandardModelType = {
61-
key: string;
62-
name: string;
63-
};
64-
export const StandardModel = {
65-
EVERYTHING_IN_DEFAULT_REGION: {
66-
key: "everything-in-default-region",
67-
name: "All Services in Default Region",
68-
} satisfies StandardModelType,
69-
EVERYTHING_IN_DEFAULT_PROFILE: {
70-
key: "everything-in-default-profile",
71-
name: "All Regions in Default Profile",
72-
} satisfies StandardModelType,
73-
EVERYTHING_IN_ALL_PROFILES: {
74-
key: "everything-in-all-profiles",
75-
name: "Everything in all Profiles",
76-
} satisfies StandardModelType,
77-
78-
get all(): StandardModelType[] {
79-
return [
80-
StandardModel.EVERYTHING_IN_DEFAULT_REGION,
81-
StandardModel.EVERYTHING_IN_DEFAULT_PROFILE,
82-
StandardModel.EVERYTHING_IN_ALL_PROFILES,
83-
];
84-
},
85-
};
86-
87-
/**
88-
* Load one of the standard (pre-defined, unmodifiable) focuses. The
89-
* result is memoized since the data will not change.
90-
*/
91-
export const loadStandardModel = memoize(
92-
(model: StandardModelType, extensionPath: string = "./") => {
93-
const jsonString: string = fs.readFileSync(
94-
path.resolve(
95-
extensionPath,
96-
"resources",
97-
"focuses",
98-
`${model.key}.focus.json`,
99-
),
100-
"utf-8",
101-
);
102-
103-
let json: unknown;
104-
try {
105-
json = JSON.parse(jsonString);
106-
} catch (error) {
107-
throw new InternalError(
108-
`Loading standard Focus '${model.key}': ${String(error)}`,
109-
);
110-
}
111-
112-
const result = Focus.safeParse(json);
113-
if (!result.success) {
114-
throw new InternalError(
115-
`Loading standard Focus '${model.key}': ${z.prettifyError(result.error)}`,
116-
);
117-
}
118-
return result.data;
119-
},
120-
);
121-
12250
/**
12351
* Build a wildcard focus that shows everything in a single profile/region.
12452
* The service wildcard (`*`) is expanded dynamically by the Resources view.

src/plugins/resource-browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { commands, window, workspace } from "vscode";
22

33
import { ProviderFactory } from "../platforms/aws/services/providerFactory.ts";
44
import { createPlugin } from "../plugins.ts";
5-
import { registerLocalStackCommands } from "../views/localstack/commands.ts";
6-
import { LocalStackViewProvider } from "../views/localstack/viewProvider.ts";
5+
import { registerLocalStackCommands } from "../views/explore/commands.ts";
6+
import { LocalStackViewProvider } from "../views/explore/viewProvider.ts";
77
import { ResourceDetailsViewProvider } from "../views/resource-details/viewProvider.ts";
88
import { ResourceArnTreeItem } from "../views/resources/treeItems.ts";
99
import { ResourceViewProvider } from "../views/resources/viewProvider.ts";

src/test/resources/instanceViewFocus.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from "node:assert";
22

33
import type { Focus } from "../../models/focus.ts";
4-
import { intersectMetamodelWithPairs } from "../../views/localstack/viewProvider.ts";
4+
import { intersectMetamodelWithPairs } from "../../views/explore/viewProvider.ts";
55

66
/**
77
* An instance view's focus is the live metamodel focus narrowed to the view's

src/test/resources/regionFilterFocus.test.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import assert from "node:assert";
2+
3+
import type { SavedView } from "../../views/explore/settings.ts";
4+
import { resolveRegionViewFocus } from "../../views/explore/viewProvider.ts";
5+
6+
/**
7+
* The region (saved) view focus selector resolves its definition live
8+
* from the current view list, so editing the active view is reflected on
9+
* refresh and removing it yields no focus (clearing the Resources view).
10+
*/
11+
suite("resolveRegionViewFocus", () => {
12+
const profile = "default";
13+
const region = "us-east-1";
14+
15+
function view(resources: SavedView["resources"]): SavedView {
16+
return { name: "My View", resources, scope: { region } };
17+
}
18+
19+
test("resolves the focus from the matching view's pairs", () => {
20+
const focus = resolveRegionViewFocus(profile, region, "My View", [
21+
view([{ service: "sqs", resourceType: "queue" }]),
22+
]);
23+
assert.ok(focus);
24+
const services = focus.profiles[0].regions[0].services;
25+
assert.deepStrictEqual(
26+
services.map((s) => s.id),
27+
["sqs"],
28+
);
29+
});
30+
31+
test("reflects an edit to the view's pairs (live resolution)", () => {
32+
/* Same name, different pairs — simulating an edit; the resolved focus
33+
* must reflect the new pairs, not a stale snapshot. */
34+
const focus = resolveRegionViewFocus(profile, region, "My View", [
35+
view([
36+
{ service: "sqs", resourceType: "queue" },
37+
{ service: "sns", resourceType: "topic" },
38+
]),
39+
]);
40+
assert.ok(focus);
41+
const serviceIds = focus.profiles[0].regions[0].services
42+
.map((s) => s.id)
43+
.sort();
44+
assert.deepStrictEqual(serviceIds, ["sns", "sqs"]);
45+
});
46+
47+
test("yields undefined when the named view is absent (removed/renamed)", () => {
48+
const focus = resolveRegionViewFocus(
49+
profile,
50+
region,
51+
"My View",
52+
[view([{ service: "sqs", resourceType: "queue" }])].filter(
53+
(v) => v.name !== "My View",
54+
),
55+
);
56+
assert.strictEqual(focus, undefined);
57+
});
58+
});

0 commit comments

Comments
 (0)