From 9d895aab13561fcddbca23a851d81c26533f06e4 Mon Sep 17 00:00:00 2001 From: David Sheldrick Date: Tue, 13 Feb 2024 16:19:17 +0000 Subject: [PATCH] [docs] Fix missing Persistence page (#2828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2826, extracted from #2680 The problem is that we had two different articles whose ids were being derived as `persistence`, the `persistence.mdx` file and the `persistence/` example. I've 1. Made it an error for two articles to have the same id 2. Renamed the `persistence/` article to `local-storage` since that's the API it's using. ### Change Type - [ ] `patch` — Bug fix - [ ] `minor` — New feature - [ ] `major` — Breaking change - [ ] `dependencies` — Changes to package dependencies[^1] - [x] `documentation` — Changes to the documentation only[^2] - [ ] `tests` — Changes to any test code only[^2] - [ ] `internal` — Any other changes that don't affect the published package[^2] - [ ] I don't know [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version ### Test Plan 1. Add a step-by-step description of how to test your PR here. 3. - [ ] Unit Tests - [ ] End to end tests ### Release Notes - Add a brief release note for your PR here. --- apps/docs/utils/addContent.ts | 55 ++++++++++--------- apps/docs/watcher.ts | 2 + apps/examples/e2e/tests/test-routes.spec.ts | 2 +- .../LocalStorageExample.tsx} | 0 .../{persistence => local-storage}/README.md | 4 +- 5 files changed, 35 insertions(+), 28 deletions(-) rename apps/examples/src/examples/{persistence/PersistenceExample.tsx => local-storage/LocalStorageExample.tsx} (100%) rename apps/examples/src/examples/{persistence => local-storage}/README.md (77%) diff --git a/apps/docs/utils/addContent.ts b/apps/docs/utils/addContent.ts index 76e2732a0..3da123ada 100644 --- a/apps/docs/utils/addContent.ts +++ b/apps/docs/utils/addContent.ts @@ -8,19 +8,19 @@ export async function addContentToDb( content: GeneratedContent ) { const sectionInsert = await db.prepare( - `REPLACE INTO sections (id, idx, title, description, path, sidebar_behavior) VALUES (?, ?, ?, ?, ?, ?)` + `INSERT INTO sections (id, idx, title, description, path, sidebar_behavior) VALUES (?, ?, ?, ?, ?, ?)` ) const categoryInsert = await db.prepare( - `REPLACE INTO categories (id, title, description, sectionId, sectionIndex, path) VALUES (?, ?, ?, ?, ?, ?)` + `INSERT INTO categories (id, title, description, sectionId, sectionIndex, path) VALUES (?, ?, ?, ?, ?, ?)` ) const headingsInsert = await db.prepare( - `REPLACE INTO headings (idx, articleId, level, title, slug, isCode, path) VALUES (?, ?, ?, ?, ?, ?, ?)` + `INSERT INTO headings (idx, articleId, level, title, slug, isCode, path) VALUES (?, ?, ?, ?, ?, ?, ?)` ) const articleInsert = await db.prepare( - `REPLACE INTO articles ( + `INSERT INTO articles ( id, groupIndex, categoryIndex, @@ -79,27 +79,32 @@ export async function addContentToDb( throw Error(`hey, article ${article.id} has no id`) } - await articleInsert.run( - article.id, - article.groupIndex, - article.categoryIndex, - article.sectionIndex, - article.groupId, - article.categoryId, - article.sectionId, - article.author, - article.title, - article.description, - article.hero, - article.status, - article.date, - article.sourceUrl, - article.componentCode, - article.componentCodeFiles, - article.keywords.join(', '), - article.content, - article.path - ) + try { + await articleInsert.run( + article.id, + article.groupIndex, + article.categoryIndex, + article.sectionIndex, + article.groupId, + article.categoryId, + article.sectionId, + article.author, + article.title, + article.description, + article.hero, + article.status, + article.date, + article.sourceUrl, + article.componentCode, + article.componentCodeFiles, + article.keywords.join(', '), + article.content, + article.path + ) + } catch (e: any) { + console.error(`ERROR: Could not add article with id '${article.id}'`) + throw e + } await db.run(`DELETE FROM headings WHERE articleId = ?`, article.id) diff --git a/apps/docs/watcher.ts b/apps/docs/watcher.ts index 8d486d3b7..46b1a339c 100644 --- a/apps/docs/watcher.ts +++ b/apps/docs/watcher.ts @@ -5,6 +5,8 @@ import { refreshContent } from './scripts/functions/refreshContent' import { debounce } from './utils/debounce' import { nicelog } from './utils/nicelog' +refreshContent({ silent: true }) + fs.watch( 'content', { persistent: true, recursive: true }, diff --git a/apps/examples/e2e/tests/test-routes.spec.ts b/apps/examples/e2e/tests/test-routes.spec.ts index dffae7677..ed0f5d3f5 100644 --- a/apps/examples/e2e/tests/test-routes.spec.ts +++ b/apps/examples/e2e/tests/test-routes.spec.ts @@ -67,7 +67,7 @@ test.describe('Routes', () => { }) test('persistence', async ({ page }) => { - await page.goto('http://localhost:5420/persistence/full') + await page.goto('http://localhost:5420/local-storage/full') await page.waitForSelector('.tl-canvas') }) diff --git a/apps/examples/src/examples/persistence/PersistenceExample.tsx b/apps/examples/src/examples/local-storage/LocalStorageExample.tsx similarity index 100% rename from apps/examples/src/examples/persistence/PersistenceExample.tsx rename to apps/examples/src/examples/local-storage/LocalStorageExample.tsx diff --git a/apps/examples/src/examples/persistence/README.md b/apps/examples/src/examples/local-storage/README.md similarity index 77% rename from apps/examples/src/examples/persistence/README.md rename to apps/examples/src/examples/local-storage/README.md index c72d9d430..b45caa322 100644 --- a/apps/examples/src/examples/persistence/README.md +++ b/apps/examples/src/examples/local-storage/README.md @@ -1,6 +1,6 @@ --- -title: Persistence -component: ./PersistenceExample.tsx +title: Local Storage +component: ./LocalStorageExample.tsx category: data/assets ---