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

EDSC-4322: Refactor CustomizableIcons.jsx and fix styling inconsistencies #1842

Merged
merged 14 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ To ensure that you're using the correct version of Node it is recommended that y

nvm use

##### Serverless Framework
##### Running Serverless Framework locally

Earthdata Search utilizes the [Serverless Framework](https://serverless.com/) for managing AWS resources. In order to fully run and manage the application you'll need to install it:

Expand Down
12 changes: 7 additions & 5 deletions static/src/js/components/AccessMethod/AccessMethod.scss
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not related to your PR, but could you tweak the hover states on lines 58 and 101 to be $color__carbon--5, instead of $color__carbon--10? That extra contrast will be good.

Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,19 @@
}

.harmony-select-item {
line-height: 1;
display: flex;
align-items: center;
height: auto;
position: relative;
user-select: none;
}

.harmony-select-item[data-highlighted] {
outline: none;
background-color: $color__carbon--10;
&:hover {
background-color: $color__carbon--10;

.meta-icon__metadata {
background-color: $color__carbon--20;
}
}
}

.harmony-scroll-area-root {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React from 'react'
import PropTypes from 'prop-types'

import { FileGeneric, Filter } from '@edsc/earthdata-react-icons/horizon-design-system/hds/ui'

import {
FaClock,
FaCubes,
FaGlobe,
FaTags
} from 'react-icons/fa'

import EDSCIcon from '../EDSCIcon/EDSCIcon'

import './AvailableCustomizationsIcons.scss'

/**
* Renders icons indicating customization options for access methods.
* @param {boolean} hasSpatialSubsetting
* @param {boolean} hasVariables
* @param {boolean} hasTransforms
* @param {boolean} hasFormats
* @param {boolean} hasTemporalSubsetting
* @param {boolean} hasCombine
*/
export const AvailableCustomizationsTooltipIcons = ({
eudoroolivares2016 marked this conversation as resolved.
Show resolved Hide resolved
hasSpatialSubsetting,
hasVariables,
hasTransforms,
hasFormats,
hasTemporalSubsetting,
hasCombine
}) => (
hasSpatialSubsetting
|| hasVariables
|| hasTransforms
|| hasFormats
|| hasTemporalSubsetting
|| hasCombine
) && (
<>
{
hasSpatialSubsetting && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white globe icon"
icon={FaGlobe}
size="0.675rem"
/>
)
}
{
hasTemporalSubsetting && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white clock icon"
icon={FaClock}
size="0.675rem"
/>
)
}
{
hasVariables && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white tags icon"
icon={FaTags}
size="0.675rem"
/>
)
}
{
hasTransforms && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white horizontal sliders icon"
icon={Filter}
size="0.675rem"
/>
)
}
{
hasFormats && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white file icon"
icon={FileGeneric}
size="0.675rem"
/>
)
}
{
hasCombine && (
<EDSCIcon
className="available-customization-icons__icon"
title="A white cubes icon"
icon={FaCubes}
size="0.675rem"
/>
)
}
</>
)

AvailableCustomizationsTooltipIcons.defaultProps = {
eudoroolivares2016 marked this conversation as resolved.
Show resolved Hide resolved
hasSpatialSubsetting: false,
hasVariables: false,
hasTransforms: false,
hasFormats: false,
hasTemporalSubsetting: false,
hasCombine: false
}

AvailableCustomizationsTooltipIcons.propTypes = {
eudoroolivares2016 marked this conversation as resolved.
Show resolved Hide resolved
hasSpatialSubsetting: PropTypes.bool,
hasVariables: PropTypes.bool,
hasTransforms: PropTypes.bool,
hasFormats: PropTypes.bool,
hasTemporalSubsetting: PropTypes.bool,
hasCombine: PropTypes.bool
}

