-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2153 Undecorate Roam node titles into core_title on publish #1317
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
Open
sid597
wants to merge
2
commits into
main
from
eng-2153-undecorate-roam-node-titles-into-core_title-on-publish
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { beforeEach, describe, expect, it, vi } from "vitest"; | ||
| import type { SupabaseContext } from "~/utils/supabaseContext"; | ||
|
|
||
| vi.mock("~/utils/getBlockProps", () => ({ default: () => ({}) })); | ||
| vi.mock("~/utils/getDiscourseNodes", () => ({ default: () => [] })); | ||
| vi.mock("~/utils/getDiscourseRelations", () => ({ default: () => [] })); | ||
| vi.mock("~/utils/createReifiedBlock", () => ({ | ||
| DISCOURSE_GRAPH_PROP_NAME: "discourse-graph", | ||
| })); | ||
| vi.mock("roamjs-components/queries/getPageTitleByPageUid", () => ({ | ||
| default: () => "", | ||
| })); | ||
|
|
||
| import { discourseNodeBlockToLocalConcept } from "~/utils/conceptConversion"; | ||
|
|
||
| const context = { spaceId: 42 } as SupabaseContext; | ||
|
|
||
| describe("discourseNodeBlockToLocalConcept", () => { | ||
| beforeEach(() => { | ||
| (globalThis as { window: unknown }).window = { | ||
| roamAlphaAPI: { | ||
| q: () => [["author-1", "page-1", 1000, 2000]], | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| it("writes the core title into literal_content", () => { | ||
| const concept = discourseNodeBlockToLocalConcept(context, { | ||
| nodeUid: "node-1", | ||
| schemaUid: "schema-1", | ||
| text: "CLM - my claim", | ||
| coreTitle: "my claim", | ||
| }); | ||
| expect(concept.literal_content).toEqual({ core_title: "my claim" }); | ||
| expect(concept.name).toBe("CLM - my claim"); | ||
| expect(concept.source_local_id).toBe("node-1"); | ||
| }); | ||
| }); |
76 changes: 76 additions & 0 deletions
76
apps/roam/src/utils/__tests__/extractContentFromTitle.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import extractContentFromTitle from "~/utils/extractContentFromTitle"; | ||
|
|
||
| describe("extractContentFromTitle", () => { | ||
| it("extracts the content from a title matching the format", () => { | ||
| expect( | ||
| extractContentFromTitle("[[CLM]] - my claim", { | ||
| format: "[[CLM]] - {content}", | ||
| }), | ||
| ).toBe("my claim"); | ||
| }); | ||
|
|
||
| it("returns the title when the type has no format", () => { | ||
| expect(extractContentFromTitle("my claim", { format: "" })).toBe( | ||
| "my claim", | ||
| ); | ||
| }); | ||
|
|
||
| it("returns the title when it does not match the format", () => { | ||
| expect( | ||
| extractContentFromTitle("random page", { | ||
| format: "[[CLM]] - {content}", | ||
| }), | ||
| ).toBe("random page"); | ||
| }); | ||
|
|
||
| it("extracts the content from a format with a {Source} placeholder", () => { | ||
| expect( | ||
| extractContentFromTitle("[[EVD]] - finding - @smith2020", { | ||
| format: "[[EVD]] - {content} - {Source}", | ||
| }), | ||
| ).toBe("finding"); | ||
| }); | ||
|
|
||
| it("preserves an empty content capture instead of falling back to the title", () => { | ||
| expect( | ||
| extractContentFromTitle("[[EVD]] - - @smith2020", { | ||
| format: "[[EVD]] - {content} - {Source}", | ||
| }), | ||
| ).toBe(""); | ||
| }); | ||
|
|
||
| it('keeps a trailing content containing " - " whole', () => { | ||
| expect( | ||
| extractContentFromTitle("[[CLM]] - a - b", { | ||
| format: "[[CLM]] - {content}", | ||
| }), | ||
| ).toBe("a - b"); | ||
| }); | ||
|
|
||
| it('extracts the shortest match when the content contains " - " before another placeholder (accepted for v0)', () => { | ||
| expect( | ||
| extractContentFromTitle("[[EVD]] - a - b - @smith2020", { | ||
| format: "[[EVD]] - {content} - {Source}", | ||
| }), | ||
| ).toBe("a"); | ||
| }); | ||
|
|
||
| it("round trips a title built from the core title", () => { | ||
| const coreTitle = "sleep improves memory"; | ||
| const simpleFormat = "[[CLM]] - {content}"; | ||
| expect( | ||
| extractContentFromTitle(simpleFormat.replace("{content}", coreTitle), { | ||
| format: simpleFormat, | ||
| }), | ||
| ).toBe(coreTitle); | ||
|
|
||
| const sourceFormat = "[[EVD]] - {content} - {Source}"; | ||
| const title = sourceFormat | ||
| .replace("{content}", coreTitle) | ||
| .replace("{Source}", "@smith2020"); | ||
| expect(extractContentFromTitle(title, { format: sourceFormat })).toBe( | ||
| coreTitle, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { | |
| nodeTypeSince, | ||
| } from "./getAllDiscourseNodesSince"; | ||
| import getDiscourseNodeFormatExpression from "./getDiscourseNodeFormatExpression"; | ||
| import extractContentFromTitle from "./extractContentFromTitle"; | ||
| import { cleanupOrphanedNodes } from "./cleanupOrphanedNodes"; | ||
| import { | ||
| getLoggedInClient, | ||
|
|
@@ -667,11 +668,17 @@ export const convertDgToSupabaseConcepts = async ({ | |
| return discourseNodeSchemaToLocalConcept(context, node); | ||
| }); | ||
|
|
||
| const formatByNodeTypeUid = new Map( | ||
| allNodeTypes.map((nodeType) => [nodeType.type, nodeType.format]), | ||
| ); | ||
| const nodeBlockToLocalConcepts = nodesSince.map((node) => { | ||
| const localConcept = discourseNodeBlockToLocalConcept(context, { | ||
| nodeUid: node.source_local_id, | ||
| schemaUid: node.type, | ||
| text: node.node_title ? `${node.node_title} ${node.text}` : node.text, | ||
| coreTitle: extractContentFromTitle(node.node_title ?? node.text, { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inlined instead of reusing the publish-side helper because |
||
| format: formatByNodeTypeUid.get(node.type) ?? "", | ||
| }), | ||
| }); | ||
| return localConcept; | ||
| }); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing reads this
coreTitleyet: this producer feedsupsert_content, notupsert_concepts. It is set so anyCrossAppNodethat reaches concept conversion carries it (the ticket lists all three producers).