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

Implement board versioning and add mutation for updating board view state #30

Merged
merged 17 commits into from
Jan 17, 2024

Conversation

claygorman
Copy link
Contributor

@claygorman claygorman commented Jan 17, 2024

Type

enhancement, bug_fix


Description

  • Added a new GraphQL mutation addItemToViewState to handle adding items to the board's view state.
  • Implemented board versioning to manage concurrent updates to the board state.
  • Refactored issue resolver to handle database transactions for atomicity and consistency.
  • Introduced new database models and migrations for board containers and container items.
  • Updated GraphQL type definitions, resolvers, and frontend components to support the new board functionalities.
  • Fixed issues related to refetching queries in the IssueStatusDropdown component and the socket message handler.
  • Added the array-move package to dependencies for array manipulation utilities.

Changes walkthrough

Relevant files                                                                                                                                 
Enhancement
18 files
gql.ts                                                                                                          
    frontend/gql/__generated__/gql.ts

    Added a new GraphQL mutation addItemToViewState and
    included the version field in the ProjectFields fragment
    for boards.

index.tsx                                                                                                    
    frontend/components/KanbanBoard/index.tsx

    Refactored the KanbanBoard component to use the new
    addItemToViewState mutation, removed unnecessary code, and
    updated the logic to handle board versioning.

index.ts                                                                                                      
    backend/src/resolvers/issue/index.ts

    Refactored the issue resolver to handle database
    transactions for atomicity and consistency, and to update
    the board version and view state when an issue is updated.

resolvers-types.ts                                                                                  
    backend/src/__generated__/resolvers-types.ts

    Updated the generated types to include the new
    AddItemToViewStateItemInput and related types for the new
    mutation.

index.ts                                                                                                      
    backend/src/resolvers/board/index.ts

    Added new resolvers for creating view states and adding
    items to view states on the board, and updated existing
    resolvers to handle board versioning.

index.ts                                                                                                      
    backend/src/resolvers/project/index.ts

    Updated the project resolvers to create default board
    containers when a new project is created.

types.ts                                                                                                      
    backend/src/db/models/types.ts

    Added new model types for BoardContainer and
    ContainerItem to support the new board view state
    structure.

20240113143058-create-board-item-tables.ts                                  
    backend/src/db/migrations/20240113143058-create-board-item-tables.ts

    Added a new database migration to create tables for board
    containers and container items.

gql-queries-mutations.ts                                                                      
    frontend/gql/gql-queries-mutations.ts

    Added the ADD_ITEM_TO_VIEW_STATE mutation to the GraphQL
    queries and mutations file.

apollo-client.ts                                                                                      
    frontend/services/apollo-client.ts

    Updated the Apollo client configuration to handle file
    uploads and batched queries and mutations.

type-defs.ts                                                                                              
    backend/src/type-defs.ts

    Updated GraphQL type definitions to include the new
    mutations for managing view states on the board.

container-item.ts                                                                                    
    backend/src/db/models/container-item.ts

    **Added a new Sequelize model for container items.
    **

board-container.ts                                                                                  
    backend/src/db/models/board-container.ts

    **Added a new Sequelize model for board containers.
    **

board.ts                                                                                                      
    backend/src/db/models/board.ts

    Updated the board model to include a version field and
    associated containers.

index.ts                                                                                                      
    backend/src/db/models/index.ts

    Updated the database models index file to include the new
    BoardContainer and ContainerItem models.

issue.ts                                                                                                      
    backend/src/db/models/issue.ts

    Updated the issue model to associate with the
    IssueStatuses model.

typings.ts                                                                                                  
    backend/src/typings.ts

    Updated typings to include the new BoardContainer and
    ContainerItem types.

20240116200136-add-version-to-board-table.ts                              
    backend/src/db/migrations/20240116200136-add-version-to-board-table.ts

    Added a new database migration to add a version field to the
    board table.

Configuration changes
1 files
codegen.ts                                                                                                  
    backend/codegen.ts

    Commented out the post-processing hooks in the code
    generation configuration file.

