Skip to content

LastUpdated cell does not support hover or banded row styling #188

Closed
campb303 opened this issue Feb 9, 2021 · 1 comment · Fixed by #225
Closed

LastUpdated cell does not support hover or banded row styling #188

campb303 opened this issue Feb 9, 2021 · 1 comment · Fixed by #225
Assignees
Labels
bug An issue that results in webqueue2 breaking

Comments

@campb303
Copy link
Collaborator

campb303 commented Feb 9, 2021

The LastUpdatedCell component does not work with the rest of the table to support banded rows or hover effects. This is likely due to the background color being set to white by default. Instead, this may need to be set to inherit by default with the :hover psuedo class also being inherited.

Screen Shot 2021-02-09 at 11 18 30 AM
@campb303 campb303 added bug An issue that results in webqueue2 breaking frontend labels Feb 9, 2021
@campb303 campb303 added this to the v2-production-ready-read-only milestone Feb 9, 2021
@campb303 campb303 removed the frontend label Mar 17, 2021
@campb303 campb303 removed this from the production-ready-read-only milestone Jul 6, 2021
@wrigh393
Copy link
Collaborator

To address this issue I made two changes to how this styling works.

LastUpdatedCell styling

Addressing the non-colored cells just required changing the default value of backgroundColor to inherit. Here is a code diff for reference

Code

 const timeToBackgroundColor = (time) => {
        const lastUpdated = new Date(time).getTime();
        const now = new Date().getTime();
        const timeDelta = now - lastUpdated;

        const day = 24 * 60 * 60 * 1000;
        const week = day * 7;
        const month = week * 4;

+       let backgroundColor = "inherit";
-        let backgroundColor = theme.palette.paper;
        // 1-6 days old
        if (timeDelta > day && timeDelta <= week) {
            backgroundColor = red[100];
        }
        // 7-28 days old
        else if (timeDelta > week && timeDelta <= month) {
            backgroundColor = red[300];
        }
        // 29+ days old
        else if (timeDelta > month) {
            backgroundColor = red[500];
        }

        return backgroundColor;
    }

Hover styling

Next in the ItemTable where the hover styles are defined, I added the child combinator (>) to the CSS that is applied when the rows are hovered over. What this does is select the elements that are direct descendants of the parent element. In our case, the parent element is the row containing the cells so this will apply the hover styles to all children of a row, which would be all the cells. Below is a code diff and a screenshot of the UI.

Code

    hoverBackgroundColor: {
+            "&:hover > *": {
-            "&:hover ": {
                // The !important is placed here to enforce CSS specificity.
                // See: https://material-ui.com/styles/advanced/#css-injection-order
                backgroundColor: `${theme.palette.primary[200]} !important`,
            },
        },

UI

image

@wrigh393 wrigh393 linked a pull request Jul 16, 2021 that will close this issue
Sign in to join this conversation on GitHub.
Labels
bug An issue that results in webqueue2 breaking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants