!disabled && handleChange(!value)}>
@@ -527,15 +636,6 @@ function getColumnForProfileOrPermSet
({
}}
disabled={disabled}
>
- {/* Rendering this custom checkbox was really slow, lot's of DOM elements */}
- {/* */}
{errorMessage && (
,
+ permissionSetsById: MapOf
+) {
+ const newColumns: ColumnWithFilter[] = [
+ {
+ ...setColumnFromType('tableLabel', 'text'),
+ name: 'Object',
+ key: 'tableLabel',
+ frozen: true,
+ width: 300,
+ getValue: ({ column, row }) => {
+ const data: PermissionTableFieldCell = row[column.key];
+ return data && `${data.label} (${data.apiName})`;
+ },
+ summaryCellClass: 'bg-color-gray-dark no-outline',
+ renderSummaryCell: ({ row }) => {
+ if (row.type === 'HEADING') {
+ return ;
+ } else if (row.type === 'ACTION') {
+ return ;
+ }
+ return undefined;
+ },
+ cellClass: (row) => {
+ if ('canSetPermission' in row && !row.canSetPermission) {
+ return 'slds-text-color_weak';
+ }
+ },
+ },
+ {
+ name: '',
+ key: '_ROW_ACTION',
+ width: 100,
+ resizable: false,
+ frozen: true,
+ renderCell: (props) => {
+ if (!props.row.canSetPermission) {
+ return (
+
+
+ This object does not have a Tab.
+
+ }
+ >
+
+
+
+ );
+ }
+ return ;
+ },
+ summaryCellClass: ({ type }) => (type === 'HEADING' ? 'bg-color-gray' : null),
+ renderSummaryCell: ({ row }) => {
+ if (row.type === 'ACTION') {
+ return ;
+ }
+ return undefined;
+ },
+ },
+ ];
+ // Create column groups for profiles
+ selectedProfiles.forEach((profileId) => {
+ const profile = profilesById[profileId];
+ (['available', 'visible'] as const).forEach((actionKey, i) => {
+ newColumns.push(
+ getColumnForProfileOrPermSet({
+ isFirstItem: i === 0,
+ permissionType: 'tabVisibility',
+ id: profileId,
+ type: 'Profile',
+ label: profile.Profile.Name,
+ actionType: startCase(actionKey) as 'Available' | 'Visible',
+ actionKey,
+ })
+ );
+ });
+ });
+ // Create column groups for permission sets
+ selectedPermissionSets.forEach((permissionSetId) => {
+ const permissionSet = permissionSetsById[permissionSetId];
+ (['available', 'visible'] as const).forEach((actionKey, i) => {
+ newColumns.push(
+ getColumnForProfileOrPermSet({
+ isFirstItem: i === 0,
+ permissionType: 'tabVisibility',
+ id: permissionSetId,
+ type: 'Permission Set',
+ label: permissionSet?.Name || '',
+ actionType: startCase(actionKey) as 'Available' | 'Visible',
+ actionKey,
+ })
+ );
+ });
+ });
+ return newColumns;
+}
+
+export function getTabVisibilityRows(selectedSObjects: string[], tabVisibilityPermissionMap: MapOf) {
+ const rows: PermissionTableTabVisibilityCell[] = [];
+ orderStringsBy(selectedSObjects).forEach((sobject) => {
+ const fieldPermission = tabVisibilityPermissionMap[sobject];
+
+ const currRow: PermissionTableTabVisibilityCell = {
+ key: sobject,
+ sobject: sobject,
+ apiName: fieldPermission.apiName,
+ label: fieldPermission.label,
+ tableLabel: `${fieldPermission.label} (${fieldPermission.apiName})`,
+ canSetPermission: fieldPermission.canSetPermission,
+ permissions: {},
+ };
+
+ fieldPermission.permissionKeys.forEach((key) => {
+ const item = fieldPermission.permissions[key];
+ currRow.permissions[key] = getRowTabVisibilityPermissionFromFieldPermissionItem(key, sobject, item);
+ });
+
+ rows.push(currRow);
+ });
+ return rows;
+}
+
+export function updateTabVisibilityRowsAfterSave(
+ rows: PermissionTableTabVisibilityCell[],
+ tabVisibilityPermissionsMap: MapOf
+): PermissionTableTabVisibilityCell[] {
+ return rows.map((oldRow) => {
+ const row = { ...oldRow };
+ tabVisibilityPermissionsMap[row.key].permissionKeys.forEach((key) => {
+ row.permissions = { ...row.permissions };
+ const objectPermission = tabVisibilityPermissionsMap[row.key].permissions[key];
+ if (objectPermission.errorMessage) {
+ row.permissions[key] = { ...row.permissions[key], errorMessage: objectPermission.errorMessage };
+ } else {
+ row.permissions[key] = getRowTabVisibilityPermissionFromFieldPermissionItem(key, row.sobject, objectPermission);
+ }
+ });
+ return row;
+ });
+}
+
+function getRowTabVisibilityPermissionFromFieldPermissionItem(
+ key: string,
+ sobject: string,
+ item: TabVisibilityPermissionItem
+): PermissionTableTabVisibilityCellPermission {
+ return {
+ rowKey: sobject,
+ parentId: key,
+ sobject,
+ visible: item.visible,
+ available: item.available,
+ visibleIsDirty: false,
+ availableIsDirty: false,
+ record: item,
+ errorMessage: item.errorMessage,
+ };
+}
+
/**
*
* JSX Components
*
*/
-export function getConfirmationModalContent(dirtyObjectCount: number, dirtyFieldCount: number) {
- let output;
- const dirtyObj = (
-
-
- {dirtyObjectCount} Object {pluralizeFromNumber('Permission', dirtyObjectCount)}
-
-
- );
- const dirtyField = (
-
-
- {dirtyFieldCount} Field {pluralizeFromNumber('Permission', dirtyFieldCount)}
-
-
- );
- if (dirtyObjectCount && dirtyFieldCount) {
- output = (
-
- {dirtyObj} and {dirtyField}
-
- );
- } else if (dirtyObjectCount) {
- output = dirtyObj;
- } else {
- output = dirtyField;
- }
+export function getConfirmationModalContent(dirtyObjectCount: number, dirtyFieldCount: number, dirtyTabVisibilityCount: number) {
return (
-
You have made changes to {output}.
+
You have made changes to:
+
+ {[
+ {
+ dirty: !!dirtyObjectCount,
+ jsx: (
+
+ {dirtyObjectCount} Object {pluralizeFromNumber('Permission', dirtyObjectCount)}
+
+ ),
+ },
+ {
+ dirty: !!dirtyFieldCount,
+ jsx: (
+
+ {dirtyFieldCount} Field {pluralizeFromNumber('Permission', dirtyFieldCount)}
+
+ ),
+ },
+ {
+ dirty: !!dirtyTabVisibilityCount,
+ jsx: (
+
+ {dirtyTabVisibilityCount} Tab Visibility {pluralizeFromNumber('Permission', dirtyTabVisibilityCount)}
+
+ ),
+ },
+ ]
+ .filter(({ dirty }) => dirty)
+ .map(({ jsx }, i) => (
+ - {jsx}
+ ))}
+
);
}
@@ -691,10 +961,10 @@ export function getConfirmationModalContent(dirtyObjectCount: number, dirtyField
/**
* Performs bulk action against a column
*/
-export function updateRowsFromColumnAction(
+export function updateRowsFromColumnAction(
type: PermissionType,
action: 'selectAll' | 'unselectAll' | 'reset',
- which: ObjectPermissionTypes | FieldPermissionTypes,
+ which: PermissionTypes,
id: string,
rows: TRows[]
): TRows[] {
@@ -731,23 +1001,34 @@ export function updateRowsFromColumnAction(
+export function updateRowsFromRowAction(
type: PermissionType,
checkboxesById: MapOf,
rows: TRows[]
@@ -762,7 +1043,7 @@ export function updateRowsFromRowAction(type: PermissionType, rows: TRows[]): TRows[] {
+export function resetRow(type: PermissionType, rows: TRows[]): TRows[] {
const newRows = [...rows];
return newRows.map((row) => {
row = { ...row };
@@ -823,7 +1111,7 @@ export function resetRow,
value: boolean
@@ -962,7 +1268,7 @@ export function updateCheckboxDependencies(
checkboxesById['viewAll'].value = true;
}
}
- } else {
+ } else if (type === 'field') {
if (which === 'read') {
checkboxesById['read'] = { ...checkboxesById['read'], value: value };
if (!checkboxesById['read'].value) {
@@ -974,55 +1280,37 @@ export function updateCheckboxDependencies(
checkboxesById['read'].value = true;
}
}
+ } else if (type === 'tabVisibility') {
+ if (which === 'available') {
+ checkboxesById['available'] = { ...checkboxesById['available'], value: value };
+ if (!checkboxesById['available'].value) {
+ checkboxesById['visible'].value = false;
+ }
+ } else if (which === 'visible') {
+ checkboxesById['visible'] = { ...checkboxesById['visible'], value: value };
+ if (checkboxesById['visible'].value) {
+ checkboxesById['available'].value = true;
+ }
+ }
}
}
-function getDirtyCount({ row, type }: { row: PermissionTableObjectCell | PermissionTableFieldCell; type: PermissionType });
-function getDirtyCount({
- row,
- type,
-}: { row: PermissionTableObjectCell; type: 'object' } | { row: PermissionTableFieldCell; type: 'field' }): number {
- let dirtyCount = 0;
- if (type === 'object') {
- // const data: PermissionTableObjectCell = rowNode.data;
- dirtyCount = Object.values(row.permissions).reduce((output, permission) => {
- output += permission.createIsDirty ? 1 : 0;
- output += permission.readIsDirty ? 1 : 0;
- output += permission.editIsDirty ? 1 : 0;
- output += permission.deleteIsDirty ? 1 : 0;
- output += permission.viewAllIsDirty ? 1 : 0;
- output += permission.modifyAllIsDirty ? 1 : 0;
- return output;
- }, 0);
- } else {
- dirtyCount = Object.values(row.permissions).reduce((output, permission) => {
- output += permission.readIsDirty ? 1 : 0;
- output += permission.editIsDirty ? 1 : 0;
- return output;
- }, 0);
- }
- return dirtyCount;
-}
-
/**
* Row action renderer
*
* This component provides a popover that the user can open to make changes that apply to an entire row
*/
-export const RowActionRenderer: FunctionComponent> = ({
- column,
- onRowChange,
- row,
-}) => {
+export const RowActionRenderer: FunctionComponent> = ({ column, onRowChange, row }) => {
const { type } = useContext(DataTableGenericContext) as PermissionManagerTableContext;
const popoverRef = useRef(null);
- const [dirtyItemCount, setDirtyItemCount] = useState(0);
- const [checkboxes, setCheckboxes] = useState(defaultRowActionCheckboxes(type, row?.allowEditPermission));
+ const [checkboxes, setCheckboxes] = useState(() => {
+ return defaultRowActionCheckboxes(type, 'allowEditPermission' in row ? row?.allowEditPermission : true);
+ });
/**
* Set all dependencies when fields change
*/
- function handleChange(which: ObjectPermissionTypes, value: boolean) {
+ function handleChange(which: PermissionTypes, value: boolean) {
const checkboxesById = getMapOf(checkboxes, 'id');
updateCheckboxDependencies(which, type, checkboxesById, value);
if (type === 'object') {
@@ -1034,8 +1322,10 @@ export const RowActionRenderer: FunctionComponent {
const [isOpen, setIsOpen] = useState(false);
const [checkboxes, setCheckboxes] = useState(defaultRowActionCheckboxes(type, true));
+ const rowCount = useMemo(() => rows.filter((row) => !('canSetPermission' in row) || row.canSetPermission).length, [rows]);
+
/**
* Set all dependencies when fields change
*/
- function handleChange(which: ObjectPermissionTypes, value: boolean) {
+ function handleChange(which: PermissionTypes, value: boolean) {
const checkboxesById = getMapOf(checkboxes, 'id');
updateCheckboxDependencies(which, type, checkboxesById, value);
if (type === 'object') {
@@ -1163,8 +1451,10 @@ export const BulkActionRenderer = () => {
checkboxesById['viewAll'],
checkboxesById['modifyAll'],
]);
- } else {
+ } else if (type === 'field') {
setCheckboxes([checkboxesById['read'], checkboxesById['edit']]);
+ } else if (type === 'tabVisibility') {
+ setCheckboxes([checkboxesById['available'], checkboxesById['visible']]);
}
}
@@ -1194,7 +1484,7 @@ export const BulkActionRenderer = () => {
-