From ce613cfa08ca647fcba18d8839811b9f44f6fdd4 Mon Sep 17 00:00:00 2001 From: Andrew Breidenbach Date: Tue, 19 Mar 2024 02:01:29 +0100 Subject: [PATCH] Fix regression where resources were treated as templates --- .../modules/project_application_blueprint.js | 14 ++++++++----- .../store/modules/template_resources.js | 21 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/oc-pages/project_overview/store/modules/project_application_blueprint.js b/packages/oc-pages/project_overview/store/modules/project_application_blueprint.js index 00a91000..8d9f902d 100644 --- a/packages/oc-pages/project_overview/store/modules/project_application_blueprint.js +++ b/packages/oc-pages/project_overview/store/modules/project_application_blueprint.js @@ -534,12 +534,16 @@ const getters = { }, resolveResource(state) { return name => { - if(!name) return - let rt = state['Resource'][name] - if(!rt && !name?.startsWith('::')) { - rt = state['Resource'][`::${name}`] + if(!name) return null + try { + let rt = state['Resource'][name] + if(!rt && !name?.startsWith('::')) { + rt = state['Resource'][`::${name}`] + } + return rt + } catch(e) { + return null } - return rt } }, resolveDeployment(state) { return name => state['Deployment'][name] }, diff --git a/packages/oc-pages/project_overview/store/modules/template_resources.js b/packages/oc-pages/project_overview/store/modules/template_resources.js index 49e85c54..08144bd4 100644 --- a/packages/oc-pages/project_overview/store/modules/template_resources.js +++ b/packages/oc-pages/project_overview/store/modules/template_resources.js @@ -369,8 +369,8 @@ const actions = { const deployment = deploymentName? rootGetters.getDeployments.find(dep => dep.name == deploymentName): rootGetters.getDeployment - deploymentName = deployment.name - const environmentName = deployment._environment + deploymentName = deployment?.name || deploymentName + const environmentName = deployment?._environment || getters.getCurrentEnvironment?.name let deploymentDict @@ -455,7 +455,6 @@ const actions = { 'pushPreparedMutation', createResourceTemplate({...matchedNested, dependentName, dependentRequirement, deploymentTemplateName: state.lastFetchedFrom.templateSlug}), ) - console.log(`adding ${match} @initMatched`) } resolvedDependencyMatch = matchedNested || resolvedDependencyMatch @@ -535,7 +534,6 @@ const actions = { let promises = [] for(const dependency of getters.getDependencies(resource.name) || resource.dependencies || []) { - console.log(dependency) promises.push(dispatch( 'initMatched', { isDeploymentTemplate, @@ -1074,12 +1072,21 @@ const getters = { return getters.getCardsStacked('*').find(card => card.name == cardName) } }, - getDependencies: (_state, getters) => { + getDependencies: (_state, getters, rootState, rootGetters) => { return function(resourceTemplateName) { - const rt = getters.dtResolveResourceTemplate(resourceTemplateName) + if(!resourceTemplateName) return null + + const rt = ( + rootGetters.resolveResource(resourceTemplateName?.name || resourceTemplateName) || + getters.dtResolveResourceTemplate(resourceTemplateName) + ) if(!rt) return null + if(rt.__typename == 'Resource') { + return rt.connections + } + let dependencies = _.cloneDeep(rt.dependencies || []) if(dependencies.length == 0) return [] @@ -1202,7 +1209,7 @@ const getters = { if(!card) return true if(card.imported) return true const dependencies = getters.getDependencies(card) - if(!dependencies.length) return true; + if(!dependencies?.length) return true; return dependencies.every(dependency => ( (dependency.constraint.min == 0 && !dependency.match) || (getters.requirementMatchIsValid(dependency) && getters.cardIsValid(dependency.match))