Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor rules feature with new rules execution object contract + eslint license header rule update to support 2025 #7300

Open
wants to merge 8 commits into
base: new-signup
Choose a base branch
from
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const getLicenseHeaderPattern = () => {
const LICENSE_HEADER_DEFAULT_PATTERN = [
"*",
{
pattern: " Copyright \\(c\\) \\b(2019|202[0-4])(?:-(202[0-4]))?, WSO2 LLC. \\(https://www.wso2.com\\).$",
pattern: " Copyright \\(c\\) \\b(2019|202[0-5])(?:-(202[0-5]))?, WSO2 LLC. \\(https://www.wso2.com\\).$",
template: " * Copyright (c) {{year}}, WSO2 LLC. (https://www.wso2.com)."
},
" *",
Expand Down
25 changes: 13 additions & 12 deletions features/admin.actions.v1/components/action-config-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { FeatureAccessConfigInterface, useRequiredScopes } from "@wso2is/access-
import { AppState } from "@wso2is/admin.core.v1";
import useGetRulesMeta from "@wso2is/admin.rules.v1/api/use-get-rules-meta";
import RulesComponent from "@wso2is/admin.rules.v1/components/rules-component";
import { RuleInterface } from "@wso2is/admin.rules.v1/models/rules";
import { RuleExecuteCollectionInterface } from "@wso2is/admin.rules.v1/models/rules";
import { getRuleInstanceValue } from "@wso2is/admin.rules.v1/providers/rules-provider";
import { AlertLevels, IdentifiableComponentInterface } from "@wso2is/core/models";
import { addAlert } from "@wso2is/core/store";
Expand Down Expand Up @@ -111,10 +111,18 @@ const ActionConfigForm: FunctionComponent<ActionConfigFormInterface> = ({
} = useGetActionsByType(actionTypeApiPath);

const {
data: RulesMeta
data: RuleExpressionsMetaData
} = useGetRulesMeta(actionTypeApiPath);

const showRulesComponent: boolean = false;
// TODO: Remove this temporary boolean once the management API is ready.
const showRulesComponent: boolean = true;

// TODO: Use this function to get the rule value.
/* eslint-disable @typescript-eslint/no-unused-vars */
const handleGetRuleValue = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handleGetRuleValue = () => {
const handleGetRuleValue = (): void => {

const ruleValue: RuleExecuteCollectionInterface = getRuleInstanceValue();
};
/* eslint-enable @typescript-eslint/no-unused-vars */

/**
* The following useEffect is used to set the current Action Authentication Type.
Expand All @@ -128,13 +136,6 @@ const ActionConfigForm: FunctionComponent<ActionConfigFormInterface> = ({
}
}, [ initialValues ]);

// TODO: Use this function to get the rule value.
/* eslint-disable @typescript-eslint/no-unused-vars */
const handleGetRuleValue = () => {
const ruleValue: RuleInterface[] = getRuleInstanceValue();
};
/* eslint-enable @typescript-eslint/no-unused-vars */

const renderInputAdornmentOfSecret = (showSecret: boolean, onClick: () => void): ReactElement => (
<InputAdornment position="end">
<Icon
Expand Down Expand Up @@ -739,10 +740,10 @@ const ActionConfigForm: FunctionComponent<ActionConfigFormInterface> = ({
{ t("actions:fields.authentication.label") }
</Heading>
{ renderAuthenticationSection() }
{ (RulesMeta && showRulesComponent) && (
{ (RuleExpressionsMetaData && showRulesComponent) && (
<>
<Divider className="divider-container" />
<RulesComponent metaData={ RulesMeta } />
<RulesComponent conditionExpressionsMetaData={ RuleExpressionsMetaData } />
</>
) }
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import Stack from "@oxygen-ui/react/Stack";
import Typography from "@oxygen-ui/react/Typography";
import useGetRulesMeta from "@wso2is/admin.rules.v1/api/use-get-rules-meta";
import RulesComponent from "@wso2is/admin.rules.v1/components/rules-component";
import { sampleExecutionsList } from "@wso2is/admin.rules.v1/data";
import {
sampleExpressionsMeta,
sampleRuleExecuteInstances,
sampleRuleExecutionMeta
} from "@wso2is/admin.rules.v1/data";
import { RuleExecuteCollectionInterface } from "@wso2is/admin.rules.v1/models/rules";
import { getRuleInstanceValue } from "@wso2is/admin.rules.v1/providers/rules-provider";
import { IdentifiableComponentInterface } from "@wso2is/core/models";
import React, { FunctionComponent, ReactElement } from "react";
import "./rules-properties.scss";
Expand All @@ -33,30 +39,51 @@ import "./rules-properties.scss";
export interface RulesPropertiesPropsInterface extends IdentifiableComponentInterface { }

/**
* Component to generate the properties for the attribute collector widget.
* Rules properties component.
*
* @param props - Props injected to the component.
* @returns The RulesProperties component.
* @returns Rules properties component.
*/
const RulesProperties: FunctionComponent<RulesPropertiesPropsInterface> = ({
["data-componentid"]: componentId = "rules-properties-component"
}: RulesPropertiesPropsInterface): ReactElement => {

// TODO: Change the glow value
// TODO: Change to collect dynamic value from the context
const {
data: RulesMeta
data: RuleExpressionsMetaData
} = useGetRulesMeta("preIssueAccessToken");

// TODO: Use this function to get the rule value.
/* eslint-disable @typescript-eslint/no-unused-vars */
const handleGetRuleValue = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const handleGetRuleValue = () => {
const handleGetRuleValue = (): void => {

const ruleValue: RuleExecuteCollectionInterface = getRuleInstanceValue();

// eslint-disable-next-line no-console
console.log(ruleValue);
};
/* eslint-enable @typescript-eslint/no-unused-vars */

return (
<Stack gap={ 2 } data-componentid={ componentId }>
<Typography variant="body2">
Define a rule to how conditionally proceed to next steps in the flow
</Typography>
{ RulesMeta &&
<RulesComponent metaData={ RulesMeta } multipleRules={ true } ruleExecutions={ sampleExecutionsList } />
}
{ RuleExpressionsMetaData && (
<RulesComponent
initialData={ sampleRuleExecuteInstances }
conditionExpressionsMetaData={ sampleExpressionsMeta }
isMultipleRules={ true }
ruleExecutionMetaData={ sampleRuleExecutionMeta } />
) }
<Box sx={ { mt: 3 } }>
<Button size="small" variant="contained" color="primary">Save</Button>
<Button
size="small"
variant="contained"
color="primary"
onClick={ handleGetRuleValue }
>
Print Data
</Button>
</Box>
</Stack>
);
Expand Down
4 changes: 2 additions & 2 deletions features/admin.rules.v1/api/use-get-rules-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import useRequest, {
} from "@wso2is/admin.core.v1/hooks/use-request";
import { store } from "@wso2is/admin.core.v1/store";
import { HttpMethods } from "@wso2is/core/models";
import { RuleComponentMetaDataInterface } from "../models/rules";
import { ConditionExpressionsMetaDataInterface } from "../models/meta";

/**
* Hook to get the rules meta data.
Expand All @@ -38,7 +38,7 @@ import { RuleComponentMetaDataInterface } from "../models/rules";
* @param shouldFetch - Should fetch the data.
* @returns SWR response object containing the data, error, isLoading, isValidating, mutate.
*/
const useGetRulesMeta = <Data = RuleComponentMetaDataInterface, Error = RequestErrorInterface>(
const useGetRulesMeta = <Data = ConditionExpressionsMetaDataInterface, Error = RequestErrorInterface>(
flow: string,
shouldFetch: boolean = true
): RequestResultInterface<Data, Error> => {
Expand Down
Loading
Loading