-
Notifications
You must be signed in to change notification settings - Fork 385
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
Use React-based component for Stylesheets box on Validated URL screen #6442
Open
delawski
wants to merge
58
commits into
develop
Choose a base branch
from
add/6441-react-stylesheets-meta-box
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
7c15cc9
Add `validated-urls` endpoint returning stylesheets data
delawski 73568d9
Introduce `ValidatedUrlData` that is returned by the `ValidatedUrlDat…
delawski 8aba364
Add Validated URL JavaScript entry point
delawski e43d296
Use local variable for storing current post
delawski 22aae9e
Remove dead code
delawski 8824f83
Fix and update unit tests
delawski 56ef32f
Calculate stylesheets sizes and add to app context
delawski e71fbf1
Add `StylesheetsSummary` component
delawski bd11a06
Add locale-aware number formatting helper
delawski 79a4ac7
Introduce `FormattedMemoryValue` with tests
delawski bf35648
Add CSS budget-related values to stylesheets summary table
delawski 74c8732
Move icons to parent `components` directory
delawski 7fac19b
Introduce validation status icon component
delawski a9e3c39
Add status icons to stylesheets summary table
delawski cd81f7b
Add warning and error notices related to CSS usage
delawski bf49de9
Use flags instead of string prop
delawski b6ed867
Use flags for stylesheets budget status designators
delawski 8f81c07
Use more accurate naming convention
delawski e7ba442
Fix minor calculation bugs and update copy
delawski 3503fad
Add missing/stale stylesheets errors
delawski cd96844
Add notice when CSS processing is limited
delawski 3693b47
Fix `propTypes` definition
delawski 6652eb7
Calculate stylesheets stats in separate side effect
delawski 7bab544
Add stylesheet details table (WIP)
delawski 546018b
Update unit test
delawski 8db7369
Add CSS code diff component to stylesheet details view
delawski 2fbca5d
Add missing dependency to `useMemo`
delawski 62fd84c
Let child component test `origin` prop instead of parent
delawski 723d95d
Migrate `AMP_Validation_Error_Taxonomy::summarize_sources` method to JS
delawski ede4e2e
Add `SourceLabel` component
delawski 24ec238
Bake in business logic into `summarizeSources` function
delawski 21d2c7a
Add sources summary column content
delawski 08e6310
Expose validated environment data in REST API and use it in Sources
delawski 1136aad
Use validated URL context directly in child component
delawski fe3e041
Use better name for validated URL context provider
delawski eec19a6
Move stylesheets stats logic to more suitable place ie. context provider
delawski 9443d23
Use constants instead of flags for source types
delawski 30a6306
Add detailed sources stack to Stylesheets meta box table
delawski cf9866c
Memoize summarized sources
delawski b9614c9
Add loading state to shaken CSS tokens diff
delawski e1165f6
Add some spacing to shaken tokens diff toggle
delawski 18ffb6b
Add Validated URL data preloading via `RESTPreloader`
delawski 937fa02
Add missing import
delawski 4ba9b42
Move `validated-url` endpoint to separate controller and add schema
delawski e8087f5
Remove server-side rendered Stylesheets meta box
delawski 78724d5
Fix phpcs issues
delawski 658fd5a
Clean up styles for Stylesheets meta box
delawski 6cd5968
Fix php unit test
delawski 477831d
Add plugins context and convert slug into plugin name
delawski cb7d331
Add themes context and convert slug into theme name
delawski 05361ad
Skip including Gutenberg in summary if there is another plugin
delawski a6708ff
Ensure property is set
delawski 612560c
Ensure sources prop has default value
delawski 0403e29
Use default labels for unrecognized themes and plugins
delawski 9d0ec88
Increase test coverage
delawski d7581b5
Replace deprecated `assertStringContains` with `assertStringContainsS…
delawski b9de4d5
Apply suggestions from code review
delawski 26525f8
Add missing service
delawski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __, _x } from '@wordpress/i18n'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { numberFormat } from '../../utils/number-format'; | ||
|
||
function getMemoryUnit( unit ) { | ||
if ( ! unit || typeof unit !== 'string' ) { | ||
return null; | ||
} | ||
|
||
switch ( unit.toLowerCase() ) { | ||
case 'b': | ||
return { | ||
name: __( 'bytes', 'amp' ), | ||
abbreviation: _x( 'B', 'abbreviation for bytes', 'amp' ), | ||
}; | ||
case 'kb': | ||
return { | ||
name: __( 'kilobytes', 'amp' ), | ||
abbreviation: _x( 'kB', 'abbreviation for kilobytes', 'amp' ), | ||
}; | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
export default function FormattedMemoryValue( { value, unit } ) { | ||
const memoryUnit = getMemoryUnit( unit ); | ||
|
||
return ( | ||
<> | ||
{ numberFormat( value ) } | ||
{ memoryUnit && ( | ||
<> | ||
{ ' ' } | ||
<abbr title={ memoryUnit.name }> | ||
{ memoryUnit.abbreviation } | ||
</abbr> | ||
</> | ||
) } | ||
{ ! memoryUnit && unit && ` ${ unit }` } | ||
</> | ||
); | ||
} | ||
FormattedMemoryValue.propTypes = { | ||
value: PropTypes.oneOfType( [ PropTypes.number, PropTypes.string ] ).isRequired, | ||
unit: PropTypes.string, | ||
}; |
95 changes: 95 additions & 0 deletions
95
assets/src/components/formatted-memory-value/test/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { render } from '@wordpress/element'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import FormattedMemoryValue from '..'; | ||
|
||
let container; | ||
|
||
describe( 'FormattedMemoryValue', () => { | ||
beforeEach( () => { | ||
container = document.createElement( 'div' ); | ||
document.body.appendChild( container ); | ||
} ); | ||
|
||
afterEach( () => { | ||
document.body.removeChild( container ); | ||
container = null; | ||
} ); | ||
|
||
it( 'prints bare value if no unit is provided', () => { | ||
act( () => { | ||
render( | ||
<FormattedMemoryValue value={ 123 } />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.textContent ).toBe( '123' ); | ||
} ); | ||
|
||
it( 'prints correct output if value is a string', () => { | ||
act( () => { | ||
render( | ||
<FormattedMemoryValue value="234" />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.textContent ).toBe( '234' ); | ||
} ); | ||
|
||
it( 'prints correct output for unknown units', () => { | ||
act( () => { | ||
render( | ||
<FormattedMemoryValue value="234" unit="FooBar" />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.textContent ).toBe( '234 FooBar' ); | ||
} ); | ||
|
||
it( 'prints correct value and unit', () => { | ||
act( () => { | ||
render( | ||
<FormattedMemoryValue value="345" unit="B" />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.textContent ).toBe( '345 B' ); | ||
expect( container.querySelector( 'abbr' ) ).not.toBeNull(); | ||
expect( container.querySelector( 'abbr' ).title ).toBe( 'bytes' ); | ||
} ); | ||
|
||
it.each( [ | ||
[ 'bytes', 'B', 'B' ], | ||
[ 'bytes', 'b', 'B' ], | ||
[ 'kilobytes', 'kB', 'kB' ], | ||
[ 'kilobytes', 'kb', 'kB' ], | ||
[ 'kilobytes', 'KB', 'kB' ], | ||
] )( | ||
'prints correct %s value and unit for the following input unit: %s', | ||
( fullName, inputUnit, abbreviation ) => { | ||
act( () => { | ||
render( | ||
<FormattedMemoryValue value="100" unit={ inputUnit } />, | ||
container, | ||
); | ||
} ); | ||
|
||
expect( container.querySelector( 'abbr' ).title ).toBe( fullName ); | ||
expect( container.querySelector( 'abbr' ).textContent ).toBe( abbreviation ); | ||
}, | ||
); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing the second service that was added:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I've added it back in 26525f8.