Skip to content

Commit 7cbfd92

Browse files
gmazoyerbilalabbad
andauthored
Do not include templates in individual menu items (#5916)
Co-authored-by: bilalabbad <[email protected]>
1 parent 0f90eec commit 7cbfd92

File tree

3 files changed

+9
-21
lines changed

3 files changed

+9
-21
lines changed

backend/infrahub/core/schema/schema_branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,7 @@ def generate_object_template_from_node(self, node: NodeSchema) -> TemplateSchema
18791879
label=f"Object template {node.label}",
18801880
description=f"Object template for {node.kind}",
18811881
branch=node.branch,
1882-
include_in_menu=True,
1882+
include_in_menu=False,
18831883
display_labels=["template_name__value"],
18841884
inherit_from=[InfrahubKind.LINEAGESOURCE, InfrahubKind.OBJECTTEMPLATE, InfrahubKind.NODE],
18851885
human_friendly_id=["template_name__value"],

frontend/app/src/config/constants.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export const NODE_OBJECT = "CoreNode";
88

99
export const PROFILE_KIND = "CoreProfile";
1010

11+
export const TEMPLATE_GENERIC_KIND = "CoreObjectTemplate";
12+
1113
export const TASK_TARGET = "CoreTaskTarget";
1214

1315
export const ACCOUNT_GENERIC_OBJECT = "CoreGenericAccount";

frontend/app/src/shared/components/form/generic-selector.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
import { PROFILE_KIND } from "@/config/constants";
1+
import { PROFILE_KIND, TEMPLATE_GENERIC_KIND } from "@/config/constants";
22
import { getObjectPermissionsQuery } from "@/entities/permission/queries/getObjectPermissions";
33
import { PermissionData } from "@/entities/permission/types";
44
import { getPermission } from "@/entities/permission/utils";
5-
import {
6-
genericSchemasAtom,
7-
nodeSchemasAtom,
8-
profileSchemasAtom,
9-
} from "@/entities/schema/stores/schema.atom";
5+
import { getSchema } from "@/entities/schema/domain/get-schema";
106
import { useSchema } from "@/entities/schema/ui/hooks/useSchema";
117
import useQuery from "@/shared/api/graphql/useQuery";
128
import { LoadingIndicator } from "@/shared/components/loading/loading-indicator";
@@ -21,7 +17,6 @@ import {
2117
} from "@/shared/components/ui/combobox";
2218
import Label from "@/shared/components/ui/label";
2319
import { gql } from "@apollo/client";
24-
import { useAtomValue } from "jotai/index";
2520
import { useId, useState } from "react";
2621

2722
type GenericSelectorProps = {
@@ -38,9 +33,6 @@ export const GenericSelector = ({
3833
onChange,
3934
}: GenericSelectorProps) => {
4035
const id = useId();
41-
const nodeSchemas = useAtomValue(nodeSchemasAtom);
42-
const nodeGenerics = useAtomValue(genericSchemasAtom);
43-
const profileSchemas = useAtomValue(profileSchemasAtom);
4436
const { schema } = useSchema(value);
4537
const [open, setOpen] = useState(false);
4638
const { data, loading } = useQuery(gql(getObjectPermissionsQuery(currentKind)));
@@ -51,23 +43,17 @@ export const GenericSelector = ({
5143

5244
const items = kindInheritingFromGeneric
5345
.map((usedByKind) => {
54-
const relatedSchema = [...nodeSchemas, ...profileSchemas].find(
55-
(schema) => schema.kind === usedByKind
56-
);
46+
const { schema: relatedSchema } = getSchema(usedByKind);
5747

5848
if (!relatedSchema) return;
5949

60-
// When choosing a profile, display informations about the related node
61-
if (currentKind === PROFILE_KIND) {
50+
// When choosing a profile/template, display information about the related node instead
51+
if (currentKind === PROFILE_KIND || currentKind === TEMPLATE_GENERIC_KIND) {
6252
const relationship = relatedSchema.relationships?.find(
6353
(relationship) => relationship.name === "related_nodes"
6454
);
6555

66-
const nodeSchema =
67-
relationship?.peer &&
68-
[...nodeSchemas, ...nodeGenerics, ...profileSchemas].find(
69-
(schema) => schema.kind === relationship.peer
70-
);
56+
const { schema: nodeSchema } = getSchema(relationship?.peer);
7157

7258
if (!nodeSchema) return;
7359

0 commit comments

Comments
 (0)