Bug_fix
2 files
IssueStatusDropdown.tsx                                                                        
    frontend/components/IssueModal/IssueStatusDropdown.tsx

    Updated the IssueStatusDropdown component to use a
    network-only fetch policy when refetching queries.

socket-handlers.ts                                                                                  
    frontend/services/socket-handlers.ts

    Commented out the refetching of queries in the socket
    message handler to avoid conflicts with board state.

Formatting
2 files
index.tsx                                                                                                    
    frontend/components/KanbanBoard/Item/index.tsx

    **Minor import reordering in the Item component.
    **

index.tsx                                                                                                    
    frontend/components/KanbanBoard/Container/index.tsx

    **Minor import reordering in the Container component.
    **

Dependencies
2 files
pnpm-lock.yaml                                                                                          
    backend/pnpm-lock.yaml

    Updated the lock file to include the new array-move
    dependency.

package.json                                                                                              
    backend/package.json

    **Added the array-move package to the dependencies.
    **


✨ Usage guide:

Overview:
The describe tool scans the PR code changes, and generates a description for the PR - title, type, summary, walkthrough and labels. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

When commenting, to edit configurations related to the describe tool (pr_description section), use the following template:

/describe --pr_description.some_config1=... --pr_description.some_config2=...

With a configuration file, use the following template:

[pr_description]
some_config1=...
some_config2=...
Enabling\disabling automation
  • When you first install the app, the default mode for the describe tool is:
pr_commands = ["/describe --pr_description.add_original_user_description=true" 
                         "--pr_description.keep_original_user_title=true", ...]

meaning the describe tool will run automatically on every PR, will keep the original title, and will add the original user description above the generated description.

  • Markers are an alternative way to control the generated description, to give maximal control to the user. If you set:
pr_commands = ["/describe --pr_description.use_description_markers=true", ...]

the tool will replace every marker of the form pr_agent:marker_name in the PR description with the relevant content, where marker_name is one of the following:

  • type: the PR type.
  • summary: the PR summary.
  • walkthrough: the PR walkthrough.

Note that when markers are enabled, if the original PR description does not contain any markers, the tool will not alter the description at all.

Custom labels

The default labels of the describe tool are quite generic: [Bug fix, Tests, Enhancement, Documentation, Other].

If you specify custom labels in the repo's labels page or via configuration file, you can get tailored labels for your use cases.
Examples for custom labels:

  • Main topic:performance - pr_agent:The main topic of this PR is performance
  • New endpoint - pr_agent:A new endpoint was added in this PR
  • SQL query - pr_agent:A new SQL query was added in this PR
  • Dockerfile changes - pr_agent:The PR contains changes in the Dockerfile
  • ...

The list above is eclectic, and aims to give an idea of different possibilities. Define custom labels that are relevant for your repo and use cases.
Note that Labels are not mutually exclusive, so you can add multiple label categories.
Make sure to provide proper title, and a detailed and well-phrased description for each label, so the tool will know when to suggest it.

Utilizing extra instructions

The describe tool can be configured with extra instructions, to guide the model to a feedback tailored to the needs of your project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Notice that the general structure of the description is fixed, and cannot be changed. Extra instructions can change the content or style of each sub-section of the PR description.

Examples for extra instructions:

