Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dailies behave as edges #274

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
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
11 changes: 11 additions & 0 deletions components/Tweaks/Filter/FilterPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ const FilterPanel = (props: FilterPanelProps) => {
isChecked={filter.dailies}
></Switch>
</Flex>
<Flex justifyContent="space-between">
<Text>Render Dailies as Links</Text>
<Switch
onChange={() => {
setFilter((curr: typeof initialFilter) => {
return { ...curr, dailiesAsPassthrough: !curr.dailiesAsPassthrough }
})
}}
isChecked={filter.dailiesAsPassthrough}
></Switch>
</Flex>
<Flex justifyContent="space-between">
<Text>Org-noter pages</Text>
<Switch
Expand Down
1 change: 1 addition & 0 deletions components/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const initialPhysics = {
export const initialFilter = {
orphans: false,
dailies: false,
dailiesAsPassthrough: false,
parent: 'heading',
filelessCites: false,
tagsBlacklist: [],
Expand Down
8 changes: 7 additions & 1 deletion org-roam-ui.el
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ unchanged."
(links . ,(mapcar
(apply-partially
#'org-roam-ui-sql-to-alist
'(source target type))
'(source target type properties))
links-db-rows))
(tags . ,(seq-mapcat
#'seq-reverse
Expand Down Expand Up @@ -487,8 +487,14 @@ Optionally set OLD to t to use the old db model (where the cites
were in the same table as the links)."
(if (not old)
(org-roam-db-query
;; I'd like to get links:outline (assuming that's a thing)
;; so I could more specifically scope the links. But I'm not sure
;; that's really what I want anyway. Ideally, I could say "only link nodes in the
;; same org header together, instead of linking nodes in the whole daily"
;; I think just grabbing the properties might do the trick? But not clear.
`[:select [links:source
links:dest
links:properties
links:type]
:from links
:where (= links:type "id")])
Expand Down
70 changes: 67 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,9 @@ export const Graph = function (props: GraphProps) {
} = props

const { dailyDir, roamDir } = variables
const isDaily = (node: OrgRoamNode) => {
return dailyDir && node.file?.includes(dailyDir);
}

const [hoverNode, setHoverNode] = useState<NodeObject | null>(null)

Expand Down Expand Up @@ -831,6 +834,7 @@ export const Graph = function (props: GraphProps) {
const filteredLinksByNodeIdRef = useRef<LinksByNodeId>({})

const hiddenNodeIdsRef = useRef<NodeById>({})
const dailiesNodeIdsRef = useRef<NodeById>({})
const filteredGraphData = useMemo(() => {
hiddenNodeIdsRef.current = {}
const filteredNodes = graphData?.nodes
Expand Down Expand Up @@ -875,7 +879,8 @@ export const Graph = function (props: GraphProps) {
return false
}

if (filter.dailies && dailyDir && node.file?.includes(dailyDir)) {
if ((filter.dailies || filter.dailiesAsPassthrough) && isDaily(node)) {
dailiesNodeIdsRef.current = {...dailiesNodeIdsRef.current, [node.id]: node }
hiddenNodeIdsRef.current = { ...hiddenNodeIdsRef.current, [node.id]: node }
return false
}
Expand Down Expand Up @@ -910,6 +915,12 @@ export const Graph = function (props: GraphProps) {
const filteredNodeIds = filteredNodes.map((node) => node.id as string)
const filteredLinks = graphData.links.filter((link) => {
const [sourceId, targetId] = normalizeLinkEnds(link)
// if we point to a daily and the config is set, check everything else that daily links to
// probably also make this a map? or just do it separately?
// after this function we'll only have links that are to nodes visible,
// which would have already filtered out dailies
// so we can just go through those, and recreate links based on what's in the dailies
// and what the dailies point to
if (
!filteredNodeIds.includes(sourceId as string) ||
!filteredNodeIds.includes(targetId as string)
Expand All @@ -926,16 +937,69 @@ export const Graph = function (props: GraphProps) {
return linkRoam.type !== 'heading'
})

filteredLinksByNodeIdRef.current = filteredLinks.reduce<LinksByNodeId>((acc, linkArg) => {
const linkMapReducer = (acc: LinksByNodeId, linkArg: LinkObject) => {
const link = linkArg as OrgRoamLink
const [sourceId, targetId] = normalizeLinkEnds(link)
return {
...acc,
[sourceId]: [...(acc[sourceId] ?? []), link],
[targetId]: [...(acc[targetId] ?? []), link],
}
}, {})
}
filteredLinksByNodeIdRef.current = filteredLinks.reduce<LinksByNodeId>(linkMapReducer, {})
if (filter.dailiesAsPassthrough) {
let additionalLinksFromDailies: LinksByNodeId = {};
const allLinks = graphData.links.reduce<LinksByNodeId>(linkMapReducer, {})
debugger;
const seenLinks: {[key: string]: boolean} = {}
filteredNodeIds.forEach((n) => {
allLinks[n]?.forEach((l) => {
const [sourceId, targetId] = normalizeLinkEnds(l)
const daily = dailiesNodeIdsRef.current[sourceId]
if (daily) {
allLinks[sourceId]?.forEach((l) => {
const [skipSourceId, skipTargetId] = normalizeLinkEnds(l)
// bit of a hack, for some reason this is getting stuff not in the list
if (
!filteredNodeIds.includes(targetId as string) ||
!filteredNodeIds.includes(skipTargetId as string)
) {
return
}
const newLink = {
source: targetId,
target: skipTargetId,
type: 'id'
}
if (seenLinks[newLink.source + '_' + newLink.target]) {
return
}
seenLinks[newLink.source + '_' + newLink.target] = true
additionalLinksFromDailies = {
...additionalLinksFromDailies,
[n]: [
...(additionalLinksFromDailies[n] ?? []),
newLink
]
}
})
}
})
})
// Why isn't this overlyaying?
Object.keys(additionalLinksFromDailies).forEach((n) => {
filteredLinksByNodeIdRef.current = {
...filteredLinksByNodeIdRef.current,
[n] : [
...(filteredLinksByNodeIdRef.current[n] ?? []),
...(additionalLinksFromDailies[n] ?? [])
]
};
filteredLinks.push(...(additionalLinksFromDailies[n] ?? []))
})
}

// todo somewhere in here? transform a daiy to a link between all things in that daily?
const weightedLinks = filteredLinks.map((l) => {
const [target, source] = normalizeLinkEnds(l)
const link = l as OrgRoamLink
Expand Down