1- import { PROFILE_KIND } from "@/config/constants" ;
1+ import { PROFILE_KIND , TEMPLATE_GENERIC_KIND } from "@/config/constants" ;
22import { getObjectPermissionsQuery } from "@/entities/permission/queries/getObjectPermissions" ;
33import { PermissionData } from "@/entities/permission/types" ;
44import { 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" ;
106import { useSchema } from "@/entities/schema/ui/hooks/useSchema" ;
117import useQuery from "@/shared/api/graphql/useQuery" ;
128import { LoadingIndicator } from "@/shared/components/loading/loading-indicator" ;
@@ -21,7 +17,6 @@ import {
2117} from "@/shared/components/ui/combobox" ;
2218import Label from "@/shared/components/ui/label" ;
2319import { gql } from "@apollo/client" ;
24- import { useAtomValue } from "jotai/index" ;
2520import { useId , useState } from "react" ;
2621
2722type 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