From ce613cfa08ca647fcba18d8839811b9f44f6fdd4 Mon Sep 17 00:00:00 2001 From: Andrew Breidenbach Date: Tue, 19 Mar 2024 02:01:29 +0100 Subject: [PATCH 1/2] 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)) From a504525d2e1ee2775373be05890a30df6a5aa94e Mon Sep 17 00:00:00 2001 From: Andrew Breidenbach Date: Tue, 19 Mar 2024 19:04:07 +0100 Subject: [PATCH 2/2] Propagate _sourceinfo for shared templates --- .../project_overview/store/modules/deployments.js | 8 ++++++-- .../project_overview/store/modules/template_resources.js | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/oc-pages/project_overview/store/modules/deployments.js b/packages/oc-pages/project_overview/store/modules/deployments.js index c01a36f7..25597564 100644 --- a/packages/oc-pages/project_overview/store/modules/deployments.js +++ b/packages/oc-pages/project_overview/store/modules/deployments.js @@ -297,15 +297,17 @@ const actions = { resource = rootGetters.getPrimaryCard } + const type = rootGetters.resolveResourceTypeFromAny(resource.type) const newObject = { name: `__${environmentName}__${deploymentName}__${resourceName}`, metadata: { - extends: rootGetters.resolveResourceTypeFromAny(resource.type)?.extends || [], + extends: type?.extends || [], }, title: resource.title, directives: ['select'], imported: `${deploymentName}:${resource.name}`, type: resource.type, + _sourceinfo: type?._sourceinfo, __typename: 'ResourceTemplate' } @@ -326,15 +328,17 @@ const actions = { const resource = rootGetters.getCardsStacked.find(card => card.name == resourceName) const name = `__${environmentName}__${deploymentName}__${resourceName}` + const type = rootGetters.resolveResourceTypeFromAny(resource.type) const newObject = { name, metadata: { - extends: rootGetters.resolveResourceTypeFromAny(resource.type)?.extends || [], + extends: type?.extends || [], }, title: resource.title, directives: ['select'], imported: `${deploymentName}:${resource.name}`, type: resource.type, + _sourceinfo: type?._sourceinfo, __typename: 'ResourceTemplate' } 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 08144bd4..59810311 100644 --- a/packages/oc-pages/project_overview/store/modules/template_resources.js +++ b/packages/oc-pages/project_overview/store/modules/template_resources.js @@ -718,7 +718,15 @@ const actions = { await dispatch('fetchDeploymentIfNeeded', resourceTemplate) } + let _sourceinfo + + if(!resourceTemplate._sourceinfo) { + const type = getters.resolveResourceTypeFromAny(resourceTemplate.type) + _sourceinfo = type?._sourceinfo + } + resourceTemplateNode = { + _sourceinfo, ...resourceTemplate, name, dependentName,