Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import { Alert, Badge, Button, OverlayTrigger, Popover } from "react-bootstrap";
import { Field } from "react-final-form";
import { useLocation } from "react-router-dom";
import blockLoading from "Images/blockLoading.gif";
import { toast } from "react-toastify";

const Loader = () => {
export const Loader = () => {
return (
<div className="loading-img">
<div id="center">
Expand Down Expand Up @@ -570,4 +571,11 @@ export const ModalLoader = () => {
);
};

export { Loader };
export const trimInputValue = (e, input) => {
const value = e.target.value;
const trimmed = value.trim();
if (value !== trimmed) {
input.onChange(trimmed);
}
input.onBlur(e); // Always call onBlur to trigger validation
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ const CreatableField = (props) => {
case "Enter":
case "Tab":
setActionInputValue("");
setActionValue([...actionValue, createOption(actionInputValue)]);
creatableOnChange([...actionValue, createOption(actionInputValue)]);
setActionValue([...actionValue, createOption(actionInputValue.trim())]);
creatableOnChange([
...actionValue,
createOption(actionInputValue.trim())
]);
e.preventDefault();
}
};

const createOption = (label) => ({
value: label,
label: label
value: label.trim(),
label: label.trim()
});

const handleInputChange = (value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,24 @@ const CustomCondition = (props) => {
width="500px"
isClearable={false}
styles={selectInputCustomStyles}
formatCreateLabel={(inputValue) =>
`Create "${inputValue.trim()}"`
}
onCreateOption={(inputValue) => {
const trimmedValue = inputValue.trim();
if (trimmedValue) {
const newOption = {
label: trimmedValue,
value: trimmedValue
};
const currentValues = selectedInputVal || [];
const newValues = Array.isArray(currentValues)
? [...currentValues, newOption]
: [newOption];
setSelectVal(newValues);
tagAccessData(newValues, m.name);
}
}}
/>
</Form.Group>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export const RegexValidation = {
/^([A-Za-z0-9_]|[\u00C0-\u017F])([a-z0-9,._\-+/@= ]|[\u00C0-\u017F])+$/i,
regexExpressionForFirstAndLastName:
/^([A-Za-z0-9_]|[\u00C0-\u017F])([a-zA-Z0-9\s_. -@]|[\u00C0-\u017F])+$/i,
regexforNameValidation: /^[a-zA-Z0-9_-][a-zA-Z0-9\s_-]{0,254}$/,
regexForNameValidation: /^[a-zA-Z0-9_-][a-zA-Z0-9\s_-]{0,254}$/,
regexExpressionForSecondaryName:
/^([A-Za-z0-9_]|[\u00C0-\u017F])([a-zA-Z0-9\s_. -@]|[\u00C0-\u017F])+$/i,
regexforServiceNameValidation: /^[a-zA-Z0-9_-][a-zA-Z0-9_-]{0,254}$/,
Expand All @@ -601,7 +601,7 @@ export const RegexValidation = {
3. Name length should be greater than one."
</>
),
regexforNameValidationMessage:
regexForNameValidationMessage:
"Name should not start with space, it should be less than 256 characters and special characters are not allowed(except _ - and space).",
secondaryNameValidationMessage: (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export const RegexMessage = {
</p>
</>
),
passwordvalidationinfomessage:
"Password should be minimum 8 characters ,atleast one uppercase letter, one lowercase letter and one numeric. For FIPS environment password should be minimum 14 characters with atleast one uppercase letter, one special characters, one lowercase letter and one numeric.",
emailvalidationinfomessage: (
passwordValidationInfoMessage:
"Password should be minimum 8 characters ,at least one uppercase letter, one lowercase letter and one numeric. For FIPS environment password should be minimum 14 characters with atleast one uppercase letter, one special characters, one lowercase letter and one numeric.",
emailValidationInfoMessage: (
<>
<p className="pd-10 mb-0" style={{ fontSize: "small" }}>
1. Email address should be start with alphabet / numeric / underscore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const keyCreateReducer = (state, action) => {
}
};

const PromtDialog = (props) => {
const PromptDialog = (props) => {
const { isDirtyField, isUnblock } = props;
usePrompt("Are you sure you want to leave", isDirtyField && !isUnblock);
return null;
Expand Down Expand Up @@ -225,7 +225,7 @@ function KeyCreate(props) {
}
}) => (
<div className="wrap">
<PromtDialog isDirtyField={dirty} isUnblock={preventUnBlock} />
<PromptDialog isDirtyField={dirty} isUnblock={preventUnBlock} />
<form
onSubmit={(event) => {
handleSubmit(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import {
BlockUi,
Loader,
scrollToError,
selectInputCustomStyles
selectInputCustomStyles,
trimInputValue
} from "Components/CommonComponents";
import { fetchApi } from "Utils/fetchAPI";
import { RangerPolicyType, getEnumElementByValue } from "Utils/XAEnums";
Expand All @@ -62,19 +63,20 @@ import PolicyPermissionItem from "../PolicyListing/PolicyPermissionItem";
import { useParams, useNavigate, useLocation } from "react-router-dom";
import PolicyValidityPeriodComp from "./PolicyValidityPeriodComp";
import PolicyConditionsComp from "./PolicyConditionsComp";
import { getAllTimeZoneList, policyConditionUpdatedJSON } from "Utils/XAUtils";
import moment from "moment";
import {
InfoIcon,
commonBreadcrumb,
isPolicyExpired,
getResourcesDefVal
getResourcesDefVal,
getAllTimeZoneList,
policyConditionUpdatedJSON,
policyInfo
} from "Utils/XAUtils";
import { useAccordionButton } from "react-bootstrap/AccordionButton";
import AccordionContext from "react-bootstrap/AccordionContext";
import usePrompt from "Hooks/usePrompt";
import { RegexMessage } from "Utils/XAMessages";
import { policyInfo } from "Utils/XAUtils";
import { getServiceDef } from "Utils/appState";
import { FieldArray } from "react-final-form-arrays";

Expand Down Expand Up @@ -290,16 +292,16 @@ export default function AddUpdatePolicyForm() {
const fetchPolicyLabel = async (inputValue) => {
let params = {};
if (inputValue) {
params["policyLabel"] = inputValue || "";
params["policyLabel"] = inputValue.trim() || "";
}
const policyLabelResp = await fetchApi({
url: "plugins/policyLabels",
params: params
});

return policyLabelResp.data.map((name) => ({
label: name,
value: name
label: name.trim(),
value: name.trim()
}));
};

Expand Down Expand Up @@ -387,15 +389,15 @@ export default function AddUpdatePolicyForm() {
});
}
if (policyId) {
data.policyName = policyData?.name;
data.policyName = policyData?.name?.trim();
data.isEnabled = policyData?.isEnabled;
data.policyPriority = policyData?.policyPriority == 0 ? false : true;
data.description = policyData?.description;
data.description = policyData?.description?.trim();
data.isAuditEnabled = policyData?.isAuditEnabled;
data.policyLabel =
policyData &&
policyData?.policyLabels?.map((val) => {
return { label: val, value: val };
return { label: val?.trim(), value: val?.trim() };
});
if (policyData?.resources) {
if (!isMultiResources) {
Expand All @@ -404,7 +406,7 @@ export default function AddUpdatePolicyForm() {
let setResources = find(serviceCompResourcesDetails, ["name", key]);
data[`resourceName-${setResources?.level}`] = setResources;
data[`value-${setResources?.level}`] = value.values.map((m) => {
return { label: m, value: m };
return { label: m?.trim(), value: m?.trim() };
});
if (setResources?.excludesSupported) {
data[`isExcludesSupport-${setResources?.level}`] =
Expand Down Expand Up @@ -449,7 +451,7 @@ export default function AddUpdatePolicyForm() {
setResources;
additionalResourcesObj[`value-${setResources?.level}`] =
value.values.map((m) => {
return { label: m, value: m };
return { label: m?.trim(), value: m?.trim() };
});
if (setResources?.excludesSupported) {
additionalResourcesObj[
Expand Down Expand Up @@ -888,7 +890,7 @@ export default function AddUpdatePolicyForm() {
data["conditions"] = [];
}

/* For create zoen policy*/
/* For create zone policy*/
if (localStorage.getItem("zoneDetails") != null) {
data["zoneName"] = JSON.parse(localStorage.getItem("zoneDetails")).label;
}
Expand Down Expand Up @@ -1299,6 +1301,7 @@ export default function AddUpdatePolicyForm() {
: "form-control"
}
data-cy="policyName"
onBlur={(e) => trimInputValue(e, input)}
/>
<InfoIcon
css="input-box-info-icon"
Expand Down Expand Up @@ -1389,6 +1392,23 @@ export default function AddUpdatePolicyForm() {
}}
defaultOptions={defaultPolicyLabelOptions}
styles={selectInputCustomStyles}
// Add this prop to trim the visual "Create" label
formatCreateLabel={(inputValue) =>
`Create "${inputValue.trim()}"`
}
// Add this prop to trim the value when a tag is created
onCreateOption={(inputValue) => {
const policyLabelVal = inputValue.trim();
if (policyLabelVal) {
input.onChange([
...input.value,
{
label: policyLabelVal,
value: policyLabelVal
}
]);
}
}}
/>
</Col>
</FormB.Group>
Expand Down Expand Up @@ -1421,6 +1441,7 @@ export default function AddUpdatePolicyForm() {
as="textarea"
rows={3}
data-cy="description"
onBlur={(e) => trimInputValue(e, input)}
/>
</Col>
</FormB.Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ export default function ResourceComp(props) {
delete formValues[`isRecursiveSupport-${levelKey}`];
}
delete formValues[`value-${grpResourcesKeys[index]}`];
let CurrentSelectedResourcs = selectedVal.name;
let currentSelectedResources = selectedVal.name;
for (let j = index + 1; j < grpResourcesKeys.length; j++) {
let level = grpResourcesKeys[j];
let nextResource = resources.find((m) => {
if (m?.parent) {
return m.parent === CurrentSelectedResourcs;
return m.parent === currentSelectedResources;
}
});
if (nextResource) {
formValues[`resourceName-${level}`] = nextResource;
CurrentSelectedResourcs = nextResource.name;
currentSelectedResources = nextResource.name;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function ResourceSelectComp(props) {
toastId.current = toast.error(error.response.data.msgDesc);
} else {
toastId.current = toast.error(
"Resouce lookup failed for current resource"
"Resource lookup failed for current resource"
);
}
}
Expand Down Expand Up @@ -216,6 +216,18 @@ export default function ResourceSelectComp(props) {
filterOption={customFilterOptions}
isLoading={isLoading}
styles={selectInputCustomStyles}
formatCreateLabel={(inputValue) => `Create "${inputValue.trim()}"`}
onCreateOption={(inputValue) => {
const trimmedValue = inputValue.trim();
if (trimmedValue) {
const newOption = { label: trimmedValue, value: trimmedValue };
const currentValue = input.value || [];
const newValue = isArray(currentValue)
? [...currentValue, newOption]
: [newOption];
input.onChange(newValue);
}
}}
/>
{formValues &&
formValues[`resourceName-${levelKey}`]?.mandatory &&
Expand Down
Loading
Loading