Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit e32ff78

Browse files
authored
Enable ToC merging into nodes with children (#773)
* add temporary(?) slug matching * deploy to pre-prd * fixup * Allow replacement of node with children
1 parent b63e232 commit e32ff78

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

.github/workflows/deploy-stg-ecs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
branches:
44
- "master"
55
- "integration"
6+
- "embedded-atlas-cli-launch"
67
concurrency:
78
group: environment-stg-${{ github.ref }}
89
cancel-in-progress: true

modules/persistence/src/services/metadata/ToC/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export interface TocOrderInsertions {
3333
};
3434
}
3535

36-
const isInsertionCandidateNode = (node: ToC, associated_products: AssociatedProduct[] = []): boolean => {
37-
const nodeInProducts = node.options?.project && associated_products.find((p) => p.name === node.options?.project);
38-
const nodeHasNoChildren = !node.children || node.children.length === 0;
39-
return !!(nodeHasNoChildren && nodeInProducts);
36+
const isInsertionCandidateNode = (node: ToC, toBeInserted: Set<string> = new Set([])): boolean => {
37+
const projectName = node.options?.project;
38+
const nodeInProducts = projectName && toBeInserted.has(projectName);
39+
return !!nodeInProducts;
4040
};
4141

4242
const mergeNode = (node: ToC, tocs: ToCInsertions, currentProject) => {
@@ -100,15 +100,16 @@ export const traverseAndMerge = (
100100
const { project } = metadata;
101101

102102
const toctree = hasAssociations(metadata) ? umbrellaToCs.original : umbrellaToCs.urlified;
103-
103+
const toBeInserted = new Set(associated_products.map((p) => p.name));
104104
let queue = [toctree];
105-
while (queue?.length) {
105+
while (queue?.length && toBeInserted.size) {
106106
let next = queue.shift();
107107
// TODO: We can exit early here once we've found all the nodes.
108108
// We should track remaining insertions in a set and add some break logic.
109-
if (next && isInsertionCandidateNode(next, associated_products)) {
109+
if (next && isInsertionCandidateNode(next, toBeInserted)) {
110110
next = mergeNode(next, tocInsertions, project);
111111
metadata.toctreeorder = mergeTocTreeOrder(metadata, next, tocOrderInsertions);
112+
toBeInserted.delete(next.options?.project);
112113
} else if (next?.children) {
113114
queue = [...queue, ...next.children];
114115
}

modules/persistence/tests/metadata/ToC.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('ToC module', () => {
7575
if (candidate) break;
7676
candidate = findTargetToc([metadata[metadataIdx].toctree as unknown as ToC]);
7777
}
78-
expect(_isInsertionCandidateNode(candidate, associatedProducts)).toBeTruthy();
78+
expect(_isInsertionCandidateNode(candidate, new Set(associatedProducts.map((p) => p.name)))).toBeTruthy();
7979
});
8080

8181
test('it returns false if node is not an associated product, or node has children', () => {
@@ -84,7 +84,7 @@ describe('ToC module', () => {
8484
if (candidate) break;
8585
candidate = findTargetToc([metadata[metadataIdx].toctree as unknown as ToC], false);
8686
}
87-
expect(_isInsertionCandidateNode(candidate, associatedProducts)).toBeFalsy();
87+
expect(_isInsertionCandidateNode(candidate, new Set(associatedProducts.map((p) => p.name)))).toBeFalsy();
8888
});
8989
});
9090

0 commit comments

Comments
 (0)