Skip to content

Commit

Permalink
Qualified export: changes for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
AjBreidenbach committed Jan 10, 2024
1 parent 70b88e8 commit 24c1347
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 22 deletions.
13 changes: 7 additions & 6 deletions cypress/support/run-recreate-deployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,14 @@ Cypress.Commands.add('recreateDeployment', options => {
} else {
cy.get(`[data-testid="create-dependency-${template.name}.${dependency.name}"]`).click()

cy.get(`[data-testid="resource-selection-${match.type}"]`).click()
cy.get('[data-testid="create-resource-template-title"]')
.invoke('val', '')
.type(match.title)
cy.wait(500)
// cy.get(`[data-testid="resource-selection-${match.type}"]`).click()
// cy.get('[data-testid="create-resource-template-title"]')
// .invoke('val', '')
// .type(match.title)
// cy.wait(500)
// TODO try to make cypress less flakey without this
cy.get(`[data-testid="resource-selection-${match.type}"]`).click()
cy.get(`[data-testid="resource-selection-${match.type}"], [data-testid="resource-selection-${match.type.split('.').pop()}"]`).click()
cy.wait(500)
cy.get('[data-testid="create-resource-template-title"]')
.invoke('val', '')
.type(match.title)
Expand Down
2 changes: 1 addition & 1 deletion packages/oc-pages/dashboard/store/modules/table_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const actions = {
deepFreeze(resource)
context.resource = resource

context.type = frozenDeploymentDict['ResourceTemplate'][resource.template]?.type
context.type = frozenDeploymentDict['ResourceTemplate'][resource.template]?.type?.split('@')?.shift()

pushContext([environmentName, deployment.name, resource.name].join('.'))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
forceCheck: false,
dryRun: false,
localDeploy: false,
isCypress: !!window.Cypress
isCypress: true//!!window.Cypress
}
},
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ const actions = {

// TODO refactor independent transformations into vue_shared/lib/normalize
transforms = {
ResourceType(resourceType) {
localNormalize(resourceType, 'ResourceType', root)
},
ResourceTemplate(resourceTemplate) {
resourceTemplate.dependencies = _.uniqBy(normalizeDependencies(resourceTemplate.dependencies), 'name')
resourceTemplate.properties = _.uniqBy(normalizeProperties(resourceTemplate.properties), 'name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const mutations = {
createReference(_state, { dependentName, dependentRequirement, resourceTemplate, fieldsToReplace}){
if(!dependentName) return
const dependent = _state.resourceTemplates[dependentName];
console.assert(dependent, `Expected parent ${dependentName} to exist for ${resourceTemplate?.name}`)
const index = dependent.dependencies.findIndex(req => req.name == dependentRequirement);
resourceTemplate.dependentName = dependentName;
resourceTemplate.dependentRequirement = dependentRequirement;
Expand Down Expand Up @@ -429,7 +430,11 @@ const actions = {
// for now we are assuming that these two fetches are redundant
// we always prefer environment repositories when the environment is available
const fetchPromise = environmentName?
dispatch('environmentFetchTypesWithParams', {environmentName, deploymentName, params}):
Promise.all([
dispatch('environmentFetchTypesWithParams', {environmentName, deploymentName, params}),
// don't fetch blueprint if deployment is already created
deploymentName? null: dispatch('blueprintFetchTypesWithParams', {params})
]):
dispatch('blueprintFetchTypesWithParams', {params})

await fetchPromise
Expand Down
24 changes: 14 additions & 10 deletions packages/oc-pages/vue_shared/client_utils/unfurl-server.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import axios from '~/lib/utils/axios_utils'
import { fetchUserAccessToken } from './user';
import { fetchLastCommit, setLastCommit, createBranch } from "./projects";
import { fetchProjectInfo, fetchLastCommit, setLastCommit, createBranch } from "./projects";
import { XhrIFrame } from './crossorigin-xhr';
import {DEFAULT_UNFURL_SERVER_URL, shouldEncodePasswordsInExportUrl, unfurlServerUrlOverride, alwaysSendLatestCommit, cloudmapRepo, lookupKey, setLocalStorageKey} from '../storage-keys';
import _ from 'lodash'

const pageAccessedByReload = (
(window.performance.navigation && window.performance.navigation.type === 1) ||
window.performance
.getEntriesByType('navigation')
.map((nav) => nav.type)
.includes('reload')
)
let pageAccessedByReload = false
try {
pageAccessedByReload= (
(window.performance.navigation && window.performance.navigation.type === 1) ||
window.performance
.getEntriesByType('navigation')
.map((nav) => nav.type)
.includes('reload')
)
} catch(e) {}

let transientOverride

Expand Down Expand Up @@ -150,9 +153,10 @@ export async function unfurlServerGetTypes({file, branch, projectPath, sendCrede
// the only other reason to hit branches would be to get the main branch

const fetchCommitPromise = (branch && !branch.startsWith('v'))? fetchLastCommit(encodeURIComponent(projectPath), branch): null
const [lastCommitResult, password] = await Promise.all([fetchCommitPromise, fetchUserAccessToken()])
const fetchProjectInfoPromise = sendCredentials ?? null == null? fetchProjectInfo(encodeURIComponent(projectPath)).then(pinfo => pinfo?.visibility): null
const [lastCommitResult, password, visibility] = await Promise.all([fetchCommitPromise, fetchUserAccessToken(), fetchProjectInfoPromise])
const [latestCommit, inferredBranch] = lastCommitResult || []
const _sendCredentials = sendCredentials ?? true
const _sendCredentials = sendCredentials ?? visibility != 'public'
await healthCheckErrorHelper(projectPath)

const cacheKey = JSON.stringify({branch, projectPath, ...params})
Expand Down
2 changes: 2 additions & 0 deletions packages/oc-pages/vue_shared/lib/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,14 @@ const transforms = {
}

export function localNormalize(object, typename=null, root) {
if(object._normalized) return
if(!(object.__typename || typename)) {
throw new Error(`Couldn't normalize ${object.name}: no typename`)
}
const t = object.__typename = typename || object.__typename

if(typeof transforms[t] == 'function') {
transforms[t](object, root)
object._normalized = true
}
}
24 changes: 21 additions & 3 deletions ufsv-patch/target-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class TargetState {
for(const dependency of template.dependencies) {
const type = dependency.constraint.resourceType
const match = dependency.match
if(match && overwrites[type]) {
const ext = fixture.ResourceType[type]?.extends?.map(t => t.split('@').shift()) || []
const overwriteKey = Object.keys(overwrites).find(o => type.startsWith(`${o}@`) || ext.includes(o))
if(match && overwrites[overwriteKey]) {
fixture.ResourceTemplate[match] = {
...JSON.parse(overwrites[type]),
...JSON.parse(overwrites[overwriteKey]),
name: match
}

Expand Down Expand Up @@ -50,6 +52,13 @@ class TargetState {
continue
}

const inputsSchema = this.store.getters.resolveResourceTypeFromAny(a.type).inputsSchema

if(!inputsSchema.properties[propertyB.name]) {
console.warn(`${propertyB.name} not found in :${JSON.stringify(inputsSchema, null, 2)}`)
continue
}

await this.store.dispatch('updateProperty', {
deploymentName: this.store.getters.getDeploymentTemplate.name,
templateName,
Expand Down Expand Up @@ -83,13 +92,22 @@ class TargetState {

await this.store.dispatch('fetchTypesForParams', {params})

const expectedType = this.ResourceTemplate[dependencyB.match].type.split('@').shift()

const selection = this.store.getters.availableResourceTypesForRequirement(dependencyA)
.find(t => t.name.startsWith(`${expectedType}@`) || t.name.startsWith(`${expectedType.split('.').pop()}@`))

if(!selection) {
throw new Error(`Could not find a match for ${expectedType} among types available for ${JSON.stringify(dependencyA, null, 2)}`)
}

const toBeCreated = {
dependentName: templateName,
dependentRequirement: dependencyB.name,
requirement: dependencyB,
name: dependencyB.match,
title: this.ResourceTemplate[dependencyB.match].title,
selection: this.store.getters.resolveResourceTypeFromAny(this.ResourceTemplate[dependencyB.match].type)
selection
}
await this.store.dispatch('createNodeResource',
toBeCreated
Expand Down

0 comments on commit 24c1347

Please sign in to comment.