Skip to content

fix: dateformat api bug - #1238

Merged
Mythie merged 7 commits into
mainfrom
fix/dateformat-api-bug
Jul 30, 2024
Merged

Mythie merged 7 commits into
mainfrom
fix/dateformat-api-bug

Conversation

@catalinpit

@catalinpit catalinpit commented Jul 23, 2024 •

Copy link
Copy Markdown
Member

The dateFormat value wasn't processed correctly for documents created via the API.

Now, it checks that the dateFormat value is valid and throws an error if it is not.

Summary by CodeRabbit

  • New Features

    • Enhanced date format and time zone validation for API requests to improve error handling.
    • Updated handling of date format and time zone settings in the UI for dynamic assignment based on predefined options.
    • Integrated OpenAPI documentation features into the API schema for better clarity on expected input formats.
  • Bug Fixes

    • Fixed an issue where invalid time zones could be accepted in settings.

@vercel

vercel Bot commented Jul 23, 2024 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
prd-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 0:38am
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 0:38am
stg-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 0:38am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 29, 2024 0:38am
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Jul 29, 2024 0:38am
prd-marketing ⬜️ Ignored (Inspect) Jul 29, 2024 0:38am

@coderabbitai

coderabbitai Bot commented Jul 23, 2024 •

Copy link
Copy Markdown
Contributor

Walkthrough

This update enhances the API's validation mechanisms for date formats and time zones, ensuring input integrity. The ApiContractV1Implementation route now confirms that provided formats are valid. The UI component, AddSettingsFormPartial, adapts to these changes by dynamically assigning date formats based on the updated validations. Additionally, schema definitions have been enriched with OpenAPI integration, improving documentation and clarity for API users.

Changes

Files Change Summary
packages/api/v1/implementation.ts
packages/ui/primitives/document-flow/add-settings.tsx
Added validation for date formats and time zones in the API handler, and updated the UI component to implement these validations for improved input handling.
packages/api/v1/schema.ts Enhanced schema definitions by integrating OpenAPI capabilities and adding metadata for dateFormat and timezone, improving documentation clarity for API consumers.

Poem

🐇 In the garden where the code does flow,
Valid dates now help our APIs glow.
With formats checked and logic bright,
Settings dance in the soft moonlight.
Hopping along, our code’s a delight! 🌙✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@github-actions

github-actions Bot commented Jul 23, 2024 •

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions for pull request titles! 💚🚀

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f8349bb and 5c6ab6d.

Files selected for processing (2)
  • packages/api/v1/implementation.ts (2 hunks)
  • packages/ui/primitives/document-flow/add-settings.tsx (1 hunks)
Additional comments not posted (2)
packages/ui/primitives/document-flow/add-settings.tsx (1)

86-88: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to AddSettingsFormPartial handle the dateFormat correctly.

Verification successful

The function usage correctly handles dateFormat.

The document object, which includes the documentMeta property, is correctly initialized and passed to AddSettingsFormPartial. This ensures that dateFormat is handled appropriately in the edit-document.tsx file.

  • apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx: Verified proper handling of dateFormat.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `AddSettingsFormPartial` handle the `dateFormat` correctly.

# Test: Search for the function usage. Expect: Proper handling of `dateFormat`.
rg --type tsx -A 10 $'AddSettingsFormPartial'

Length of output: 72


Script:

#!/bin/bash
# Description: Verify all function calls to `AddSettingsFormPartial` handle the `dateFormat` correctly.

# Test: Search for the function usage. Expect: Proper handling of `dateFormat`.
rg -A 10 'AddSettingsFormPartial'

Length of output: 3662


Script:

#!/bin/bash
# Description: Extract more lines around the usage of `AddSettingsFormPartial` in `edit-document.tsx` to verify the handling of `dateFormat`.

# Test: Extract lines around the usage of `AddSettingsFormPartial`. Expect: Proper handling of `dateFormat`.
rg 'AddSettingsFormPartial' -A 20 -B 20 apps/web/src/app/(dashboard)/documents/[id]/edit-document.tsx

Length of output: 238


Script:

#!/bin/bash
# Description: Extract more lines around the usage of `AddSettingsFormPartial` in `edit-document.tsx` to verify the handling of `dateFormat`.

