Skip to content

Commit 70f659e

Browse files
authored
ENG-1407 Move Stored Relations toggle + migration flow to Personal Settings (#829)
1 parent 2a876de commit 70f659e

5 files changed

Lines changed: 260 additions & 179 deletions

File tree

apps/roam/src/components/settings/AdminPanel.tsx

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "@blueprintjs/core";
1515
import Description from "roamjs-components/components/Description";
1616
import { Select } from "@blueprintjs/select";
17-
import { getSetting, setSetting } from "~/utils/extensionSettings";
1817
import {
1918
getSupabaseContext,
2019
getLoggedInClient,
@@ -27,17 +26,13 @@ import {
2726
type NodeSignature,
2827
type PConceptFull,
2928
} from "@repo/database/lib/queries";
30-
import migrateRelations from "~/utils/migrateRelations";
31-
import { countReifiedRelations } from "~/utils/createReifiedBlock";
3229
import type { DGSupabaseClient } from "@repo/database/lib/client";
3330
import internalError from "~/utils/internalError";
3431
import SuggestiveModeSettings from "./SuggestiveModeSettings";
3532
import { getFormattedConfigTree } from "~/utils/discourseConfigRef";
3633
import refreshConfigTree from "~/utils/refreshConfigTree";
3734
import createBlock from "roamjs-components/writes/createBlock";
3835
import deleteBlock from "roamjs-components/writes/deleteBlock";
39-
import { USE_REIFIED_RELATIONS } from "~/data/userSettings";
40-
import posthog from "posthog-js";
4136
import { setFeatureFlag } from "~/components/settings/utils/accessors";
4237

4338
const NodeRow = ({ node }: { node: PConceptFull }) => {
@@ -258,98 +253,7 @@ const NodeListTab = (): React.ReactElement => {
258253
);
259254
};
260255

261-
const MigrationTab = (): React.ReactElement => {
262-
let initial = true;
263-
const [useMigrationResults, setMigrationResults] = useState<string>("");
264-
const [useOngoing, setOngoing] = useState<boolean>(false);
265-
const [useDryRun, setDryRun] = useState<boolean>(false);
266-
const enabled = getSetting<boolean>(USE_REIFIED_RELATIONS, false);
267-
const doMigrateRelations = async () => {
268-
setOngoing(true);
269-
try {
270-
posthog.capture("Reified Relations: Migration Started", {
271-
dryRun: useDryRun,
272-
});
273-
const before = await countReifiedRelations();
274-
const numProcessed = await migrateRelations(useDryRun);
275-
const after = await countReifiedRelations();
276-
if (after - before < numProcessed)
277-
setMigrationResults(
278-
`${after - before} new relations created out of ${numProcessed} distinct relations processed`,
279-
);
280-
else setMigrationResults(`${numProcessed} new relations created`);
281-
posthog.capture("Reified Relations: Migration Completed", {
282-
dryRun: useDryRun,
283-
processed: numProcessed,
284-
before,
285-
after,
286-
created: after - before,
287-
});
288-
} catch (e) {
289-
console.error("Relation migration failed", e);
290-
setMigrationResults(
291-
`Migration failed: ${(e as Error).message ?? "see console for details"}`,
292-
);
293-
posthog.capture("Reified Relations: Migration Failed", {
294-
dryRun: useDryRun,
295-
error: (e as Error).message ?? "unknown error",
296-
});
297-
} finally {
298-
setOngoing(false);
299-
}
300-
};
301-
useEffect(() => {
302-
void (async () => {
303-
if (initial) {
304-
const numRelations = await countReifiedRelations();
305-
setMigrationResults(
306-
numRelations > 0
307-
? `${numRelations} already migrated`
308-
: "No migrated relations",
309-
);
310-
// eslint-disable-next-line react-hooks/exhaustive-deps
311-
initial = false;
312-
}
313-
})();
314-
return () => {
315-
initial;
316-
};
317-
}, []);
318-
319-
return (
320-
<>
321-
<p>
322-
<Button
323-
className="p-4"
324-
onClick={() => {
325-
void doMigrateRelations();
326-
}}
327-
disabled={!enabled || useOngoing}
328-
text="Migrate all relations"
329-
></Button>
330-
<Checkbox
331-
className="left-6 inline-block"
332-
defaultChecked={useDryRun}
333-
onChange={(e) => {
334-
const target = e.target as HTMLInputElement;
335-
setDryRun(target.checked);
336-
}}
337-
labelElement={<>Dry run</>}
338-
/>
339-
</p>
340-
{useOngoing ? (
341-
<Spinner />
342-
) : (
343-
<p id="migrationResultsLabel">{useMigrationResults}</p>
344-
)}
345-
</>
346-
);
347-
};
348-
349256
const FeatureFlagsTab = (): React.ReactElement => {
350-
const [useReifiedRelations, setUseReifiedRelations] = useState<boolean>(
351-
getSetting<boolean>(USE_REIFIED_RELATIONS, false),
352-
);
353257
const settings = useMemo(() => {
354258
refreshConfigTree();
355259
return getFormattedConfigTree();
@@ -442,31 +346,6 @@ const FeatureFlagsTab = (): React.ReactElement => {
442346
</p>
443347
</Alert>
444348

445-
<Checkbox
446-
defaultChecked={useReifiedRelations}
447-
onChange={(e) => {
448-
const target = e.target as HTMLInputElement;
449-
setUseReifiedRelations(target.checked);
450-
void setSetting(USE_REIFIED_RELATIONS, target.checked).catch(
451-
() => undefined,
452-
);
453-
setFeatureFlag("Reified relation triples", target.checked);
454-
posthog.capture("Reified Relations: Toggled", {
455-
enabled: target.checked,
456-
});
457-
}}
458-
labelElement={
459-
<>
460-
Reified relation triples
461-
<Description
462-
description={
463-
"When ON, relations are read/written as reifiedRelationUid in [[roam/js/discourse-graph/relations]]."
464-
}
465-
/>
466-
</>
467-
}
468-
/>
469-
470349
<Button
471350
className="w-96"
472351
icon="send-message"
@@ -508,15 +387,6 @@ const AdminPanel = (): React.ReactElement => {
508387
</div>
509388
}
510389
/>
511-
<Tab
512-
id="migration"
513-
title="Migration"
514-
panel={
515-
<div className="flex flex-col gap-4 p-1">
516-
<MigrationTab />
517-
</div>
518-
}
519-
/>
520390
<Tab
521391
id="node-list"
522392
title="Node list"

0 commit comments

Comments
 (0)