+export const ResourceLinkTailIsActive = connect(
+ (state: RootState, props: { uuid: string, disabled?: boolean }) => {
+ const link = getResource<LinkResource>(props.uuid)(state.resources);
+ const tailResource = getResource<UserResource>(link?.tailUuid || '')(state.resources);
+
+ return tailResource ? {...tailResource, disabled: !!props.disabled} : { isActive: false, kind: ResourceKind.NONE };
+ }, { toggleIsActive }
+)(renderIsActive);
+
+const renderIsHidden = (props: {
+ memberLinkUuid: string,
+ permissionLinkUuid: string,
+ visible: boolean,
+ canManage: boolean,
+ setMemberIsHidden: (memberLinkUuid: string, permissionLinkUuid: string, hide: boolean) => void
+ }) => {
+ if (props.memberLinkUuid) {
+ return <Checkbox
+ data-cy="user-visible-checkbox"
+ color="primary"
+ checked={props.visible}
+ disabled={!props.canManage}
+ onClick={() => props.setMemberIsHidden(props.memberLinkUuid, props.permissionLinkUuid, !props.visible)} />;
+ } else {
+ return <Typography />;
+ }
+}
+
+export const ResourceLinkTailIsVisible = connect(
+ (state: RootState, props: { uuid: string }) => {
+ const link = getResource<LinkResource>(props.uuid)(state.resources);
+ const member = getResource<Resource>(link?.tailUuid || '')(state.resources);
+ const group = getResource<GroupResource>(link?.headUuid || '')(state.resources);
+ const permissions = filterResources((resource: LinkResource) => {
+ return resource.linkClass === LinkClass.PERMISSION
+ && resource.headUuid === link?.tailUuid
+ && resource.tailUuid === group?.uuid
+ && resource.name === PermissionLevel.CAN_READ;
+ })(state.resources);
+
+ const permissionLinkUuid = permissions.length > 0 ? permissions[0].uuid : '';
+ const isVisible = link && group && permissions.length > 0;
+ // Consider whether the current user canManage this resurce in addition when it's possible
+ const isBuiltin = isBuiltinGroup(link?.headUuid || '');
+
+ return member?.kind === ResourceKind.USER
+ ? { memberLinkUuid: link?.uuid, permissionLinkUuid, visible: isVisible, canManage: !isBuiltin }
+ : { memberLinkUuid: '', permissionLinkUuid: '', visible: false, canManage: false };
+ }, { setMemberIsHidden }
+)(renderIsHidden);
+