Skip to content

Comments

feat(wikibase-schema-editor): integrate schema API in frontend#77

Merged
DaxServer merged 1 commit intomainfrom
wikibase-editor-task5
Jul 20, 2025
Merged

feat(wikibase-schema-editor): integrate schema API in frontend#77
DaxServer merged 1 commit intomainfrom
wikibase-editor-task5

Conversation

@DaxServer
Copy link
Owner

Addresses Task 5 of #66

@coderabbitai
Copy link

coderabbitai bot commented Jul 20, 2025

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Introduced new utilities for building and parsing Wikibase schema objects.
    • Added a composable for managing schema-related API interactions, including loading, creating, updating, and deleting schemas.
  • Refactor

    • Refactored schema store to use individual state properties instead of a nested schema object, simplifying state management and actions.
  • Bug Fixes

    • Improved type safety for validation errors and schema labels/descriptions.
  • Tests

    • Added comprehensive tests for schema API interactions and refactored store tests for improved coverage and maintainability.
  • Chores

    • Updated ESLint and auto-import configurations for new utilities and types.
    • Added type declarations for .vue files and improved TypeScript support.
    • Removed obsolete TypeScript configuration file.
    • Updated development dependencies and scripts.

Walkthrough

This change introduces a major refactor of the frontend schema store by flattening its state from a nested object to individual reactive properties. It adds new composables for schema API integration and schema building/parsing, updates types for clarity and reuse, and includes comprehensive tests for both the store and the new composables. TypeScript and ESLint configurations are updated accordingly.

Changes

File(s) Change Summary
.kiro/specs/wikibase-schema-editor/tasks.md Marked "Build API integration composable" as complete (with TDD), updated requirements.
frontend/.eslintrc-auto-import.json
frontend/auto-imports.d.ts
frontend/env.d.ts
Added global auto-imports and typings for new composables (useSchemaApi, useSchemaBuilder) and types (CreateSchemaRequest, Label). Added Vue file type declarations.
frontend/package.json
frontend/tsconfig.typecheck.json
Added @pinia/testing to devDependencies; simplified the typecheck script; removed the separate typecheck tsconfig.
frontend/src/composables/useSchemaApi.ts
frontend/src/composables/useSchemaBuilder.ts
Introduced new composables for schema API integration and schema building/parsing. Exposed functions for CRUD operations, schema construction, and parsing.
frontend/src/composables/tests/useSchemaApi.test.ts Added comprehensive test suite for useSchemaApi composable, covering all CRUD operations and error handling.
frontend/src/stores/schema.store.ts Refactored schema store: replaced nested schema object with individual refs for each property; updated all actions to operate on these refs; removed computed properties and some actions; renamed/modified reset logic.
frontend/src/stores/tests/schema.store.test.ts Refactored tests to match new store structure; switched to property-based assertions; introduced full mocking of schema builder composable; added tests for integration with mocked builder.
frontend/src/types/wikibase-schema.ts Refined types: introduced Label alias, updated TermsSchemaMapping to use it, and made ValidationError.context more specific with a ValidationContext interface.

Sequence Diagram(s)

