-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Catalogue menu Add typing the menu items data fetch Fix usage of menu items data fetch ( use same filter as page) Closes #4322
- Loading branch information
1 parent
b84ce11
commit 4ff7727
Showing
7 changed files
with
112 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,86 @@ | ||
import type { UIResource, UIResourceType } from "~/interfaces/types"; | ||
|
||
interface Resp<T> { | ||
data: T; | ||
error?: any; | ||
} | ||
|
||
interface IHeaderQuery { | ||
Resources: UIResource[]; | ||
Variables_agg: { count: number }; | ||
Resources_groupBy: UIResourceType[]; | ||
} | ||
|
||
export async function useHeaderData() { | ||
const route = useRoute(); | ||
const scoped = route.params.catalogue !== "all"; | ||
const catalogueRouteParam = route.params.catalogue; | ||
|
||
const { data, error } = await $fetch(`/${route.params.schema}/graphql`, { | ||
key: `header-${route.params.catalogue}`, | ||
method: "POST", | ||
body: { | ||
query: ` | ||
query HeaderQuery($networksFilter:ResourcesFilter, $variablesFilter:VariablesFilter) { | ||
Resources(filter:$networksFilter) { | ||
const { data, error } = await $fetch<Resp<IHeaderQuery>>( | ||
`/${route.params.schema}/graphql`, | ||
{ | ||
method: "POST", | ||
body: { | ||
query: ` | ||
query HeaderQuery($resourceFilter:ResourcesFilter, $variablesFilter:VariablesFilter) { | ||
Resources(filter:$resourceFilter) { | ||
id, | ||
resources_agg { count } | ||
resources_groupBy { count , type {name}} | ||
logo { url } | ||
} | ||
Variables_agg(filter:$variablesFilter) { | ||
} | ||
Variables_agg(filter:$variablesFilter) { | ||
count | ||
} | ||
Resources_groupBy(filter:$resourceFilter) { | ||
type { name, definition } | ||
count | ||
} | ||
}`, | ||
variables: { | ||
networksFilter: scoped | ||
? { id: { equals: catalogueRouteParam } } | ||
: undefined, | ||
variablesFilter: scoped | ||
? { | ||
_or: [ | ||
{ resource: { id: { equals: catalogueRouteParam } } }, | ||
//also include network of networks | ||
{ | ||
resource: { | ||
type: { name: { equals: "Network" } }, | ||
} | ||
}`, | ||
variables: { | ||
resourceFilter: scoped | ||
? { | ||
_or: [ | ||
{ partOfResources: { id: { equals: catalogueRouteParam } } }, | ||
{ | ||
partOfResources: { | ||
id: { equals: catalogueRouteParam }, | ||
partOfResources: { id: { equals: catalogueRouteParam } }, | ||
}, | ||
}, | ||
], | ||
} | ||
: undefined, | ||
variablesFilter: scoped | ||
? { | ||
_or: [ | ||
{ resource: { id: { equals: catalogueRouteParam } } }, | ||
//also include network of networks | ||
{ | ||
resource: { | ||
type: { name: { equals: "Network" } }, | ||
partOfResources: { | ||
id: { equals: catalogueRouteParam }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
} | ||
: //should only include harmonised variables | ||
{ resource: { type: { name: { equals: "Network" } } } }, | ||
], | ||
} | ||
: //should only include harmonised variables | ||
{ resource: { type: { name: { equals: "Network" } } } }, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
); | ||
|
||
if (error) { | ||
const contextMsg = "Error on fetching page header data"; | ||
logError(error, contextMsg); | ||
throw new Error(contextMsg); | ||
} | ||
|
||
const catalogue = data.Resources ? data.Resources[0] : null; | ||
const catalogue = data.Resources ? data.Resources[0] : undefined; | ||
const variableCount = data.Variables_agg.count || 0; | ||
const resourceTypes = data.Resources_groupBy.filter( | ||
(resourceType: { count: number }) => resourceType.count > 0 | ||
); | ||
|
||
return { catalogue, variableCount }; | ||
return { catalogue, variableCount, resourceTypes }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters