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

🤴🏾 Jobs priorisation UI #930

Merged
merged 17 commits into from
Oct 14, 2024
Merged

🤴🏾 Jobs priorisation UI #930

merged 17 commits into from
Oct 14, 2024

Conversation

cristianpb
Copy link
Member

@cristianpb cristianpb commented Sep 18, 2024

  • L'api qui permet de consulter la liste des jobs renvoie la liste des jobs pour l'utilisateur (sauf pour le superutilisateur qui peut consulter tous les jobs)
  • L'api qui permet de supprimer les jobs est accessible de l'utilisateur auteur du job. Ainsi un utilisateur pourra annuler son traitement depuis l'UI de la liste des jobs.

Exemple utilisateur user1

image

  • Le délai de conservation est paramétrable par l'utilisateur (minimum: 1 min) - pour permettre lors de l'automatisation de protéger ses données

Voici une proposition:

image

Summary by CodeRabbit

  • New Features
    • Introduced a new file persistence duration option in the configuration settings, allowing users to select from predefined time intervals.
  • Access Control Changes
    • The /jobs route is now accessible without authentication, broadening user access to the jobs administration page.
    • Simplified access control in the LinkJobs component, allowing all users to view job data once the component is ready.
  • Improvements
    • Enhanced job metrics by shifting from average delay to average processing time for completed jobs.
    • Updated table headers in the LinkJobs component to include "creation date," "end date," and "deletion date."
    • Improved job processing and error management in the LinkJob component for better user feedback during uploads and downloads.
    • Adjusted rendering logic in the MatchIDHeader for clearer visibility of admin-related menu items.
    • Streamlined scrolling functionality in multiple components for improved user experience.
    • Updated the scrolling library to enhance performance and functionality.

Copy link

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce a new module for job data management, enhancing how job-related information is fetched and processed. The /jobs route has been made publicly accessible by removing the authentication requirement. The LinkJobs.svelte component has been updated to simplify access control and improve job metrics calculations. A new file persistence duration option has been added to the LinkConfigureOptions.svelte component. Additionally, the scrolling functionality has transitioned to a new library, and several components have undergone various updates to improve user experience and error handling.

Changes

