GroupSearch: add "publicOnly" boolean

This commit is contained in:
Matilde Park 2021-02-10 15:05:03 -05:00
parent 0995019ef9
commit 0d53e0791b
2 changed files with 20 additions and 6 deletions

View File

@ -126,7 +126,7 @@ export function EditProfile(props: any) {
</Col>
</Row>
<Checkbox mb={3} id="isPublic" label="Public Profile" />
<GroupSearch label="Pinned Groups" id="groups" groups={props.groups} associations={props.associations} />
<GroupSearch label="Pinned Groups" id="groups" groups={props.groups} associations={props.associations} publicOnly />
<AsyncButton primary loadingText="Updating..." border mt={3}>
Submit
</AsyncButton>

View File

@ -21,6 +21,7 @@ import { Associations, Association } from '~/types/metadata-update';
interface GroupSearchProps<I extends string> {
disabled?: boolean;
adminOnly?: boolean;
publicOnly?: boolean;
groups: Groups;
associations: Associations;
label: string;
@ -69,7 +70,7 @@ type FormValues<I extends string> = {
export function GroupSearch<I extends string, V extends FormValues<I>>(props: GroupSearchProps<I>) {
const { id, caption, label } = props;
const {
const {
values,
touched: touchedFields,
errors,
@ -84,8 +85,8 @@ export function GroupSearch<I extends string, V extends FormValues<I>>(props: Gr
const error = _.compact(errors[id] as string[]);
const groups: Association[] = useMemo(() => {
return props.adminOnly
? Object.values(
if (props.adminOnly) {
return Object.values(
Object.keys(props.associations?.groups)
.filter(
e => roleForShip(props.groups[e], window.ship) === 'admin'
@ -94,8 +95,21 @@ export function GroupSearch<I extends string, V extends FormValues<I>>(props: Gr
obj[key] = props.associations?.groups[key];
return obj;
}, {}) || {}
)
: Object.values(props.associations?.groups || {});
);
} else if (props.publicOnly) {
return Object.values(
Object.keys(props.associations?.groups)
.filter(
e => props.groups?.[e]?.policy?.open
)
.reduce((obj, key) => {
obj[key] = props.associations?.groups[key];
return obj;
}, {}) || {}
);
} else {
return Object.values(props.associations?.groups || {});
}
}, [props.associations?.groups]);
return (