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

Refactor Code to Use Utility Function for Course Metadata Retrieval #211

Open
nomadbitcoin opened this issue Aug 5, 2024 · 0 comments
Open

Comments

@nomadbitcoin
Copy link
Contributor

Description:

With the recent update to source course metadata from language-specific metadata fields, there are multiple instances in our codebase where this retrieval logic is repeated. This redundancy can lead to maintenance challenges and potential bugs. We need to refactor the code to use a dynamic utility function that centralizes this logic and retrieves all available fields.

Tasks:

  1. Create a Dynamic Utility Function:

    • Develop a utility function that dynamically retrieves all metadata fields from course.metadata based on the specified language.
    • The function should fall back to the root object fields if the metadata fields are not available.
    const getCourseMetadata = (course, language) => {
      const metadata = course?.metadata?.[language] || {};
      const rootFields = course || {};
      
      // Combine metadata and root fields, giving priority to metadata
      return Object.keys(rootFields).reduce((fields, key) => {
        fields[key] = metadata[key] || rootFields[key];
        return fields;
      }, {});
    };
  2. Refactor Existing Code:

    • Identify all instances in the codebase where metadata fields are being fetched from course.metadata.
    • Replace these instances with calls to the new utility function.

    Example refactor:

    const courseMetadata = getCourseMetadata(course, language);
  3. Update Components and Functions:

    • Ensure that all components and functions that rely on these fields use the utility function to fetch the metadata.
  4. Test the Refactor:

    • Test thoroughly to ensure that the utility function works correctly across different parts of the application.
    • Validate that features depending on these metadata fields are functioning correctly.
@nomadbitcoin nomadbitcoin converted this from a draft issue Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant