From 848c63b9799df4acba6229f98f83c94105484635 Mon Sep 17 00:00:00 2001 From: Kanad Gupta <8854718+kanadgupta@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:11:09 -0600 Subject: [PATCH] fix: page deletion order in `docs:prune` (#737) * chore: fix spacing after trash bin emoji * fix: move parent pages to the end of the deletion queue * test: fix --- __tests__/cmds/docs/prune.test.ts | 6 +++--- src/lib/deleteDoc.ts | 2 +- src/lib/getDocs.ts | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/__tests__/cmds/docs/prune.test.ts b/__tests__/cmds/docs/prune.test.ts index 8b71ca2db..05c840b41 100644 --- a/__tests__/cmds/docs/prune.test.ts +++ b/__tests__/cmds/docs/prune.test.ts @@ -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(); @@ -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(); @@ -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(); diff --git a/src/lib/deleteDoc.ts b/src/lib/deleteDoc.ts index 974a89f1e..9d3d4ce81 100644 --- a/src/lib/deleteDoc.ts +++ b/src/lib/deleteDoc.ts @@ -36,5 +36,5 @@ export default async function deleteDoc( ), }) .then(handleRes) - .then(() => `šŸ—‘ļø successfully deleted \`${slug}\`.`); + .then(() => `šŸ—‘ļø successfully deleted \`${slug}\`.`); } diff --git a/src/lib/getDocs.ts b/src/lib/getDocs.ts index 91d5cfd46..fa76403ce 100644 --- a/src/lib/getDocs.ts +++ b/src/lib/getDocs.ts @@ -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; }