Skip to content
Merged
2 changes: 1 addition & 1 deletion ngui/ui/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ButtonText = ExclusiveUnion<{
pepega: string;
}>;

type ButtonProps = MuiButtonProps &
export type ButtonProps = MuiButtonProps &
ButtonText &
NavProps & {
dataTestId?: string;
Expand Down
8 changes: 7 additions & 1 deletion ngui/ui/src/components/CloudResourceId/CloudResourceId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ const CloudResourceId = (props) => {

// Additional check to handle cloudResourceIdentifier having 'null' or 'undefined' substring
if (separator && cloudResourceIdentifier.includes(separator)) {
const shortenedCloudResourceId = `${SHORTENED_CLOUD_RESOURCE_ID_PREFIX}${cloudResourceIdentifier.split(separator).pop()}`;
// If the path ends with "/", take last 3 segments (last segment is empty)
// Example: "path/to/resource/" -> ["to", "resource", ""] -> "to/resource/"
const shortId = cloudResourceIdentifier.endsWith(separator)
? cloudResourceIdentifier.split(separator).slice(-3).join(separator)
: cloudResourceIdentifier.split(separator).pop();

const shortenedCloudResourceId = `${SHORTENED_CLOUD_RESOURCE_ID_PREFIX}${shortId}`;

return (
<CloudResourceIdString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import AwsUseAwsEdpDiscount from "../AwsUseAwsEdpDiscount";
const AwsAssumedRoleInputs = ({
readOnlyFields = [],
showAssumedRoleCredentialsInModal = false,
showAdvancesOptions = true
showAdvancedOptions = true
}: {
readOnlyFields?: string[];
showAssumedRoleCredentialsInModal?: boolean;
showAdvancesOptions?: boolean;
showAdvancedOptions?: boolean;
}) => (
<>
<AwsAssumedRoleCredentials readOnlyFields={readOnlyFields} />
{showAdvancesOptions && (
{showAdvancedOptions && (
<>
<AwsUseAwsEdpDiscount />
<Typography gutterBottom data-test-id="p_cost_and_usage_report_parameters_description">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ const AwsProperties = ({ accountId, config, createdAt }: AwsPropertiesProps) =>

const getAwsAccountTypeMessageId = () => {
if (linked) {
return "linked";
return "member";
}

return "managementStandalone";
};

const getAwsAuthenticationTypeMessageId = () => {
if (isAssumeRole) {
return "assumedRole";
}

return "root";
return "accessKey";
};

return (
Expand Down Expand Up @@ -60,6 +64,11 @@ const AwsProperties = ({ accountId, config, createdAt }: AwsPropertiesProps) =>
value: `p_${AWS_CNR}_value`
}}
/>
<KeyValueLabel
keyMessageId="awsAuthenticationType"
value={<FormattedMessage id={getAwsAuthenticationTypeMessageId()} />}
dataTestIds={{ key: "p_authentication_type_key", value: "p_authentication_type_value" }}
/>
{isAssumeRole && (
<KeyValueLabel
variant="property"
Expand Down
19 changes: 10 additions & 9 deletions ngui/ui/src/components/WrapperCard/WrapperCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import IconButton from "components/IconButton";
import Tooltip from "components/Tooltip";
import WidgetTitle from "components/WidgetTitle";
import WrapperCardTitlePdf from "components/WrapperCardTitlePdf/WrapperCardTitlePdf";
import { TitleProps, WrapperCardProps } from "./types";
import useStyles from "./WrapperCard.styles";

const renderButton = (type, buttonProps) => (type === "icon" ? <IconButton {...buttonProps} /> : <Button {...buttonProps} />);
const Title = ({ title, titleButton, dataTestId }: TitleProps) => {
const titleMessage = <WidgetTitle dataTestId={dataTestId}>{title}</WidgetTitle>;

const renderTitleButton = (options) => {
const { type, tooltip, buttonProps } = options;
return tooltip ? <Tooltip title={tooltip.title}>{renderButton(type, buttonProps)}</Tooltip> : renderButton(type, buttonProps);
};
if (!titleButton) {
return titleMessage;
}

const Title = ({ title, titleButton, dataTestId }) => {
const titleMessage = <WidgetTitle dataTestId={dataTestId}>{title}</WidgetTitle>;
const { type, tooltip, buttonProps } = titleButton;
const buttonElement = type === "icon" ? <IconButton {...buttonProps} /> : <Button {...buttonProps} />;

const button = titleButton && renderTitleButton(titleButton);
const button = tooltip ? <Tooltip title={tooltip.title}>{buttonElement}</Tooltip> : buttonElement;

return button ? (
<Box display="flex" marginBottom={"20px"} alignItems="center">
Expand All @@ -35,7 +36,7 @@ const Title = ({ title, titleButton, dataTestId }) => {
);
};

const WrapperCard = forwardRef(
const WrapperCard = forwardRef<HTMLDivElement, WrapperCardProps>(
(
{
title,
Expand Down
54 changes: 54 additions & 0 deletions ngui/ui/src/components/WrapperCard/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { ReactNode } from "react";
import type { CardProps } from "@mui/material";
import { ButtonProps } from "components/Button/Button";
import { IconButtonProps } from "components/IconButton/IconButton";
import { TODO } from "utils/types";

type ButtonConfig =
| {
type: "icon";
buttonProps: IconButtonProps;
}
| {
type: "button";
buttonProps: ButtonProps;
};

type TitleButtonOptions = {
tooltip?: { title: ReactNode };
} & ButtonConfig;

type DataTestIdsOptions = {
wrapper?: string;
title?: string;
titleCaption?: string;
button?: string;
};

type ButtonOptions = {
show: boolean;
href?: string;
link?: string;
messageId: string;
};

export type TitleProps = {
title: ReactNode;
titleButton?: TitleButtonOptions;
dataTestId?: string;
};

export type WrapperCardProps = Omit<CardProps, "title"> & {
title: ReactNode;
titleCaption?: ReactNode;
titleButton?: TitleButtonOptions;
dataTestIds?: DataTestIdsOptions;
children?: ReactNode;
className?: string;
button?: ButtonOptions;
needAlign?: boolean;
titlePdf?: {
id: string;
renderData: () => TODO;
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ import DatabricksLogoIcon from "icons/DatabricksLogoIcon";
import GcpLogoIcon from "icons/GcpLogoIcon";
import K8sLogoIcon from "icons/K8sLogoIcon";
import NebiusLogoIcon from "icons/NebiusLogoIcon";
import { intl } from "translations/react-intl-config";
import {
DATABRICKS_CREATE_SERVICE_PRINCIPAL,
DOCS_HYSTAX_AWS_LINKED_DISCOVER_RESOURCES,
DOCS_HYSTAX_CONNECT_ALIBABA_CLOUD,
DOCS_HYSTAX_CONNECT_AWS_LINKED,
DOCS_HYSTAX_CONNECT_AWS_ROOT,
DOCS_HYSTAX_CONNECT_AZURE_SUBSCRIPTION,
DOCS_HYSTAX_CONNECT_AZURE_TENANT,
DOCS_HYSTAX_CONNECT_GOOGLE_CLOUD,
DOCS_HYSTAX_CONNECT_GOOGLE_CLOUD_TENANT,
DOCS_HYSTAX_CONNECT_KUBERNETES,
GITHUB_HYSTAX_EXTRACT_LINKED_REPORTS,
GITHUB_HYSTAX_K8S_COST_METRICS_COLLECTOR
} from "urls";
import { GA_EVENT_CATEGORIES, trackEvent } from "utils/analytics";
Expand Down Expand Up @@ -74,11 +69,11 @@ import { ConnectionInputs, DataSourceNameField } from "./FormElements";
import {
AuthenticationTypeSelector,
getAwsConnectionTypeDescriptions,
useAuthenticationType
} from "./FormElements/Aws/components/AwsDescription";
import { AUTHENTICATION_TYPES } from "./FormElements/Aws/constants/AwsConstants";
import { AuthenticationType } from "./FormElements/Aws/types/AwsForm.types";
import { AWS_ROOT_INPUTS_FIELD_NAMES } from "./FormElements/ConnectionFields";
useAuthenticationType,
AUTHENTICATION_TYPES,
AWS_ROOT_INPUTS_FIELD_NAMES,
AuthenticationType
} from "./FormElements/AwsConnectionForm";
import { FIELD_NAME as DATA_SOURCE_NAME_FIELD_NAME } from "./FormElements/DataSourceNameField";

type ConnectionType = ObjectValues<typeof CONNECTION_TYPES>;
Expand Down Expand Up @@ -113,9 +108,7 @@ const CLOUD_PROVIDER_TYPES: CloudProviderTypes = {
[CLOUD_PROVIDERS.AWS]: [
{ connectionType: CONNECTION_TYPES.AWS_MANAGEMENT, messageId: "management", cloudType: AWS_CNR },
{ connectionType: CONNECTION_TYPES.AWS_MEMBER, messageId: "member", cloudType: AWS_CNR },
{ connectionType: CONNECTION_TYPES.AWS_STANDALONE, messageId: "standalone", cloudType: AWS_CNR },
{ connectionType: CONNECTION_TYPES.AWS_ROOT, messageId: "root", cloudType: AWS_CNR },
{ connectionType: CONNECTION_TYPES.AWS_LINKED, messageId: "linked", cloudType: AWS_CNR }
{ connectionType: CONNECTION_TYPES.AWS_STANDALONE, messageId: "standalone", cloudType: AWS_CNR }
],
[CLOUD_PROVIDERS.AZURE]: [
{ connectionType: CONNECTION_TYPES.AZURE_TENANT, messageId: "tenant", cloudType: AZURE_TENANT },
Expand Down Expand Up @@ -185,17 +178,6 @@ const getAwsRootParameters = (formData: FieldValues, connectionType: string) =>
};
};

// MPT_TODO: disabled to meet BDR requirements
// const getAwsLinkedParameters = (formData: FieldValues) => ({
// name: formData[DATA_SOURCE_NAME_FIELD_NAME],
// type: AWS_CNR,
// config: {
// access_key_id: formData[AWS_LINKED_CREDENTIALS_FIELD_NAMES.ACCESS_KEY_ID],
// secret_access_key: formData[AWS_LINKED_CREDENTIALS_FIELD_NAMES.SECRET_ACCESS_KEY],
// linked: true
// }
// });

const getAwsAssumedRoleParameters = (formData: FieldValues, connectionType: string) => {
const extraParams = {
use_edp_discount: formData[AWS_USE_AWS_EDP_DISCOUNT_FIELD_NAMES.USE_EDP_DISCOUNT],
Expand All @@ -222,17 +204,6 @@ const getAwsAssumedRoleParameters = (formData: FieldValues, connectionType: stri
};
};

// MPT_TODO: disabled to meet BDR requirements
// const getAwsParametersByConnectionType = (connectionType: string) => {
// console.log(connectionType);
// const parameters = {
// [CONNECTION_TYPES.AWS_LINKED]: getAwsLinkedParameters,
// [CONNECTION_TYPES.AWS_ROLE]: getAwsAssumedRoleParameters
// }[connectionType];
//
// return parameters || getAwsRootParameters;
// };

const getAwsParametersByAuthenticationType = (connectionType: string, authenticationType: AuthenticationType) =>
authenticationType === AUTHENTICATION_TYPES.ACCESS_KEY
? (formData: FieldValues) => getAwsRootParameters(formData, connectionType)
Expand Down Expand Up @@ -294,7 +265,7 @@ const getGoogleParameters = async (formData: FieldValues) => {
name: formData[DATA_SOURCE_NAME_FIELD_NAME],
type: GCP_CNR,
config: {
credentials: JSON.parse(credentials),
credentials: JSON.parse(credentials as string),
billing_data: {
dataset_name: formData[GCP_CREDENTIALS_FIELD_NAMES.BILLING_DATA_DATASET],
table_name: formData[GCP_CREDENTIALS_FIELD_NAMES.BILLING_DATA_TABLE],
Expand All @@ -320,7 +291,7 @@ const getGoogleTenantParameters = async (formData: FieldValues) => {
name: formData[DATA_SOURCE_NAME_FIELD_NAME],
type: GCP_TENANT,
config: {
credentials: JSON.parse(credentials),
credentials: JSON.parse(credentials as string),
billing_data: {
dataset_name: formData[GCP_TENANT_CREDENTIALS_FIELD_NAMES.BILLING_DATA_DATASET],
table_name: formData[GCP_TENANT_CREDENTIALS_FIELD_NAMES.BILLING_DATA_TABLE]
Expand Down Expand Up @@ -440,67 +411,6 @@ const renderConnectionTypeInfoMessage = (connectionType: ConnectionType, authent
}
}
]),
[CONNECTION_TYPES.AWS_ROLE]: renderConnectionTypeDescription([
{
key: "createAwsAssumedRoleDescription",
messageId: "createAwsAssumedRoleDescription",
values: { action: intl.formatMessage({ id: "connect" }) }
}
]),
[CONNECTION_TYPES.AWS_ROOT]: renderConnectionTypeDescription([
{
key: "createAwsRootDocumentationReference",
messageId: "createAwsRootDocumentationReference",
values: {
link: (chunks: ReactNode) => (
<Link data-test-id="link_guide" href={DOCS_HYSTAX_CONNECT_AWS_ROOT} target="_blank" rel="noopener">
{chunks}
</Link>
),
strong: (chunks: ReactNode) => <strong>{chunks}</strong>
}
}
]),
[CONNECTION_TYPES.AWS_LINKED]: renderConnectionTypeDescription([
{
key: "createAwsLinkedDocumentationReference1",
messageId: "createAwsLinkedDocumentationReference1",
values: {
autoBillingAwsLink: (chunks: ReactNode) => (
<Link data-test-id="link_guide" href={DOCS_HYSTAX_CONNECT_AWS_LINKED} target="_blank" rel="noopener">
{chunks}
</Link>
)
}
},
{
key: "createAwsLinkedDocumentationReference2",
messageId: "createAwsLinkedDocumentationReference2",
values: {
extractLinkedReports: (
<Link
data-test-id="extract_linked_reports"
href={GITHUB_HYSTAX_EXTRACT_LINKED_REPORTS}
target="_blank"
rel="noopener"
>
{GITHUB_HYSTAX_EXTRACT_LINKED_REPORTS}
</Link>
)
}
},
{
key: "createAwsLinkedDocumentationReference3",
messageId: "createAwsLinkedDocumentationReference3",
values: {
discoverResourcesLink: (chunks: ReactNode) => (
<Link data-test-id="link_iam_user" href={DOCS_HYSTAX_AWS_LINKED_DISCOVER_RESOURCES} target="_blank" rel="noopener">
{chunks}
</Link>
)
}
}
]),
[CONNECTION_TYPES.KUBERNETES]: renderConnectionTypeDescription([
{
key: "createKubernetesDocumentationReference1",
Expand Down Expand Up @@ -669,7 +579,7 @@ const ConnectCloudAccountForm = ({ onSubmit, onCancel, isLoading = false, showCa
: isDataSourceConnectionTypeEnabled(providerTypes.connectionType);
});

const renderTabs = () => {
const renderFormTabs = () => {
if (!Array.isArray(CLOUD_PROVIDER_TYPES[selectedProvider])) {
return null;
}
Expand Down Expand Up @@ -738,7 +648,7 @@ const ConnectCloudAccountForm = ({ onSubmit, onCancel, isLoading = false, showCa
))}
</Box>
<Box>
{renderTabs()}
{renderFormTabs()}
<Box sx={{ marginBottom: SPACING_2 }}>{renderConnectionTypeInfoMessage(connectionType, authenticationType)}</Box>
<form
onSubmit={
Expand Down
Loading