# Test: Extract lines around the usage of `AddSettingsFormPartial`. Expect: Proper handling of `dateFormat`.
rg 'AddSettingsFormPartial' -A 20 -B 20 apps/web/src/app/\(dashboard\)/documents/\[id\]/edit-document.tsx

Length of output: 3478


Script:

#!/bin/bash
# Description: Search for the definition and initialization of the `document` variable within the `edit-document.tsx` file to verify the handling of `dateFormat`.

# Test: Search for the definition and initialization of `document`. Expect: Proper initialization of `documentMeta` including `dateFormat`.
rg 'document' -A 10 -B 10 apps/web/src/app/\(dashboard\)/documents/\[id\]/edit-document.tsx

Length of output: 11778

packages/api/v1/implementation.ts (1)

226-236: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to createDocument handle the dateFormat correctly.

@Mythie

Mythie commented Jul 29, 2024

Copy link
Copy Markdown
Collaborator

If I recall there is also a way to add extra information to the generated OpenAPI spec using TS-REST which is where we could also list the formats that we accept.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5c6ab6d and 8f9e0e1.

Files selected for processing (1)
  • packages/api/v1/schema.ts (3 hunks)
Additional comments not posted (3)
packages/api/v1/schema.ts (3)

1-4: Imports look good.

The new imports are necessary for extending Zod with OpenAPI capabilities and for validating date formats.


16-17: Extension of Zod with OpenAPI capabilities looks good.

This line is necessary for integrating OpenAPI documentation features into Zod schemas.


105-108: Enhancement of dateFormat field looks good.

The dateFormat field now includes OpenAPI-specific metadata, improving the documentation and usability of the API.

Ensure that DATE_FORMATS is correctly defined and used throughout the codebase.

Verification successful

Enhancement of dateFormat field looks good.

The dateFormat field now includes OpenAPI-specific metadata, improving the documentation and usability of the API. The DATE_FORMATS constant is correctly defined and used throughout the codebase.

  • DATE_FORMATS definition is correct and includes the expected date formats.
  • Usage in schema.ts aligns with the intended functionality.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the definition and usage of `DATE_FORMATS`.

# Test: Search for the definition and usage of `DATE_FORMATS`. Expect: Correct definition and usage.
rg --type js --type ts 'DATE_FORMATS'

Length of output: 1236


Script:

#!/bin/bash
# Description: Inspect the definition of `DATE_FORMATS` in the specified file.

# Display the definition of `DATE_FORMATS` to verify its correctness.
rg --type js --type ts --context 10 'export const DATE_FORMATS' packages/lib/constants/date-formats.ts

Length of output: 490

@catalinpit

Copy link
Copy Markdown
Member Author

If I recall there is also a way to add extra information to the generated OpenAPI spec using TS-REST which is where we could also list the formats that we accept.

Great catch, thanks!

CleanShot 2024-07-29 at 12 05 27@2x

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8f9e0e1 and 93b7893.

Files selected for processing (1)
  • packages/api/v1/schema.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/api/v1/schema.ts

@github-actions

Copy link
Copy Markdown
Contributor

🚨 @catalinpit has 5 pull requests awaiting review. Please consider reviewing them when possible. 🚨

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 93b7893 and 43e2550.

Files selected for processing (3)
  • packages/api/v1/implementation.ts (3 hunks)
  • packages/api/v1/schema.ts (3 hunks)
  • packages/ui/primitives/document-flow/add-settings.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • packages/api/v1/implementation.ts
  • packages/api/v1/schema.ts
  • packages/ui/primitives/document-flow/add-settings.tsx

@Mythie
Mythie merged commit 4b48526 into main Jul 30, 2024
@Mythie
Mythie deleted the fix/dateformat-api-bug branch July 30, 2024 06:13

This branch was successfully deployed

4 active deployments
Preview – stg-app — 43e2550c Deployed Jul 29, 2024 by vercel[bot]
Preview – stg-docs — 43e2550c Deployed Jul 29, 2024 by vercel[bot]
Preview – stg-marketing — 43e2550c Deployed Jul 29, 2024 by vercel[bot]
Preview – prd-docs — 43e2550c Deployed Jul 29, 2024 by vercel[bot]
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.

2 participants