export default AvailableCustomizationsTooltipIcons
eudoroolivares2016 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.available-customization-icons {
border-bottom: 1px solid $border-color;

&__icon {
margin-right: 0.25rem;
position: relative;
top: -0.05rem;

&:last-child {
margin-right: 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import React from 'react'
import PropTypes from 'prop-types'

import { FileGeneric, Filter } from '@edsc/earthdata-react-icons/horizon-design-system/hds/ui'

import {
FaClock,
FaCubes,
FaGlobe,
FaTags
} from 'react-icons/fa'

import EDSCIcon from '../EDSCIcon/EDSCIcon'
import './AvailableCustomizationsTooltipIcons.scss'

/**
* Renders tool-tip-icons indicating customization options for access methods.
* @param {boolean} hasSpatialSubsetting
* @param {boolean} hasVariables
* @param {boolean} hasTransforms
* @param {boolean} hasFormats
* @param {boolean} hasTemporalSubsetting
* @param {boolean} hasCombine
*/
export const availableCustomizationsTooltipIcons = ({
hasSpatialSubsetting,
hasVariables,
hasTransforms,
hasFormats,
hasTemporalSubsetting,
hasCombine
}) => (
hasSpatialSubsetting
|| hasVariables
|| hasTransforms
|| hasFormats
|| hasTemporalSubsetting
|| hasCombine
) && (
<>
<div>
Supports customization:
</div>
<ul className="available-customizations-tooltip-icons__tooltip-feature-list">
{
hasSpatialSubsetting && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white globe icon"
size="0.725rem"
icon={FaGlobe}
/>
Spatial subset
</li>
)
}
{
hasTemporalSubsetting && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white clock icon"
size="0.725rem"
icon={FaClock}
/>
Temporal subset
</li>
)
}
{
hasVariables && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white tags icon"
size="0.725rem"
icon={FaTags}
/>
Variable subset
</li>
)
}
{
hasTransforms && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white horizontal sliders icon"
size="0.725rem"
icon={Filter}
/>
Transform
</li>
)
}
{
hasFormats && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white file icon"
size="0.725rem"
icon={FileGeneric}
/>
Reformat
</li>
)
}
{
hasCombine && (
<li>
<EDSCIcon
className="available-customizations-tooltip-icons__tooltip-feature-icon"
title="A white cubes icon"
size="0.725rem"
icon={FaCubes}
/>
Combine
</li>
)
}
</ul>
</>
)

availableCustomizationsTooltipIcons.defaultProps = {
forAccessMethodRadio: false,
hasSpatialSubsetting: false,
hasVariables: false,
hasTransforms: false,
hasFormats: false,
hasTemporalSubsetting: false,
hasCombine: false
}

availableCustomizationsTooltipIcons.propTypes = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried combining these two the issue becomes that these are props to MetaIcon when its used so we'd need to refactor MetaIcon as well and its being used that way in other places as well for non customizable icons

hasSpatialSubsetting: PropTypes.bool,
hasVariables: PropTypes.bool,
hasTransforms: PropTypes.bool,
hasFormats: PropTypes.bool,
hasTemporalSubsetting: PropTypes.bool,
hasCombine: PropTypes.bool,
forAccessMethodRadio: PropTypes.bool
}

export default availableCustomizationsTooltipIcons
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.available-customizations-tooltip-icons {
&__tooltip-feature-list {
width: auto;
margin: 0 auto;
padding: 0;
list-style: none;
text-align: center;
}

&__tooltip-feature-icon {
margin-right: 0.325rem;
color: $color__carbon--30;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { render, screen } from '@testing-library/react'

import CustomizableIcons from '../CustomizableIcons'
import AvailableCustomizationsIcons from '../AvailableCustomizationsIcons'

const setup = (overrideProps) => {
const props = {
Expand All @@ -16,19 +16,14 @@ const setup = (overrideProps) => {
}

return render(
<CustomizableIcons {...props} />
<AvailableCustomizationsIcons {...props} />
)
}

describe('CustomizableIcons component', () => {
describe('AvailableCustomizationsIcons component', () => {
test('on load should contain all of the custom icons for the customizable options', () => {
setup()

// Ensure the when not using the `forAccessMethodRadio` use `metaIconClasses`
const metaIcon = screen.getByText('Customize')
const metaIconWrapper = metaIcon.parentElement
expect(metaIconWrapper.className).toEqual('meta-icon collection-results-item__meta-icon collection-results-item__meta-icon--customizable')

// Ensure that each of the icons rendered
expect(screen.getByTitle('A white globe icon')).toBeInTheDocument()
expect(screen.getByTitle('A white clock icon')).toBeInTheDocument()
Expand All @@ -38,29 +33,13 @@ describe('CustomizableIcons component', () => {
expect(screen.getByTitle('A white cubes icon')).toBeInTheDocument()
})

describe('if the customizableIcon is for the access method radio', () => {
test('the class name should be appended with', () => {
setup({ forAccessMethodRadio: true })

// Ensure the when using the `forAccessMethodRadio` adds the `meta-icon__accessMethod` to classname
const metaIcon = screen.getByText('Customize')
const metaIconWrapper = metaIcon.parentElement
expect(metaIconWrapper.className).toEqual('meta-icon collection-results-item__meta-icon collection-results-item__meta-icon--customizable meta-icon__accessMethod')
})
})

describe('if some of the conditionals are false', () => {
describe('when some of the dat customizations are not supported', () => {
test('those icons do not render', () => {
setup({
hasVariables: false,
hasCombine: false
})

// Ensure the when not using the `forAccessMethodRadio` use `metaIconClasses`
const metaIcon = screen.getByText('Customize')
const metaIconWrapper = metaIcon.parentElement
expect(metaIconWrapper.className).toEqual('meta-icon collection-results-item__meta-icon collection-results-item__meta-icon--customizable')

// Ensure that each of the icons that are supposed to render do
expect(screen.getByTitle('A white globe icon')).toBeInTheDocument()
expect(screen.getByTitle('A white clock icon')).toBeInTheDocument()
Expand Down
Loading
Loading