diff --git a/Source/SelfService/Web/applications/microservice/microserviceDetails/configurationFilesSection/setupSection/setupSection.tsx b/Source/SelfService/Web/applications/microservice/microserviceDetails/configurationFilesSection/setupSection/setupSection.tsx index 3863eff0b..56d14b604 100644 --- a/Source/SelfService/Web/applications/microservice/microserviceDetails/configurationFilesSection/setupSection/setupSection.tsx +++ b/Source/SelfService/Web/applications/microservice/microserviceDetails/configurationFilesSection/setupSection/setupSection.tsx @@ -22,6 +22,8 @@ import { PublicUrlFields } from '../../../components/form/publicUrlFields'; import { RestartMicroserviceDialog } from '../../../components/restartMicroserviceDialog'; import { SetupFields } from '../../../components/form/setupFields'; +import { getMicroserviceInfo } from '../../../utils/getMicroserviceInfo'; + export type SetupSectionProps = { application: HttpResponseApplication; currentMicroservice: MicroserviceStore; @@ -40,21 +42,22 @@ export const SetupSection = ({ application, currentMicroservice }: SetupSectionP const microserviceId = currentMicroservice.id; const microserviceEnvironment = currentMicroservice.environment; const microserviceName = currentMicroservice.name; - const microserviceInfo = currentMicroservice.edit?.extra; + const microserviceInfo = getMicroserviceInfo(application, currentMicroservice); + const microserviceInfoExtra = microserviceInfo.extra; const canDelete = canDeleteMicroservice(application.environments, microserviceEnvironment, microserviceId); const availableEnvironments = application.environments.map(env => env.name); - const currentRuntimeImageNumber = microserviceInfo?.runtimeImage; - const hasPublicUrl = microserviceInfo?.isPublic || false; + const currentRuntimeImageNumber = microserviceInfoExtra?.runtimeImage; + const hasPublicUrl = microserviceInfoExtra?.isPublic || false; const hasM3ConnectorOption = application.environments.find(env => env.name === microserviceEnvironment)?.connections?.m3Connector || false; // Remove extra slash from ingress path as it is there already with startAdornment. - const cleanedIngressPath = microserviceInfo?.ingress?.path?.replace(/\//, '') || ''; + const cleanedIngressPath = microserviceInfoExtra?.ingress?.path?.replace(/\//, '') || ''; // Convert the head arguments to the format that the form expects. - const headArgumentValues = microserviceInfo?.headCommand?.args?.map((arg: string) => ({ value: arg })) || []; + const headArgumentValues = microserviceInfoExtra?.headCommand?.args?.map((arg: string) => ({ value: arg })) || []; const handleMicroserviceEdit = async ({ microserviceName, headImage, runtimeVersion }: MicroserviceFormParameters) => { - if (microserviceName === currentMicroservice.name && headImage === microserviceInfo?.headImage && runtimeVersion === currentRuntimeImageNumber) { + if (microserviceName === currentMicroservice.name && headImage === microserviceInfoExtra?.headImage && runtimeVersion === currentRuntimeImageNumber) { return; } @@ -128,8 +131,8 @@ export const SetupSection = ({ application, currentMicroservice }: SetupSectionP microserviceName, developmentEnvironment: microserviceEnvironment, runtimeVersion: currentRuntimeImageNumber, - headImage: microserviceInfo?.headImage, - headPort: microserviceInfo?.headPort, + headImage: microserviceInfoExtra?.headImage, + headPort: microserviceInfoExtra?.headPort, entrypoint: '', isPublic: hasPublicUrl, headArguments: headArgumentValues, diff --git a/Source/SelfService/Web/applications/microservice/microserviceDetails/microserviceDetails.tsx b/Source/SelfService/Web/applications/microservice/microserviceDetails/microserviceDetails.tsx index 6ed8b84a9..c88869f9a 100644 --- a/Source/SelfService/Web/applications/microservice/microserviceDetails/microserviceDetails.tsx +++ b/Source/SelfService/Web/applications/microservice/microserviceDetails/microserviceDetails.tsx @@ -7,9 +7,8 @@ import { Box, Typography } from '@mui/material'; import { StatusIndicator, Tabs } from '@dolittle/design-system'; -import { MicroserviceStore, canEditMicroservice } from '../../stores/microservice'; +import { MicroserviceStore } from '../../stores/microservice'; -import { MicroserviceSimple } from '../../../apis/solutions/index'; import { getPodStatus, HttpResponsePodStatus } from '../../../apis/solutions/api'; import { HttpResponseApplication } from '../../../apis/solutions/application'; @@ -51,60 +50,6 @@ export const MicroserviceDetails = ({ application, currentMicroservice }: Micros const podsStatuses = () => podsData.pods.flatMap(pod => pod.containers.map(container => container.state)); const microserviceHealthStatus = getContainerStatus(podsStatuses()); - // // What is the purpose of this?? - - // const canEdit = canEditMicroservice(application.environments, microserviceEnvironment, microserviceId); - - // let ms = {} as MicroserviceSimple; - - // let hasEditData = false; - - // if (canEdit) { - // hasEditData = true; - // ms = currentMicroservice.edit; - // } - - // Does this ever run?? - // if (!hasEditData) { - // // Can I not move this to the store? - // const headImage = currentMicroservice.live.images.find(img => img.name === 'head')?.image - // || 'N/A'; - // const runtimeImage = currentMicroservice.live.images.find(img => img.name === 'runtime')?.image - // || 'N/A'; - - // const headCommand = { - // command: [], - // args: [], - // }; - - // const environmentInfo = application.environments.find(environment => environment.name === microserviceEnvironment)!; - - // // TODO currently we don't use the ms.extra.ingress in the view - // // Look to "liveIngressView" for how we "set" the data to uniq paths - // ms = { - // dolittle: { - // applicationId, - // customerId: application.customerId, - // microserviceId, - // }, - // name: microserviceName, - // kind: 'unknown', - // environment: microserviceEnvironment, - // extra: { - // ingress: { - // path: '', - // pathType: '', - // }, - // headPort: 80, - // isPublic: true, - // headImage, - // runtimeImage, - // headCommand, - // connections: environmentInfo.connections, - // }, - // }; - // } - const tabs = [ { label: 'Configuration', diff --git a/Source/SelfService/Web/applications/microservice/microservices/microservicesDataGrid.tsx b/Source/SelfService/Web/applications/microservice/microservices/microservicesDataGrid.tsx index d408dbebf..79ea16088 100644 --- a/Source/SelfService/Web/applications/microservice/microservices/microservicesDataGrid.tsx +++ b/Source/SelfService/Web/applications/microservice/microservices/microservicesDataGrid.tsx @@ -14,6 +14,8 @@ import { DataGridWrapper, dataGridDefaultProps } from '@dolittle/design-system'; import { microservicesDataGridColumns } from './microservicesDataGridColumns'; +import { getMicroserviceInfo } from '../utils/getMicroserviceInfo'; + export type MicroservicesDataGridProps = { application: HttpResponseApplication; microservices: MicroserviceObject[]; @@ -29,13 +31,16 @@ export const MicroservicesDataGrid = ({ application, microservices }: Microservi setIsLoadingRows(true); Promise.all(microservices.map(async microservice => { + const microserviceInfo = getMicroserviceInfo(application, microservice); const status = await getMicroserviceStatus(microservice.id, microservice.environment); return { ...microservice, + edit: microserviceInfo, phase: status[0]?.phase, } as MicroserviceObject; - })).then(data => setMicroserviceRows(data)) + })) + .then(setMicroserviceRows) .finally(() => setIsLoadingRows(false)); }, [microservices]); diff --git a/Source/SelfService/Web/applications/microservice/utils/getMicroserviceInfo.ts b/Source/SelfService/Web/applications/microservice/utils/getMicroserviceInfo.ts new file mode 100644 index 000000000..1e8633b1a --- /dev/null +++ b/Source/SelfService/Web/applications/microservice/utils/getMicroserviceInfo.ts @@ -0,0 +1,52 @@ +// Copyright (c) Dolittle. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +import { canEditMicroservice, MicroserviceStore } from '../../stores/microservice'; + +import { MicroserviceSimple } from '../../../apis/solutions/index'; +import { HttpResponseApplication } from '../../../apis/solutions/application'; + +// Check if there is microservice.edit data. If not, use microservice.live data. +export const getMicroserviceInfo = (application: HttpResponseApplication, microservice: MicroserviceStore): MicroserviceSimple => { + const canEdit = canEditMicroservice(application.environments, microservice.environment, microservice.id); + + if (canEdit) { + return microservice.edit; + } else { + // Can I not move this to the store? + const headImage = microservice.live.images.find(img => img.name === 'head')?.image || 'N/A'; + const runtimeImage = microservice.live.images.find(img => img.name === 'runtime')?.image || 'N/A'; + + const headCommand = { + command: [], + args: [], + }; + + const environmentInfo = application.environments.find(environment => environment.name === microservice.environment)!; + + // TODO currently we don't use the ms.extra.ingress in the view + // Look to "liveIngressView" for how we "set" the data to uniq paths + return { + dolittle: { + applicationId: application.id, + customerId: application.customerId, + microserviceId: microservice.id, + }, + name: microservice.name, + kind: 'unknown', + environment: microservice.environment, + extra: { + ingress: { + path: '', + pathType: '', + }, + headPort: 80, + isPublic: true, + headImage, + runtimeImage, + headCommand, + connections: environmentInfo.connections, + }, + }; + } +};