Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): show inherited space rules on caps dashboard

Richie McIlroy5799f496d116
diff --git a/apps/web/app/(org)/dashboard/caps/Caps.tsx b/apps/web/app/(org)/dashboard/caps/Caps.tsx
index 4106cc732..418945982 100644
--- a/apps/web/app/(org)/dashboard/caps/Caps.tsx
+++ b/apps/web/app/(org)/dashboard/caps/Caps.tsx
@@ -2,6 +2,7 @@
import type { VideoMetadata } from "@cap/database/types";
import { Button } from "@cap/ui";
+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import type { ImageUpload, Video } from "@cap/web-domain";
import { faFolderPlus, faInfoCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -45,11 +46,18 @@ export type VideoData = {
name: string;
isOrg: boolean;
organizationId: string;
+ iconUrl?: ImageUpload.ImageUrl | null;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
}[];
ownerName: string;
metadata?: VideoMetadata;
hasPassword: boolean;
+ hasInheritedPassword?: boolean;
+ inheritedPasswordSources?: SpaceRuleSource[];
+ inheritedSpaceSettings?: Partial<Record<ViewerSettingKey, SpaceRuleSource[]>>;
hasActiveUpload: boolean;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
}[];
export const Caps = ({
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
index 7f77fffae..278cd4b20 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -9,6 +9,7 @@ import {
DropdownMenuTrigger,
} from "@cap/ui";
import { calculateStrokeDashoffset, getProgressCircleConfig } from "@cap/utils";
+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import type { ImageUpload, Video } from "@cap/web-domain";
import { HttpClient } from "@effect/platform";
import {
@@ -85,10 +86,18 @@ export interface CapCardProps extends PropsWithChildren {
name: string;
iconUrl?: ImageUpload.ImageUrl | null;
organizationId: string;
+ isOrg?: boolean;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
}[];
ownerName: string | null;
metadata?: VideoMetadata;
hasPassword?: boolean;
+ hasInheritedPassword?: boolean;
+ inheritedPasswordSources?: SpaceRuleSource[];
+ inheritedSpaceSettings?: Partial<
+ Record<ViewerSettingKey, SpaceRuleSource[]>
+ >;
hasActiveUpload: boolean | undefined;
duration?: number;
settings?: {
@@ -98,7 +107,7 @@ export interface CapCardProps extends PropsWithChildren {
disableChapters?: boolean;
disableReactions?: boolean;
disableTranscript?: boolean;
- };
+ } | null;
};
analytics: number;
isLoadingAnalytics: boolean;
@@ -138,6 +147,8 @@ export const CapCard = ({
const [passwordProtected, setPasswordProtected] = useState(
cap.hasPassword || false,
);
+ const effectivePasswordProtected =
+ passwordProtected || Boolean(cap.hasInheritedPassword);
const { webUrl } = usePublicEnv();
const [copyPressed, setCopyPressed] = useState(false);
@@ -261,7 +272,7 @@ export const CapCard = ({
return element;
};
- const handleDragStart = (e: React.DragEvent<HTMLDivElement>) => {
+ const handleDragStart = (e: React.DragEvent<HTMLElement>) => {
if (anyCapSelected || !isOwner) return;
// Set the data transfer
@@ -318,16 +329,6 @@ export const CapCard = ({
});
};
- const handleCardClick = (e: React.MouseEvent) => {
- if (anyCapSelected) {
- e.preventDefault();
- e.stopPropagation();
- if (onSelectToggle) {
- onSelectToggle();
- }
- }
- };
-
const handleSelectClick = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
@@ -359,11 +360,13 @@ export const CapCard = ({
onSharingUpdated={handleSharingUpdated}
isPublic={cap.public}
hasPassword={passwordProtected}
+ inheritedPasswordSources={cap.inheritedPasswordSources}
onPasswordUpdated={handlePasswordUpdated}
/>
<SettingsDialog
isOpen={isSettingsDialogOpen}
- settingsData={cap.settings}
+ settingsData={cap.settings ?? undefined}
+ inheritedSpaceSettings={cap.inheritedSpaceSettings}
capId={cap.id}
onClose={() => setIsSettingsDialogOpen(false)}
/>
@@ -374,8 +377,8 @@ export const CapCard = ({
hasPassword={passwordProtected}
onPasswordUpdated={handlePasswordUpdated}
/>
- <div
- onClick={handleCardClick}
+ <fieldset
+ aria-label={cap.name}
draggable={isOwner && !anyCapSelected}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
@@ -391,7 +394,12 @@ export const CapCard = ({
)}
>
{anyCapSelected && !sharedCapCard && (
- <div className="absolute inset-0 z-10" onClick={handleCardClick} />
+ <button
+ type="button"
+ aria-label={`Select ${cap.name}`}
+ className="absolute inset-0 z-10"
+ onClick={handleSelectClick}
+ />
)}
<div
@@ -430,6 +438,7 @@ export const CapCard = ({
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
+ aria-hidden="true"
className="text-gray-12 size-5 svgpathanimation"
>
<path d="M20 6 9 17l-5-5" />
@@ -536,7 +545,7 @@ export const CapCard = ({
>
<FontAwesomeIcon
className="size-3"
- icon={passwordProtected ? faLock : faUnlock}
+ icon={effectivePasswordProtected ? faLock : faUnlock}
/>
<p className="text-sm text-gray-12">
{passwordProtected ? "Edit password" : "Add password"}
@@ -571,7 +580,9 @@ export const CapCard = ({
</div>
{!sharedCapCard && onSelectToggle && (
- <div
+ <button
+ type="button"
+ aria-label={isSelected ? "Deselect cap" : "Select cap"}
className={clsx(
"absolute top-2 left-2 z-[49] duration-200",
isSelected || anyCapSelected || isDropdownOpen
@@ -595,7 +606,7 @@ export const CapCard = ({
<FontAwesomeIcon icon={faCheck} className="text-white size-3" />
)}
</div>
- </div>
+ </button>
)}
<div className="relative aspect-video w-full">
@@ -641,6 +652,7 @@ export const CapCard = ({
<svg
className="w-4 h-4 animate-spin"
viewBox="0 0 20 20"
+ aria-hidden="true"
>
<circle
cx="10"
@@ -667,6 +679,7 @@ export const CapCard = ({
<svg
className="w-4 h-4 transform -rotate-90"
viewBox="0 0 20 20"
+ aria-hidden="true"
>
<circle
cx="10"
@@ -726,6 +739,18 @@ export const CapCard = ({
uploadProgress.status !== "error"
}
/>
+ {effectivePasswordProtected && (
+ <div
+ className="absolute right-2 top-2 z-10 flex size-7 items-center justify-center rounded-full bg-black/70 text-white"
+ title={
+ cap.hasInheritedPassword
+ ? "Password required by space"
+ : "Password protected"
+ }
+ >
+ <FontAwesomeIcon icon={faLock} className="size-3" />
+ </div>
+ )}
</Link>
</div>
<div
@@ -751,7 +776,7 @@ export const CapCard = ({
totalReactions={cap.totalReactions}
/>
</div>
- </div>
+ </fieldset>
</>
);
};
diff --git a/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
index 80715a66f..968edddc8 100644
--- a/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/SettingsDialog.tsx
@@ -7,6 +7,7 @@ import {
DialogTitle,
Switch,
} from "@cap/ui";
+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import type { Video } from "@cap/web-domain";
import { faGear } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -22,6 +23,7 @@ interface SettingsDialogProps {
onClose: () => void;
capId: Video.VideoId;
settingsData?: OrganizationSettings;
+ inheritedSpaceSettings?: Partial<Record<ViewerSettingKey, SpaceRuleSource[]>>;
}
const options: {
@@ -70,6 +72,7 @@ export const SettingsDialog = ({
onClose,
capId,
settingsData,
+ inheritedSpaceSettings,
}: SettingsDialogProps) => {
const { user, organizationSettings } = useDashboardContext();
const [saveLoading, setSaveLoading] = useState(false);
@@ -141,6 +144,8 @@ export const SettingsDialog = ({
);
const getEffectiveValue = (key: keyof OrganizationSettings) => {
+ const inheritedSources = inheritedSpaceSettings?.[key];
+ if (inheritedSources && inheritedSources.length > 0) return true;
const videoValue = settings?.[key];
const orgValue = organizationSettings?.[key] ?? false;
return videoValue !== undefined || videoValue === true
@@ -148,6 +153,13 @@ export const SettingsDialog = ({
: orgValue;
};
+ const getInheritedLabel = (key: keyof OrganizationSettings) => {
+ const sources = inheritedSpaceSettings?.[key];
+ if (!sources || sources.length === 0) return null;
+ if (sources.length === 1) return `Required by ${sources[0]?.name}`;
+ return `Required by ${sources.length} spaces`;
+ };
+
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent className="max-w-md min-w-fit">
@@ -162,6 +174,7 @@ export const SettingsDialog = ({
const key = option.value as keyof OrganizationSettings;
const effectiveValue = getEffectiveValue(key);
const orgValue = organizationSettings?.[key] ?? false;
+ const inheritedLabel = getInheritedLabel(key);
return (
<div
key={option.value}
@@ -182,7 +195,8 @@ export const SettingsDialog = ({
)}
{effectiveValue && (
<p className="py-1 px-1.5 text-[10px] leading-none font-medium rounded-full text-gray-11 bg-gray-5">
- Org {orgValue ? "disabled" : "enabled"}
+ {inheritedLabel ??
+ `Org ${orgValue ? "disabled" : "enabled"}`}
</p>
)}
</div>
@@ -190,6 +204,7 @@ export const SettingsDialog = ({
</div>
<Switch
disabled={
+ Boolean(inheritedLabel) ||
(option.pro && !user.isPro) ||
((key === "disableSummary" || key === "disableChapters") &&
getEffectiveValue(
diff --git a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
index 6dac2c825..156dbe797 100644
--- a/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/SharingDialog.tsx
@@ -8,6 +8,7 @@ import {
Input,
Switch,
} from "@cap/ui";
+import type { SpaceRuleSource, ViewerSettingKey } from "@cap/web-backend";
import { type ImageUpload, Space, type Video } from "@cap/web-domain";
import { faCopy, faShareNodes } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -39,11 +40,15 @@ interface SharingDialogProps {
name: string;
iconUrl?: string | null;
organizationId: string;
+ isOrg?: boolean;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
}[];
onSharingUpdated: (updatedSharedSpaces: string[]) => void;
isPublic?: boolean;
spacesData?: Spaces[] | null;
hasPassword?: boolean;
+ inheritedPasswordSources?: SpaceRuleSource[];
onPasswordUpdated?: (protectedStatus: boolean) => void;
user?: CurrentUser | null;
onUpgradeRequest?: (open: boolean) => void;
@@ -59,6 +64,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
isPublic = false,
spacesData: propSpacesData = null,
hasPassword = false,
+ inheritedPasswordSources = [],
onPasswordUpdated,
user: propUser,
onUpgradeRequest: propOnUpgradeRequest,
@@ -281,6 +287,26 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
) || [];
const allShareableItems = [...organizationEntries, ...realSpaces];
+ const selectedInheritedPasswordSources = [
+ ...inheritedPasswordSources.filter((source) =>
+ selectedSpaces.has(source.id),
+ ),
+ ...sharedSpaces
+ .filter((space) => selectedSpaces.has(space.id) && space.hasPassword)
+ .map((space) => ({ id: space.id, name: space.name })),
+ ...allShareableItems
+ .filter((space) => selectedSpaces.has(space.id) && space.hasPassword)
+ .map((space) => ({ id: space.id, name: space.name })),
+ ].filter(
+ (source, index, sources) =>
+ sources.findIndex((item) => item.id === source.id) === index,
+ );
+ const inheritedPasswordLabel =
+ selectedInheritedPasswordSources.length === 1
+ ? `Required by ${selectedInheritedPasswordSources[0]?.name}`
+ : selectedInheritedPasswordSources.length > 1
+ ? `Required by ${selectedInheritedPasswordSources.length} spaces`
+ : null;
const filteredSpaces = searchTerm
? allShareableItems.filter((space) =>
@@ -306,7 +332,8 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
<div className="flex w-full h-12 border-b bg-gray-1 border-gray-4">
{tabs.map((tab) => (
- <div
+ <button
+ type="button"
key={tab}
className={clsx(
"flex relative flex-1 justify-center items-center w-full min-w-0 text-sm font-medium transition-colors",
@@ -326,7 +353,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
>
{tab}
</p>
- </div>
+ </button>
))}
</div>
@@ -360,6 +387,25 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
/>
</div>
+ {inheritedPasswordLabel && (
+ <div className="flex justify-between items-center p-3 mb-4 rounded-lg border bg-gray-1 border-gray-4">
+ <div className="flex gap-3 items-center">
+ <div className="flex justify-center items-center w-8 h-8 rounded-full bg-gray-3">
+ <Lock className="w-4 h-4 text-gray-11" />
+ </div>
+ <div>
+ <p className="text-sm font-medium text-gray-12">
+ Password required
+ </p>
+ <p className="text-xs text-gray-10">
+ {inheritedPasswordLabel}
+ </p>
+ </div>
+ </div>
+ <Switch checked disabled />
+ </div>
+ )}
+
<div
className={clsx(
"mb-4 rounded-lg border bg-gray-1 border-gray-4",
@@ -377,11 +423,15 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
? initialPasswordEnabled
? "Password protected"
: "Password protection"
- : "Add password"}
+ : inheritedPasswordLabel
+ ? "Add another password"
+ : "Add password"}
</p>
<p className="text-xs text-gray-10">
{passwordEnabled
- ? "Viewers must enter a password to view"
+ ? inheritedPasswordLabel
+ ? "Viewers can use this password or a space password"
+ : "Viewers must enter a password to view"
: "Restrict access with a password"}
</p>
</div>
@@ -522,6 +572,8 @@ const SpaceCard = ({
name: string;
iconUrl?: ImageUpload.ImageUrl | null;
organizationId: string;
+ settings?: Partial<Record<ViewerSettingKey, boolean>> | null;
+ hasPassword?: boolean;
};
selectedSpaces: Set<string>;
handleToggleSpace: (spaceId: string) => void;
@@ -537,7 +589,8 @@ const SpaceCard = ({
: space.name
}
>
- <div
+ <button
+ type="button"
className={clsx(
"flex items-center relative overflow-visible flex-col justify-center gap-2 border transition-colors bg-gray-2",
"duration-200 w-full p-2.5 rounded-xl cursor-pointer",
@@ -557,6 +610,11 @@ const SpaceCard = ({
<p className="max-w-full text-xs truncate transition-colors duration-200 text-gray-10">
{space.name}
</p>
+ {space.hasPassword && (
+ <div className="absolute top-1 left-1 flex size-4 items-center justify-center rounded-full bg-amber-500 text-white">
+ <Lock size={10} />
+ </div>
+ )}
<motion.div
key={space.id}
animate={{
@@ -575,7 +633,7 @@ const SpaceCard = ({
>
<Check className="text-white" size={10} />
</motion.div>
- </div>
+ </button>
</Tooltip>
);
};
diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsx
index c534ed2f5..8d5681c4a 100644
--- a/apps/web/app/(org)/dashboard/caps/page.tsx
+++ b/apps/web/app/(org)/dashboard/caps/page.tsx
@@ -12,7 +12,11 @@ import {
videoUploads,
} from "@cap/database/schema";
import { serverEnv } from "@cap/env";
-import { Database, ImageUploads } from "@cap/web-backend";
+import {
+ Database,
+ ImageUploads,
+ resolveEffectiveVideoRules,
+} from "@cap/web-backend";
import { type ImageUpload, Video } from "@cap/web-domain";
import { and, count, desc, eq, inArray, isNull, sql } from "drizzle-orm";
import { type Array, Effect } from "effect";
@@ -41,6 +45,9 @@ const getSharedSpacesForVideos = Effect.fn(function* (
id: spaces.id,
name: spaces.name,
organizationId: spaces.organizationId,
+ iconUrl: spaces.iconUrl,
+ settings: spaces.settings,
+ hasPassword: sql`${spaces.password} IS NOT NULL`.mapWith(Boolean),
})
.from(spaceVideos)
.innerJoin(spaces, eq(spaceVideos.spaceId, spaces.id))
@@ -74,6 +81,9 @@ const getSharedSpacesForVideos = Effect.fn(function* (
name: string;
organizationId: string;
isOrg: boolean;
+ iconUrl?: ImageUpload.ImageUrlOrKey | null;
+ settings?: (typeof spaces.$inferSelect)["settings"];
+ hasPassword: boolean;
}>
> = {};
@@ -87,6 +97,9 @@ const getSharedSpacesForVideos = Effect.fn(function* (
name: space.name,
organizationId: space.organizationId,
isOrg: false,
+ iconUrl: space.iconUrl,
+ settings: space.settings,
+ hasPassword: space.hasPassword,
});
});
@@ -100,6 +113,9 @@ const getSharedSpacesForVideos = Effect.fn(function* (
name: org.name,
organizationId: org.organizationId,
isOrg: true,
+ iconUrl: org.iconUrl,
+ settings: null,
+ hasPassword: false,
});
});
@@ -190,6 +206,10 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
videos.name,
videos.createdAt,
videos.metadata,
+ videos.duration,
+ videos.public,
+ videos.password,
+ videos.settings,
videos.orgId,
users.name,
)
@@ -227,13 +247,23 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
Effect.fn(function* (video) {
const imageUploads = yield* ImageUploads;
- const { effectiveDate, ...videoWithoutEffectiveDate } = video;
+ const { effectiveDate: _effectiveDate, ...videoWithoutEffectiveDate } =
+ video;
+ const sharedSpaces = sharedSpacesMap[video.id] ?? [];
+ const rules = resolveEffectiveVideoRules({
+ videoSettings: video.settings,
+ organizationSettings: null,
+ spaces: sharedSpaces.filter((space) => !space.isOrg),
+ });
return {
...videoWithoutEffectiveDate,
id: Video.VideoId.make(video.id),
foldersData,
settings: video.settings,
+ hasInheritedPassword: rules.hasInheritedPassword,
+ inheritedPasswordSources: rules.inheritedPasswordSources,
+ inheritedSpaceSettings: rules.inheritedSettings,
sharedOrganizations: yield* Effect.all(
(video.sharedOrganizations ?? [])
.filter((organization) => organization.id !== null)
@@ -248,12 +278,23 @@ export default async function CapsPage(props: PageProps<"/dashboard/caps">) {
}),
),
),
- sharedSpaces: sharedSpacesMap[video.id] ?? [],
+ sharedSpaces: yield* Effect.all(
+ sharedSpaces.map(
+ Effect.fn(function* (space) {
+ return {
+ ...space,
+ iconUrl: space.iconUrl
+ ? yield* imageUploads.resolveImageUrl(space.iconUrl)
+ : null,
+ };
+ }),
+ ),
+ ),
ownerName: video.ownerName ?? "",
metadata: video.metadata as
| {
customCreatedAt?: string;
- [key: string]: any;
+ [key: string]: unknown;
}
| undefined,
};