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: introduce streamlit integration #68

Merged
merged 7 commits into from
Mar 21, 2024
Merged

Feat: introduce streamlit integration #68

merged 7 commits into from
Mar 21, 2024

Conversation

voznik
Copy link
Owner

@voznik voznik commented Mar 14, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

The PR introduces Streamlit integration into the project, aiming to enhance development and extend capabilities with new features. Key changes include:

  • Streamlit Integration: Introduces RxDB integration within Streamlit environments, e.g. managing RxDB collection as dataframe in Streamlit
  • Project Structure Refactoring: Refactors tokens names, import statements and project structure to conform to framework-agnostic approach (import & compile service(s) under non-Angular environment)

This PR represents a significant effort to improve interactivity, project structure, and functionality, aiming for a more intuitive and efficient development experience.

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

Does this PR introduce a breaking change?

[x] Yes
[ ] No
  • New Features
    • Added functionality for creating and managing a RxDB collection using dataframe in Streamlit.
  • Refactor
    • Updated services to be plain JS classes (use anywhere), and moved provider tokens for Angular to separate root folder (updated import paths everywhere)
    • Removed RxDBDevModePlugin from auto-loaded plugins, add only on app level
  • Documentation
    • Added and updated READMEs and licenses for new packages.
  • Style
    • Introduced global styles for the Streamlit RxDB Dataframe web application.
  • Tests
    • Added test cases for rendering dataframes in a Streamlit app and for RxDB services.
  • Chores
    • Configured project settings for TypeScript, JavaScript, and Vite in the Streamlit RxDB Dataframe package.

Summary by CodeRabbit

  • New Features
    • Introduced new plugins for enhanced database functionality and configuration.
    • Added a custom Streamlit component for connecting and managing RxDB collections as dataframes.
    • Streamlit users can now create and manage todo lists with RxDB Dataframe, including filtering and displaying data in various formats.
  • Documentation
    • Updated README files with new plugin information and usage instructions.
    • Provided detailed guides for setting up and using the new Streamlit component.
  • Refactor
    • Updated various modules and services to use RxDBCollectionService for improved consistency and performance.
    • Renamed services and imports for clearer identification and usage.
  • Tests
    • Added new test cases for validating the behavior of RxDB dataframe functionalities and schema configurations.

Copy link

coderabbitai bot commented Mar 15, 2024

Walkthrough

The updates encompass a broad restructuring and enhancement of the RxDB integration within Angular and Streamlit environments. Key changes include renaming classes and services for consistency, refining RxDB configuration and service implementations, and introducing new functionalities like managing RxDB dataframes in Streamlit. The modifications streamline development workflows, improve code readability, and expand the capabilities of applications using RxDB for database management.

Changes

Files Change Summary
.vscode/launch.json
.vscode/settings.json
Added configurations for Python and Streamlit in VS Code.
examples/demo/src/app/todos/todos.module.ts
examples/demo/src/app/todos.service.ts
examples/demo/src/app/todos.pipe.ts
Updated imports and services for RxDB integration.
examples/shared/index.ts
examples/shared/todos.schema.ts
Added todos.schema export and defined TODO_SCHEMA.
packages/rxdb/collection/...
packages/rxdb/core/...
packages/rxdb/signals/...
packages/rxdb/src/lib/...
Renamed services, updated imports, and refactored RxDB integration.
packages/rxdb/config/...
packages/rxdb/query-params/...
Updated configuration and removed unnecessary exports.
packages/rxdb/prepare/... Introduced utility exports and updated plugin imports.
packages/rxdb/utils/... Added utility functions and removed unused imports.
packages/streamlit-rxdb-dataframe/... Introduced Streamlit integration for RxDB dataframes, including setup, testing, and frontend.

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:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 tests 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 tests.
    • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

.vscode/settings.json Outdated Show resolved Hide resolved
packages/streamlit-rxdb-dataframe/frontend/src/main.tsx Outdated Show resolved Hide resolved
packages/streamlit-rxdb-dataframe/frontend/vite.config.ts Outdated Show resolved Hide resolved
packages/rxdb/src/lib/rxdb.module.spec.ts Outdated Show resolved Hide resolved
packages/rxdb/signals/src/with-collection-service.ts Outdated Show resolved Hide resolved
packages/rxdb/src/lib/rxdb.providers.ts Outdated Show resolved Hide resolved
@voznik voznik force-pushed the feat/streamlit branch 3 times, most recently from 63bb1fc to e237a20 Compare March 15, 2024 11:19
Repository owner deleted a comment from what-the-diff bot Mar 15, 2024
Repository owner deleted a comment from coderabbitai bot Mar 15, 2024
Copy link

sonarcloud bot commented Mar 21, 2024

Quality Gate Passed Quality Gate passed

Issues
37 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
1.0% Duplication on New Code

See analysis details on SonarCloud

@voznik voznik marked this pull request as ready for review March 21, 2024 15:51
@voznik voznik merged commit 272a16b into master Mar 21, 2024
3 checks passed
@voznik voznik deleted the feat/streamlit branch March 21, 2024 15:52
Comment on lines +66 to +71
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
Copy link

Choose a reason for hiding this comment

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

Adding new plugins (RxDBDevModePlugin, RxDBAttachmentsPlugin, RxDBLeaderElectionPlugin) enhances the functionality significantly. However, it's crucial to document the specific use cases and benefits of each plugin within the README to help users understand their purpose and how they can leverage them in their projects.

Would you like assistance in drafting brief descriptions for these plugins?

Comment on lines +188 to +193
plugins: [
// will be loaded by together with core plugins
RxDBDevModePlugin, // <- add only for development
RxDBAttachmentsPlugin,
RxDBLeaderElectionPlugin,
],
Copy link

Choose a reason for hiding this comment

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

Repeating the addition of new plugins (RxDBDevModePlugin, RxDBAttachmentsPlugin, RxDBLeaderElectionPlugin) in the standalone configuration is consistent with the NgModule configuration. This ensures that the enhanced functionality is available across different types of application setups. Just like before, adding descriptions for these plugins in the documentation would be beneficial for users.

Would you like help with adding these plugin descriptions to the standalone section as well?