sequenceDiagram
  participant Component
  participant useSchemaApi
  participant apiClient
  participant schemaStore
  participant errorHandler

  Component->>useSchemaApi: loadSchema(projectId, schemaId)
  useSchemaApi->>schemaStore: setLoading(true)
  useSchemaApi->>apiClient: getSchema(projectId, schemaId)
  alt Success
    useSchemaApi->>schemaStore: update refs with schema data
    useSchemaApi->>schemaStore: setLoading(false)
  else Error
    useSchemaApi->>errorHandler: showError(error)
    useSchemaApi->>schemaStore: $reset()
    useSchemaApi->>schemaStore: setLoading(false)
  end

  Component->>useSchemaApi: createSchema(projectId, data)
  useSchemaApi->>schemaStore: setLoading(true)
  useSchemaApi->>apiClient: createSchema(projectId, data)
  alt Success
    useSchemaApi->>schemaStore: update refs with new schema
    useSchemaApi->>schemaStore: setLoading(false)
  else Error
    useSchemaApi->>errorHandler: showError(error)
    useSchemaApi->>schemaStore: setLoading(false)
  end

  Component->>useSchemaApi: updateSchema(projectId, schemaId, data)
  useSchemaApi->>schemaStore: setLoading(true)
  useSchemaApi->>apiClient: updateSchema(projectId, schemaId, data)
  alt Success
    useSchemaApi->>schemaStore: update refs
    useSchemaApi->>schemaStore: markAsSaved()
    useSchemaApi->>schemaStore: setLoading(false)
  else Error
    useSchemaApi->>errorHandler: showError(error)
    useSchemaApi->>schemaStore: setLoading(false)
  end

  Component->>useSchemaApi: deleteSchema(projectId, schemaId)
  useSchemaApi->>apiClient: deleteSchema(projectId, schemaId)
  alt Success
    useSchemaApi->>schemaStore: $reset()
  else Error
    useSchemaApi->>errorHandler: showError(error)
  end
Loading

Possibly related PRs

  • DaxServer/dataforge#75: Introduced the initial schema store with a nested schema object and computed properties; this PR represents a significant refactor and evolution of that store.
  • DaxServer/dataforge#65: Added the initial comprehensive tasks plan for the Wikibase Schema Editor; this PR updates the same tasks file to mark API integration as complete.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🔭 Outside diff range comments (1)
frontend/src/stores/schema.store.ts (1)

122-127: Do not override server updatedAt in markAsSaved

markAsSaved currently resets the store’s updatedAt to the client’s “now,” which immediately clobbers the API-returned timestamp loaded via loadSchemaIntoStore. Instead, let the backend drive updatedAt and reserve markAsSaved for clearing the dirty flag and tracking the client’s save moment:

• File: frontend/src/stores/schema.store.ts
• Lines: 122–127

Suggested change:

 const markAsSaved = () => {
   const now = new Date()
   isDirty.value = false
   lastSaved.value = now
-  updatedAt.value = now.toISOString()
 }

—remove the updatedAt.value = … line so that updatedAt remains the timestamp from the server response.

🧹 Nitpick comments (3)
frontend/package.json (1)

8-10: Consider migrating from Vite to Bun for consistency with coding guidelines.

The coding guidelines specify using Bun.serve() for frontend development instead of Vite, and bun build for building HTML/TypeScript/CSS files. Consider updating the scripts to align with these guidelines.

-    "dev": "vite",
-    "build": "vite build",
-    "preview": "vite preview",
+    "dev": "bun run dev.ts",
+    "build": "bun build src/main.ts --outdir dist",
+    "preview": "bun run preview.ts",
frontend/env.d.ts (1)

1-1: Consider updating to align with Bun usage guidelines.

The coding guidelines specify using Bun instead of Vite for frontend development. Consider whether Vite client types are still needed if migrating to Bun.

frontend/src/composables/__tests__/useSchemaApi.test.ts (1)

139-164: Use undefined assignment instead of delete operator for better performance

