Skip to content

Commit

Permalink
'getMicroserviceInfo' when there is no 'edit' data
Browse files Browse the repository at this point in the history
  • Loading branch information
N00bG1rl committed Sep 27, 2023
1 parent 5e70290 commit ce6f15b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

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

Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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]);

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

0 comments on commit ce6f15b

Please sign in to comment.