Files
deployment-portal-fe/src/coreform/FormUtil.tsx
Ashvin S 4e85760c85 INFRA-4076 | Ashvin | Add availability zone field (#730)
* INFRA-4076 | Ashvin | Add availability zone field

This will let users choose the AWS AZ they want to deploy their services in.

Backend and kutegen already supported this feature, see this for details https://github.com/navi-infra/kutegen/pull/218

* INFRA-4076 | Ashvin | Show AdvancedDeploymentConfigurationCard in all environments

* INFRA-4076 | Ashvin | Add all AZ to new manifest
2024-12-17 10:52:21 +05:30

113 lines
3.4 KiB
TypeScript

import { Box, Divider, MenuItem } from '@material-ui/core';
import React from 'react';
import { TabPanelProps, TabType } from './Types';
import { FormikProps } from 'formik';
import { AutoCompleteOption } from '@src/types/Types';
import { ZoneElement } from '@src/types/Deployment';
import * as _m from '../models/Manifest';
import {
clusterZoneMapping,
emptyEndpointNamePlaceholder,
requiredEndpointNamePlaceholder,
} from './deployment/constants';
export const Debug = (props: FormikProps<any>) => {
return (
<>
<Divider />
<b> ERRORS: </b>
<pre>{JSON.stringify(props.errors, null, 2)}</pre>
<b> VALUES: </b>
<pre>{JSON.stringify(props.values, null, 2)}</pre>
<Divider />
</>
);
};
export const toMenuItems = (options: ReadonlyArray<string>) => {
return options?.map(option => (
<MenuItem key={option} value={option}>
{option}
</MenuItem>
));
};
// export function getInUndef()
export function tabA11yProps(index: any, tabtype: TabType) {
return {
id: `${tabtype}-tab-${index}`,
'aria-controls': `${tabtype}-tabpanel-${index}`,
};
}
export function TabPanel(props: TabPanelProps) {
const { children, value, index, tabtype, ...other } = props;
return (
<div
role="tabpanel"
hidden={value !== index}
id={`${tabtype}-tabpanel-${index}`}
aria-labelledby={`${tabtype}-tab-${index}`}
style={{ width: '100%' }}
{...other}
>
{value === index && <Box p={2}>{children}</Box>}
</div>
);
}
export const maxAllocatedStorageBasedOnDbSize = (dbSize: number) =>
Math.max(Math.ceil(1.1 * dbSize), 100);
export const getUniqueExposedPortsName = (exposedPorts): string[] => {
return [...new Set<string>(exposedPorts.map(({ name }) => name))];
};
export const toLabelIdOption = (option: string): AutoCompleteOption => ({
label: option,
id: option,
});
export const toLabelIdOptions = (
options: ReadonlyArray<ZoneElement> | undefined,
): AutoCompleteOption[] => {
if (!options) return [];
return options?.map(option => toLabelIdOption(option?.zone));
};
export const getEndpointFromEndpointNameAndZone = (endpointName: string, zone: string): string => {
if (endpointName != '' && endpointName != emptyEndpointNamePlaceholder) {
return `${endpointName}.${zone}`;
} else {
return zone;
}
};
export const getEndpointNameFromEndpoint = (endpoint: string, cluster: string): string => {
if (!endpoint) return requiredEndpointNamePlaceholder;
const zone = getZoneFromEndpoint(endpoint, cluster);
if (!zone) return requiredEndpointNamePlaceholder;
const indexOfZone = endpoint?.indexOf(zone);
return indexOfZone <= 1 ? emptyEndpointNamePlaceholder : endpoint?.slice(0, indexOfZone - 1);
};
export const getZoneFromEndpoint = (endpoint: string, cluster: string): string => {
if (!endpoint) return '';
const sortedZonesForCluster: ZoneElement[] = clusterZoneMapping?.[cluster]?.toSorted(
(a: ZoneElement, b: ZoneElement) => b?.zone?.length - a?.zone?.length,
);
const zone: ZoneElement | undefined = sortedZonesForCluster?.find(availableZone =>
endpoint?.includes(availableZone?.zone),
);
if (!zone) return '';
return zone.zone;
};
export const getClusters = (environment: string) => {
if (_m.prodEnv.has(environment)) {
return _m.clusters[window.config.INFRA_VERTICAL]['prod'];
} else if (_m.nonProdEnv.has(environment)) {
return _m.clusters[window.config.INFRA_VERTICAL]['nonprod'];
}
return [];
};