Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unresolvable Vue typings #203

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Hawxy
Copy link

@Hawxy Hawxy commented Oct 3, 2024

Please explain how to summarize this PR for the Changelog:

Fixed unresolvable Vue TS typings

Tell code reviewer how and what to test:

This just fixes type resolution for the Vue package. I've also updated the Vue app to use script setup + typescript templates. This does cause a weird type incompatibility issue for listener + workload types within App.vue that I'm hoping someone from the flatfile team can look at.

I do have another branch that modernizes the build tooling of the vue package itself if you're interested, that rollup config is pain.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2024

Walkthrough

The pull request introduces significant structural changes to the App.vue and Simplified.vue components, transitioning them to use the <script setup> syntax in TypeScript. This change simplifies the components by removing the traditional defineComponent method and integrating the template sections directly with the script logic. Additionally, the config.ts file has been updated to enhance type safety for the workbook constant by explicitly typing it with properties from the Flatfile.CreateWorkbookConfig interface.

Changes

File Change Summary
apps/vue/src/App.vue Restructured to use <script setup> syntax; removed defineComponent; integrated template with script logic; modified themeConfig structure; updated event binding to @click.
apps/vue/src/Simplified.vue Transitioned to <script setup> syntax; added template section; defined showSpace using ref; updated onSubmit and onRecordHook signatures; modified themeConfig.
apps/vue/src/config.ts Introduced type import from @flatfile/api; updated workbook declaration to use Pick<Flatfile.CreateWorkbookConfig> for enhanced type safety.

Possibly related PRs

  • feat/allowForExternalSpaceConfigure #171: The changes in this PR involve modifications to the FlatfileContext.tsx and FlatfileProvider.tsx files, which relate to the handling of space configurations and the management of workbooks. This is relevant to the main PR's restructuring of the App.vue component, as both involve the management of spaces and configurations within the Flatfile ecosystem.

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>, please review it.
    • 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 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 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 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 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
Contributor

@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: 6

🧹 Outside diff range and nitpick comments (5)
apps/vue/src/config.ts (1)

3-6: LGTM: Improved type safety for workbook.

The explicit typing of workbook using Pick<Flatfile.CreateWorkbookConfig, ...> is an excellent improvement. It enhances type safety and makes the code more maintainable by clearly defining the expected shape of the workbook object.

Consider using a type alias for better readability:

type WorkbookConfig = Pick<Flatfile.CreateWorkbookConfig, 'name' | 'labels' | 'sheets' | 'actions'>;

export const workbook: WorkbookConfig = {
  // ... existing object ...
};

This would make the code more readable and reusable if you need to use this type elsewhere.

apps/vue/src/App.vue (3)

15-16: Assist with TypeScript type incompatibility of 'listener' and 'workbook' imports

I notice that you're experiencing TypeScript type incompatibility issues with listener and workload types in App.vue. This might be due to mismatched type definitions between the imported modules and the expected types in spaceProps.

Would you like me to help identify and resolve the type incompatibilities?


20-20: Placeholder 'your_key' used for 'FLATFILE_PUBLISHABLE_KEY'

The FLATFILE_PUBLISHABLE_KEY is set to 'your_key', which appears to be a placeholder. Ensure to replace this with your actual Flatfile publishable key before deploying.


52-54: Add return type annotation to 'toggleSpace' function

For better type safety and clarity, consider adding a return type annotation to the toggleSpace function.

Apply this diff to add the return type annotation:

