Enable new collection permissions UI

This commit is contained in:
Tom Moor
2024-05-27 09:34:34 -04:00
parent 7858133e71
commit 1f097258f4
5 changed files with 32 additions and 13 deletions

View File

@@ -16,6 +16,7 @@ import { CollectionEdit } from "~/components/Collection/CollectionEdit";
import { CollectionNew } from "~/components/Collection/CollectionNew"; import { CollectionNew } from "~/components/Collection/CollectionNew";
import CollectionDeleteDialog from "~/components/CollectionDeleteDialog"; import CollectionDeleteDialog from "~/components/CollectionDeleteDialog";
import DynamicCollectionIcon from "~/components/Icons/CollectionIcon"; import DynamicCollectionIcon from "~/components/Icons/CollectionIcon";
import SharePopover from "~/components/Sharing/Collection/SharePopover";
import { getHeaderExpandedKey } from "~/components/Sidebar/components/Header"; import { getHeaderExpandedKey } from "~/components/Sidebar/components/Header";
import { createAction } from "~/actions"; import { createAction } from "~/actions";
import { CollectionSection } from "~/actions/sections"; import { CollectionSection } from "~/actions/sections";
@@ -100,18 +101,34 @@ export const editCollectionPermissions = createAction({
icon: <PadlockIcon />, icon: <PadlockIcon />,
visible: ({ stores, activeCollectionId }) => visible: ({ stores, activeCollectionId }) =>
!!activeCollectionId && !!activeCollectionId &&
stores.policies.abilities(activeCollectionId).update && stores.policies.abilities(activeCollectionId).update,
!FeatureFlags.isEnabled(Feature.newCollectionSharing), perform: ({ t, stores, activeCollectionId }) => {
perform: ({ t, activeCollectionId }) => {
if (!activeCollectionId) { if (!activeCollectionId) {
return; return;
} }
const collection = stores.collections.get(activeCollectionId);
if (!collection) {
return;
}
stores.dialogs.openModal({ if (FeatureFlags.isEnabled(Feature.newCollectionSharing)) {
title: t("Collection permissions"), stores.dialogs.openModal({
fullscreen: true, title: t("Share this collection"),
content: <CollectionPermissions collectionId={activeCollectionId} />, content: (
}); <SharePopover
collection={collection}
onRequestClose={stores.dialogs.closeAllModals}
visible
/>
),
});
} else {
stores.dialogs.openModal({
title: t("Collection permissions"),
fullscreen: true,
content: <CollectionPermissions collectionId={activeCollectionId} />,
});
}
}, },
}); });

View File

@@ -10,7 +10,6 @@ import Squircle from "@shared/components/Squircle";
import { CollectionPermission } from "@shared/types"; import { CollectionPermission } from "@shared/types";
import Collection from "~/models/Collection"; import Collection from "~/models/Collection";
import Group from "~/models/Group"; import Group from "~/models/Group";
import Share from "~/models/Share";
import User from "~/models/User"; import User from "~/models/User";
import Avatar, { AvatarSize } from "~/components/Avatar/Avatar"; import Avatar, { AvatarSize } from "~/components/Avatar/Avatar";
import InputSelectPermission from "~/components/InputSelectPermission"; import InputSelectPermission from "~/components/InputSelectPermission";
@@ -35,8 +34,6 @@ import CollectionMemberList from "./CollectionMemberList";
type Props = { type Props = {
/** The collection to share. */ /** The collection to share. */
collection: Collection; collection: Collection;
/** The existing share model, if any. */
share: Share | null | undefined;
/** Callback fired when the popover requests to be closed. */ /** Callback fired when the popover requests to be closed. */
onRequestClose: () => void; onRequestClose: () => void;
/** Whether the popover is visible. */ /** Whether the popover is visible. */

View File

@@ -48,7 +48,6 @@ function ShareButton({ collection }: Props) {
<Popover {...popover} aria-label={t("Share")} width={400}> <Popover {...popover} aria-label={t("Share")} width={400}>
<SharePopover <SharePopover
collection={collection} collection={collection}
share={share}
onRequestClose={popover.hide} onRequestClose={popover.hide}
visible={popover.visible} visible={popover.visible}
/> />

View File

@@ -6,6 +6,11 @@ export enum Feature {
newCollectionSharing = "newCollectionSharing", newCollectionSharing = "newCollectionSharing",
} }
/** Default values for feature flags */
const FeatureDefaults: Record<Feature, boolean> = {
[Feature.newCollectionSharing]: true,
};
/** /**
* A simple feature flagging system that stores flags in browser storage. * A simple feature flagging system that stores flags in browser storage.
*/ */
@@ -23,7 +28,7 @@ export class FeatureFlags {
this.initalized = true; this.initalized = true;
} }
return this.cache.has(flag); return this.cache.has(flag) ?? FeatureDefaults[flag];
} }
public static enable(flag: Feature) { public static enable(flag: Feature) {

View File

@@ -6,6 +6,7 @@
"Edit collection": "Edit collection", "Edit collection": "Edit collection",
"Permissions": "Permissions", "Permissions": "Permissions",
"Collection permissions": "Collection permissions", "Collection permissions": "Collection permissions",
"Share this collection": "Share this collection",
"Search in collection": "Search in collection", "Search in collection": "Search in collection",
"Star": "Star", "Star": "Star",
"Unstar": "Unstar", "Unstar": "Unstar",