Policy selector fix (#2123)
This commit is contained in:
@@ -35,8 +35,9 @@ import api from "../../../common/api";
|
||||
import TableWrapper from "../Common/TableWrapper/TableWrapper";
|
||||
import SearchBox from "../Common/SearchBox";
|
||||
import { setModalErrorSnackMessage } from "../../../systemSlice";
|
||||
import { useAppDispatch } from "../../../store";
|
||||
import { AppState, useAppDispatch } from "../../../store";
|
||||
import { setSelectedPolicies } from "../Users/AddUsersSlice";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface ISelectPolicyProps {
|
||||
classes: any;
|
||||
@@ -84,9 +85,11 @@ const PolicySelectors = ({
|
||||
const [loading, isLoading] = useState<boolean>(false);
|
||||
const [filter, setFilter] = useState<string>("");
|
||||
|
||||
const currentPolicies = useSelector((state: AppState) => state.createUser.selectedPolicies);
|
||||
|
||||
const fetchPolicies = useCallback(() => {
|
||||
isLoading(true);
|
||||
|
||||
|
||||
api
|
||||
.invoke("GET", `/api/v1/policies?limit=1000`)
|
||||
.then((res: PolicyList) => {
|
||||
@@ -112,11 +115,12 @@ const PolicySelectors = ({
|
||||
}, [loading, fetchPolicies]);
|
||||
|
||||
const selectionChanged = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
const targetD = e.target;
|
||||
const value = targetD.value;
|
||||
const checked = targetD.checked;
|
||||
|
||||
let elements: string[] = [...selectedPolicy]; // We clone the checkedUsers array
|
||||
|
||||
let elements: string[] = [...currentPolicies]; // We clone the checkedUsers array
|
||||
|
||||
if (checked) {
|
||||
// If the user has checked this field we need to push this to checkedUsersList
|
||||
@@ -127,7 +131,7 @@ const PolicySelectors = ({
|
||||
}
|
||||
// remove empty values
|
||||
elements = elements.filter((element) => element !== "");
|
||||
|
||||
|
||||
dispatch(setSelectedPolicies(elements));
|
||||
};
|
||||
|
||||
@@ -162,7 +166,7 @@ const PolicySelectors = ({
|
||||
<TableWrapper
|
||||
columns={[{ label: "Policy", elementKey: "name" }]}
|
||||
onSelect={selectionChanged}
|
||||
selectedItems={selectedPolicy}
|
||||
selectedItems={currentPolicies}
|
||||
isLoading={loading}
|
||||
records={filteredRecords}
|
||||
entityName="Policies"
|
||||
|
||||
@@ -36,7 +36,9 @@ import PolicySelectors from "./PolicySelectors";
|
||||
import PredefinedList from "../Common/FormComponents/PredefinedList/PredefinedList";
|
||||
import { encodeURLString } from "../../../common/utils";
|
||||
import { setModalErrorSnackMessage } from "../../../systemSlice";
|
||||
import { useAppDispatch } from "../../../store";
|
||||
import { AppState, useAppDispatch } from "../../../store";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface ISetPolicyProps {
|
||||
classes: any;
|
||||
@@ -46,6 +48,8 @@ interface ISetPolicyProps {
|
||||
open: boolean;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const styles = (theme: Theme) =>
|
||||
createStyles({
|
||||
...modalBasic,
|
||||
@@ -72,7 +76,7 @@ const SetPolicy = ({
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [actualPolicy, setActualPolicy] = useState<string[]>([]);
|
||||
const [selectedPolicy, setSelectedPolicy] = useState<string[]>([]);
|
||||
|
||||
const currentPolicies = useSelector((state: AppState) => state.createUser.selectedPolicies);
|
||||
const setPolicyAction = () => {
|
||||
let users = null;
|
||||
let groups = null;
|
||||
@@ -88,7 +92,7 @@ const SetPolicy = ({
|
||||
|
||||
api
|
||||
.invoke("PUT", `/api/v1/set-policy-multi`, {
|
||||
name: selectedPolicy,
|
||||
name: currentPolicies,
|
||||
groups: groups,
|
||||
users: users,
|
||||
})
|
||||
|
||||
@@ -28,7 +28,8 @@ import ModalWrapper from "../Common/ModalWrapper/ModalWrapper";
|
||||
import api from "../../../common/api";
|
||||
import PolicySelectors from "../Policies/PolicySelectors";
|
||||
import { setModalErrorSnackMessage } from "../../../systemSlice";
|
||||
import { useAppDispatch } from "../../../store";
|
||||
import { AppState, useAppDispatch } from "../../../store";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
interface ISetUserPoliciesProps {
|
||||
classes: any;
|
||||
@@ -60,6 +61,8 @@ const SetUserPolicies = ({
|
||||
const [actualPolicy, setActualPolicy] = useState<string[]>([]);
|
||||
const [selectedPolicy, setSelectedPolicy] = useState<string[]>([]);
|
||||
|
||||
const statePolicies = useSelector((state: AppState) => state.createUser.selectedPolicies);
|
||||
|
||||
const SetUserPoliciesAction = () => {
|
||||
let entity = "user";
|
||||
let value = selectedUser;
|
||||
@@ -68,7 +71,7 @@ const SetUserPolicies = ({
|
||||
|
||||
api
|
||||
.invoke("PUT", `/api/v1/set-policy`, {
|
||||
name: selectedPolicy,
|
||||
name: statePolicies,
|
||||
entityName: value,
|
||||
entityType: entity,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user