Skip to content

feat: support list fields#525

Merged
carlbrugger merged 4 commits intomainfrom
feat/support-list-fields
May 23, 2024
Merged

feat: support list fields#525
carlbrugger merged 4 commits intomainfrom
feat/support-list-fields

Conversation

@carlbrugger
Copy link
Contributor

@carlbrugger carlbrugger commented May 14, 2024

Please explain how to summarize this PR for the Changelog:

This PR adds support for the string-list and enum-list field types.

Tell code reviewer how and what to test:

Record hook:

listener.use(
  recordHook('fieldTypes', (record: FlatfileRecord) => {
    const colors = record.get('enum-list') as string[]
    console.log({ colors })
    if (colors.includes('green')) {
      record.addWarning('enum-list', 'Green is questionable', 'green')
    }

    if (colors.includes('pink')) {
      record.addInfo('enum-list', 'Pink is yayaay', 'pink')
    }

    if (colors.includes('blue')) {
      record.addError('enum-list', 'Blue is naaay', 'blue')
    }

    const names = record.get('strings') as any[]
    console.log({ names })
    names?.forEach((name) => {
      if (!isNaN(Number(name))) {
        record.addWarning('strings', `${name} is a number`, name)
      }
    })

    return record
  })
)

Sheet config:

{
  name: 'Field Types',
  slug: 'fieldTypes',
  fields: [
    {
      key: 'string',
      type: 'string',
      label: 'String',
    },
    {
      key: 'number',
      type: 'number',
      label: 'Number',
    },
    {
      key: 'date',
      type: 'date',
      label: 'Date',
    },
    {
      key: 'boolean',
      type: 'boolean',
      label: 'Boolean',
    },
    {
      key: 'strings',
      type: 'string-list',
      label: 'String List',
    },
    {
      key: 'enum',
      type: 'enum',
      label: 'Enum',
      config: {
        options: [
          { label: 'Pending', value: 'pending' },
          { label: 'Approved', value: 'approved' },
          { label: 'Rejected', value: 'rejected' },
        ],
      },
    },
    {
      key: 'enum-list',
      type: 'enum-list',
      label: 'Enum List',
      config: {
        options: [
          {
            value: 'red',
            label: 'Red',
          },
          {
            value: 'blue',
            label: 'Blue',
          },
          {
            value: 'green',
            label: 'Green',
          },
          {
            value: 'yellow',
            label: 'Yellow',
          },
          {
            value: 'pink',
            label: 'Pink',
          },
        ],
      },
    },
    {
      key: 'reference',
      type: 'reference',
      label: 'Reference',
      config: {
        key: 'email',
        ref: 'contacts',
        relationship: 'has-one',
      },
    },
  ],
}

@carlbrugger carlbrugger force-pushed the feat/support-list-fields branch from d090b2d to d6aabef Compare May 21, 2024 01:35
@carlbrugger carlbrugger marked this pull request as ready for review May 23, 2024 03:20
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 23, 2024

Walkthrough

The recent updates primarily involve modifying type references across various files within the plugin modules. The type TPrimitive has been replaced with TRecordValue to enhance type handling and control flow. These changes affect the casting functions and value assignments, ensuring more precise type management and improving the robustness of the code.

Changes

Files Change Summary
plugins/autocast/src/autocast.plugin.ts Updated type references from TPrimitive to TRecordValue for casting functions, affecting control flow and type handling.
plugins/constraints/src/external.sheet.constraint.ts Replaced TPrimitive with TRecordValue in type declarations within externalSheetConstraint and partialObject functions.
plugins/record-hook/src/record.translator.ts Introduced TRecordValue and refined value assignments in RecordTranslator class for better type and value handling.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8652661 and e60640a.
Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • plugins/autocast/package.json is excluded by !**/*.json
  • plugins/record-hook/package.json is excluded by !**/*.json
Files selected for processing (3)
  • plugins/autocast/src/autocast.plugin.ts (5 hunks)
  • plugins/constraints/src/external.sheet.constraint.ts (3 hunks)
  • plugins/record-hook/src/record.translator.ts (3 hunks)
Additional comments not posted (9)
plugins/constraints/src/external.sheet.constraint.ts (2)

85-85: Type update to Record<string, TRecordValue> is appropriate for handling partial objects.


24-24: Updated type TRecordValue enhances type handling and control flow.

Verification successful

The externalSheetConstraint function is correctly integrated and used with the new type TRecordValue in the external.sheet.constraint.e2e.spec.ts file. The test setup and usage align with the updated type handling.

  • plugins/constraints/src/external.sheet.constraint.e2e.spec.ts: Verified correct usage of externalSheetConstraint.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `externalSheetConstraint` function is correctly integrated and used with the new type `TRecordValue`.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript $'externalSheetConstraint'

Length of output: 81



Script:

#!/bin/bash
# Description: Verify that the `externalSheetConstraint` function is correctly integrated and used with the new type `TRecordValue`.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg 'externalSheetConstraint'

Length of output: 537



Script:

#!/bin/bash
# Description: Extract relevant lines from `external.sheet.constraint.e2e.spec.ts` to verify the usage of `externalSheetConstraint`.

# Extract lines around the usage of `externalSheetConstraint`.
rg -A 5 -B 5 'externalSheetConstraint' plugins/constraints/src/external.sheet.constraint.e2e.spec.ts

Length of output: 633

plugins/record-hook/src/record.translator.ts (2)

37-37: Type update to TRecordValue aligns with the PR's objective to enhance type handling.


71-78: Handling of object values and inclusion of path property enhance data integrity and error tracking.

Verification successful

The toXRecords method is correctly referenced and integrated within record.utils.ts. The comments and function usage indicate that the method is used to convert records back into their original format after certain callbacks have been executed, aligning with the new implementation.

  • plugins/record-hook/src/record.utils.ts: Lines referencing toXRecords confirm its correct usage and integration.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `toXRecords` method is correctly integrated and used with the new changes.

# Test: Search for the method usage. Expect: Only occurrences of the new method implementation.
rg --type typescript $'toXRecords'

Length of output: 68



Script:

#!/bin/bash
# Description: Verify that the `toXRecords` method is correctly integrated and used with the new changes.

# Test: Search for the method usage. Expect: Only occurrences of the new method implementation.
rg --type ts 'toXRecords'

Length of output: 351



Script:

#!/bin/bash
# Description: Extract lines from `record.utils.ts` where `toXRecords` is referenced to verify correct integration.

# Extract lines where `toXRecords` is referenced.
rg --type ts 'toXRecords' -A 5 -B 5 plugins/record-hook/src/record.utils.ts

Length of output: 1172

plugins/autocast/src/autocast.plugin.ts (5)

2-2: Type update to TRecordValue in autocast function enhances type handling.


73-73: Type update to TRecordValue in castString function enhances type handling.


84-84: Type update to TRecordValue in castNumber function enhances type handling.


101-101: Type update to TRecordValue in castBoolean function enhances type handling.


119-119: Type update to TRecordValue in castDate function enhances type handling.


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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
Collaborator

@bangarang bangarang left a comment

Choose a reason for hiding this comment

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

Awesome! Glad this works with the autocast and external constraints plugin too - makes me want to figure out a clever way to add autocasting to the enum field types now though 🤩

@carlbrugger carlbrugger merged commit a2b195c into main May 23, 2024
@carlbrugger carlbrugger deleted the feat/support-list-fields branch May 23, 2024 16:06
@carlbrugger carlbrugger mentioned this pull request May 23, 2024
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