Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/Configure/content/fields/ReEnableReadObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useInstallation } from "src/headless/installation/useInstallation";
import { useSelectedConfigureState } from "../useSelectedConfigureState";
import { useSelectedObject } from "../useSelectedObject";

import { SubscribeStillActiveBox } from "./SubscribeStillActiveBox";
import { useToggleReadingObject } from "./useToggleReadingObject";

export function ReEnableReadObject() {
Expand All @@ -19,6 +20,9 @@ export function ReEnableReadObject() {
const readObject = selectedObjectName
? installation?.config?.content?.read?.objects?.[selectedObjectName]
: undefined;
const subscribeObject = selectedObjectName
? installation?.config?.content?.subscribe?.objects?.[selectedObjectName]
: undefined;
if (!readObject) return null;

// If reading is already enabled, show a success box
Expand Down Expand Up @@ -86,6 +90,14 @@ export function ReEnableReadObject() {
: `Re-enable reading from ${selectedObjectDisplayName}`}
</Button>
</FormCalloutBox>
{subscribeObject && (
<SubscribeStillActiveBox
subscribeObject={subscribeObject}
objectDisplayName={
selectedObjectDisplayName ?? selectedObjectName ?? ""
}
/>
)}
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { SubscribeConfigObject } from "@generated/api/src";
import { CheckCircledIcon } from "@radix-ui/react-icons";
import { FormSuccessBox } from "src/components/FormSuccessBox";

interface SubscribeStillActiveBoxProps {
subscribeObject: SubscribeConfigObject;
objectDisplayName: string;
}

function getSubscribedEventLabels(
subscribeObject: SubscribeConfigObject,
): string[] {
const labels: string[] = [];
if (subscribeObject.createEvent) labels.push("Created");
if (subscribeObject.updateEvent) labels.push("Updated");
if (subscribeObject.deleteEvent) labels.push("Deleted");
if (subscribeObject.otherEvents?.length)
labels.push(...subscribeObject.otherEvents);
return labels;
}

export function SubscribeStillActiveBox({
subscribeObject,
objectDisplayName,
}: SubscribeStillActiveBoxProps) {
const events = getSubscribedEventLabels(subscribeObject);

return (
<FormSuccessBox style={{ marginTop: "0.75rem" }}>
<div
style={{
display: "flex",
alignItems: "center",
gap: "0.5rem",
}}
>
<CheckCircledIcon
style={{
width: "16px",
height: "16px",
flexShrink: 0,
}}
/>
<span style={{ fontWeight: 600 }}>
Event subscriptions are still active
</span>
</div>
<p style={{ marginTop: "0.5rem", fontSize: "0.875rem" }}>
You&apos;ll continue to receive <b>{objectDisplayName}</b> events even
though reading is disabled.
</p>
{events.length > 0 && (
<p style={{ marginTop: "0.25rem", fontSize: "0.875rem" }}>
<span style={{ fontWeight: 600 }}>Subscribed events: </span>
{events.join(", ")}
</p>
)}
<p
style={{
marginTop: "0.5rem",
fontSize: "0.75rem",
opacity: 0.75,
}}
>
This reflects configured subscriptions and does not confirm event
delivery.
</p>
</FormSuccessBox>
);
}
Loading