diff --git a/ui/src/app/applications/components/application-create-panel/application-create-panel.tsx b/ui/src/app/applications/components/application-create-panel/application-create-panel.tsx index 41919fc62f..58c023a113 100644 --- a/ui/src/app/applications/components/application-create-panel/application-create-panel.tsx +++ b/ui/src/app/applications/components/application-create-panel/application-create-panel.tsx @@ -64,6 +64,23 @@ const AutoSyncFormField = ReactFormField((props: {fieldApi: FieldApi, className: ); }); +function normalizeAppSource(app: models.Application, type: string): boolean { + const repoType = app.spec.source.hasOwnProperty('chart') && 'helm' || 'git'; + if (repoType !== type) { + if (type === 'git') { + app.spec.source.path = app.spec.source.chart; + delete(app.spec.source.chart); + app.spec.source.targetRevision = 'HEAD'; + } else { + app.spec.source.chart = app.spec.source.path; + delete(app.spec.source.path); + app.spec.source.targetRevision = ''; + } + return true; + } + return false; +} + export const ApplicationCreatePanel = (props: { app: models.Application, onAppChanged: (app: models.Application) => any; @@ -92,10 +109,15 @@ export const ApplicationCreatePanel = (props: { .map((cluster) => ({label: clusterTitle(cluster), value: cluster.server})) .sort((first, second) => first.label.localeCompare(second.label)), ), - services.repos.list().then((repos) => repos.map((repo) => repo.repo).sort()), - ]).then(([projects, clusters, repos]) => ({projects, clusters, repos}))}> - {({projects, clusters, repos}) => { + services.repos.list(), + ]).then(([projects, clusters, reposInfo]) => ({projects, clusters, reposInfo}))}> + {({projects, clusters, reposInfo}) => { + const repos = reposInfo.map((info) => info.repo).sort(); const app = deepMerge(DEFAULT_APP, props.app || {}); + const repoInfo = reposInfo.find((info) => info.repo === app.spec.source.repoURL); + if (repoInfo) { + normalizeAppSource(app, repoInfo.type || 'git'); + } return (
SOURCE
-{repoType.toUpperCase()}
)} items={['git', 'helm'].map( - (type: 'git' | 'helm') => ({ title: type.toUpperCase(), action: () => { - if (repoType !== type) { - const updatedApp = api.getFormState().values as models.Application; - if (type === 'git') { - updatedApp.spec.source.path = updatedApp.spec.source.chart; - delete(updatedApp.spec.source.chart); - updatedApp.spec.source.targetRevision = 'HEAD'; - } else { - updatedApp.spec.source.chart = updatedApp.spec.source.path; - delete(updatedApp.spec.source.path); - updatedApp.spec.source.targetRevision = ''; - } - api.setAllValues(updatedApp); - } - }}))} - /> -{repoType.toUpperCase()}
)} items={['git', 'helm'].map( + (type: 'git' | 'helm') => ({ title: type.toUpperCase(), action: () => { + if (repoType !== type) { + const updatedApp = api.getFormState().values as models.Application; + if (normalizeAppSource(updatedApp, type)) { + api.setAllValues(updatedApp); + } + } + }}))} + /> + )} +