- const toggleSpace = () => {
+ const toggleSpace = (): void => {
apps/vue/src/Simplified.vue (1)

49-49: Correct the typo in the 'name' property.

The name property in spaceProps is set to 'Trste!'. If this is a typo, consider correcting it to 'Test!' or the intended name.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ee85b70 and 517c959.

⛔ Files ignored due to path filters (3)
  • apps/vue/package.json is excluded by !**/*.json
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • packages/vue/package.json is excluded by !**/*.json
📒 Files selected for processing (3)
  • apps/vue/src/App.vue (1 hunks)
  • apps/vue/src/Simplified.vue (2 hunks)
  • apps/vue/src/config.ts (1 hunks)
🔇 Additional comments (5)
apps/vue/src/config.ts (1)

1-1: LGTM: Type import added correctly.

The addition of the type import from "@flatfile/api" is appropriate and necessary for the updated type definition of workbook. Using a type-only import is a good practice as it doesn't affect the runtime bundle size.

apps/vue/src/App.vue (1)

36-36: Verify the 'themeConfig' structure

Please verify that the themeConfig structure matches the expected format required by the Flatfile SDK. Incorrect nesting under root may prevent theme settings from being applied.

If the SDK expects primaryColor and textColor directly under themeConfig, consider updating the code:

-  themeConfig: { root: { primaryColor: '#546a76', textColor: '#fff' }},
+  themeConfig: { primaryColor: '#546a76', textColor: '#fff' },
apps/vue/src/Simplified.vue (3)

70-70: Confirm the structure of 'themeConfig' matches Flatfile's expectations.

The themeConfig nests primaryColor and textColor under a root key. Verify that this structure aligns with Flatfile's theming configuration. If the root key is unnecessary or if the keys should be at the top level, adjust the structure accordingly:

-themeConfig: { root: { primaryColor: "#546a76", textColor: "#fff" } },
+themeConfig: { primaryColor: "#546a76", textColor: "#fff" },

85-85: Ensure proper destructuring when initializing Flatfile.

Confirm that initializeFlatfile returns the Space component and OpenEmbed function as expected. If there are issues, verify the import and the API usage:

const { Space, OpenEmbed } = initializeFlatfile(spaceProps);

66-69: ⚠️ Potential issue

Verify the 'operation' value in 'closeSpace' configuration.

The operation is set to 'submitActionFg' in the closeSpace object. Ensure that 'submitActionFg' is a valid operation recognized by the Flatfile API. If not, update it to the correct operation value as per the documentation.

const publishableKey = FLATFILE_PUBLISHABLE_KEY
const spaceProps = ref({
// apiUrl: 'https://platform.flatfile.com/api',
name: 'Trste!',
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Typo in 'name' property of 'spaceProps'

The name property is set to 'Trste!', which might be a typo. Consider correcting it to 'Test!' or your intended space name.

Apply this diff to fix the typo:

-  name: 'Trste!',
+  name: 'Test!',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: 'Trste!',
name: 'Test!',

Comment on lines +5 to +11
<button @click="toggleSpace()">{{ showSpace ? 'Close' : 'Open' }} space</button>
</div>

<div class="space-wrapper" v-if="showSpace">
<Space />
</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Review the toggle logic for 'showSpace' and usage of 'OpenEmbed()'.

There appears to be a potential conflict between toggling showSpace to conditionally render <Space /> in the template and calling OpenEmbed() in the toggleSpace function. If OpenEmbed() handles displaying the Flatfile Space modal independently, managing showSpace might be redundant or cause inconsistent UI states. Consider the following:

  • Option 1: Rely solely on OpenEmbed() to open the Space modal and remove showSpace and the conditional <Space /> rendering.
  • Option 2: Use showSpace to control the visibility of <Space /> and remove the OpenEmbed() call if unnecessary.

Also applies to: 45-90

Comment on lines +53 to +56
onSubmit: async ({ job, sheet }: { job: any, sheet: any }) => {
const data = await sheet.allData()
console.log('onSubmit', data)
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance type safety by specifying exact types in 'onSubmit'.

The onSubmit function currently uses any types for job and sheet. To leverage TypeScript's benefits, consider importing and using the specific types provided by @flatfile/vue or defining appropriate interfaces:

import { FlatfileJob, FlatfileSheet } from '@flatfile/vue';

// ...

onSubmit: async ({ job, sheet }: { job: FlatfileJob; sheet: FlatfileSheet }) => {
  // ...
},

Comment on lines +57 to +64
onRecordHook: (record: any, event: any) => {
const firstName = record.get('firstName')
const lastName = record.get('lastName')
if (firstName && !lastName) {
record.set('lastName', 'Rock')
record.addInfo('lastName', 'Welcome to the Rock fam')
}
return record
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Specify precise types in 'onRecordHook' for better type safety.

In the onRecordHook function, record and event are typed as any. Define or import appropriate types to enhance type checking and reduce potential runtime errors:

import { FlatfileRecord, FlatfileEvent } from '@flatfile/vue';

// ...

onRecordHook: (record: FlatfileRecord, event: FlatfileEvent) => {
  // ...
},

Comment on lines +87 to +90
const toggleSpace = () => {
showSpace.value = !showSpace.value;
OpenEmbed()
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Adjust 'toggleSpace' function based on the display logic chosen.

Depending on how you decide to manage the space display (as per the earlier suggestion), update the toggleSpace function accordingly:

  • If using OpenEmbed() exclusively, you might not need to toggle showSpace.value.
  • If controlling the display with showSpace, ensure toggleSpace only updates showSpace.value.

Comment on lines +48 to +85
const spaceProps = ref({
name: 'Trste!',
environmentId,
publishableKey,
sheet,
onSubmit: async ({ job, sheet }: { job: any, sheet: any }) => {
const data = await sheet.allData()
console.log('onSubmit', data)
},
onRecordHook: (record: any, event: any) => {
const firstName = record.get('firstName')
const lastName = record.get('lastName')
if (firstName && !lastName) {
record.set('lastName', 'Rock')
record.addInfo('lastName', 'Welcome to the Rock fam')
}
return record
},
render(props, ctx) {
const Space = props.Space

return (
<div>
<div class="description">
<button onClick={props.toggleSpace}>{ props.showSpace ? 'Close' : 'Open' } space</button>
</div>

{props.showSpace && <div class="space-wrapper">
<Space />
</div>}
</div>
)
closeSpace: {
operation: 'submitActionFg',
onClose: () => { showSpace.value = false; },
},
themeConfig: { root: { primaryColor: "#546a76", textColor: "#fff" } },
userInfo: {
name: 'my space name'
},
spaceInfo: {
name: 'my space name'
},
displayAsModal: true,
spaceBody: {
metadata: {
random: 'param'
}
}
});

const { Space, OpenEmbed } = initializeFlatfile(spaceProps.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify 'spaceProps' by removing unnecessary 'ref'.

Since spaceProps does not appear to require reactivity, you can define it as a plain object. This eliminates the need to access .value when initializing Flatfile:

-const spaceProps = ref({
+const spaceProps = {
  // ...properties
-});
+};

Update the initialization accordingly:

-const { Space, OpenEmbed } = initializeFlatfile(spaceProps.value);
+const { Space, OpenEmbed } = initializeFlatfile(spaceProps);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const spaceProps = ref({
name: 'Trste!',
environmentId,
publishableKey,
sheet,
onSubmit: async ({ job, sheet }: { job: any, sheet: any }) => {
const data = await sheet.allData()
console.log('onSubmit', data)
},
onRecordHook: (record: any, event: any) => {
const firstName = record.get('firstName')
const lastName = record.get('lastName')
if (firstName && !lastName) {
record.set('lastName', 'Rock')
record.addInfo('lastName', 'Welcome to the Rock fam')
}
return record
},
render(props, ctx) {
const Space = props.Space
return (
<div>
<div class="description">
<button onClick={props.toggleSpace}>{ props.showSpace ? 'Close' : 'Open' } space</button>
</div>
{props.showSpace && <div class="space-wrapper">
<Space />
</div>}
</div>
)
closeSpace: {
operation: 'submitActionFg',
onClose: () => { showSpace.value = false; },
},
themeConfig: { root: { primaryColor: "#546a76", textColor: "#fff" } },
userInfo: {
name: 'my space name'
},
spaceInfo: {
name: 'my space name'
},
displayAsModal: true,
spaceBody: {
metadata: {
random: 'param'
}
}
});
const { Space, OpenEmbed } = initializeFlatfile(spaceProps.value);
const spaceProps = {
name: 'Trste!',
environmentId,
publishableKey,
sheet,
onSubmit: async ({ job, sheet }: { job: any, sheet: any }) => {
const data = await sheet.allData()
console.log('onSubmit', data)
},
onRecordHook: (record: any, event: any) => {
const firstName = record.get('firstName')
const lastName = record.get('lastName')
if (firstName && !lastName) {
record.set('lastName', 'Rock')
record.addInfo('lastName', 'Welcome to the Rock fam')
}
return record
},
closeSpace: {
operation: 'submitActionFg',
onClose: () => { showSpace.value = false; },
},
themeConfig: { root: { primaryColor: "#546a76", textColor: "#fff" } },
userInfo: {
name: 'my space name'
},
spaceInfo: {
name: 'my space name'
},
displayAsModal: true,
spaceBody: {
metadata: {
random: 'param'
}
}
};
const { Space, OpenEmbed } = initializeFlatfile(spaceProps);

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