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

[WEB-2628] fix: Sorting by estimates #5988

Merged
merged 4 commits into from
Nov 13, 2024
Merged

Conversation

rahulramesha
Copy link
Collaborator

@rahulramesha rahulramesha commented Nov 11, 2024

This PR makes changes to fix sorting of estimates. This fixes the issue in All the places required.

This PR also changes the Key for estimates from estimate_point to estimate_point__key.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced sorting capabilities with new estimate point keys for better data management.
    • Improved issue synchronization and retrieval processes, including error handling and logging.
  • Bug Fixes

    • Corrected variable naming and improved error handling in workspace data loading.
  • Documentation

    • Updated constants and methods to reflect new key structures and sorting logic.

These updates aim to enhance user experience by improving data accuracy and retrieval efficiency within the application.

Copy link
Contributor

coderabbitai bot commented Nov 11, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the handling of estimation points within various components of the application. The TIssueOrderByOptions type has been updated to reflect new key references for estimation points, which are now denoted as "estimate_point__key" and "-estimate_point__key". Additionally, the SPREADSHEET_PROPERTY_DETAILS constant and several methods in the Storage class have been adjusted to incorporate these new keys. Enhancements to error handling and logging have also been implemented across multiple files, improving the robustness of data retrieval and synchronization processes.

Changes

File Path Change Summary
packages/types/src/view-props.d.ts Updated TIssueOrderByOptions: changed "estimate_point" to "estimate_point__key" and vice versa.
web/core/constants/spreadsheet.ts Updated SPREADSHEET_PROPERTY_DETAILS: changed ascendingOrderKey and descendingOrderKey for estimate.
web/core/local-db/storage.sqlite.ts Enhanced Storage class: added logging in getIssues, error handling in syncIssues, and improved logic in getSubIssues.
web/core/local-db/utils/load-workspace.ts Updated getEstimatePoints: changed const to let for objects, corrected variable name memebers to members, and added checks in loadWorkSpaceData.
web/core/local-db/utils/query-constructor.ts Updated SPECIAL_ORDER_BY to include new keys for estimate_point. Modified SQL logic in issueFilterQueryConstructor.
web/core/local-db/utils/query.utils.ts Altered translateQueryParams and getSingleFilterFields to refine handling of order_by and query parameters.
web/core/store/issue/helpers/base-issues.store.ts Updated ISSUE_ORDERBY_KEY to include new estimate point keys and modified populateIssueDataForSorting method.

Possibly related PRs

Suggested labels

🌟enhancement, ⚙️backend

Suggested reviewers

  • SatishGandham
  • sriramveeraghanta

🐰 In the code we hop and play,
With estimates in a brand new way.
From points to keys, we redefine,
Sorting issues, all in line.
With logs and checks, we make it bright,
Hopping forward, coding with delight! 🐇✨


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.

SatishGandham and others added 2 commits November 12, 2024 12:59
- Fix a bug with with sorting on special fields on spreadsheet layout
- Cleanup logging
@rahulramesha rahulramesha added 🌐frontend 🐛bug Something isn't working labels Nov 12, 2024
@rahulramesha rahulramesha marked this pull request as ready for review November 12, 2024 12:08
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: 3

🧹 Outside diff range and nitpick comments (6)
web/core/local-db/utils/load-workspace.ts (1)

107-109: Consider adding error logging for database initialization failures

While the null check prevents runtime errors, silently returning might hide database initialization issues. Consider logging the error state.

 if (!persistence.db || !persistence.db.exec) {
+  log("Database initialization failed - database or exec method is undefined");
   return;
 }
web/core/constants/spreadsheet.ts (1)

82-84: Consider adding a comment explaining the estimate point structure.

