-
Notifications
You must be signed in to change notification settings - Fork 7
ENG-2129 Populate reference_content from CrossAppNode and roles from CrossAppNodeSchema
#1324
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ const getConceptMap = async ( | |
| conceptIds: number[], | ||
| spaceMap: Record<number, string>, | ||
| ): Promise<Record<number, string>> => { | ||
| if (conceptIds.length === 0) return {}; | ||
| const request = await client | ||
| .from("my_concepts") | ||
| .select("id, space_id, source_local_id") | ||
|
|
@@ -79,12 +80,22 @@ const asSimpleLocalId = ( | |
| return rid; | ||
| }; | ||
|
|
||
| export const dbNodeSchemaToCrossApp = ( | ||
| schema: Concept, | ||
| spaceMap: Record<number, string>, | ||
| accountMap: Record<number, string>, | ||
| ): CrossAppNodeSchema => { | ||
| const { template, template_content, ...other } = | ||
| export const dbNodeSchemaToCrossApp = ({ | ||
| schema, | ||
| spaceMap, | ||
| accountMap, | ||
| schemaMap, | ||
| }: { | ||
| schema: Concept; | ||
| spaceMap: Record<number, string>; | ||
| accountMap: Record<number, string>; | ||
| schemaMap: Record<number, string>; | ||
| }): CrossAppNodeSchema => { | ||
| const referenceContent = (schema.reference_content ?? {}) as Record< | ||
| string, | ||
| number | ||
| >; | ||
| const { template, template_content, roles, ...other } = | ||
| schema.literal_content as Record<string, Json>; | ||
| const authorId = accountMap[schema.author_id || 0]; | ||
| if (authorId === undefined) throw new Error("Missing author"); | ||
|
|
@@ -95,6 +106,14 @@ export const dbNodeSchemaToCrossApp = ( | |
| schema.source_local_id!, | ||
| "schema", | ||
| ); | ||
| const slotDefinitions: Record<string, string> = Object.fromEntries( | ||
| ((roles as string[] | undefined) ?? []) | ||
| .map((r) => [ | ||
| r, | ||
| asSimpleLocalId(schemaMap[referenceContent[r] ?? 0], spaceUrl), | ||
| ]) | ||
| .filter(([, s]) => s !== undefined) as [string, string][], | ||
|
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.
When a schema declares a role without a Useful? React with 👍 / 👎. |
||
| ); | ||
| return { | ||
| rid, | ||
| localId: schema.source_local_id!, | ||
|
|
@@ -105,6 +124,7 @@ export const dbNodeSchemaToCrossApp = ( | |
| template: template_content as string | undefined, | ||
| templateTitle: template as string | undefined, | ||
| authorId, | ||
| slotDefinitions, | ||
| }; | ||
| }; | ||
|
|
||
|
|
@@ -126,7 +146,11 @@ export const dbNodeSchemasToCrossApp = async ({ | |
| ); | ||
| accountMap = await getAccountMap(client, [...authorIds]); | ||
| } | ||
| return schemas.map((r) => dbNodeSchemaToCrossApp(r, spaceMap, accountMap)); | ||
| const referredSchemaIds = schemas.flatMap((schema) => schema.refs); | ||
| const schemaMap = await getConceptMap(client, referredSchemaIds, spaceMap); | ||
| return schemas.map((schema) => | ||
| dbNodeSchemaToCrossApp({ schema, spaceMap, accountMap, schemaMap }), | ||
| ); | ||
| }; | ||
|
|
||
| export const dbRelationTypeSchemaToCrossApp = ( | ||
|
|
||
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.
Avoid
!whenever possible. If not possible, document why it is absolutely required.Looks like it isn't required here so let's not leave ourselves a footgun.