Skip to content

Commit

Permalink
Bumping minimum revision count until display to two:
Browse files Browse the repository at this point in the history
- same behaviour as post editor
- since revisions includes the current saved post, so we need at least two in order to switch
  • Loading branch information
ramonjd committed Dec 23, 2022
1 parent eb63ba3 commit fcca8f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useEffect,
useMemo,
} from '@wordpress/element';
import { check } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -31,6 +32,9 @@ import { GlobalStylesContext } from './context';
import { decodeEntities } from '@wordpress/html-entities';
import { isGlobalStyleConfigEqual } from './utils';

export const MINIMUM_REVISION_COUNT = 2;
const SELECTOR_MINIMUM_REVISION_COUNT = 10;

function RevisionsSelect( { userRevisions, currentRevisionId, onChange } ) {
const userRevisionsOptions = useMemo( () => {
return ( userRevisions ?? [] ).map( ( revision ) => {
Expand Down Expand Up @@ -73,6 +77,7 @@ function RevisionsButtons( { userRevisions, currentRevisionId, onChange } ) {
) }
variant={ isActive ? 'tertiary' : 'secondary' }
disabled={ isActive }
icon={ isActive ? check : null }
onClick={ () => {
onChange( revision );
} }
Expand Down Expand Up @@ -101,7 +106,7 @@ function ScreenRevisions() {
[]
);
const [ currentRevisionId, setCurrentRevisionId ] = useState();
const hasRevisions = userRevisions.length > 0;
const hasRevisions = userRevisions.length >= MINIMUM_REVISION_COUNT;

useEffect( () => {
if ( ! hasRevisions ) {
Expand Down Expand Up @@ -129,7 +134,9 @@ function ScreenRevisions() {
);

const RevisionsComponent =
userRevisions.length >= 10 ? RevisionsSelect : RevisionsButtons;
userRevisions.length >= SELECTOR_MINIMUM_REVISION_COUNT
? RevisionsSelect
: RevisionsButtons;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { NavigationButtonAsItem } from './navigation-button';
import ContextMenu from './context-menu';
import StylesPreview from './preview';
import { GlobalStylesContext } from './context';
import { MINIMUM_REVISION_COUNT } from './screen-revisions';

function ScreenRoot() {
const { userConfigRevisionsCount: revisionsCount } =
Expand Down Expand Up @@ -135,7 +136,7 @@ function ScreenRoot() {
</>
) }

{ revisionsCount > 0 ? (
{ revisionsCount >= MINIMUM_REVISION_COUNT ? (
<>
<CardDivider />
<CardBody>
Expand Down

1 comment on commit fcca8f6

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3763704940
📝 Reported issues:

Please sign in to comment.