Skip to content

Commit

Permalink
fix: page deletion order in docs:prune (#737)
Browse files Browse the repository at this point in the history
* chore: fix spacing after trash bin emoji

* fix: move parent pages to the end of the deletion queue

* test: fix
  • Loading branch information
kanadgupta authored Jan 31, 2023
1 parent 06da423 commit 848c63b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions __tests__/cmds/docs/prune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('rdme docs:prune', () => {
confirm: true,
version,
})
).resolves.toBe('🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.');
).resolves.toBe('🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.');

apiMocks.done();
versionMock.done();
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('rdme docs:prune', () => {
key,
version,
})
).resolves.toBe('🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.');
).resolves.toBe('🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.');

apiMocks.done();
versionMock.done();
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('rdme docs:prune', () => {
version,
})
).resolves.toBe(
'🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.\n🗑️ successfully deleted `this-child-is-also-missing`.'
'🗑️ successfully deleted `this-child-is-also-missing`.\n🗑️ successfully deleted `this-doc-should-be-missing-in-folder`.'
);

apiMocks.done();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/deleteDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export default async function deleteDoc(
),
})
.then(handleRes)
.then(() => `🗑️ successfully deleted \`${slug}\`.`);
.then(() => `🗑️ successfully deleted \`${slug}\`.`);
}
5 changes: 5 additions & 0 deletions src/lib/getDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ function flatten(data: Document[][]): Document[] {
});
}
});

// Docs with children cannot be deleted unless the children are deleted first,
// so move those parent docs to the back of the list
allDocs.sort(a => (a.children?.length ? 1 : -1));

return allDocs;
}

Expand Down

0 comments on commit 848c63b

Please sign in to comment.