Skip to content

Commit

Permalink
Improve organization discovery feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashmini committed Oct 27, 2023
1 parent 133ea5c commit 20e2995
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Chip from "@oxygen-ui/react/Chip";
import FormHelperText from "@oxygen-ui/react/FormHelperText";
import InputLabel from "@oxygen-ui/react/InputLabel";
import TextField from "@oxygen-ui/react/TextField";
import { hasRequiredScopes } from "@wso2is/core/helpers";
import {
AlertLevels,
IdentifiableComponentInterface,
Expand All @@ -39,13 +40,13 @@ import {
} from "@wso2is/form";
import { EmphasizedSegment, Hint, PrimaryButton } from "@wso2is/react-components";
import isEmpty from "lodash-es/isEmpty";
import React, { FunctionComponent, ReactElement, SyntheticEvent, useMemo, useState } from "react";
import React, { FunctionComponent, ReactElement, SyntheticEvent, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { Dispatch } from "redux";
import { AppState, FeatureConfigInterface } from "../../core";
import { AppConstants } from "../../core/constants/app-constants";
import { history } from "../../core/helpers/history";
import { FeatureConfigInterface } from "../../core/models/config";
import useGetOrganizations from "../../organizations/api/use-get-organizations";
import { OrganizationInterface } from "../../organizations/models/organizations";
import addOrganizationEmailDomain from "../api/add-organization-email-domains";
Expand Down Expand Up @@ -90,17 +91,35 @@ const FORM_ID: string = "edit-organization-email-domains-form";
const AddOrganizationDiscoveryDomains: FunctionComponent<AddOrganizationDiscoveryDomainsPropsInterface> = (
props: AddOrganizationDiscoveryDomainsPropsInterface
): ReactElement => {
const { ["data-componentid"]: componentId } = props;
const {
isReadOnly,
["data-componentid"]: componentId
} = props;

const { t } = useTranslation();

const dispatch: Dispatch = useDispatch();

const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes);
const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features);

const { data: organizations } = useGetOrganizations(true, null, null, null, null, true);

const { data: discoverableOrganizations } = useGetOrganizationDiscovery(true, null, null, null);

const [ emailDomains, setEmailDomains ] = useState<string[]>([]);
const [ hasScopes, setHasScopes ] = useState(false);

/**
* Set the hasScopes state based on the feature config.
*/
useEffect(() => {
setHasScopes(
!hasRequiredScopes(
featureConfig?.organizationDiscovery,
featureConfig?.organizationDiscovery?.scopes?.update,
allowedScopes));
}, [ featureConfig ]);

/**
* Filter the already configured organizations from the list of organizations.
Expand Down Expand Up @@ -273,17 +292,19 @@ const AddOrganizationDiscoveryDomains: FunctionComponent<AddOrganizationDiscover
</FormHelperText>
<FormSpy subscription={ { values: true } }>
{ ({ values }: { values: AddOrganizationDiscoveryDomainsFormValuesInterface }) => (
<PrimaryButton
data-componentid={ `${componentId}-form-submit-button` }
disabled={
submitting || isEmpty(emailDomains) || isEmpty(values?.organizationName)
}
loading={ submitting }
type="submit"
style={ { marginTop: "20px" } }
>
{ t("common:update") }
</PrimaryButton>
!isReadOnly && !hasScopes && (
<PrimaryButton
data-componentid={ `${componentId}-form-submit-button` }
disabled={
submitting || isEmpty(emailDomains) || isEmpty(values?.organizationName)
}
loading={ submitting }
type="submit"
style={ { marginTop: "20px" } }
>
{ t("console:manage.features.organizationDiscovery.assign.buttons.assign") }
</PrimaryButton>
)
) }
</FormSpy>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const DiscoverableOrganizationsList: FunctionComponent<DiscoverableOrganizations
t("console:manage.placeholders.emptySearchResult.subtitles.0", {
// searchQuery looks like "name co OrganizationName", so we only remove the filter string
// only to get the actual user entered query
query: searchQuery.split("organizationName co ")[1]
query: searchQuery.split(" ").pop()
}),
t("console:manage.placeholders.emptySearchResult.subtitles.1")
] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Chip from "@oxygen-ui/react/Chip";
import FormHelperText from "@oxygen-ui/react/FormHelperText";
import InputLabel from "@oxygen-ui/react/InputLabel";
import TextField from "@oxygen-ui/react/TextField";
import { hasRequiredScopes } from "@wso2is/core/helpers";
import {
AlertLevels,
IdentifiableComponentInterface,
Expand All @@ -34,9 +35,9 @@ import { FinalForm, FinalFormField, FormRenderProps, TextFieldAdapter } from "@w
import { ContentLoader, EmphasizedSegment, Hint, PrimaryButton } from "@wso2is/react-components";
import React, { FunctionComponent, ReactElement, SyntheticEvent, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { Dispatch } from "redux";
import { FeatureConfigInterface } from "../../core";
import { AppState, FeatureConfigInterface } from "../../core";
import updateOrganizationDiscoveryAttributes from "../api/update-organization-email-domains";
import {
OrganizationDiscoveryAttributeDataInterface,
Expand Down Expand Up @@ -101,7 +102,11 @@ const EditOrganizationDiscoveryDomains: FunctionComponent<EditOrganizationDiscov

const dispatch: Dispatch<any> = useDispatch();

const allowedScopes: string = useSelector((state: AppState) => state?.auth?.allowedScopes);
const featureConfig: FeatureConfigInterface = useSelector((state: AppState) => state.config.ui.features);

const [ emailDomains, setEmailDomains ] = useState<string[]>([]);
const [ hasScopes, setHasScopes ] = useState(false);

const optionsArray: string[] = [];

Expand All @@ -113,6 +118,17 @@ const EditOrganizationDiscoveryDomains: FunctionComponent<EditOrganizationDiscov
setEmailDomains(organizationDiscoveryAttributes?.attributes[0]?.values ?? []);
}, [ organizationDiscoveryAttributes ]);

/**
* Set the hasScopes state based on the feature config.
*/
useEffect(() => {
setHasScopes(
!hasRequiredScopes(
featureConfig?.organizationDiscovery,
featureConfig?.organizationDiscovery?.scopes?.update,
allowedScopes));
}, [ featureConfig, organization ]);

/**
* Function to handle the form submit action.
*
Expand Down Expand Up @@ -264,7 +280,7 @@ const EditOrganizationDiscoveryDomains: FunctionComponent<EditOrganizationDiscov
) }
</Hint>
</FormHelperText>
{ !isReadOnly && (
{ !isReadOnly && !hasScopes && (
<PrimaryButton
data-componentid={ `${componentId}-form-save-button` }
disabled={ submitting }
Expand Down
3 changes: 3 additions & 0 deletions modules/i18n/src/models/namespaces/console-ns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,9 @@ export interface ConsoleNS {
hint: string;
}
}
},
buttons: {
assign: string;
}
},
emailDomains: {
Expand Down
27 changes: 15 additions & 12 deletions modules/i18n/src/translations/en-US/portals/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9390,6 +9390,9 @@ export const console: ConsoleNS = {
hint: "Enter the name of the organization you wish to add the domain mapping."
}
}
},
buttons: {
assign: "Assign"
}
},
emailDomains: {
Expand Down Expand Up @@ -9422,56 +9425,56 @@ export const console: ConsoleNS = {
message: "Adding unsuccessful"
},
success: {
description: "Email domains added successfully",
description: "Email domains added successfully.",
message: "Added successfully"
}
},
disableEmailDomainDiscovery: {
error: {
description: "An error occurred while disabling email domain discovery",
description: "An error occurred while disabling email domain discovery.",
message: "Disabling unsuccessful"
},
success: {
description: "Successfully disabled email domain discovery",
description: "Successfully disabled email domain discovery.",
message: "Disabled successfully"
}
},
enableEmailDomainDiscovery: {
error: {
description: "An error occurred while enabling email domain discovery",
description: "An error occurred while enabling email domain discovery.",
message: "Enabling unsuccessful"
},
success: {
description: "Successfully enabled email domain discovery",
description: "Successfully enabled email domain discovery.",
message: "Enabled successfully"
}
},
fetchOrganizationDiscoveryAttributes: {
error: {
description: "An error occurred while fetching the organization discovery attributes",
description: "An error occurred while fetching the organization discovery attributes.",
message: "Retrieval unsuccessful"
}
},
getEmailDomainDiscovery: {
error: {
description: "An error occurred while retrieving email domain discovery configuration",
description: "An error occurred while retrieving email domain discovery configuration.",
message: "Retrieval unsuccessful"
}
},
getOrganizationListWithDiscovery: {
error: {
description: "An error occurred while getting the organization list with discovery attributes",
description: "An error occurred while getting the organization list with discovery attributes.",
message: "Retrieval unsuccessful"
}
},
updateOrganizationDiscoveryAttributes: {
error: {
description: "An error occurred while updating the organization discovery attributes",
message: "Updated unsuccessful"
description: "An error occurred while updating the organization discovery attributes.",
message: "Update unsuccessful"
},
success: {
description: "Successfully updated the organization discovery attributes",
message: "Updated successful"
description: "Successfully updated the organization discovery attributes.",
message: "Update successful"
}
}
},
Expand Down
45 changes: 24 additions & 21 deletions modules/i18n/src/translations/fr-FR/portals/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7619,6 +7619,9 @@ export const console: ConsoleNS = {
hint: "Entrez le nom de l'organisation que vous souhaitez ajouter le mappage de domaine."
}
}
},
buttons: {
assign: "Attribuer"
}
},
emailDomains: {
Expand Down Expand Up @@ -7648,59 +7651,59 @@ export const console: ConsoleNS = {
addEmailDomains: {
error: {
description: "L'ajout des domaines de messagerie à l'organisation a échoué.",
message: "Impossible d'ajouter des domaines de messagerie"
message: "Ajout échoué"
},
success: {
description: "Les domaines de messagerie ajoutés avec succès",
message: "Ajout avec succès les domaines de messagerie à l'organisation."
description: "Domaines de messagerie ajoutés avec succès.",
message: "Ajouté avec succès"
}
},
disableEmailDomainDiscovery: {
error: {
description: "Erreur lors de la désactivation de la découverte de domaine de messagerie",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de la désactivation de la découverte de domaines de messagerie.",
message: "Désactivation échouée"
},
success: {
description: "La découverte du domaine de messagerie a été désactivée avec succès",
message: "La découverte du domaine de messagerie a été désactivée avec succès"
description: "La découverte du domaine de messagerie a été désactivée avec succès.",
message: "Désactivé avec succès"
}
},
enableEmailDomainDiscovery: {
error: {
description: "Une erreur s'est produite lors de l'activation de la découverte de domaines de messagerie",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de l'activation de la découverte de domaines de messagerie.",
message: "Activation échouée"
},
success: {
description: "La découverte du domaine de messagerie a été activée avec succès",
message: "La découverte du domaine de messagerie a été activée avec succès"
description: "La découverte du domaine de messagerie a été activée avec succès.",
message: "Activé avec succès"
}
},
fetchOrganizationDiscoveryAttributes: {
error: {
description: "Une erreur s'est produite lors de la récupération des attributs de découverte de l'organisation",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de la récupération des attributs de découverte de l'organisation.",
message: "Récupération échouée"
}
},
getEmailDomainDiscovery: {
error: {
description: "Une erreur s'est produite lors de la récupération de la configuration de la découverte du domaine de messagerie",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de la récupération de la configuration de la découverte du domaine de messagerie.",
message: "Récupération échouée"
}
},
getOrganizationListWithDiscovery: {
error: {
description: "Une erreur s'est produite lors de l'obtention de la liste des organisations avec les attributs de découverte",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de l'obtention de la liste des organisations avec les attributs de découverte.",
message: "Récupération échouée"
}
},
updateOrganizationDiscoveryAttributes: {
error: {
description: "Une erreur s'est produite lors de la mise à jour des attributs de découverte de l'organisation",
message: "Quelque chose s'est mal passé"
description: "Une erreur s'est produite lors de la mise à jour des attributs de découverte de l'organisation.",
message: "Échec de la mise à jour"
},
success: {
description: "Mise à jour réussie des attributs de découverte de l'organisation",
message: "Attributs de découverte d'organisation mis à jour avec succès"
description: "Mise à jour réussie des attributs de découverte de l'organisation.",
message: "Mise à jour réussie"
}
}
},
Expand Down
Loading

0 comments on commit 20e2995

Please sign in to comment.