Files Change Summary
src/components/tools/routes.js Removed auth: true from the /jobs route, allowing public access.
src/components/views/LinkConfigureOptions.svelte Added a new option for file persistence duration with predefined time settings.
src/components/views/LinkJobs.svelte Simplified access control by removing admin checks, updated job metrics calculation from average delay to average processing time, and streamlined data fetching logic.
src/components/views/MatchIDHeader.svelte Repositioned the closing {#if $admin} block to adjust the rendering order of admin-related menu items without altering the overall structure.
src/components/views/LinkJob.svelte Added a line to include tmpfilePersistence in the form data for submission and improved job processing and error management during uploads and downloads.
src/components/views/Link.svelte Updated the reset function to accept an optional boolean parameter for enhanced functionality.
src/components/tools/jobs.js Introduced a new module for job data management, including functions for fetching and processing job data.
package.json Updated dependency from "svelte-scrollto": "0.2.0" to "svelte-scrolling": "1.4.0".
Makefile Modified environment variable export statements and updated commands to reflect the new APP_URL variable.
src/components/views/EditsList.svelte Replaced scrolling method using svelte-scrollto with svelte-scrolling, updating the scrolling functionality.
src/components/views/Info.svelte Updated scrolling method from animateScroll to scrollTo using the new svelte-scrolling library.

Poem

🐇 In the fields where changes bloom,
Routes now open, dispelling gloom.
With options for time, persistence shines,
Jobs now gather, crossing lines.
A menu dances, admin's delight,
Hopping forward, all feels right! 🌼


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

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

Outside diff range and nitpick comments (1)
src/components/views/LinkJobs.svelte (1)

56-57: Minor: Ensure consistent capitalization in table headers

The new headers provide valuable information about job lifecycle. However, for consistency with other headers, consider capitalizing "Creation Date" and "Deletion Date".

-                                    <th>creation date</th>
-                                    <th>deletion date</th>
+                                    <th>Creation Date</th>
+                                    <th>Deletion Date</th>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d701b82 and 4f10fb4.

Files selected for processing (1)
  • src/components/views/LinkJobs.svelte (7 hunks)
Additional comments not posted (5)
src/components/views/LinkJobs.svelte (5)

1-1: LGTM: Improved accessibility for all users

The simplified rendering condition aligns with the PR objective of making job information accessible to all users, not just admins.


34-34: LGTM: Improved accuracy in job metrics calculation

Using processing_time instead of delay for calculating the average processing rate provides a more accurate representation of job performance.


69-69: LGTM: Added deletion date information

The addition of the deletion date in the table row provides users with valuable information about their job data retention, aligning with the PR objective of implementing a configurable retention period.


122-122: LGTM: Improved authentication logic

The changes simplify the component's logic by using the accessToken for authorization instead of relying on admin status. This aligns with the PR objective of making job information accessible to all authenticated users.

Also applies to: 127-134


184-184: LGTM: Added deletion time and improved date formatting

The addition of deletionTime to the job object and the consistent formatting of job.date improve the job information display. These changes align with the PR objectives of implementing a configurable retention period and enhancing the job management interface.

Also applies to: 188-188

Comment on lines 158 to 160
const dateTostr = (_date) => {
return `${_date.getFullYear()}-${_date.getMonth() + 1}-${_date.getDate()} ${(_date.getHours() < 10 ? '0' : '') + _date.getHours()}:${ (_date.getMinutes() < 10 ? '0' : '') + _date.getMinutes()}`;
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Suggestion: Improve date formatting function

The dateTostr function centralizes date formatting, which is good for maintainability. However, consider the following improvements:

  1. Use template literals for better readability.
  2. Use padStart() for consistent two-digit formatting.
  3. Consider using toISOString() or a date formatting library for more robust handling of edge cases.

Here's an improved version of the function:

const dateTostr = (_date) => {
  const pad = (num) => num.toString().padStart(2, '0');
  return `${_date.getFullYear()}-${pad(_date.getMonth() + 1)}-${pad(_date.getDate())} ${pad(_date.getHours())}:${pad(_date.getMinutes())}`;
}

Alternatively, consider using a date formatting library like date-fns for more robust date handling.

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: 0

🧹 Outside diff range and nitpick comments (2)
src/components/views/EditsList.svelte (1)

155-156: Review scrolling behavior and timing.

The update to use the new scrollTo function from 'svelte-scrolling' looks good and aligns with the import change.

Consider the following suggestions:

  1. Review the need for the 400ms setTimeout delay before scrolling. The new library might not require this delay for smooth scrolling.

  2. Test the scrolling behavior thoroughly to ensure it meets your expectations, especially regarding smoothness and timing.

If the delay is indeed unnecessary, you could simplify the code as follows:

- setTimeout(() => {
-     scrollTo({ref: `#${id}`, duration: 400});
- }, 400);
+ scrollTo({ref: `#${id}`, duration: 400});

This would make the scrolling action immediate while still maintaining the 400ms duration for the scroll animation itself.

src/components/views/Info.svelte (1)

Line range hint 1-524: Consider project-wide implications of scrolling library change

The changes in this file correctly implement the migration from 'svelte-scrollto' to 'svelte-scrolling'. However, consider the following project-wide implications:

  1. Ensure all other components using the scrolling functionality have been updated similarly.
  2. Update the project's dependencies in package.json to remove 'svelte-scrollto' and add 'svelte-scrolling'.
  3. Update any documentation or comments referencing the old scrolling library.
  4. If there are any significant differences in behavior or API between the two libraries, consider adding a comment explaining the change and any new considerations for developers.

To verify the complete migration, run the following script:

#!/bin/bash
echo "Checking for any remaining 'svelte-scrollto' dependencies:"
grep -n "svelte-scrollto" package.json

echo "Verifying 'svelte-scrolling' is added to dependencies:"
grep -n "svelte-scrolling" package.json

echo "Checking for any remaining usages of 'svelte-scrollto' in the project:"
rg --type svelte "svelte-scrollto"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb45bc5 and 620968e.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (3)
  • package.json (1 hunks)
  • src/components/views/EditsList.svelte (3 hunks)
  • src/components/views/Info.svelte (2 hunks)
🔇 Additional comments not posted (5)
package.json (1)

35-35: 🛠️ Refactor suggestion

Verify the impact of switching from svelte-scrollto to svelte-scrolling

The change from "svelte-scrollto" (v0.2.0) to "svelte-scrolling" (v1.4.0) represents a significant library switch for handling scroll animations. While this update may bring improvements or new features, it's important to ensure it doesn't introduce breaking changes.

Please run the following script to identify potential areas affected by this change:

After running the script:

  1. Review the identified files and update the scroll-related code to use the new "svelte-scrolling" library.
  2. Test thoroughly to ensure all scrolling functionality works as expected with the new library.
  3. Update any documentation or comments related to scrolling functionality.

Consider adding a comment in the package.json file explaining the reason for this library change, which can be helpful for future maintenance.

Verification successful

Dependency change verified successfully

The switch from "svelte-scrollto" to "svelte-scrolling" has been correctly implemented. There are no remaining references to "svelte-scrollto" in the codebase, and "svelte-scrolling" is actively used in the relevant components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Identify usage of svelte-scrollto in the codebase

# Search for imports or usage of svelte-scrollto
echo "Searching for svelte-scrollto usage:"
rg --type svelte --type javascript 'from [\'"]svelte-scrollto[\'"]|import.*[\'"]svelte-scrollto[\'"]'

# Search for scroll-related function calls that might need updating
echo "Searching for potential scroll function calls:"
rg --type svelte --type javascript '\b(scrollTo|scroll)\b'

Length of output: 287


Script:

#!/bin/bash
# Description: Identify usage of svelte-scrollto in the codebase

# Search for imports or usage of svelte-scrollto
echo "Searching for svelte-scrollto usage:"
rg --type svelte --type javascript 'from [\'"]svelte-scrollto[\'"]|import.*[\'"]svelte-scrollto[\'"]'

# Search for scroll-related function calls that might need updating
echo "Searching for potential scroll function calls:"
rg --type svelte --type javascript "\\b(scrollTo|scroll)\\b"

Length of output: 176


Script:

#!/bin/bash
# Description: Identify usage of svelte-scrollto in the codebase

# Search for imports or usage of svelte-scrollto
echo "Searching for svelte-scrollto usage:"
rg --type svelte --type javascript "from ['\"]svelte-scrollto['\"]|import.*['\"]svelte-scrollto['\"]"

# Search for scroll-related function calls that might need updating
echo "Searching for potential scroll function calls:"
rg --type svelte --type javascript "\\b(scrollTo|scroll)\\b"

Length of output: 420


Script:

#!/bin/bash
# Description: Identify usage of svelte-scrollto in the codebase

# Search for imports or usage of svelte-scrollto in .svelte and .js files
echo "Searching for svelte-scrollto usage:"
rg --glob "*.svelte" --glob "*.js" "from ['\"]svelte-scrollto['\"]|import.*['\"]svelte-scrollto['\"]"

# Search for scroll-related function calls in .svelte and .js files
echo "Searching for potential scroll function calls:"
rg --glob "*.svelte" --glob "*.js" "\\b(scrollTo|scroll)\\b"

Length of output: 970

src/components/views/EditsList.svelte (2)

Line range hint 1-171: Summary of changes and recommendations

The changes in this file are focused on updating the scrolling library from 'svelte-scrollto' to 'svelte-scrolling'. The implementation looks good, and the necessary adjustments have been made to accommodate the new library.

To ensure a smooth transition and optimal performance, consider the following recommendations:

  1. Update the project dependencies to include 'svelte-scrolling' and remove 'svelte-scrollto' if it's no longer used elsewhere in the project.
  2. Review and test the scrolling behavior throughout the application to ensure it meets expectations and performs well with the new library.
  3. Consider removing the setTimeout delay before scrolling if it's no longer necessary with the new library.
  4. Update any documentation or comments related to the scrolling functionality to reflect the new library and usage.

Overall, these changes should improve the scrolling functionality in the EditsList component and potentially throughout the application.


115-115: Verify impact of scrolling library change across the codebase.

The change from 'svelte-scrollto' to 'svelte-scrolling' looks good. This update might offer improved scrolling functionality or performance.

To ensure a smooth transition, please:

  1. Update the project dependencies to include 'svelte-scrolling' and remove 'svelte-scrollto' if it's no longer used.
  2. Verify that this change doesn't break scrolling functionality in other components.

Run the following script to check for any remaining usage of 'svelte-scrollto':

If the script returns any results, those files may need to be updated to use the new 'svelte-scrolling' library.

Verification successful

Scrolling library update verified successfully.

All references to 'svelte-scrollto' and 'animateScroll' have been removed from .svelte files.

Please ensure that 'svelte-scrollto' is also removed from the project dependencies if it is no longer in use.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining usage of 'svelte-scrollto'

# Test: Search for 'svelte-scrollto' imports
echo "Checking for 'svelte-scrollto' imports:"
rg --type svelte "from 'svelte-scrollto'" || echo "No 'svelte-scrollto' imports found."

# Test: Search for 'animateScroll' usage
echo -e "\nChecking for 'animateScroll' usage:"
rg --type svelte "animateScroll" || echo "No 'animateScroll' usage found."

Length of output: 498


Script:

#!/bin/bash
# Description: Check for remaining usage of 'svelte-scrollto' and 'animateScroll' in .svelte files

# Test: Search for 'svelte-scrollto' imports
echo "Checking for 'svelte-scrollto' imports in .svelte files:"
rg "from ['\"]svelte-scrollto['\"]" -g "*.svelte" || echo "No 'svelte-scrollto' imports found."

# Test: Search for 'animateScroll' usage
echo -e "\nChecking for 'animateScroll' usage in .svelte files:"
rg "animateScroll" -g "*.svelte" || echo "No 'animateScroll' usage found."

Length of output: 510

src/components/views/Info.svelte (2)

502-502: Approve updated usage of scrollTo function

The usage of the new scrollTo function has been correctly updated to match the API of the 'svelte-scrolling' library. The ref parameter is now used instead of element, while maintaining the duration parameter for consistent scrolling behavior.


63-63: Approve import change and verify scrolling functionality

The import statement has been updated to use the scrollTo function from the 'svelte-scrolling' library instead of animateScroll from 'svelte-scrollto'. This change is approved as it appears to be a deliberate migration to a different scrolling library.

Please ensure the following:

  1. Update all usages of animateScroll.scrollTo to scrollTo throughout the component.
  2. Verify that the scrolling functionality still works as expected with the new library.
  3. Update the project dependencies to include 'svelte-scrolling' and remove 'svelte-scrollto' if no longer used.

Run the following script to check for any remaining usages of the old scrolling library:

Verification successful

Scrolling import update verified successfully

All instances of svelte-scrollto and animateScroll have been removed from the .svelte files, and the import statement now correctly uses scrollTo from the 'svelte-scrolling' library. The scrolling functionality should work as expected with the new implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any remaining usages of 'svelte-scrollto' in the project
echo "Checking for 'svelte-scrollto' usages:"
rg --type svelte "svelte-scrollto"

echo "Checking for 'animateScroll' usages:"
rg --type svelte "animateScroll"

Length of output: 311


Script:

#!/bin/bash
# Check for any remaining usages of 'svelte-scrollto' in .svelte files
echo "Checking for 'svelte-scrollto' usages in .svelte files:"
rg "svelte-scrollto" -g "*.svelte"

echo "Checking for 'animateScroll' usages in .svelte files:"
rg "animateScroll" -g "*.svelte"

Length of output: 317

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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 620968e and de46053.

📒 Files selected for processing (1)
  • src/components/views/LinkJobs.svelte (7 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/components/views/LinkJobs.svelte (5)

56-58: Table headers updated appropriately

The addition of "création," "fin," and "suppression" headers improves the clarity of the table, making it easier for users to understand the job timeline.


70-71: Displaying finished and deletion times accurately

Including job.finishedOnTime and job.deletionTime provides valuable information about when jobs are finished and when they are scheduled for deletion.


159-162: Date formatting function implemented correctly

The dateTostr function effectively formats dates, enhancing the readability and consistency of displayed dates.


186-187: Verify timezone handling in time calculations

When calculating deletionTime, ensure that timezone differences and daylight saving time are properly accounted for to prevent inconsistencies in time display.


191-192: Consistent formatting of job creation dates

Formatting j.date using dateTostr ensures that all date fields in the job data are presented consistently.

src/components/views/LinkJobs.svelte Outdated Show resolved Hide resolved
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: 14

🧹 Outside diff range and nitpick comments (3)
Makefile (1)

34-34: LGTM with a suggestion for APP_URL

The changes to APP_DNS and the introduction of APP_URL are good improvements:

  1. Using ?= for APP_DNS allows easier overriding of the value.
  2. APP_URL provides a complete URL, which is more convenient for use elsewhere.

However, consider making APP_URL more flexible:

-export APP_URL?=https://${APP_DNS}
+export APP_URL?=${APP_PROTOCOL:-https}://${APP_DNS}

This change allows for easy switching between http and https protocols, which can be useful in different environments (e.g., local development).

Also applies to: 113-113

src/components/views/Link.svelte (1)

Line range hint 284-291: Ensure $linkOptions is defined before setting its properties

In the reset function, you are assigning undefined to $linkOptions.csv:

$linkOptions.csv = undefined;

If $linkOptions is undefined, this will throw a runtime error. Please ensure that $linkOptions is initialized before setting its properties.

Apply this diff to initialize $linkOptions if it is undefined:

const reset = async (full = false) => {
    await clearAll();
    ...
    $linkFileSize = undefined;
+   if (!$linkOptions) {
+       $linkOptions = {};
+   }
    $linkOptions.csv = undefined;
    $linkSourceHeader = undefined;
    $linkSourceHeaderTypes = undefined;
    ...
}
src/components/views/LinkJob.svelte (1)

145-154: Align axios header configurations for consistency

In axiosUploadConfig, headers are set directly within a reactive statement:

$: axiosUploadConfig.headers = { Authorization: `Bearer ${$accessToken}` };

However, in axiosDownloadConfig, a separate headers object is created and updated:

const headers = {};

const axiosDownloadConfig = {
    onDownloadProgress: (progressEvent) => {
        progressDownload = /* ... */;
    },
    headers: headers
};

$: headers.Authorization = `Bearer ${$accessToken}`;

For consistency and clarity, consider using the same approach for both configurations. This simplifies the code and improves maintainability.

Apply this diff to align the configurations:

-const headers = {};

const axiosDownloadConfig = {
    onDownloadProgress: (progressEvent) => {
        progressDownload = progressEvent && progressEvent.currentTarget && progressEvent.currentTarget.response && progressEvent.currentTarget.response.length ? progressEvent.currentTarget.response.length * 100 / (($linkFileSize || 1000) * upDownRatio) : 0;
    },
-    headers: headers
+    headers: { Authorization: `Bearer ${$accessToken}` }
};

-$: headers.Authorization = `Bearer ${$accessToken}`;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between de46053 and 28fd1b4.

📒 Files selected for processing (5)
  • Makefile (4 hunks)
  • src/components/tools/jobs.js (1 hunks)
  • src/components/views/Link.svelte (3 hunks)
  • src/components/views/LinkJob.svelte (5 hunks)
  • src/components/views/LinkJobs.svelte (5 hunks)
🧰 Additional context used
🪛 Biome
src/components/tools/jobs.js

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (7)
src/components/views/LinkJobs.svelte (3)

56-58: Improved job lifecycle visibility

The addition of "création," "fin," and "suppression" columns enhances the job listing by providing a clear timeline of each job's lifecycle. This change aligns well with the PR objectives and improves the user experience.


Line range hint 1-141: Summary: Successful implementation of PR objectives

The changes in this file successfully implement the key features outlined in the PR objectives:

  1. Job Listing API: The implementation of getJobsFilteredData likely handles user-specific job filtering.
  2. Job Deletion API: The UI now includes a delete option for active jobs.
  3. Enhanced Job Information: The addition of creation, completion, and deletion times provides users with a clearer view of job lifecycles.

These changes significantly improve the job management interface, enhancing user experience and control over submitted jobs. The implementation also considers security aspects by limiting information visibility based on user roles.

Overall, the changes align well with the PR objectives and represent a substantial improvement to the application.


70-80: Enhanced job information and improved security

The addition of finishedOnTime and deletionTime fields, along with the conditional rendering of job IDs, improves both the information provided to users and the security of the application. These changes align well with the PR objectives.

However, the implementation of the dateTostr function used for formatting these new fields is missing from the provided code.

Could you please provide the implementation of the dateTostr function? This will ensure consistent date formatting across the application.

Makefile (2)

282-285: LGTM: Consistent use of APP_URL

The change from API_URL to APP_URL in the backend-dev target is consistent with the earlier introduction of the APP_URL variable. This modification:

  1. Ensures consistency throughout the Makefile.
  2. Simplifies the configuration by using a single variable for both the application and API URL.

300-303: LGTM: Consistent use of APP_URL across targets

The change from API_URL to APP_URL in the backend target is approved:

  1. It maintains consistency with the earlier introduction of the APP_URL variable.
  2. The change is identical to the one made in the backend-dev target, ensuring consistency across different targets.
  3. It simplifies the configuration by using a single variable for both the application and API URL.

This consistency across targets will make the Makefile easier to maintain and understand.

src/components/tools/jobs.js (1)

31-34: Ensure j.processedOn Is Defined Before Calculating delay

The calculation of delay assumes that j.processedOn is defined. If it's undefined, the calculation may result in NaN or unexpected values. Ensure that j.processedOn is valid before performing the calculation.

Run the following script to check if any jobs have undefined processedOn:

Replace jobs.json with the JSON file containing the jobs data.

src/components/views/LinkJob.svelte (1)

165-165: Form data parameter tmpfilePersistence added correctly

The tmpfilePersistence parameter is appended to formData, enhancing the upload functionality with the customizable retention period.

Comment on lines +132 to +141
import { getJobsFilteredData} from '../tools/jobs.js';
let jobs = [];
let ready = false;
let headers;

$: headers = {
headers: {
Authorization: `Bearer ${$accessToken}`
}
};
$: if (!ready && $accessToken) {
getJobsFilteredData($accessToken).then(j => {
jobs = j;
ready = true;
});
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize job data fetching

The replacement of getJobsData with getJobsFilteredData and the use of a reactive statement for job data fetching align well with the PR objectives. However, the current implementation might lead to unnecessary API calls if $accessToken changes frequently.

Consider optimizing the data fetching logic:

import { onMount } from 'svelte';

let jobs = [];
let ready = false;

onMount(async () => {
  if ($accessToken) {
    jobs = await getJobsFilteredData($accessToken);
    ready = true;
  }
});

$: if ($accessToken && !ready) {
  getJobsFilteredData($accessToken).then(j => {
    jobs = j;
    ready = true;
  });
}

This approach ensures that the initial data fetch occurs on component mount and subsequent fetches only happen when necessary, reducing the risk of unnecessary API calls.

tmpJobs.push({
rows: j.data.totalRows,
id: j.id,
user: j.data && j.data.user,
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Optional Chaining to Access j.data.user

Utilize optional chaining to safely access j.data.user, which improves code readability.

Apply this diff:

-user: j.data && j.data.user,
+user: j.data?.user,
📝 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
user: j.data && j.data.user,
user: j.data?.user,
🧰 Tools
🪛 Biome

[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

waiting_time: j.processedOn && (j.processedOn - j.timestamp) / 1000,
processing_time: delay,
columns: validColumns.filter(c => j.data && j.data[c]),
processing_rate: j.processedOn && Math.floor((progress / 100) * (j.data.totalRows / delay)),
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Prevent Division by Zero in processing_rate Calculation

There is a potential division by zero when calculating processing_rate if delay is zero. Ensure that delay is greater than zero before performing the division.

Apply this diff to add a safety check:

-processing_rate: j.processedOn && Math.floor((progress / 100) * (j.data.totalRows / delay)),
+processing_rate: j.processedOn && delay > 0 ? Math.floor((progress / 100) * (j.data.totalRows / delay)) : 0,
📝 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
processing_rate: j.processedOn && Math.floor((progress / 100) * (j.data.totalRows / delay)),
processing_rate: j.processedOn && delay > 0 ? Math.floor((progress / 100) * (j.data.totalRows / delay)) : 0,

status: j.status,
waiting_time: j.processedOn && (j.processedOn - j.timestamp) / 1000,
processing_time: delay,
columns: validColumns.filter(c => j.data && j.data[c]),
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify Column Filtering with Optional Chaining

You can simplify the filtering of columns by using optional chaining when accessing j.data[c].

Apply this diff:

-columns: validColumns.filter(c => j.data && j.data[c]),
+columns: validColumns.filter(c => j.data?.[c]),
📝 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
columns: validColumns.filter(c => j.data && j.data[c]),
columns: validColumns.filter(c => j.data?.[c]),
🧰 Tools
🪛 Biome

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


export const getJobData = async (accessToken, linkJob) => {
const jobs = await getJobsData(accessToken);
return jobs.find(j => j.data && j.data.randomKey && j.data.randomKey === linkJob);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use Optional Chaining in Job Search

Simplify the search for the specific job by using optional chaining when accessing j.data.randomKey.

Apply this diff:

-return jobs.find(j => j.data && j.data.randomKey && j.data.randomKey === linkJob);
+return jobs.find(j => j.data?.randomKey === linkJob);
📝 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
return jobs.find(j => j.data && j.data.randomKey && j.data.randomKey === linkJob);
return jobs.find(j => j.data?.randomKey === linkJob);
🧰 Tools
🪛 Biome

[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

} else {
progressJob = 0;
}
} catch(err) {;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unnecessary semicolon after catch keyword

At line 194, there's an unnecessary semicolon after the catch keyword:

} catch(err) {;

This semicolon is extraneous and should be removed to prevent potential syntax issues.

Apply this diff to correct the syntax:

         } catch(err) {;
-            error = formatError(err);
+            error = formatError(err);
         }

if (err.response.data && err.response.data.msg) {
if (/column header mismatch/.test(err.response.data.msg)) {
error += `<br>le nombre de colonnes n'est pas conforme à l'entête CSV`;
errorMessage += `<br>le nombre de colonnes n'est pas conforme à l'entête CSV`;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct spelling in error message for accuracy

In the error message, "l'entête CSV" should be "l'en-tête CSV" to correctly spell "en-tête" in French.

Apply this diff to fix the spelling:

     if (/column header mismatch/.test(err.response.data.msg)) {
-        errorMessage += `<br>le nombre de colonnes n'est pas conforme à l'entête CSV`;
+        errorMessage += `<br>le nombre de colonnes n'est pas conforme à l'en-tête CSV`;
     } else {
📝 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
errorMessage += `<br>le nombre de colonnes n'est pas conforme à l'entête CSV`;
errorMessage += `<br>le nombre de colonnes n'est pas conforme à l'en-tête CSV`;

} else {
error = error + '<br>' + JSON.stringify(err.response.data.msg);
errorMessage = errorerrorMessage + '<br>' + JSON.stringify(err.response.data.msg);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in variable name to prevent reference error

At line 263, there's a typo in the variable name errorerrorMessage. It should be errorMessage.

Apply this diff to correct the variable name:

     } else {
-        errorMessage = errorerrorMessage + '<br>' + JSON.stringify(err.response.data.msg);
+        errorMessage = errorMessage + '<br>' + JSON.stringify(err.response.data.msg);
     }
📝 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
errorMessage = errorerrorMessage + '<br>' + JSON.stringify(err.response.data.msg);
errorMessage = errorMessage + '<br>' + JSON.stringify(err.response.data.msg);

Comment on lines +189 to +191
let res;
if ($linkJob && $linkJob !== 'failed' && !error) {
let res;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove redundant declaration of res to prevent scoping issues

The variable res is declared twice:

  • Line 189: let res;
  • Line 191: let res;

The inner declaration shadows the outer one and is unnecessary. This can lead to confusion and potential bugs.

Apply this diff to remove the redundant declaration:

     let res;
     if ($linkJob && $linkJob !== 'failed' && !error) {
-        let res;
         try {
             res = await axios.get(`__BACKEND_PROXY_PATH__/search/csv/${$linkJob}`, axiosDownloadConfig);
📝 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
let res;
if ($linkJob && $linkJob !== 'failed' && !error) {
let res;
let res;
if ($linkJob && $linkJob !== 'failed' && !error) {
try {

} else if (err.response.status === 502) {
error += `<br>le serveur est indisponible, veuiller réessayer ultérieurement ou nous contacter à ${mailTo}`
errorMessage += `<br>le serveur est indisponible, veuiller réessayer ultérieurement ou nous contacter à ${mailTo}`
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Correct typo in error message for user clarity

In the error message at line 269, "veuiller réessayer" should be "veuillez réessayer" to use the correct imperative form in French.

Apply this diff to fix the typo:

     } else if (err.response.status === 502) {
-        errorMessage += `<br>le serveur est indisponible, veuiller réessayer ultérieurement ou nous contacter à ${mailTo}`;
+        errorMessage += `<br>le serveur est indisponible, veuillez réessayer ultérieurement ou nous contacter à ${mailTo}`;
     } else if (err.response.status === 500) {
📝 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
errorMessage += `<br>le serveur est indisponible, veuiller réessayer ultérieurement ou nous contacter à ${mailTo}`
errorMessage += `<br>le serveur est indisponible, veuillez réessayer ultérieurement ou nous contacter à ${mailTo}`

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: 0

🧹 Outside diff range and nitpick comments (4)
src/components/views/LinkJob.svelte (4)

149-151: LGTM: Improved download progress calculation

The onDownloadProgress function now includes more robust checks for the presence of response data, enhancing the reliability of progress calculations. This change aligns with the PR's goal of improving user feedback during job processing.

Consider using optional chaining for a more concise syntax:

- progressDownload = progressEvent && progressEvent.currentTarget && progressEvent.currentTarget.response && progressEvent.currentTarget.response.length ? progressEvent.currentTarget.response.length * 100 / (($linkFileSize || 1000) * upDownRatio) : 0;
+ progressDownload = progressEvent?.currentTarget?.response?.length ? progressEvent.currentTarget.response.length * 100 / (($linkFileSize || 1000) * upDownRatio) : 0;

165-165: LGTM: Added configurable retention period

The addition of tmpfilePersistence to the form data aligns with the PR objective of implementing a configurable retention period for jobs. This enhancement provides users with more control over their data.

Consider adding a comment explaining the purpose and expected format of tmpfilePersistence for better code maintainability:

+ // tmpfilePersistence: duration in minutes for which the job data should be retained
formData.append('tmpfilePersistence', $linkOptions.csv.tmpfilePersistence);

189-239: LGTM: Enhanced job monitoring and metadata handling

The watchJob function has been significantly improved:

  1. Better error handling and job status tracking.
  2. Restoration of job metadata from the server, enhancing robustness in case of page reloads or disconnections.

These changes align well with the PR objectives of improving job management and user experience.

Consider extracting the job metadata restoration logic into a separate function for better readability and maintainability:

const restoreJobMetadata = async (jobId) => {
  const job = await getJobData($accessToken, jobId);
  console.log('Restore job metadata from server');
  // ... (rest of the metadata restoration logic)
};

// In watchJob function:
if (!$linkMapping || !$linkFileName || !$linkOptions.csv || !$linkSourceHeader) {
  await restoreJobMetadata($linkJob);
}

Line range hint 244-286: LGTM: Improved error handling and user feedback

The error handling has been significantly enhanced:

  1. More detailed and user-friendly error messages.
  2. Improved logging of errors for easier debugging.
  3. Specific handling for different error scenarios (e.g., column mismatch, server unavailability).

These improvements align with the PR's goal of enhancing user experience and providing better feedback.

Consider using a switch statement or object literal for mapping error statuses to messages for better maintainability:

const errorMessages = {
  default: `erreur inconnue, merci de nous contacter à ${mailTo}`
};

errorMessage += `<br>${errorMessages[err.response.status] || errorMessages.default}`;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 28fd1b4 and 146906a.

📒 Files selected for processing (2)
  • src/components/views/Link.svelte (3 hunks)
  • src/components/views/LinkJob.svelte (5 hunks)
🧰 Additional context used
🔇 Additional comments (2)
src/components/views/LinkJob.svelte (2)

61-64: LGTM: New imports enhance job handling capabilities

The addition of linkFileName and linkSourceHeader to the store imports, along with the new validColumns and getJobData functions from jobs.js, suggests improved handling of job metadata and file information. These changes align well with the PR objectives of enhancing job management.


Line range hint 1-386: Overall assessment: Significant improvements to job management and user experience

This PR introduces several valuable enhancements to the LinkJob component:

  1. Improved job metadata handling and restoration.
  2. Enhanced error handling with more user-friendly messages.
  3. More robust progress tracking for uploads and downloads.
  4. Implementation of configurable job retention periods.

These changes align well with the PR objectives of improving job management and enhancing the user interface. The code quality is good, with only minor suggestions for further improvements.

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: 3

🧹 Outside diff range and nitpick comments (2)
src/components/tools/jobs.js (1)

1-68: Overall assessment: Good implementation with room for improvement

This new file introduces crucial job management functionalities. The implementation is generally good, with well-defined constants and utility functions. However, there are several areas where improvements can be made:

  1. Error handling: Add robust error handling to getJobsData and getJobData functions.
  2. Code simplification: Use optional chaining and modern JavaScript features to simplify complex expressions.
  3. Refactoring: Consider breaking down the getJobsFilteredData function into smaller, more manageable pieces.

Addressing these points will significantly enhance the reliability and maintainability of this module.

🧰 Tools
🪛 Biome

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/components/views/LinkJobs.svelte (1)

70-80: LGTM: Enhanced job details and improved security

The addition of finishedOnTime and deletionTime fields provides more detailed job information, aligning with the PR objectives. The conditional rendering of job ID based on user role enhances security.

Consider using the #if block for the entire <td> element to simplify the structure:

<td>
    {#if $admin}
        {job.user}
    {:else if job.link}
        <a href={job.link}>{job.id.substring(0,10) + '...'}</a>
    {:else}
        {job.id.substring(0,10) + '...'}
    {/if}
</td>

This change would make the code slightly more readable and maintainable.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 146906a and ce8c767.

📒 Files selected for processing (2)
  • src/components/tools/jobs.js (1 hunks)
  • src/components/views/LinkJobs.svelte (5 hunks)
🧰 Additional context used
🪛 Biome
src/components/tools/jobs.js

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (8)
src/components/tools/jobs.js (5)

1-14: LGTM: Well-defined constant for valid columns

The validColumns constant provides a centralized list of valid column names for job data. This approach enhances maintainability and ensures consistency across the application.


65-68: LGTM: Well-implemented date formatting utility

The dateTostr function is a well-implemented utility for date formatting. It uses modern JavaScript features like template literals and the padStart method for consistent formatting. Keeping it as a private function is appropriate for its utility nature.


16-25: ⚠️ Potential issue

Add error handling to getJobsData function

The current implementation lacks error handling, which could lead to unhandled exceptions if the network request fails or if the server returns an error status. Consider adding try-catch block to manage these scenarios gracefully.

Apply this diff to add error handling:

 export const getJobsData = async (accessToken) => {
     const headers = {
         headers: {
             Authorization: `Bearer ${accessToken}`
         }
     }
-    let response = await fetch('__BACKEND_PROXY_PATH__/queue/jobs', headers);
-    const list = (await response.json()).jobs || [];
-    return list
+    try {
+        const response = await fetch('__BACKEND_PROXY_PATH__/queue/jobs', headers);
+        if (!response.ok) {
+            throw new Error(`HTTP error! status: ${response.status}`);
+        }
+        const data = await response.json();
+        return data.jobs || [];
+    } catch (error) {
+        console.error('Error fetching jobs data:', error);
+        return [];
+    }
 }

27-57: 🛠️ Refactor suggestion

⚠️ Potential issue

Refactor getJobsFilteredData for improved readability and safety

The function is complex and could benefit from some refactoring. Here are some suggestions:

  1. Prevent division by zero in processing_rate calculation:
-processing_rate: j.processedOn && Math.floor((progress / 100) * (j.data.totalRows / delay)),
+processing_rate: j.processedOn && delay > 0 ? Math.floor((progress / 100) * (j.data.totalRows / delay)) : 0,
  1. Simplify progress calculation using optional chaining:
-progress = j.status && j.status === "completed" ?
-    "100" : j.progress && j.progress.percentage ?
-        Math.round(j.progress.percentage) : 0
+progress = j.status === "completed" ?
+    "100" : Math.round(j.progress?.percentage) || 0
  1. Use optional chaining for j.data.user and column filtering:
-user: j.data && j.data.user,
+user: j.data?.user,

-columns: validColumns.filter(c => j.data && j.data[c]),
+columns: validColumns.filter(c => j.data?.[c]),

These changes will improve code readability and reduce the risk of runtime errors.

🧰 Tools
🪛 Biome

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


60-63: 🛠️ Refactor suggestion

Improve getJobData function with optional chaining and error handling

The function can be improved in two ways:

  1. Use optional chaining for better readability:
-return jobs.find(j => j.data && j.data.randomKey && j.data.randomKey === linkJob);
+return jobs.find(j => j.data?.randomKey === linkJob);
  1. Add error handling for cases where the job is not found:
 export const getJobData = async (accessToken, linkJob) => {
     const jobs = await getJobsData(accessToken);
-    return jobs.find(j => j.data?.randomKey === linkJob);
+    const job = jobs.find(j => j.data?.randomKey === linkJob);
+    if (!job) {
+        throw new Error(`Job with randomKey ${linkJob} not found`);
+    }
+    return job;
 }

These changes will improve code readability and provide better error handling.

🧰 Tools
🪛 Biome

[error] 62-62: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

src/components/views/LinkJobs.svelte (3)

56-58: LGTM: Improved job information display

The addition of "création," "fin," and "suppression" headers enhances the job management interface by providing more detailed information about the job lifecycle. This change aligns well with the PR objectives.


132-132: LGTM: Updated job data retrieval

The import of getJobsFilteredData from '../tools/jobs.js' aligns with the PR objectives to update the job listing API. This change likely improves the job data retrieval process by providing filtered results.


146-149: LGTM: Improved job status labels

The addition of 'cancelled', 'active', and 'waiting' status labels enhances the clarity of job status display. This change aligns well with the PR objectives to improve the job management interface.

Comment on lines +27 to +57
export const getJobsFilteredData = async (accessToken) => {
const list = await getJobsData(accessToken);
const tmpJobs = [];
list.forEach(j => {
const delay = (
(j.finishedOn ? j.finishedOn : Math.floor(Date.now()))
- j.processedOn
) / 1000;
const progress = j.status && j.status === "completed" ?
"100" : j.progress && j.progress.percentage ?
Math.round(j.progress.percentage) : 0
tmpJobs.push({
rows: j.data.totalRows,
id: j.id,
user: j.data && j.data.user,
date: j.timestamp,
status: j.status,
waiting_time: j.processedOn && (j.processedOn - j.timestamp) / 1000,
processing_time: delay,
columns: validColumns.filter(c => j.data && j.data[c]),
processing_rate: j.processedOn && Math.floor((progress / 100) * (j.data.totalRows / delay)),
finishedOnTime: j.finishedOn ? dateTostr(new Date(j.finishedOn)) : 'en cours',
deletionTime: j.status === 'completed' ? dateTostr(new Date(j.finishedOn + (j.data.tmpfilePersistence || 3600000))) : (j.status === 'failed' ? dateTostr(new Date(j.finishedOn)) : 'en cours'),
link: (['active', 'created', 'waiting', 'wait'].includes(j.status) || j.status === 'completed' && j.finishedOn && (Date.now() < new Date(j.finishedOn + (j.data.tmpfilePersistence || 3600000)))) ? `/link?job=${j.data.randomKey}` : undefined,
progress: progress
})});
return tmpJobs.sort((a,b) => (b.date - a.date)).map(j => {
j.date= dateTostr(new Date(j.date));
return j;
});
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider extracting helper functions for clarity

The getJobsFilteredData function is quite long and performs multiple operations. Consider extracting some of the logic into helper functions to improve readability and maintainability. For example:

  1. Create a function to calculate job progress.
  2. Create a function to format dates.
  3. Create a function to calculate processing metrics.

This refactoring will make the main function easier to understand and test.

🧰 Tools
🪛 Biome

[error] 36-36: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 41-41: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +34 to 37
jobs.filter(j => j.status === 'completed').map(j =>j.processing_time).reduce((a,b) => a+b)
)
}
label="Lignes / Seconde"/>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize calculation and handle potential division by zero

While using processing_time is an improvement, consider optimizing the calculation and handling potential division by zero:

const completedJobs = jobs.filter(j => j.status === 'completed');
const totalRows = completedJobs.reduce((sum, j) => sum + j.rows, 0);
const totalProcessingTime = completedJobs.reduce((sum, j) => sum + j.processing_time, 0);

<StatsTile
    number={totalProcessingTime > 0 ? Math.floor(totalRows / totalProcessingTime) : 0}
    label="Lignes / Seconde"/>

This approach reduces redundant calculations and handles the case where total processing time might be zero.

Comment on lines +136 to +141
$: if (!ready && $accessToken) {
getJobsFilteredData($accessToken).then(j => {
jobs = j;
ready = true;
});
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize job data fetching

While the reactive statement ensures job data is fetched when the access token is available, it might lead to unnecessary API calls if $accessToken changes frequently. Consider optimizing the data fetching logic:

import { onMount } from 'svelte';

let jobs = [];
let ready = false;

onMount(async () => {
  if ($accessToken) {
    jobs = await getJobsFilteredData($accessToken);
    ready = true;
  }
});

$: if ($accessToken && !ready) {
  getJobsFilteredData($accessToken).then(j => {
    jobs = j;
    ready = true;
  });
}

This approach ensures that the initial data fetch occurs on component mount and subsequent fetches only happen when necessary, reducing the risk of unnecessary API calls.

@rhanka rhanka merged commit fc45673 into dev Oct 14, 2024
5 checks passed
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