Skip to content

Commit

Permalink
Add readonly state
Browse files Browse the repository at this point in the history
  • Loading branch information
DonOmalVindula committed Jun 5, 2024
1 parent 89e2dbd commit b482419
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
16 changes: 14 additions & 2 deletions features/admin.branding.ai.v1/components/branding-ai-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,25 @@ import {
DocumentationLink,
useDocumentation
} from "@wso2is/react-components";
import React, { FunctionComponent, ReactElement, useState } from "react";
import React, { FunctionComponent, PropsWithChildren, ReactElement, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import useAIBrandingPreference from "../hooks/use-ai-branding-preference";
import useGenerateAIBrandingPreference,
{ GenerateAIBrandingPreferenceFunc } from "../hooks/use-generate-ai-branding-preference";
import { BannerState } from "../models/types";
import "./branding-ai-banner.scss";

interface BrandingAIBannerProps {
readonly?: boolean;
}

/**
* Branding AI banner component.
*/
const BrandingAIBanner: FunctionComponent = (): ReactElement => {
const BrandingAIBanner: FunctionComponent<PropsWithChildren<BrandingAIBannerProps>> = (
props: PropsWithChildren<BrandingAIBannerProps>): ReactElement => {

const { readonly } = props;

const { t } = useTranslation();

Expand Down Expand Up @@ -96,6 +103,7 @@ const BrandingAIBanner: FunctionComponent = (): ReactElement => {
className="oxygen-chip-beta mb-1 ml-2"
/>
) }
readonly={ readonly }
/>
</Collapse>
<Collapse in={ bannerState === BannerState.INPUT || bannerState === BannerState.COLLAPSED }>
Expand Down Expand Up @@ -177,4 +185,8 @@ const BrandingAIBanner: FunctionComponent = (): ReactElement => {
);
};

BrandingAIBanner.defaultProps = {
readonly: false
};

export default BrandingAIBanner;
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ import AIFeatureContext from "../context/ai-branding-feature-context";
import { BrandingGenerationResultAPIResponseInterface } from "../models/branding-preferences";
import { BannerState } from "../models/types";

type AIBrandingPreferenceProviderProps = PropsWithChildren;
interface AIBrandingPreferenceProviderProps {
readonly?: boolean;
}

/**
* Provider for the AI branding preference context.
*
* @param props - Props injected to the component.
* @returns AI branding preference provider.
*/
const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProviderProps> = (
props: AIBrandingPreferenceProviderProps
const AIBrandingPreferenceProvider: FunctionComponent<PropsWithChildren<AIBrandingPreferenceProviderProps>> = (
props: PropsWithChildren<AIBrandingPreferenceProviderProps>
): ReactElement => {

const { children } = props;
const { readonly, children } = props;

const { t } = useTranslation();

Expand Down Expand Up @@ -192,7 +194,7 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid
!brandingDisabledFeatures?.includes(AI_BRANDING_FEATURE_ID) &&
!isSubOrganization() && (
<div className="mb-2">
<BrandingAIBanner/>
<BrandingAIBanner readonly={ readonly }/>
</div>
)
}
Expand All @@ -204,4 +206,11 @@ const AIBrandingPreferenceProvider: FunctionComponent<AIBrandingPreferenceProvid
);
};

/**
* Default props for the component.
*/
AIBrandingPreferenceProvider.defaultProps = {
readonly: false
};

export default AIBrandingPreferenceProvider;
14 changes: 8 additions & 6 deletions features/admin.branding.v1/components/branding-page-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ const BrandingPageLayout: FunctionComponent<BrandingPageLayoutInterface> = (
} }
variants={ animationVariants }>
{ resolveBrandingDescription() }
<DocumentationLink
link={ getLink("develop.branding.learnMore") }
>
{ t("common:learnMore") }
</DocumentationLink>
</motion.div>
</AnimatePresence>
<DocumentationLink
link={ getLink("develop.branding.learnMore") }
>
{ t("common:learnMore") }
</DocumentationLink>
</div>
) }
data-componentid={ `${ componentId }-layout` }
Expand All @@ -377,7 +377,9 @@ const BrandingPageLayout: FunctionComponent<BrandingPageLayoutInterface> = (
}
</motion.div>
<motion.div layout>
<AIBrandingPreferenceProvider>
<AIBrandingPreferenceProvider
readonly={ brandingMode === BrandingModes.APPLICATION && !selectedApplication }
>
<BrandingCore />
</AIBrandingPreferenceProvider>
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ export const BrandingPreferenceTabs: FunctionComponent<BrandingPreferenceTabsInt
disabled={ brandingMode === BrandingModes.APPLICATION }
>
{ t("branding:tabs.text.label") }
{ isSAASDeployment && (
{ isSAASDeployment && brandingMode !== BrandingModes.APPLICATION && (
<Chip
size="small"
sx={ { marginLeft: 1 } }
Expand Down
11 changes: 11 additions & 0 deletions features/common.ai.v1/components/ai-banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface AIBannerProps extends IdentifiableComponentInterface {
onActionButtonClick?: () => void;
actionButtonText?: string;
titleLabel?: ReactElement;
readonly?: boolean;
}

/**
Expand All @@ -47,6 +48,7 @@ const AIBanner = (props: AIBannerProps): ReactElement => {
aiText,
description,
onActionButtonClick,
readonly,
title,
titleLabel
} = props;
Expand Down Expand Up @@ -81,6 +83,7 @@ const AIBanner = (props: AIBannerProps): ReactElement => {
onClick={ onActionButtonClick }
color="primary"
variant="contained"
disabled={ readonly }
>
{ actionButtonText }
</Button>
Expand All @@ -90,4 +93,12 @@ const AIBanner = (props: AIBannerProps): ReactElement => {
);
};

/**
* Default props for the component.
*/
AIBanner.defaultProps = {
"data-componentid": "ai-banner",
readonly: false
};

export default AIBanner;

0 comments on commit b482419

Please sign in to comment.