Skip to content

Commit b749d76

Browse files
committed
filter out child resources
1 parent 095d644 commit b749d76

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/components/app-sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import {
99
SidebarRail,
1010
} from "@/components/ui/sidebar";
1111
import { useAppDispatch, useAppSelector } from "@/hooks/store";
12-
import { selectHeaders, selectResources, setHeaders } from "@/state/store";
12+
import { selectHeaders, selectParentResources, setHeaders } from "@/state/store";
1313
import { Label } from "./ui/label";
1414
import { ResourceTypeList } from "@/app/sidebar/resource_type_list";
1515

1616
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
17-
const resources = useAppSelector(selectResources);
17+
const resources = useAppSelector(selectParentResources);
1818

1919
return (
2020
<Sidebar {...props}>

src/state/openapi.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ class ResourceSchema {
4949
}
5050
return properties;
5151
}
52+
53+
parents(): string[] {
54+
const resource = this.schema["x-aep-resource"]
55+
if ('parents' in resource) {
56+
return resource.parents;
57+
} else {
58+
return [];
59+
}
60+
}
5261
}
5362

5463
class PropertySchema {
@@ -90,6 +99,10 @@ class OpenAPI {
9099
return resources;
91100
}
92101

102+
parentResources(): ResourceSchema[] {
103+
return this.resources().filter((resource) => resource.parents().length == 0);
104+
}
105+
93106
resourceForName(plural: string): ResourceSchema {
94107
const resources = this.resources();
95108
for (const resource of resources) {

src/state/store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ export const selectResources = (state: RootState) => {
3535
}
3636
}
3737

38+
export const selectParentResources = (state: RootState) => {
39+
if (state.schema.value != null) {
40+
return state.schema.value.parentResources();
41+
} else {
42+
return [];
43+
}
44+
}
45+
3846
export const schemaState = (state: RootState) => state.schema.state
3947

4048
// Headers reducers + selectors.

0 commit comments

Comments
 (0)