Skip to content
Open
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
32 changes: 32 additions & 0 deletions apps/obsidian/src/components/AdminPanelSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useState, useCallback } from "react";
import { usePlugin } from "./PluginContext";
import { Notice } from "obsidian";
import { updateUsername } from "~/utils/supabaseContext";
import { initializeSupabaseSync } from "~/utils/syncDgNodesToSupabase";

export const AdminPanelSettings = () => {
const plugin = usePlugin();
const [syncModeEnabled, setSyncModeEnabled] = useState<boolean>(
plugin.settings.syncModeEnabled ?? false,
);
const [username, setUsername] = useState<string>(
plugin.settings.username || "",
);

const handleSyncModeToggle = useCallback(
async (newValue: boolean) => {
Expand All @@ -30,6 +34,13 @@ export const AdminPanelSettings = () => {
[plugin],
);

const handleSetUsername = async (newValue: string) => {
setUsername(newValue);
plugin.settings.username = newValue;
await plugin.saveSettings();
await updateUsername(plugin, newValue);
};

return (
<div className="general-settings">
<div className="setting-item">
Expand All @@ -48,6 +59,27 @@ export const AdminPanelSettings = () => {
</div>
</div>
</div>
<div
className={
"setting-item " + (plugin.settings.syncModeEnabled ? "" : "hidden")
}
>
<div className="setting-item-info">
<div className="setting-item-name">Username</div>
<div className="setting-item-description">
A username that will be associated with your vault if you share
data.
</div>
</div>
<div className="setting-item-control">
<input
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
onBlur={(e) => void handleSetUsername(e.target.value)}
/>
</div>
</div>
</div>
);
};
24 changes: 22 additions & 2 deletions apps/obsidian/src/components/DiscourseContextView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { getDiscourseNodeFormatExpression } from "~/utils/getDiscourseNodeFormat
import { RelationshipSection } from "~/components/RelationshipSection";
import { VIEW_TYPE_DISCOURSE_CONTEXT } from "~/types";
import { PluginProvider, usePlugin } from "~/components/PluginContext";
import { getNodeTypeById, getAndFormatImportSource } from "~/utils/typeUtils";
import {
getNodeTypeById,
getAndFormatImportSource,
getUserNameById,
} from "~/utils/typeUtils";
import { refreshImportedFile } from "~/utils/importNodes";
import { publishNode } from "~/utils/publishNode";
import { createBaseForNodeType } from "~/utils/baseForNodeType";
Expand Down Expand Up @@ -161,6 +165,13 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
!isImported &&
!!frontmatter.nodeTypeId;

const formattedVaultName = isImported
? getAndFormatImportSource(
frontmatter.importedFromRid as string,
plugin.settings.spaceNames,
)
: "";

return (
<>
<div className="mb-6">
Expand Down Expand Up @@ -232,7 +243,7 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
View only
</span>
<InfoTooltip
content={`Imported from ${getAndFormatImportSource(frontmatter.importedFromRid as string, plugin.settings.spaceNames)}. Direct edits will be overwritten when refreshed.`}
content={`Imported from ${formattedVaultName}. Direct edits will be overwritten when refreshed.`}
/>
</div>
)}
Expand All @@ -244,6 +255,15 @@ const DiscourseContext = ({ activeFile }: DiscourseContextProps) => {
</div>
)}

{isImported &&
frontmatter.authorId &&
typeof frontmatter.authorId === "number" && (
<div className="text-modifier-text mt-2 text-xs">
<div>
Author: {getUserNameById(plugin, frontmatter.authorId)}
</div>
</div>
)}
{isImported && sourceDates && (
<div className="text-modifier-text mt-2 text-xs">
<div>Created in source: {sourceDates.createdAt}</div>
Expand Down
25 changes: 23 additions & 2 deletions apps/obsidian/src/components/ImportNodesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { createRoot, Root } from "react-dom/client";
import { StrictMode, useState, useEffect, useCallback } from "react";
import type DiscourseGraphPlugin from "../index";
import type { ImportableNode, GroupWithNodes } from "~/types";
import { getUserNameById } from "~/utils/typeUtils";
import {
fetchUserNames,
getAvailableGroupIds,
getPublishedNodesForGroups,
getLocalNodeInstanceIds,
Expand Down Expand Up @@ -61,6 +63,8 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
return;
}

await fetchUserNames(plugin, client);

const publishedNodes = await getPublishedNodesForGroups({
client,
groupIds,
Expand Down Expand Up @@ -106,21 +110,26 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
groupName:
spaceNames.get(node.space_id) ?? `Space ${node.space_id}`,
nodes: [],
authorIds: new Set(),
});
}

const group = grouped.get(groupId)!;
const spaceName =
spaceNames.get(node.space_id) ?? `Space ${node.space_id}`;
group.nodes.push({
nodeInstanceId: node.source_local_id,
title: node.text,
spaceId: node.space_id,
spaceName: spaceNames.get(node.space_id) ?? `Space ${node.space_id}`,
spaceName,
groupId,
selected: false,
createdAt: node.createdAt,
modifiedAt: node.modifiedAt,
filePath: node.filePath,
authorId: node.authorId,
});
if (node.authorId) group.authorIds.add(node.authorId);
}

setGroupsWithNodes(Array.from(grouped.values()));
Expand Down Expand Up @@ -258,6 +267,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
number,
{
spaceName: string;
authorIds: Set<number>;
nodes: Array<{
node: ImportableNode;
groupId: string;
Expand All @@ -271,6 +281,7 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
if (!nodesBySpace.has(node.spaceId)) {
nodesBySpace.set(node.spaceId, {
spaceName: node.spaceName,
authorIds: group.authorIds,
nodes: [],
});
}
Expand Down Expand Up @@ -322,14 +333,19 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {

<div className="max-h-96 overflow-y-auto rounded border">
{Array.from(nodesBySpace.entries()).map(
([spaceId, { spaceName, nodes }]) => {
([spaceId, { spaceName, nodes, authorIds }]) => {
return (
<div key={spaceId} className="border-b">
<div className="bg-muted/10 flex items-center px-3 py-2">
<span className="mr-2">📂</span>
<span className="text-accent-foreground line-clamp-1 font-medium italic">
{spaceName}
</span>
{authorIds.size === 1 && (
<span>
&nbsp;({getUserNameById(plugin, [...authorIds][0]!)})
</span>
)}
<span className="text-muted ml-2 text-sm">
({nodes.length} node{nodes.length !== 1 ? "s" : ""})
</span>
Expand All @@ -349,6 +365,11 @@ const ImportNodesContent = ({ plugin, onClose }: ImportNodesModalProps) => {
<div className="min-w-0 flex-1">
<div className="line-clamp-3 font-medium">
{node.title}
{node.authorId && authorIds.size > 1 && (
<span className="font-light">
&nbsp;({getUserNameById(plugin, node.authorId)})
</span>
)}
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions apps/obsidian/src/components/NodeTypeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getImportInfo,
formatImportSource,
getAndFormatImportSource,
getUserNameById,
} from "~/utils/typeUtils";
import { FolderSuggestInput } from "./GeneralSettings";
import { createBaseForNodeType } from "~/utils/baseForNodeType";
Expand Down Expand Up @@ -581,6 +582,8 @@ const NodeTypeSettings = () => {
</div>
{isImported && importInfo.spaceUri && (
<span className="text-muted pl-6 text-xs">
{nodeType.authorId &&
`by ${getUserNameById(plugin, nodeType.authorId)} `}
from{" "}
{formatImportSource(
importInfo.spaceUri || "",
Expand Down
21 changes: 15 additions & 6 deletions apps/obsidian/src/components/RelationshipSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getNodeTypeById,
getAndFormatImportSource,
isAcceptedSchema,
getUserNameById,
} from "~/utils/typeUtils";
import type { RelationInstance } from "~/types";
import {
Expand Down Expand Up @@ -527,7 +528,19 @@ const CurrentRelationships = ({
</div>
<ul className="m-0 ml-6 list-none p-0">
{group.linkedEntries.map((entry) => (
<li key={entry.relation.id} className="mt-1 flex items-center gap-2">
<li
Comment thread
maparent marked this conversation as resolved.
key={entry.relation.id}
className="mt-1 flex items-center gap-2"
title={
entry.relation.importedFromRid && entry.relation.authorId
? `relation by ${getUserNameById(plugin, entry.relation.authorId)} from space ${getAndFormatImportSource(entry.relation.importedFromRid, plugin.settings.spaceNames)}`
: entry.relation.authorId
? `relation by ${getUserNameById(plugin, entry.relation.authorId)}`
: entry.relation.importedFromRid
? `relation from space ${getAndFormatImportSource(entry.relation.importedFromRid, plugin.settings.spaceNames)}`
: ""
}
>
<a
href="#"
className="text-accent-text flex-1"
Expand Down Expand Up @@ -612,11 +625,7 @@ const CurrentRelationships = ({
e.preventDefault();
void acceptRelation(entry.relation.id);
}}
title={
entry.relation.importedFromRid
? `Accept relation from space ${getAndFormatImportSource(entry.relation.importedFromRid, plugin.settings.spaceNames)}`
: "Accept relationship"
}
title="Accept relationship"
>
</button>
Expand Down
3 changes: 3 additions & 0 deletions apps/obsidian/src/components/RelationshipSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
formatImportSource,
isAcceptedSchema,
isProvisionalSchema,
getUserNameById,
} from "~/utils/typeUtils";
import generateUid from "~/utils/generateUid";

Expand Down Expand Up @@ -285,6 +286,8 @@ const RelationshipSettings = () => {
)}
{importInfo.spaceUri && (
<span>
{relation.authorId &&
`by ${getUserNameById(plugin, relation.authorId)} `}
from{" "}
{formatImportSource(
importInfo.spaceUri,
Expand Down
3 changes: 3 additions & 0 deletions apps/obsidian/src/components/RelationshipTypeSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getImportInfo,
formatImportSource,
isProvisionalSchema,
getUserNameById,
} from "~/utils/typeUtils";

type ColorPickerProps = {
Expand Down Expand Up @@ -346,6 +347,8 @@ const RelationshipTypeSettings = () => {
)}
{importInfo.spaceUri && (
<span>
{relationType.authorId &&
`by ${getUserNameById(plugin, relationType.authorId)} `}
from{" "}
{formatImportSource(
importInfo.spaceUri,
Expand Down
7 changes: 4 additions & 3 deletions apps/obsidian/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ export default class DiscourseGraphPlugin extends Plugin {
if (!this.settings.showIdsInFrontmatter) {
keysToHide.push(
...[
"nodeTypeId",
"authorId",
"importedAssets",
"importedFromRid",
"lastModified",
"nodeInstanceId",
"nodeTypeId",
"publishedToGroups",
"lastModified",
"importedAssets",
],
);
keysToHide.push(...this.settings.relationTypes.map((rt) => rt.id));
Expand Down
9 changes: 8 additions & 1 deletion apps/obsidian/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type DiscourseNode = {
created: number;
modified: number;
importedFromRid?: string;
authorId?: number;
};

export type ImportStatus = "provisional" | "accepted";
Expand All @@ -28,6 +29,7 @@ export type DiscourseRelationType = {
modified: number;
importedFromRid?: string;
status?: ImportStatus;
authorId?: number;
};

export type DiscourseRelation = {
Expand All @@ -39,6 +41,7 @@ export type DiscourseRelation = {
modified: number;
importedFromRid?: string;
status?: ImportStatus;
authorId?: number;
};

export type RelationInstance = {
Expand All @@ -47,12 +50,12 @@ export type RelationInstance = {
source: string;
destination: string;
created: number;
author: string;
lastModified?: number;
publishedToGroupId?: string[];
importedFromRid?: string;
/** Tracks acceptance of imported relations. false = imported, not yet accepted. true or undefined = accepted/local. */
tentative?: boolean;
authorId?: number;
};

export type Settings = {
Expand All @@ -69,6 +72,8 @@ export type Settings = {
syncModeEnabled?: boolean;
/** Maps spaceUri (e.g. "obsidian:abc123") to human-readable name (e.g. "My Vault") */
spaceNames?: Record<string, string>;
username?: string;
userNames?: Record<number, string>;
};

export type BulkImportCandidate = {
Expand Down Expand Up @@ -96,12 +101,14 @@ export type ImportableNode = {
createdAt?: number;
modifiedAt?: number;
filePath?: string;
authorId?: number;
};

export type GroupWithNodes = {
groupId: string;
groupName?: string;
nodes: ImportableNode[];
authorIds: Set<number>;
};

export const VIEW_TYPE_DISCOURSE_CONTEXT = "discourse-context-view";
Loading
Loading