Comment on lines +269 to +271
- Persist collection query ([mango-query-syntax](https://github.com/cloudant/mango)) in URL with new plugin `query-params-plugin` (in demo, set localStorage `_ngx_rxdb_queryparams` )
- provide Observable of current URL (automatically for Angular)
- simple methods to set or patch filter, sort, limit, skip
Copy link

Choose a reason for hiding this comment

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

The introduction of the query-params-plugin for persisting collection queries in the URL is an innovative feature that can enhance user experience by maintaining state across sessions. It's important to provide examples and documentation on how to use this plugin effectively, including how to set up and retrieve the persisted queries.

If needed, I can contribute examples and documentation for the query-params-plugin. Would you like me to do so?

Comment on lines +40 to +71
def test_get_dataframe_by_schema():
# Test case 1: Empty schema
schema = {}
expected_df = pd.DataFrame()
assert get_dataframe_by_schema(schema).equals(expected_df)

# Test case 2: Schema with string properties
schema = {
"properties": {
"name": {"type": "string"},
"age": {"type": "string"},
"city": {"type": "string"},
}
}
expected_df = pd.DataFrame(
{
"name": pd.Series(dtype="object"),
"age": pd.Series(dtype="object"),
"city": pd.Series(dtype="object"),
}
)
assert get_dataframe_by_schema(schema).equals(expected_df)

# Test case 3: Schema with boolean properties
schema = {
"properties": {"is_active": {"type": "boolean"}, "has_permission": {"type": "boolean"}}
}
expected_df = pd.DataFrame(
{"is_active": pd.Series(dtype="bool"), "has_permission": pd.Series(dtype="bool")}
)
assert get_dataframe_by_schema(schema).equals(expected_df)

Copy link

Choose a reason for hiding this comment

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

The test_get_dataframe_by_schema function is duplicated, which will result in only the latter being executed. Consider merging these tests into a single function or renaming one to ensure all intended tests are run.

- def test_get_dataframe_by_schema():
+ def test_get_dataframe_by_schema_additional_cases():

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.

Suggested change
def test_get_dataframe_by_schema():
# Test case 1: Empty schema
schema = {}
expected_df = pd.DataFrame()
assert get_dataframe_by_schema(schema).equals(expected_df)
# Test case 2: Schema with string properties
schema = {
"properties": {
"name": {"type": "string"},
"age": {"type": "string"},
"city": {"type": "string"},
}
}
expected_df = pd.DataFrame(
{
"name": pd.Series(dtype="object"),
"age": pd.Series(dtype="object"),
"city": pd.Series(dtype="object"),
}
)
assert get_dataframe_by_schema(schema).equals(expected_df)
# Test case 3: Schema with boolean properties
schema = {
"properties": {"is_active": {"type": "boolean"}, "has_permission": {"type": "boolean"}}
}
expected_df = pd.DataFrame(
{"is_active": pd.Series(dtype="bool"), "has_permission": pd.Series(dtype="bool")}
)
assert get_dataframe_by_schema(schema).equals(expected_df)
def test_get_dataframe_by_schema_additional_cases():
# Test case 1: Empty schema
schema = {}
expected_df = pd.DataFrame()
assert get_dataframe_by_schema(schema).equals(expected_df)
# Test case 2: Schema with string properties
schema = {
"properties": {
"name": {"type": "string"},
"age": {"type": "string"},
"city": {"type": "string"},
}
}
expected_df = pd.DataFrame(
{
"name": pd.Series(dtype="object"),
"age": pd.Series(dtype="object"),
"city": pd.Series(dtype="object"),
}
)
assert get_dataframe_by_schema(schema).equals(expected_df)
# Test case 3: Schema with boolean properties
schema = {
"properties": {"is_active": {"type": "boolean"}, "has_permission": {"type": "boolean"}}
}
expected_df = pd.DataFrame(
{"is_active": pd.Series(dtype="bool"), "has_permission": pd.Series(dtype="bool")}
)
assert get_dataframe_by_schema(schema).equals(expected_df)

Comment on lines +109 to +127
provide: RXDB_COLLECTION,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // INFO: no need for typings here, nothing's exposed, but ts complains // NOSONAR
useFactory: (config, dbService, ngZone, currentUrl, updateQueryParamsFn) =>
new RxDBCollectionService(
config,
dbService,
ngZone,
currentUrl,
updateQueryParamsFn
),
deps: [
//
RXDB_CONFIG_COLLECTION,
RXDB,
NgZone,
CURRENT_URL,
updateQueryParams,
],
Copy link

Choose a reason for hiding this comment

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

The introduction of new injection tokens and refactoring align with improving modularity and maintainability. However, the use of // @ts-ignore should be addressed to ensure type safety. Consider resolving the underlying TypeScript type issue directly.

-      // @ts-ignore // INFO: no need for typings here, nothing's exposed, but ts complains // NOSONAR
+      // Consider resolving the type issue here instead of using @ts-ignore to ensure type safety.

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.

Suggested change
provide: RXDB_COLLECTION,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // INFO: no need for typings here, nothing's exposed, but ts complains // NOSONAR
useFactory: (config, dbService, ngZone, currentUrl, updateQueryParamsFn) =>
new RxDBCollectionService(
config,
dbService,
ngZone,
currentUrl,
updateQueryParamsFn
),
deps: [
//
RXDB_CONFIG_COLLECTION,
RXDB,
NgZone,
CURRENT_URL,
updateQueryParams,
],
provide: RXDB_COLLECTION,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// Consider resolving the type issue here instead of using @ts-ignore to ensure type safety.
useFactory: (config, dbService, ngZone, currentUrl, updateQueryParamsFn) =>
new RxDBCollectionService(
config,
dbService,
ngZone,
currentUrl,
updateQueryParamsFn
),
deps: [
//
RXDB_CONFIG_COLLECTION,
RXDB,
NgZone,
CURRENT_URL,
updateQueryParams,
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant