Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resource sharing regressions, propagate _sourceinfo for shared #508

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}

Expand All @@ -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'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -455,7 +455,6 @@ const actions = {
'pushPreparedMutation',
createResourceTemplate({...matchedNested, dependentName, dependentRequirement, deploymentTemplateName: state.lastFetchedFrom.templateSlug}),
)
console.log(`adding ${match} @initMatched`)
}

resolvedDependencyMatch = matchedNested || resolvedDependencyMatch
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -720,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,
Expand Down Expand Up @@ -1074,12 +1080,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 []
Expand Down Expand Up @@ -1202,7 +1217,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))
Expand Down
Loading