Skip to content

Commit

Permalink
Merge pull request #7044 from brionmario/feat-multi-tenancy-issues-25-10
Browse files Browse the repository at this point in the history
Support reading `tenant_mgt.tenant_deletion` in Tenants feature
  • Loading branch information
brionmario authored Oct 25, 2024
2 parents c756b12 + 03b93c2 commit 17c3610
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-wombats-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wso2is/console": patch
---

Support reading `tenant_mgt.tenant_deletion`
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,9 @@
{% if console.tenants is defined %}
"tenants": {
"disabledFeatures": [
{% if tenant_mgt.tenant_deletion is not defined or tenant_mgt.tenant_deletion == false %}
"tenants.deletion"{{ "," if console.tenants.disabled_features is defined }}
{% endif %}
{% if console.tenants.disabled_features is defined %}
{% for feature in console.tenants.disabled_features %}
"{{ feature }}"{{ "," if not loop.last }}
Expand Down
1 change: 1 addition & 0 deletions apps/console/src/public/deployment.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@
"tenants": {
"disabledFeatures": [
"tenants.add.tenant.from.dropdown",
"tenants.deletion",
"tenants.make.default",
"tenants.organizations.quick.nav.from.dropdown"
],
Expand Down
25 changes: 18 additions & 7 deletions features/admin.tenants.v1/components/edit-tenant/edit-tenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ import Button from "@oxygen-ui/react/Button";
import Card from "@oxygen-ui/react/Card";
import Collapse from "@oxygen-ui/react/Collapse";
import Stack from "@oxygen-ui/react/Stack";
import { AppState } from "@wso2is/admin.core.v1";
import { IdentifiableComponentInterface } from "@wso2is/core/models";
import { DangerZone, DangerZoneGroup } from "@wso2is/react-components";
import React, { FunctionComponent, ReactElement, useMemo } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import EditTenantForm from "./edit-tenant-form";
import TenantConstants from "../../constants/tenant-constants";
import useTenants from "../../hooks/use-tenants";
import { Tenant } from "../../models/tenants";
import "./edit-tenant.scss";
Expand All @@ -53,6 +56,12 @@ const EditTenant: FunctionComponent<EditTenantProps> = ({
}: EditTenantProps): ReactElement => {
const { t } = useTranslation();

const isTenantDeletionEnabled: boolean = useSelector((state: AppState) => {
return !state?.config?.ui?.features?.tenants?.disabledFeatures?.includes(
TenantConstants.FEATURE_DICTIONARY.TENANT_DELETION
);
});

const { deleteTenant, disableTenant, enableTenant } = useTenants();

const showDisabledAlert: boolean = useMemo(() => {
Expand Down Expand Up @@ -98,13 +107,15 @@ const EditTenant: FunctionComponent<EditTenantProps> = ({
onActionClick={ (): void => disableTenant(tenant) }
/>
) }
<DangerZone
data-componentid={ `${componentId}-danger-zone-delete` }
actionTitle={ t("tenants:editTenant.dangerZoneGroup.delete.actionTitle") }
header={ t("tenants:editTenant.dangerZoneGroup.delete.header") }
subheader={ t("tenants:editTenant.dangerZoneGroup.delete.subheader") }
onActionClick={ (): void => deleteTenant(tenant) }
/>
{ isTenantDeletionEnabled && (
<DangerZone
data-componentid={ `${componentId}-danger-zone-delete` }
actionTitle={ t("tenants:editTenant.dangerZoneGroup.delete.actionTitle") }
header={ t("tenants:editTenant.dangerZoneGroup.delete.header") }
subheader={ t("tenants:editTenant.dangerZoneGroup.delete.subheader") }
onActionClick={ (): void => deleteTenant(tenant) }
/>
) }
</DangerZoneGroup>
</Stack>
);
Expand Down
26 changes: 17 additions & 9 deletions features/admin.tenants.v1/components/tenant-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import moment from "moment";
import React, { FunctionComponent, ReactElement, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useSelector } from "react-redux";
import TenantConstants from "../constants/tenant-constants";
import useTenants from "../hooks/use-tenants";
import { Tenant } from "../models/tenants";
import "./tenant-card.scss";
Expand Down Expand Up @@ -74,6 +75,11 @@ const TenantCard: FunctionComponent<TenantCardProps> = ({
const { t } = useTranslation();

const clientHost: string = useSelector((state: AppState) => state.config?.deployment?.clientHost);
const isTenantDeletionEnabled: boolean = useSelector((state: AppState) => {
return !state?.config?.ui?.features?.tenants?.disabledFeatures?.includes(
TenantConstants.FEATURE_DICTIONARY.TENANT_DELETION
);
});

const { deleteTenant, disableTenant, enableTenant } = useTenants();

Expand Down Expand Up @@ -245,15 +251,17 @@ const TenantCard: FunctionComponent<TenantCardProps> = ({
: t("tenants:status.activate") }
</ListItemText>
</MenuItem>
<MenuItem
className="tenant-card-footer-dropdown-item error"
onClick={ () => deleteTenant(tenant) }
>
<ListItemIcon>
<TrashIcon size={ 14 } />
</ListItemIcon>
<ListItemText>{ t("tenants:listing.item.actions.delete.label") }</ListItemText>
</MenuItem>
{ isTenantDeletionEnabled && (
<MenuItem
className="tenant-card-footer-dropdown-item error"
onClick={ () => deleteTenant(tenant) }
>
<ListItemIcon>
<TrashIcon size={ 14 } />
</ListItemIcon>
<ListItemText>{ t("tenants:listing.item.actions.delete.label") }</ListItemText>
</MenuItem>
) }
</Menu>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion features/admin.tenants.v1/constants/tenant-constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ export default class TenantConstants {
MAKING_TENANTS_DEFAULT: string;
MANAGING_TENANTS_FROM_DROPDOWN: string;
ORGANIZATIONS_QUICK_NAV_FROM_DROPDOWN: string;
TENANT_DELETION: string;
} = {
ADD_TENANTS_FROM_DROPDOWN: "tenants.add.tenant.from.dropdown",
MAKING_TENANTS_DEFAULT: "tenants.make.default",
MANAGING_TENANTS_FROM_DROPDOWN: "tenants.manage.tenants.from.dropdown",
ORGANIZATIONS_QUICK_NAV_FROM_DROPDOWN: "tenants.organizations.quick.nav.from.dropdown"
ORGANIZATIONS_QUICK_NAV_FROM_DROPDOWN: "tenants.organizations.quick.nav.from.dropdown",
TENANT_DELETION: "tenants.deletion"
};
}

0 comments on commit 17c3610

Please sign in to comment.