To improve maintainability, consider adding a comment explaining that estimate_point__key refers to a nested key property within the estimate point structure.

  estimate: {
    title: "Estimate",
+   // estimate_point is an object with a key property used for sorting
    ascendingOrderKey: "estimate_point__key",
    ascendingOrderTitle: "Low",
    descendingOrderKey: "-estimate_point__key",
    descendingOrderTitle: "High",
web/core/local-db/utils/query-constructor.ts (2)

79-82: Consider adding error handling for invalid estimate points

While the SQL construction is correct, consider adding error handling for cases where estimate points might be invalid or null. This would improve the robustness of the sorting functionality.

    } else if (order_by.includes("estimate")) {
-      sql += ` s.key as ${name} `;
+      sql += ` COALESCE(s.key, 0) as ${name} `;
    } else {

24-24: Consider adding documentation for special ordering logic

The SQL construction for special ordering cases (including the new estimate point handling) is complex. Consider adding documentation explaining the different cases and their implications.

web/core/local-db/utils/query.utils.ts (1)

339-341: LGTM! Consider adding tests for estimate point sorting.

The code correctly includes the estimate_point field when sorting by estimate_point__key, which is essential for the sorting functionality to work properly.

Consider adding test cases to verify:

  1. Sorting by estimate_point__key includes the estimate_point field
  2. The sorting works correctly in both ascending and descending order
web/core/store/issue/helpers/base-issues.store.ts (1)

289-297: Add a TODO for the temporary code

The comment // Temporary code to fix no load order by indicates a temporary fix. Consider adding a TODO comment or creating an issue to ensure this code is revisited and properly addressed in the future.

Would you like me to create a GitHub issue to track this temporary code for future improvement?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between db8c4f9 and e21e9ce.

📒 Files selected for processing (7)
  • packages/types/src/view-props.d.ts (1 hunks)
  • web/core/constants/spreadsheet.ts (1 hunks)
  • web/core/local-db/storage.sqlite.ts (1 hunks)
  • web/core/local-db/utils/load-workspace.ts (4 hunks)
  • web/core/local-db/utils/query-constructor.ts (2 hunks)
  • web/core/local-db/utils/query.utils.ts (2 hunks)
  • web/core/store/issue/helpers/base-issues.store.ts (15 hunks)
🔇 Additional comments (12)
web/core/local-db/utils/load-workspace.ts (2)

90-94: LGTM: Array handling improvements

The changes improve the clarity of array manipulation by using explicit reassignment instead of mutation. The null check for estimates is properly maintained.


118-118: LGTM: Variable name typo fix

The correction of the variable name from 'memebers' to 'members' improves code clarity.

packages/types/src/view-props.d.ts (1)

43-44: LGTM! Verify estimate key changes across the codebase.

The addition of estimate_point__key options aligns with the PR objectives to fix sorting by estimates.

Let's verify the consistency of these changes across the codebase:

web/core/constants/spreadsheet.ts (1)

82-84: LGTM! Verify the estimate point structure.

The change from estimate_point to estimate_point__key looks correct for fixing the sorting functionality. This suggests that estimate points are now structured objects with a key property.

Let's verify the estimate point structure in the API response:

✅ Verification successful

Estimate point structure correctly updated.

The estimate_point__key structure is consistent across the codebase and properly handled by the SpreadsheetEstimateColumn component.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for estimate point structure in API-related files
rg -g '*.ts' -g '*.tsx' -A 5 'estimate_point'

# Search for the EstimateColumn component to verify handling
ast-grep --pattern 'SpreadsheetEstimateColumn'

Length of output: 41698

web/core/local-db/utils/query-constructor.ts (2)

21-22: LGTM: Consistent mapping for estimate point keys

The new mappings correctly handle both ascending and descending sort orders for estimate points while maintaining consistency with the existing pattern.


90-92: Verify index existence on estimate_points table

The LEFT JOIN with estimate_points table is correctly implemented. However, to ensure optimal query performance, verify that appropriate indexes exist.

✅ Verification successful

Index on estimate_points table exists

The necessary index on the estimate_points table is present, ensuring optimal query performance.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for indexes on estimate_points table
# Note: This assumes SQLite schema is available in the repository

# Search for CREATE TABLE or CREATE INDEX statements related to estimate_points
rg -A 5 "CREATE (TABLE|INDEX).*estimate_points"

Length of output: 523

web/core/local-db/utils/query.utils.ts (2)

Line range hint 1-385: Verify end-to-end sorting functionality for estimates.

The changes look good overall. Let's verify the complete sorting functionality:

#!/bin/bash
# Description: Verify estimate point sorting implementation
# Expected: Find all related estimate point handling code

# Check for estimate point related SQL queries
rg "estimate_point" --type ts

# Check for order_by handling with estimate points
rg "order_by.*estimate_point" --type ts -A 2

# Check for any potential edge cases in estimate point handling
rg "estimate_point__key|estimate_point" --type test

48-48: LGTM! Verify the order_by behavior across layout switches.

The condition correctly handles order_by when switching from spreadsheet layout to other layouts.

Let's verify the SPECIAL_ORDER_BY keys and their usage:

✅ Verification successful

Verified: The order_by handling for non-spreadsheet layouts is correctly implemented and SPECIAL_ORDER_BY is properly defined and utilized.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check SPECIAL_ORDER_BY usage and layout-specific ordering
# Expected: Find SPECIAL_ORDER_BY definition and any layout-specific order_by handling

# Check for SPECIAL_ORDER_BY definition
rg "SPECIAL_ORDER_BY.*=.*{" -A 5

# Check for other layout-specific order_by handling
rg "layout.*[!=]=.*[\"']spreadsheet[\"'].*order_by" -A 2

Length of output: 13351


Script:

#!/bin/bash
# Description: Check SPECIAL_ORDER_BY usage and layout-specific order_by handling with corrected file type
# Expected: Find SPECIAL_ORDER_BY definition and any layout-specific order_by handling

# Check for SPECIAL_ORDER_BY definition
rg "SPECIAL_ORDER_BY\s*=\s*{" --type ts -A 5

# Check for other layout-specific order_by handling
rg "layout\s*!=\s*['\"]spreadsheet['\"]\s*&&\s*order_by" --type ts -A 2

Length of output: 236


Script:

#!/bin/bash
# Description: Check SPECIAL_ORDER_BY usage and layout-specific order_by handling with corrected regex
# Expected: Find SPECIAL_ORDER_BY definition and any layout-specific order_by handling

# Check for SPECIAL_ORDER_BY definition
rg "SPECIAL_ORDER_BY\\s*=\\s*\\{" --type ts -A 5

# Check for other layout-specific order_by handling
rg "layout\\s*!=\\s*[\"']spreadsheet[\"']\\s*&&\\s*order_by" --type ts -A 2

Length of output: 600

web/core/local-db/storage.sqlite.ts (1)

302-304: Verify query constructor compatibility with new estimate key.

Since the PR changes the estimate key from estimate_point to estimate_point__key, ensure that the issueFilterQueryConstructor and related query utilities properly handle the new key format.

Let's verify the query construction implementation:

#!/bin/bash
# Description: Check query constructor implementation for estimate key handling

# Search for estimate-related query construction
rg -A 5 'estimate_point' web/core/local-db/utils/query-constructor.ts

# Check for any direct references to the old key
rg -l 'estimate_point[^_]' 
web/core/store/issue/helpers/base-issues.store.ts (3)

39-39: Importing SPECIAL_ORDER_BY

The import statement correctly adds SPECIAL_ORDER_BY from "@/local-db/utils/query-constructor", which is necessary for the updated sorting logic.


168-169: Update ISSUE_ORDERBY_KEY with estimate point keys

The mapping correctly adds estimate_point__key and -estimate_point__key to ISSUE_ORDERBY_KEY, aligning with the new keys used for estimate points in sorting.


1718-1721: Ensure all calls to populateIssueDataForSorting include projectId

The function populateIssueDataForSorting now includes projectId as a parameter. Please verify that all calls to this function have been updated to include the projectId argument to prevent potential runtime errors.

Run the following script to find any calls to populateIssueDataForSorting missing the projectId parameter:

Comment on lines +90 to 94
let objects: IEstimatePoint[] = [];
(estimates || []).forEach((estimate: IEstimate) => {
if (estimate?.points) {
objects.concat(estimate.points);
objects = objects.concat(estimate.points);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Schema does not support the new estimate point key structure

The estimatePointSchema does not include estimate_point__key. Please update the schema to support the new key structure.

🔗 Analysis chain

Verify schema compatibility with estimate point key changes

Given that the PR changes the estimate point key from estimate_point to estimate_point__key, we should verify that the database schema and related components support this change.

Also applies to: 127-127

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the estimate point schema and related components support the new key structure

# Check the estimate point schema definition
rg -A 10 "estimatePointSchema.*=" 

# Check for any references to the old and new estimate point keys
rg "estimate_point[^_]"
rg "estimate_point__key"

Length of output: 35316

@@ -300,6 +300,7 @@ export class Storage {
const { cursor, group_by, sub_group_by } = queries;

const query = issueFilterQueryConstructor(this.workspaceSlug, projectId, queries);
log("#### Query", query);
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Inconsistent logging patterns detected in query-related operations.

The added logging statement is not consistent with existing logging practices across other query-related methods. Please ensure that logging is applied uniformly to facilitate debugging and maintenance.

  • web/core/local-db/storage.sqlite.ts (Line 303)
🔗 Analysis chain

LGTM! Helpful debug logging addition.

The added logging statement for the constructed query is well-placed and consistent with the existing logging pattern in the file. This will be particularly useful for debugging the sorting functionality changes related to estimate_point__key.

Let's verify the logging implementation is consistent across query-related operations:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent logging patterns across query-related operations

# Search for logging patterns in query-related code
rg -A 2 'log\(' web/core/local-db/storage.sqlite.ts

Length of output: 3677

Comment on lines +1775 to +1794
case "estimate_point": {
// return if project Id does not exist
if (!projectId) break;
// get the estimate ID for the current Project
const currentProjectEstimateId =
this.rootIssueStore.rootStore.projectEstimate.currentActiveEstimateIdByProjectId(projectId);
// return if current Estimate Id for the project is not available
if (!currentProjectEstimateId) break;
// get Estimate based on Id
const estimate = this.rootIssueStore.rootStore.projectEstimate.estimateById(currentProjectEstimateId);
// If Estimate is not available, then return
if (!estimate) break;
// Get Estimate Value
const estimateKey = estimate?.estimatePointById(dataIds as string)?.key;

// If Value string i not available or empty then return
if (estimateKey === undefined) break;

dataValues.push(estimateKey);
}
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

Handle dataIds type correctly in estimate_point case

In the "estimate_point" case, dataIds is cast to string with dataIds as string, but dataIds can be string | string[] | null | undefined. Casting without checking can cause runtime errors if dataIds is an array or null.

Consider modifying the code to handle both string and string[] types for dataIds. Apply the following diff to fix the issue:

 case "estimate_point": {
   if (!projectId) break;
   const currentProjectEstimateId =
     this.rootIssueStore.rootStore.projectEstimate.currentActiveEstimateIdByProjectId(projectId);
   if (!currentProjectEstimateId) break;
   const estimate = this.rootIssueStore.rootStore.projectEstimate.estimateById(currentProjectEstimateId);
   if (!estimate) break;
-  const estimateKey = estimate?.estimatePointById(dataIds as string)?.key;
-  if (estimateKey === undefined) break;
-  dataValues.push(estimateKey);
+  const dataIdsArray = Array.isArray(dataIds) ? dataIds : [dataIds];
+  for (const id of dataIdsArray) {
+    if (!id) continue;
+    const estimateKey = estimate.estimatePointById(id)?.key;
+    if (estimateKey !== undefined) {
+      dataValues.push(estimateKey);
+    }
+  }
 }

This change ensures that both single and multiple dataIds are handled correctly, preventing potential runtime errors.

📝 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
case "estimate_point": {
// return if project Id does not exist
if (!projectId) break;
// get the estimate ID for the current Project
const currentProjectEstimateId =
this.rootIssueStore.rootStore.projectEstimate.currentActiveEstimateIdByProjectId(projectId);
// return if current Estimate Id for the project is not available
if (!currentProjectEstimateId) break;
// get Estimate based on Id
const estimate = this.rootIssueStore.rootStore.projectEstimate.estimateById(currentProjectEstimateId);
// If Estimate is not available, then return
if (!estimate) break;
// Get Estimate Value
const estimateKey = estimate?.estimatePointById(dataIds as string)?.key;
// If Value string i not available or empty then return
if (estimateKey === undefined) break;
dataValues.push(estimateKey);
}
case "estimate_point": {
// return if project Id does not exist
if (!projectId) break;
// get the estimate ID for the current Project
const currentProjectEstimateId =
this.rootIssueStore.rootStore.projectEstimate.currentActiveEstimateIdByProjectId(projectId);
// return if current Estimate Id for the project is not available
if (!currentProjectEstimateId) break;
// get Estimate based on Id
const estimate = this.rootIssueStore.rootStore.projectEstimate.estimateById(currentProjectEstimateId);
// If Estimate is not available, then return
if (!estimate) break;
// Get Estimate Value
const dataIdsArray = Array.isArray(dataIds) ? dataIds : [dataIds];
for (const id of dataIdsArray) {
if (!id) continue;
const estimateKey = estimate.estimatePointById(id)?.key;
if (estimateKey !== undefined) {
dataValues.push(estimateKey);
}
}
}

@pushya22 pushya22 merged commit f44db89 into preview Nov 13, 2024
22 of 23 checks passed
@pushya22 pushya22 deleted the fix-estimates-sorting branch November 13, 2024 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working 🌐frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants