Skip to content

Commit

Permalink
RANGER-4370: Select All permissions for all components checkbox missi…
Browse files Browse the repository at this point in the history
…ng in tag based policy permission popup

Signed-off-by: Dineshkumar Yadav <dineshkumar.yadav@outlook.com>
  • Loading branch information
Brijesh619 authored and dineshkumar-yadav committed Nov 24, 2023
1 parent 3947910 commit 98558ad
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,9 @@ li.list-group-item:hover {
.Toastify__toast-icon {
width: 16px;
}
.td-padding-modal {
padding: 0.5rem 0.75rem !important;
}
.manage-service .dropdown-toggle::after {
vertical-align: 0.125em;
}
Expand All @@ -2557,5 +2560,5 @@ li.list-group-item:hover {
.resource-block {
padding: 0.5rem 0;
border-bottom: 1px solid #dddddd;
margin:1rem 2rem;
margin: 1rem 2rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {
isEmpty,
includes,
difference,
map
map,
every,
cloneDeep
} from "lodash";
import { RangerPolicyType } from "Utils/XAEnums";
import { getServiceDef } from "../../utils/appState";
Expand Down Expand Up @@ -197,6 +199,15 @@ export default function TagBasePermissionItem(props) {
);
};

const isSelectAllChecked = (values) => {
let fieldValues = !isEmpty(values) ? [...values] : [];
return !isEmpty(fieldValues)
? every(fieldValues, (p) => {
return p?.permission?.length == tagServicePerms[p.serviceName].length;
})
: false;
};

const handleChange = (e, value, input) => {
let val = [...input.value] || [];
if (e.target.checked) {
Expand All @@ -217,7 +228,22 @@ export default function TagBasePermissionItem(props) {
fieldVal.permission = val;
fields.update(index, fieldVal);
};
const selectAllPermissions = (e, values, form) => {
const { checked } = e.target;
const fieldValues = cloneDeep(values?.tableList);
if (!isEmpty(fieldValues)) {
fieldValues.filter((p) => {
let val = [];
val = tagServicePerms[p.serviceName].map(({ value }) => value);
p.permission = checked ? val : [];
});

form.batch(() => {
form.change("selectAll", checked);
form.change("tableList", fieldValues);
});
}
};
const formInitialData = () => {
let formData = {};
if (inputVal?.value?.tableList?.length > 0) {
Expand Down Expand Up @@ -307,8 +333,7 @@ export default function TagBasePermissionItem(props) {
form: {
mutators: { push, remove }
},
submitting,
pristine,
form,
values
}) => (
<form onSubmit={handleSubmit}>
Expand All @@ -318,7 +343,7 @@ export default function TagBasePermissionItem(props) {
<Modal.Body>
<Field
name="servicesDefType"
render={({ input, meta }) => (
render={({ input }) => (
<FormB.Group className="mb-3">
<b>Select Component:</b>
<Select
Expand Down Expand Up @@ -351,20 +376,40 @@ export default function TagBasePermissionItem(props) {
<Table striped bordered>
<thead>
<tr>
<th className="bg-white text-dark align-middle text-center">
Component
<th className="bg-white text-dark align-middle">
<FormB.Group className="d-flex align-items-center mb-0">
<Field
name="selectAll"
type="checkbox"
render={({ input }) => (
<>
<input
{...input}
className="mr-1"
checked={isSelectAllChecked(
values?.tableList
)}
onChange={(e) => {
selectAllPermissions(e, values, form);
}}
/>
Component
</>
)}
/>
</FormB.Group>
</th>
<th className="bg-white text-dark align-middle text-center">
<th className="bg-white text-dark align-middle">
Permission
</th>
</tr>
</thead>
<tbody>
<FieldArray name="tableList">
{({ fields, value }) =>
{({ fields }) =>
fields.map((name, index) => (
<tr className="bg-white" key={index}>
<td className="align-middle">
<td className="align-middle td-padding-modal">
<h6>
<FormB.Group className="d-inline">
<FormB.Check
Expand Down Expand Up @@ -393,7 +438,7 @@ export default function TagBasePermissionItem(props) {
<Field
className="form-control"
name={`${name}.permission`}
render={({ input, meta }) => (
render={({ input }) => (
<div>
{tagServicePerms[
fields.value[index].serviceName
Expand Down

0 comments on commit 98558ad

Please sign in to comment.