The static analysis tool correctly identifies that the delete operator can impact performance. Use undefined assignment as suggested.

   if (originalUseApi) {
     globalThis.useApi = originalUseApi
   } else {
-    delete globalThis.useApi
+    globalThis.useApi = undefined as any
   }

   if (originalUseErrorHandling) {
     globalThis.useErrorHandling = originalUseErrorHandling
   } else {
-    delete globalThis.useErrorHandling
+    globalThis.useErrorHandling = undefined as any
   }

   if (originalUseSchemaBuilder) {
     globalThis.useSchemaBuilder = originalUseSchemaBuilder
   } else {
-    delete globalThis.useSchemaBuilder
+    globalThis.useSchemaBuilder = undefined as any
   }

   if (originalUseSchemaStore) {
     globalThis.useSchemaStore = originalUseSchemaStore
   } else {
-    delete globalThis.useSchemaStore
+    globalThis.useSchemaStore = undefined as any
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d011ccb and f55b940.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • .kiro/specs/wikibase-schema-editor/tasks.md (1 hunks)
  • frontend/.eslintrc-auto-import.json (3 hunks)
  • frontend/auto-imports.d.ts (3 hunks)
  • frontend/env.d.ts (1 hunks)
  • frontend/package.json (2 hunks)
  • frontend/src/composables/__tests__/useSchemaApi.test.ts (1 hunks)
  • frontend/src/composables/useSchemaApi.ts (1 hunks)
  • frontend/src/composables/useSchemaBuilder.ts (1 hunks)
  • frontend/src/stores/__tests__/schema.store.test.ts (9 hunks)
  • frontend/src/stores/schema.store.ts (5 hunks)
  • frontend/src/types/wikibase-schema.ts (2 hunks)
  • frontend/tsconfig.typecheck.json (0 hunks)
💤 Files with no reviewable changes (1)
  • frontend/tsconfig.typecheck.json
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{js,ts,jsx,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc
**/*.{html,ts,css}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc
**/*.{html,js,ts,jsx,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc
**/*.test.{js,ts,jsx,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc
🧠 Learnings (3)
frontend/package.json (4)
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.test.{js,ts,jsx,tsx} : Use `bun test` instead of `jest` or `vitest` for running tests.
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Use `bun <file>` instead of `node <file>` or `ts-node <file>` for running scripts.
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{html,ts,css} : Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild` for building HTML, TypeScript, or CSS files.
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{html,js,ts,jsx,tsx} : Use HTML imports with `Bun.serve()` instead of `vite` for frontend development.
frontend/env.d.ts (3)
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{html,js,ts,jsx,tsx} : Use HTML imports with `Bun.serve()` instead of `vite` for frontend development.
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Do not use dotenv; Bun automatically loads .env files.
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.html : HTML files can import `.tsx`, `.jsx`, or `.js` files directly and Bun's bundler will transpile and bundle automatically.
frontend/auto-imports.d.ts (1)
Learnt from: CR
PR: DaxServer/dataforge#0
File: .cursor/rules/use-bun-instead-of-node-vite-npm-pnpm.mdc:0-0
Timestamp: 2025-07-19T07:24:31.852Z
Learning: Applies to **/*.{html,js,ts,jsx,tsx} : Use HTML imports with `Bun.serve()` instead of `vite` for frontend development.
🧬 Code Graph Analysis (1)
frontend/src/composables/useSchemaBuilder.ts (1)
frontend/src/types/wikibase-schema.ts (9)
  • Label (73-73)
  • ColumnMapping (81-85)
  • StatementSchemaMapping (109-116)
  • WikibaseSchemaMapping (57-65)
  • ItemSchemaMapping (67-71)
  • TermsSchemaMapping (75-79)
  • PropertyReference (118-122)
  • ValueMapping (124-128)
  • StatementRank (140-140)
🪛 Biome (1.9.4)
frontend/env.d.ts

[error] 5-5: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 5-5: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

frontend/src/composables/__tests__/useSchemaApi.test.ts

[error] 144-144: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 150-150: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 156-156: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 162-162: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 GitHub Check: test
frontend/src/composables/useSchemaApi.ts

[failure] 29-29: TypeError: Right side of assignment cannot be destructured

  at loadSchemaIntoStore (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:29:9)
  at <anonymous> (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:56:7)

[failure] 29-29: TypeError: Right side of assignment cannot be destructured

  at loadSchemaIntoStore (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:29:9)
  at <anonymous> (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:104:7)

[failure] 29-29: TypeError: Right side of assignment cannot be destructured

  at loadSchemaIntoStore (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:29:9)
  at <anonymous> (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:104:7)

[failure] 29-29: TypeError: Right side of assignment cannot be destructured

  at loadSchemaIntoStore (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:29:9)
  at <anonymous> (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:81:7)

[failure] 29-29: TypeError: Right side of assignment cannot be destructured

  at loadSchemaIntoStore (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:29:9)
  at <anonymous> (/home/runner/work/dataforge/dataforge/frontend/src/composables/useSchemaApi.ts:56:7)
🪛 GitHub Actions: Run tests
frontend/src/composables/__tests__/useSchemaApi.test.ts

[error] 1-1: Unknown error reported in test file. No further details provided.

🔇 Additional comments (19)
frontend/package.json (2)

12-12: LGTM! Typecheck script simplification is appropriate.

The simplified vue-tsc --skipLibCheck command is sufficient for type checking, especially after removing the separate tsconfig.typecheck.json file.


30-30: Good addition of Pinia testing utilities.

Adding @pinia/testing aligns well with the new test suites for schema stores and composables mentioned in the AI summary.

.kiro/specs/wikibase-schema-editor/tasks.md (1)

27-27: LGTM! Task completion accurately reflects the implemented work.

The marking of Task 5 as completed aligns with the implementation of the useSchemaApi composable and its comprehensive test suite mentioned in the AI summary.

frontend/.eslintrc-auto-import.json (3)

12-12: LGTM! Type addition supports auto-import functionality.

Adding CreateSchemaRequest to globals enables its usage without explicit imports, consistent with the new schema API integration.


34-34: LGTM! Label type addition enhances development experience.

Adding the Label type to globals facilitates its usage across components without manual imports.


317-318: LGTM! Composable auto-imports improve developer experience.

Adding useSchemaApi and useSchemaBuilder to globals enables seamless usage of these new composables throughout the application.

frontend/env.d.ts (1)

3-7: LGTM! Standard Vue module declaration pattern.

The {} type usage flagged by static analysis is acceptable here as it's the standard pattern for declaring Vue components in TypeScript. The DefineComponent<{}, {}, any> signature is appropriate for generic .vue file declarations.

frontend/src/types/wikibase-schema.ts (3)

26-26: LGTM! Improved type safety with ValidationContext.

Replacing the generic context property with the specific ValidationContext interface provides better type safety and clearer expectations for validation error context data.


73-73: LGTM! Label type alias enhances code clarity.

The Label type alias improves code readability and reusability for language-to-column mappings.


76-77: LGTM! Consistent use of Label type improves maintainability.

Using the Label type alias for both labels and descriptions properties enhances type consistency and makes future modifications easier.

frontend/src/composables/__tests__/useSchemaApi.test.ts (1)

166-487: Excellent test coverage!

The test suite comprehensively covers all CRUD operations, error scenarios, and state management. The tests are well-structured and provide confidence in the composable's functionality.

frontend/src/stores/__tests__/schema.store.test.ts (1)

53-365: Well-structured tests for the refactored store!

The test suite effectively covers the flattened store structure and all its operations. The tests properly verify the integration with mocked dependencies and edge cases.

frontend/src/stores/schema.store.ts (3)

17-32: Well-structured state refactoring!

The flattened state structure using individual reactive refs is a solid design choice that improves reactivity tracking, type inference, and testability.


41-90: Clean implementation of term management actions.

The label, description, and alias management actions are well-implemented with proper initialization, cleanup of empty arrays, and consistent dirty state tracking.


92-120: Good integration with the schema builder composable.

The statement management properly delegates construction to buildStatement and maintains consistent state updates with dirty tracking.

frontend/auto-imports.d.ts (4)

262-263: LGTM! Composable declarations properly added.

The new useSchemaApi and useSchemaBuilder composables are correctly declared following the established pattern and maintain alphabetical ordering.


349-350: LGTM! Type export correctly declared.

The CreateSchemaRequest type export follows the established pattern and is properly positioned within the global type declarations.


358-358: LGTM! Label type correctly added.

The Label type is properly added to the existing type exports from wikibase-schema, maintaining consistency with the auto-generated format.


619-620: LGTM! Vue component properties correctly declared.

The readonly properties for the new composables are properly added to the Vue component custom properties interface, maintaining the established pattern and alphabetical ordering.

@DaxServer DaxServer merged commit eb4c3f8 into main Jul 20, 2025
4 of 6 checks passed
@DaxServer DaxServer deleted the wikibase-editor-task5 branch July 20, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant