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

feat: Update To use New React Components #11

Merged
merged 2 commits into from
May 31, 2024

Conversation

bangarang
Copy link
Collaborator

@bangarang bangarang commented Apr 26, 2024

First pass at updating the example repo to use the latest React Components

  • feat: update creating new Space example
  • feat: adds example for re-using a space

Summary by CodeRabbit

  • New Features

    • Integrated advanced record manipulation and event handling for job outcomes across multiple components.
    • Enhanced user interaction with new plugin integrations for improved data processing and job handling.
    • Introduced state management and asynchronous data fetching in specific components for better user experience.
  • Refactor

    • Updated several components to utilize new Flatfile React hooks and APIs, enhancing functionality and simplifying codebase.
    • Modified component properties and configurations to align with updated API standards and improve integration capabilities.
  • Documentation

    • Updated component declarations and configurations to reflect new import structures and usage patterns.

@bangarang bangarang marked this pull request as ready for review April 26, 2024 07:39
Copy link

coderabbitai bot commented Apr 26, 2024

Walkthrough

This update focuses on integrating and refining the use of Flatfile's React hooks and components across several files. It enhances event handling, introduces new configurations, and updates state management to improve functionality and code clarity in handling data imports and user interfaces.

Changes

Files Change Summary
app/NewSpace/index.tsx Updated imports, component structure, and event handling for job outcomes.
app/ReuseSpace/index.tsx Refactored to use new hooks and plugins, changed event handling and data logic.
pages/new-space/index.tsx Added FlatfileProvider, modified spaceProps to include metadata.
pages/reuse-space/index.tsx Introduced state management, asynchronous data fetching, and updated rendering.

Possibly related issues


Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8ebe89f and fab5cb8.
Files selected for processing (4)
  • app/NewSpace/index.tsx (1 hunks)
  • app/ReuseSpace/index.tsx (1 hunks)
  • pages/new-space/index.tsx (2 hunks)
  • pages/reuse-space/index.tsx (2 hunks)
Additional comments not posted (13)
pages/new-space/index.tsx (4)

10-31: The error handling for missing PUBLISHABLE_KEY is clear and user-friendly. Consider adding a link or instructions on how to obtain or set the publishableKey.


33-40: The spaceProps configuration is well-defined. Ensure that the metadata properties like theme and sidebarConfig are correctly utilized in the NewSpaceApp component.


54-56: The FlatfileProvider is correctly configured with the publishableKey. Ensure that the config prop in NewSpaceApp is properly handled.


Line range hint 6-56: The overall structure of the component is clear and logical. Good use of conditional rendering and component separation.

app/ReuseSpace/index.tsx (3)

14-18: The use of useFlatfile and context is appropriate for managing the state and lifecycle of the Flatfile portal. Ensure that the context is used effectively throughout the component.


20-31: The event and plugin handling using useEvent and usePlugin is well-implemented. Ensure that the events and hooks are correctly configured and tested.


86-89: The conditional rendering and button functionality are correctly implemented. Ensure that the open state is managed correctly across all component states.

pages/reuse-space/index.tsx (3)

8-11: The initial checks for SPACE_ID are appropriate. Consider providing more detailed error handling or user guidance on how to set the SPACE_ID.


16-42: The data fetching and error handling are implemented using useEffect. Ensure that the error handling is robust and covers all potential error scenarios.


45-87: The conditional rendering for loading and error states is well-implemented. Ensure that the UI updates correctly based on the state changes.

app/NewSpace/index.tsx (3)

16-18: The use of useFlatfile and state management for success is appropriate. Ensure that the state transitions are handled correctly throughout the component lifecycle.


24-31: The event and plugin handling using useEvent and usePlugin is well-implemented. Ensure that the events and hooks are correctly configured and tested.


84-94: The conditional rendering and button functionality are correctly implemented. Ensure that the open state is managed correctly across all component states.


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.

@bangarang bangarang changed the title feat/updateToNewReactComponents feat: Update To use New React Components Apr 26, 2024
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: 4

Out of diff range and nitpick comments (5)
pages/new-space/index.tsx (1)

1-1: Ensure that all necessary imports are used and remove any unused imports to keep the code clean.

app/ReuseSpace/index.tsx (1)

2-11: Ensure that all imports are necessary and used within the component. Consider removing any unused imports to optimize the bundle size.

pages/reuse-space/index.tsx (2)

2-4: Ensure that all imports are necessary and used within the component. Consider removing any unused imports to optimize the bundle size.


Line range hint 2-103: The overall structure of the component is clear and logical. Good use of state management and conditional rendering. Ensure that all functionalities are covered by unit tests.

Would you like me to help with writing unit tests for this component?

app/NewSpace/index.tsx (1)

2-13: Ensure that all imports are necessary and used within the component. Consider removing any unused imports to optimize the bundle size.

Comment on lines +34 to +63
"job:ready",
{ job: "workbook:submitActionFg" },
async ({ context: { jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: "Getting started.",
progress: 10,
});

if (!spaceId) {
setLoading(false);
return;
}
// Make changes after cells in a Sheet have been updated
console.log("Make changes here when an action is clicked");

fetchData(spaceId).catch((err) => {
setLoading(false);
setError(err);
});
}, [spaceId, environmentId]);
await api.jobs.complete(jobId, {
outcome: {
acknowledge: true,
message: "This is now complete.",
next: {
type: "wait",
},
},
});
} catch (error: any) {
console.error("Error:", error.stack);

if (loading) {
return (
<button className="btn">
<span className="loading loading-spinner"></span>
loading
</button>
);
}
if (!spaceId || error) {
return (
<div className="alert alert-error">
<svg
xmlns="http://www.w3.org/2000/svg"
className="stroke-current shrink-0 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span className="flex-col">
{(!spaceId || !environmentId) && (
<span>
Please add a <pre>spaceId</pre> and <pre>environmentId</pre>
</span>
)}
{error && (
<span>
{error} Make sure to set the <pre>FLATFILE_API_KEY</pre> in your{" "}
<pre>.env</pre> file. <br />
You can find that in your Flatfile Dashboard under Developer
Settings.
</span>
)}
</span>
</div>
);
}
await api.jobs.fail(jobId, {
outcome: {
message: "This job encountered an error.",
},
});
}
Copy link

Choose a reason for hiding this comment

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

The API interaction and error handling are robust. However, consider adding more detailed error messages and handling specific error types to improve the user experience.

Comment on lines +2 to +103
fill="none"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span className="flex-col">
{(!spaceId || !environmentId) && (
<span>
Please add a <pre>spaceId</pre> and <pre>environmentId</pre>
</span>
)}
{error && (
<span>
{error} Make sure to set the <pre>FLATFILE_API_KEY</pre> in your{" "}
<pre>.env</pre> file. <br />
You can find that in your Flatfile Dashboard under Developer
Settings.
</span>
)}
</span>
</div>
);
}
await api.jobs.fail(jobId, {
outcome: {
message: "This job encountered an error.",
},
});
}
}
);

useEvent(
"job:outcome-acknowledged",
{
operation: "submitActionFg",
status: "complete",
},
async (event) => {
// any logic related to the event needed for closing the event
console.log("Window Closed!");
// close the portal iFrame window
closePortal();
}
);
return (
<div>
<div>
<button
className="btn btn-primary"
onClick={() => {
setShowSpace(!showSpace);
open ? closePortal() : openPortal();
}}
>
{showSpace === true ? "Close" : "Open existing"} space
{open ? "Close" : "Open existing"} space
</button>
</div>
{showSpace && (
<div id="flatfile_iFrameContainer">
{data?.accessToken ? (
<Space setShowSpace={setShowSpace} config={data} />
) : (
<div className="alert alert-error">
<svg
xmlns="http://www.w3.org/2000/svg"
className="stroke-current shrink-0 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span>No access token available.</span>
</div>
)}
</div>
)}
<div id="flatfile_iFrameContainer">
<Space
id={spaceId}
config={{
metadata: {
sidebarConfig: {
showSidebar: true,
},
},
}}
/>
</div>
Copy link

Choose a reason for hiding this comment

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

The overall structure of the component is clear and logical. Good use of hooks and API interactions. Ensure that all functionalities are covered by unit tests.

Would you like me to help with writing unit tests for this component?

Comment on lines +33 to +63
useEvent(
"job:ready",
{ job: "workbook:submitActionFg" },
async ({ context: { jobId } }) => {
try {
await api.jobs.ack(jobId, {
info: "Getting started.",
progress: 10,
});

// Make changes after cells in a Sheet have been updated
console.log("Make changes here when an action is clicked");

await api.jobs.complete(jobId, {
outcome: {
acknowledge: true,
message: "This is now complete.",
next: {
type: "wait",
},
},
});
} catch (error: any) {
console.error("Error:", error.stack);

await api.jobs.fail(jobId, {
outcome: {
message: "This job encountered an error.",
},
});
}
Copy link

Choose a reason for hiding this comment

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

The API interaction and error handling are robust. However, consider adding more detailed error messages and handling specific error types to improve the user experience.

Comment on lines +2 to +96
acknowledge: true,
message: "This is now complete.",
next: {
type: "wait",
},
},
});
} catch (error: any) {
console.error("Error:", error.stack);

await api.jobs.fail(jobId, {
outcome: {
message: "This job encountered an error.",
},
});
}
}
);

useEvent(
"job:outcome-acknowledged",
{
operation: "submitActionFg",
onClose: () => callback(),
status: "complete",
},
});
};
async (event) => {
// any logic related to the event needed for closing the event
console.log("Window Closed!");
// close the portal iFrame window
closePortal();
setSuccess(true);
}
);

export default function NewSpace({ config }: { config: ISpace }) {
const [showSpace, setShowSpace] = useState(false);
const [success, setSuccess] = useState(false);
const credentials = !!config.publishableKey;
return (
<div>
{credentials ? (
<>
<div>
<button
className="btn btn-primary"
onClick={() => {
setShowSpace(!showSpace);
}}
>
{showSpace === true ? "Close" : "Open and create new"} space
</button>
</div>
{showSpace && (
<div id="flatfile_iFrameContainer">
<Space
callback={() => {
setShowSpace(false);
setSuccess(true);
}}
config={config}
/>
</div>
)}
</>
) : (
<div className="alert alert-error">
<svg
xmlns="http://www.w3.org/2000/svg"
className="stroke-current shrink-0 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="2"
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
<span>
Error! Please add your <pre>publishableKey</pre> and{" "}
<pre>environmentId</pre>
</span>
<>
<div>
<button className="btn btn-primary" onClick={openPortal}>
{open === true ? "Close" : "Open and create new"} space
</button>
</div>
)}
<div id="flatfile_iFrameContainer">
<Space config={config}>
<Workbook config={workbook} />
</Space>
</div>
</>

Copy link

Choose a reason for hiding this comment

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

The overall structure of the component is clear and logical. Good use of hooks and API interactions. Ensure that all functionalities are covered by unit tests.

Would you like me to help with writing unit tests for this component?

@bangarang bangarang merged commit 02fb4b5 into main May 31, 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