[pr_description] 
extra_instructions="""
- The PR title should be in the format: '<PR type>: <title>'
- The title should be short and concise (up to 10 words)
- ...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the describe usage page for a comprehensive guide on using this tool.

This commit implements mechanisms needed to modify a board's view state. A new GraphQL mutation, `addItemToViewState`, has been added. The backend `package.json` was modified to include `array-move@4.0.0` for sorting utilities. Changes have also been made to various resolvers, and some code was commented out for later adjustments.
Cleaned up the KanbanBoard component by eliminating unused imports, queries, state fields, and methods. This simplifies the code, making it easier to maintain and understand. Removed unnecessary mutations like UPDATE_BOARD_MUTATION and redundant hooks like useLazyQuery. This refactoring ensures only relevant dependencies and state values remain in use.
There were significant changes in the way the 'boards' resolver handled fetching boards. We refactored the resolver from the project's code to a shared function, ensuring to take into account if the parent type is a Project. Additionally, the function is now exported directly from the 'board' resolver's index file. This should improve readability and maintainability in the long run.
Removed unused type imports in the board index resolver file. "Maybe", "ResolversObject", and "ResolversTypes" were decluttered to streamline the code base and improve readability.
The update consists of reworking code in several index.ts files to perform database operations within transactions, ensuring atomicity. This is mainly implemented in board and issue resolvers, where multiple actions are performed within the same code block. This ensures consistency and rollbacks in case of any errors occurring during the operations.
The commit eliminates large portions of commented code in the issue resolver file, 'index.ts'. This helps to streamline the codebase and reduce clutter, enhancing readability and overall code maintenance.
The sequence of import statements in Item and Container components under KanbanBoard has been revised for a cleaner code organization. External dependencies now precede internal dependencies in order to provide consistency and enhance readability.
The comments referencing a GitHub link and a personal compliment were removed from the KanbanBoard's index.tsx file. These comments were not providing any significant context or crucial information for the understanding or functioning of the code.
This commit introduces the 'AddItemToViewState' mutation to the graphql schema and modifies board resolver logic. It ensures that a new item can be added to a given view state by manipulating the view state's positional index. The changes include validation checks for the 'columnPositionIndex' and different handling for existing and new items. This update enhances the functionality, making the system more dynamic and flexible.
The code for reordering container items has been adjusted to use row level locking for improved concurrency control. This has been achieved by replacing the previous sorting method with an SQL query that includes a lock and transaction. This change is currently being tested.
The code disables data pre-loading in the resolvers and refetching for WebSocket messages in frontend services. This change was made to prevent a possible performance issue. However, the impact on the system's overall performance and functionality should be carefully monitored and evaluated.
Included an asynchronous refetch function onCompleted in the KanbanBoard component. This is to ensure that the most recent project information is displayed, though additional review is needed to confirm its necessity.
The underlying logic for updating an issue's status in the Kanban board has been modified. An additional early exit condition has been introduced when the containers array is empty. The refetching of project info upon completion of updating issues has been modified and simplified for efficiency. Moreover, the logic has been restructured to enhance readability and maintainability.
The code modifications update how issue status is changed - it now involves actions specific to the issue board. Moreover, they ensure data consistency by checking for remote data changes on the Kanban board page and updating the page state accordingly. This adjustment helps prevent any discrepancies caused by stale data.
A new version field has been added to the board table in the database. This new field has been incorporated into the backend and frontend, and it is reflected in all related graphql queries and type definitions.
In the KanbanBoard component, a new function has been added to increment the boardVersion state whenever a new item is completed and added to the board. This ensures that the version of the board is always up-to-date after an item is added.
The updated code removes unnecessary comments and simplifies the behavior when remote data changes. Superfluous logs and checks have been minimized. The complexity of the code related to issue handling and board states are greatly reduced, making the functionality clearer. The changes improve code readability and maintainability.
@claygorman
Copy link
Contributor Author

/describe

Copy link
Contributor

PR Analysis

  • 🎯 Main theme: Implementation of a new Kanban board approach with database schema changes and GraphQL updates.
  • 📝 PR summary: This PR introduces a new approach to handling the Kanban board's view state, including database schema changes to support board containers and items, GraphQL schema updates, and corresponding frontend adjustments. It also includes refactoring of the KanbanBoard component, removal of unnecessary code, and updates to transaction handling in the backend resolvers.
  • 📌 Type of PR: Enhancement
  • ⏱️ Estimated effort to review [1-5]: 4, because the PR includes a significant number of changes across multiple files, including database migrations, backend resolver logic, GraphQL schema updates, and frontend component adjustments. The changes impact core functionality related to the Kanban board's state management and require careful review to ensure data integrity and application stability.
  • 🔒 Security concerns: No security concerns found

PR Feedback

💡 General suggestions: The PR introduces a comprehensive set of changes that are well-scoped to the task of improving the Kanban board's view state management. It is recommended to ensure thorough testing, particularly around the database migrations and the new transaction handling in the backend resolvers. Additionally, consider verifying the frontend behavior to ensure that the new state management logic aligns with user expectations and that the UI updates reflect the backend changes accurately.

🤖 Code feedback:
relevant filebackend/src/resolvers/issue/index.ts
suggestion      

Consider using the DataLoader pattern for batch loading within transactions to improve performance and reduce the number of database queries. [important]

relevant line// [EXPECTED_OPTIONS_KEY]: dataLoaderContext,

relevant filefrontend/components/KanbanBoard/index.tsx
suggestion      

Implement a mechanism to handle potential race conditions between mutations and queries, especially when dragging and dropping items on the Kanban board. [important]

relevant line// TODO: FIX

relevant filebackend/src/db/migrations/20240116200136-add-version-to-board-table.ts
suggestion      

Ensure that the version column addition to the boards table is accompanied by a corresponding model update in the Sequelize model definitions. [medium]

relevant lineawait queryInterface.addColumn(TABLE_NAME, 'version', {

relevant filefrontend/services/socket-handlers.ts
suggestion      

Revisit the WebSocket message handling to ensure that board updates do not conflict with the new state management logic. [medium]

relevant line// TODO: This currently fights the board state, need to figure out a better way to do this


✨ Usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.
When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:

/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...

With a configuration file, use the following template:

[pr_reviewer]
some_config1=...
some_config2=...
Utilizing extra instructions

The review tool can be configured with extra instructions, which can be used to guide the model to a feedback tailored to the needs of your project.

Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify the relevant sub-tool, and the relevant aspects of the PR that you want to emphasize.

Examples for extra instructions:

[pr_reviewer] # /review #
extra_instructions="""
In the code feedback section, emphasize the following:
- Does the code logic cover relevant edge cases?
- Is the code logic clear and easy to understand?
- Is the code logic efficient?
...
"""

Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

How to enable\disable automation
  • When you first install PR-Agent app, the default mode for the review tool is:
pr_commands = ["/review", ...]

meaning the review tool will run automatically on every PR, with the default configuration.
Edit this field to enable/disable the tool, or to change the used configurations

About the 'Code feedback' section

The review tool provides several type of feedbacks, one of them is code suggestions.
If you are interested only in the code suggestions, it is recommended to use the improve feature instead, since it dedicated only to code suggestions, and usually gives better results.
Use the review tool if you want to get a more comprehensive feedback, which includes code suggestions as well.

Auto-labels

The review tool can auto-generate two specific types of labels for a PR:

  • a possible security issue label, that detects possible security issues (enable_review_labels_security flag)
  • a Review effort [1-5]: x label, where x is the estimated effort to review the PR (enable_review_labels_effort flag)
Extra sub-tools

The review tool provides a collection of possible feedbacks about a PR.
It is recommended to review the possible options, and choose the ones relevant for your use case.
Some of the feature that are disabled by default are quite useful, and should be considered for enabling. For example:
require_score_review, require_soc2_review, enable_review_labels_effort, and more.

More PR-Agent commands

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To list the possible configuration parameters, add a /config comment.

See the review usage page for a comprehensive guide on using this tool.

@github-actions github-actions bot changed the title new-kanban-board-approach Implement board versioning and add mutation for updating board view state Jan 17, 2024
@github-actions github-actions bot added enhancement New feature or request bug_fix labels Jan 17, 2024
Copy link
Contributor

PR Description updated to latest commit (e331806)

@claygorman claygorman merged commit fbb601f into master Jan 17, 2024
2 checks passed
@claygorman claygorman deleted the new-kanban-board-approach branch January 17, 2024 23:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug_fix enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant