Skip to content

Commit

Permalink
Merge pull request #7140 from dasuni-30/fix/27350
Browse files Browse the repository at this point in the history
Fix saving issue when a custom layout is not configured for application branding
  • Loading branch information
dasuni-30 authored Dec 3, 2024
2 parents c79eb43 + d75068c commit 415fd49
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .changeset/strong-stingrays-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@wso2is/admin.branding.v1": patch
"@wso2is/console": patch
---

Fix saving issue when a custom layout is not configured for application branding
1 change: 1 addition & 0 deletions apps/console/src/extensions/i18n/models/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,7 @@ export interface Extensions {
};
fetch: {
customLayoutNotFound: {
appBrandingDescription: string;
description: string;
message: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,7 @@ export const extensions: Extensions = {
fetch: {
customLayoutNotFound: {
description: "There is no deployed custom layout for {{ tenant }}.",
appBrandingDescription: "There is no deployed custom layout for this application.",
message: "Couldn't activate the custom layout"
},
genericError: {
Expand Down
26 changes: 19 additions & 7 deletions features/admin.branding.v1/api/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import useRequest, {
RequestResultInterface
} from "@wso2is/admin.core.v1/hooks/use-request";
import { HttpMethods } from "@wso2is/core/models";
import { BrandingModes } from "../constants";
import { PredefinedLayouts } from "../meta";

/**
Expand All @@ -37,7 +38,9 @@ import { PredefinedLayouts } from "../meta";
export const useLayout = <Data = Blob, Error = RequestErrorInterface>(
layout: PredefinedLayouts,
tenantDomain: string,
shouldFetch: boolean = true
shouldFetch: boolean = true,
brandingMode?: BrandingModes,
appName?: string
): RequestResultInterface<Data, Error> => {
const basename: string = AppConstants.getAppBasename()
? `/${AppConstants.getAppBasename()}`
Expand All @@ -52,12 +55,21 @@ export const useLayout = <Data = Blob, Error = RequestErrorInterface>(
responseType: "blob",
url:
layout === PredefinedLayouts.CUSTOM
? `${
Config.getDeploymentConfig().extensions?.layoutStoreURL
? (Config.getDeploymentConfig().extensions.layoutStoreURL as string)
.replace("${tenantDomain}", tenantDomain)
: `https://${window.location.host}${basename}/libs/login-portal-layouts`}/body.html`
: `https://${window.location.host}${basename}/libs/login-portal-layouts/${layout}/body.html`
? (
brandingMode === BrandingModes.APPLICATION
? (
`${Config.getDeploymentConfig().extensions?.layoutStoreURL
? (Config.getDeploymentConfig().extensions.layoutStoreURL as string)
.replace("${tenantDomain}", tenantDomain)
: `https://${window.location.host}
${basename}/libs/login-portal-layouts`}/apps/${appName}/body.html`
) : (
`${Config.getDeploymentConfig().extensions?.layoutStoreURL
? (Config.getDeploymentConfig().extensions.layoutStoreURL as string)
.replace("${tenantDomain}", tenantDomain)
: `https://${window.location.host}${basename}/libs/login-portal-layouts`}/body.html`
)
) : (`https://${window.location.host}${basename}/libs/login-portal-layouts/${layout}/body.html`)
};

const {
Expand Down
1 change: 1 addition & 0 deletions features/admin.branding.v1/components/branding-core.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ const BrandingCore: FunctionComponent<BrandingCoreInterface> = (
onPreviewResize={ (width: number): void => {
setCurrentWidth(width);
} }
appName= { resolvedName }
/>
<ConfirmationModal
onClose={ (): void => setShowBrandingPublishStatusConfirmationModal(false) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ interface BrandingPreferenceTabsInterface extends IdentifiableComponentInterface
* On preview resize callback.
*/
onPreviewResize: (width: number) => void;
/**
* Name of the application
*/
appName?: string;
}

/**
Expand All @@ -130,6 +134,7 @@ export const BrandingPreferenceTabs: FunctionComponent<BrandingPreferenceTabsInt
isSplitView,
isUpdating,
readOnly,
appName,
onSubmit,
onLayoutChange,
onPreviewResize
Expand Down Expand Up @@ -275,6 +280,7 @@ export const BrandingPreferenceTabs: FunctionComponent<BrandingPreferenceTabsInt
onLayoutChange(values);
} }
readOnly={ readOnly }
appName={ appName }
data-componentid="branding-preference-design-form"
/>
</Segment>
Expand Down
29 changes: 22 additions & 7 deletions features/admin.branding.v1/components/design/design-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ interface DesignFormPropsInterface extends IdentifiableComponentInterface {
* Is readonly.
*/
readOnly?: boolean;
/**
* Application name.
*/
appName?: string;
/**
* Ref for the form.
*/
Expand Down Expand Up @@ -149,6 +153,7 @@ export const DesignForm: FunctionComponent<DesignFormPropsInterface> = forwardRe
isLoading,
onSubmit,
readOnly,
appName,
["data-componentid"]: componentId
} = props;

Expand Down Expand Up @@ -190,15 +195,21 @@ export const DesignForm: FunctionComponent<DesignFormPropsInterface> = forwardRe
*/
const [ layoutDesignExtensionsName, setLayoutDesignExtensionsName ] = useState<string>(null);

const {
data: customLayoutBlob,
isLoading: customLayoutLoading
} = useLayout(PredefinedLayouts.CUSTOM, tenantDomain, commonConfig?.checkCustomLayoutExistanceBeforeEnabling);

const {
brandingMode
} = useBrandingPreference();

const {
data: customLayoutBlob,
isLoading: customLayoutLoading
} = useLayout(
PredefinedLayouts.CUSTOM,
tenantDomain,
commonConfig?.checkCustomLayoutExistanceBeforeEnabling,
brandingMode as BrandingModes,
appName
);

/**
* Set the internal initial theme state.
*/
Expand Down Expand Up @@ -351,8 +362,12 @@ export const DesignForm: FunctionComponent<DesignFormPropsInterface> = forwardRe
} else {
dispatch(addAlert<AlertInterface>({
description:
t("extensions:develop.branding.notifications.fetch.customLayoutNotFound.description",
{ tenant: tenantDomain }),
brandingMode === BrandingModes.APPLICATION
? t("extensions:develop.branding.notifications.fetch.customLayoutNotFound."
+ "appBrandingDescription")
: t("extensions:develop.branding.notifications.fetch.customLayoutNotFound.description",
{ tenant: tenantDomain })
,
level: AlertLevels.ERROR,
message: t("extensions:develop.branding.notifications.fetch.customLayoutNotFound.message")
}));
Expand Down

0 comments on commit 415fd49

Please sign in to comment.