Available In Column Does Not Behave As Expected

by ADMIN 50 views

Introduction

As a Strapi user, you may have encountered issues with the "Available In" column in the list view. This column is meant to display the locales in which a content entry is available, but it often breaks and decreases the usability of the table. In this article, we will explore the issues with the "Available In" column and provide a solution to fix these problems.

Problem Description

The "Available In" column styling breaks when there are more than a few locales. This causes two main issues:

  • The table becomes too wide and readability is difficult.
  • The dropdown positioning breaks when clicking on the available in column after scrolling right.

Additionally, when a locale is clicked, a dropdown appears, but when an option is clicked, it does not take you to that locale version of the entry. Instead, it always takes you to the en locale.

Steps to Reproduce

To reproduce this issue, follow these steps:

  1. Create a localised content entry with a lot of locales.
  2. Look at the list view.

Expected Behavior

Ideally, the "Available In" column should be truncated after 3 locales. When the available in column value is clicked, the opened dropdown should allow you to click on an element and take you to that locale version.

Logs

# No logs available

Code Snippets

No code snippets are available for this issue.

Media

The following images demonstrate the issue:

  • Giant list that scrolls on for a while Image
  • Dropdown position can vary after scroll, but it is often on the left or top edge Image

Similar Issue

There has been a similar issue filed in the past, but it seems it was just marked as done and lost: https://github.com/strapi/strapi/issues/20520. Resurfacing again as the current behaviour still seems broken.

Confirmation Checklist

Before submitting this issue, please make sure to:

  • [x] I have checked the existing issues for duplicates.
  • [x] I agree to follow this project's Code of Conduct.

Solution

To fix this issue, we need to modify the "Available In" column to truncate the locales after 3 and make the dropdown positioning work correctly. We also need to make sure that clicking on a locale in the dropdown takes you to that locale version.

Here is a possible solution:

  • Modify the "Available In" column to truncate the locales after 3 using CSS.
  • Use JavaScript to make the dropdown positioning work correctly.
  • Modify the dropdown to take you to the correct locale version when an option is clicked.

Code

// Modify the "Available In" column to truncate the locales after 3
const availableInColumn = document.querySelector('.available-in-column');
availableInColumn.style.width = '200px'; // Set the width of the column
availableInColumn.style.overflow = 'hidden'; // Hide the overflow
availableInColumn.style.textOverflow = 'ellipsis'; // Add an ellipsis to the end of the text

// Use JavaScript to make the dropdown positioning work correctly
const dropdown = document.querySelector('.dropdown');
dropdown.addEventListener('click', () => {
    // Get the position of the dropdown
    const dropdownPosition = dropdown.getBoundingClientRect();
    // Get the position of the available in column
    const availableInColumnPosition = availableInColumn.getBoundingClientRect();
    // Calculate the position of the dropdown relative to the available in column
    const relativePosition = {
        top: dropdownPosition.top - availableInColumnPosition.top,
        left: dropdownPosition.left - availableInColumnPosition.left,
    };
    // Set the position of the dropdown
    dropdown.style.top = `${relativePosition.top}px`;
    dropdown.style.left = `${relativePosition.left}px`;
});

// Modify the dropdown to take you to the correct locale version when an option is clicked
const dropdownOptions = document.querySelectorAll('.dropdown-option');
dropdownOptions.forEach((option) => {
    option.addEventListener('click', () => {
        // Get the locale of the option
        const locale = option.dataset.locale;
        // Take the user to the correct locale version
        window.location.href = `/locale/${locale}`;
    });
});

Conclusion

Q: What is the issue with the "Available In" column in Strapi's list view?

A: The "Available In" column in Strapi's list view has several issues that make it difficult to use. The column becomes too wide and readability is difficult, and the dropdown positioning breaks when clicking on the available in column after scrolling right. Additionally, when a locale is clicked, a dropdown appears, but when an option is clicked, it does not take you to that locale version of the entry.

Q: Why does the table become too wide and readability is difficult?

A: The table becomes too wide and readability is difficult because the "Available In" column is not truncated after 3 locales. This causes the column to expand and make the table too wide, making it difficult to read.

Q: Why does the dropdown positioning break when clicking on the available in column after scrolling right?

A: The dropdown positioning breaks when clicking on the available in column after scrolling right because the dropdown is not positioned correctly relative to the available in column. This causes the dropdown to appear in the wrong position, making it difficult to use.

Q: Why does clicking on a locale in the dropdown not take you to that locale version of the entry?

A: Clicking on a locale in the dropdown does not take you to that locale version of the entry because the dropdown is not configured correctly to take the user to the correct locale version.

Q: How can I fix these issues?

A: To fix these issues, you need to modify the "Available In" column to truncate the locales after 3 and make the dropdown positioning work correctly. You also need to make sure that clicking on a locale in the dropdown takes you to that locale version.

Q: What code changes do I need to make to fix these issues?

A: To fix these issues, you need to make the following code changes:

  • Modify the "Available In" column to truncate the locales after 3 using CSS.
  • Use JavaScript to make the dropdown positioning work correctly.
  • Modify the dropdown to take you to the correct locale version when an option is clicked.

Q: Can you provide an example of the code changes I need to make?

A: Yes, here is an example of the code changes you need to make:

// Modify the "Available In" column to truncate the locales after 3
const availableInColumn = document.querySelector('.available-in-column');
availableInColumn.style.width = '200px'; // Set the width of the column
availableInColumn.style.overflow = 'hidden'; // Hide the overflow
availableInColumn.style.textOverflow = 'ellipsis'; // Add an ellipsis to the end of the text

// Use JavaScript to make the dropdown positioning work correctly
const dropdown = document.querySelector('.dropdown');
dropdown.addEventListener('click', () => {
    // Get the position of the dropdown
    const dropdownPosition = dropdown.getBoundingClientRect();
    // Get the position of the available in column
    const availableInColumnPosition = availableInColumn.getBoundingClientRect();
    // Calculate the position of the dropdown relative to the available in column
    const relativePosition = {
        top: dropdownPosition.top - availableInColumnPosition.top,
        left: dropdownPosition.left - availableInColumnPosition.left,
    };
    // Set the position of the dropdown
    dropdown.style.top = `${relativePosition.top}px`;
    dropdown.style.left = `${relativePosition.left}px`;
});

// Modify the dropdown to take you to the correct locale version when an option is clicked
const dropdownOptions = document.querySelectorAll('.dropdown-option');
dropdownOptions.forEach((option) => {
    option.addEventListener('click', () => {
        // Get the locale of the option
        const locale = option.dataset.locale;
        // Take the user to the correct locale version
        window.location.href = `/locale/${locale}`;
    });
});

Q: Are there any other issues with the "Available In" column that I should be aware of?

A: Yes, there are several other issues with the "Available In" column that you should be aware of. These include:

  • The column becomes too wide and readability is difficult.
  • The dropdown positioning breaks when clicking on the available in column after scrolling right.
  • Clicking on a locale in the dropdown does not take you to that locale version of the entry.

Q: How can I prevent these issues from occurring in the future?

A: To prevent these issues from occurring in the future, you should:

  • Modify the "Available In" column to truncate the locales after 3 using CSS.
  • Use JavaScript to make the dropdown positioning work correctly.
  • Modify the dropdown to take you to the correct locale version when an option is clicked.

By making these changes, you can prevent the issues with the "Available In" column from occurring in the future.