Skip to content

Commit ed18734

Browse files
simplify code for getting labels for permission checkboxes
1 parent d79ec0e commit ed18734

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

jsapp/js/components/permissions/userAssetPermsEditor.component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
CHECKBOX_NAMES,
1818
CHECKBOX_PERM_PAIRS,
1919
PARTIAL_IMPLIED_CHECKBOX_PAIRS,
20+
CHECKBOX_LABELS,
2021
} from './permConstants';
2122
import type {
2223
CheckboxNameAll,
@@ -27,7 +28,7 @@ import type {
2728
import type {AssignablePermsMap} from './sharingForm.component';
2829
import type {PermissionBase} from 'js/dataInterface';
2930
import userExistence from 'js/users/userExistence.store';
30-
import {getPartialByUsersListName, getCheckboxLabel} from './utils';
31+
import {getPartialByUsersListName} from './utils';
3132

3233
const PARTIAL_PLACEHOLDER = t('Enter usernames separated by comma');
3334
const USERNAMES_SEPARATOR = ',';
@@ -513,7 +514,7 @@ export default class UserAssetPermsEditor extends React.Component<
513514
checked={this.state[checkboxName]}
514515
disabled={isDisabled}
515516
onChange={this.onCheckboxChange.bind(this, checkboxName)}
516-
label={getCheckboxLabel(checkboxName)}
517+
label={CHECKBOX_LABELS[checkboxName]}
517518
/>
518519
);
519520
}

jsapp/js/components/permissions/utils.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,6 @@ export function getCheckboxNameByPermission(
256256
return found;
257257
}
258258

259-
/**
260-
* A wrapper function for getting item from `CHECKBOX_LABELS`. If anything goes
261-
* awry, we will return checkbox name as fallback.
262-
*/
263-
export function getCheckboxLabel(checkboxName: CheckboxNameAll) {
264-
if (checkboxName in CHECKBOX_LABELS) {
265-
return CHECKBOX_LABELS[checkboxName];
266-
}
267-
return checkboxName;
268-
}
269-
270259
/** Detects if partial permissions is of "by users" kind */
271260
export function isPartialByUsers(perm: UserPerm) {
272261
// TODO for now this only checks if this is partial permission, as there is
@@ -296,8 +285,8 @@ export function getPermLabel(perm: UserPerm) {
296285
if (permDef) {
297286
const checkboxName = getCheckboxNameByPermission(permDef.codename);
298287

299-
if (checkboxName && checkboxName in CHECKBOX_LABELS) {
300-
return getCheckboxLabel(checkboxName);
288+
if (checkboxName) {
289+
return CHECKBOX_LABELS[checkboxName];
301290
}
302291
}
303292

0 commit comments

Comments
 (0)