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

Site Editor: Redesign table views #50766

Merged
merged 20 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 10 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
696 changes: 348 additions & 348 deletions package-lock.json
SaxonF marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions packages/edit-site/src/components/filter-bar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* WordPress dependencies
*/
import { useState, useEffect } from '@wordpress/element';
import {
__experimentalHStack as HStack,
SearchControl,
} from '@wordpress/components';

/**
* Internal dependencies
*/

// accepts a type and returns a filter component that handles that type
const MappedComponent = ( { onChange, value, type, ...props } ) => {
switch ( type ) {
case 'search':
return (
<SearchControl
className="edit-site-page-filter-bar__search"
value={ value }
onChange={ onChange }
{ ...props }
/>
);
}
};

// accepts string one.two.three and returns the value of obj.one.two.three
function getDataValue( obj, propPath ) {
SaxonF marked this conversation as resolved.
Show resolved Hide resolved
const [ head, ...rest ] = propPath.split( '.' );

return ! rest.length
? obj[ head ]
: getDataValue( obj[ head ], rest.join( '.' ) );
}

export default function FilterBar( { data, onFilter, properties = [] } ) {
SaxonF marked this conversation as resolved.
Show resolved Hide resolved
// properties is an array of objects that describe the filters
const [ filters, setFilters ] = useState(
properties.reduce( ( accFilters, property ) => {
switch ( property.type ) {
case 'search':
accFilters[ property.key ] = '';
}
return accFilters;
}, {} )
);

// this function is called when a filter is changed
const handleChange = ( key, value ) => {
setFilters( { ...filters, [ key ]: value } );
};

// when the filters change, filter the data and return via onFilter
useEffect( () => {
let newData = [ ...data ];
properties.forEach( ( property ) => {
if ( property.type === 'search' ) {
newData = newData.filter( ( item ) => {
const value = getDataValue( item, property.key );
if ( typeof value !== 'string' ) return false;

return getDataValue( item, property.key )
.toLowerCase()
.includes( filters[ property.key ] );
} );
}
} );
onFilter( newData );
}, [ filters, data, onFilter, properties ] );

return (
<HStack
className="edit-site-page-filter-bar"
spacing={ 3 }
alignment="left"
>
{ properties.map( ( { type, key, ...props } ) => (
<MappedComponent
key={ key }
value={ filters[ key ] }
onChange={ ( value ) => handleChange( key, value ) }
type={ type }
{ ...props }
/>
) ) }
</HStack>
);
}
36 changes: 36 additions & 0 deletions packages/edit-site/src/components/filter-bar/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.edit-site-page-filter-bar {
.components-text-control__input {
// background: $gray-800;
// border: 1px solid $gray-700;
// color: $gray-100;
}
// .components-toggle-group-control {
// border: none;
// background: $gray-100;
// box-shadow: none;
// }
.components-base-control__field {
margin: 0;
// .components-toggle-group-control-option-base {
// color: $gray-700;
// }
}
}

.edit-site-page-filter-bar__search {
flex-grow: 1;
svg {
// fill: $gray-400;
}
input[type="search"].components-search-control__input {
// background: $gray-800;
// color: $gray-100;
height: 40px;
SaxonF marked this conversation as resolved.
Show resolved Hide resolved
// border: none;
// &:focus {
// background: $gray-800;
// border: 1px solid $gray-700;
// box-shadow: none;
// }
SaxonF marked this conversation as resolved.
Show resolved Hide resolved
}
}
115 changes: 60 additions & 55 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
*/
import Sidebar from '../sidebar';
import Editor from '../editor';
import ListPage from '../list';
import ErrorBoundary from '../error-boundary';
import { store as editSiteStore } from '../../store';
import getIsListPage from '../../utils/get-is-list-page';
Expand All @@ -48,6 +47,7 @@ import SavePanel from '../save-panel';
import KeyboardShortcutsRegister from '../keyboard-shortcuts/register';
import KeyboardShortcutsGlobal from '../keyboard-shortcuts/global';
import { useEditModeCommands } from '../../hooks/commands/use-edit-mode-commands';
import PageMain from '../page-main';
import { useIsSiteEditorLoading } from './hooks';

const { useCommands } = unlock( coreCommandsPrivateApis );
Expand Down Expand Up @@ -201,63 +201,68 @@ export default function Layout() {
<SavePanel />

{ showCanvas && (
<div
className={ classnames(
'edit-site-layout__canvas-container',
{
'is-resizing': isResizing,
}
) }
>
{ canvasResizer }
{ !! canvasSize.width && (
<motion.div
whileHover={
isEditorPage && canvasMode === 'view'
? {
scale: 1.005,
transition: {
duration:
disableMotion ||
isResizing
? 0
: 0.5,
ease: 'easeOut',
},
}
: {}
}
initial={ false }
layout="position"
className="edit-site-layout__canvas"
transition={ {
type: 'tween',
duration:
disableMotion || isResizing
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
<>
{ isListPage && <PageMain /> }
{ isEditorPage && (
<div
className={ classnames(
'edit-site-layout__canvas-container',
{
'is-resizing': isResizing,
}
) }
>
<ErrorBoundary>
{ isEditorPage && (
<ResizableFrame
isReady={ ! isEditorLoading }
isFullWidth={ isEditing }
oversizedClassName="edit-site-layout__resizable-frame-oversized"
>
<Editor
isLoading={
isEditorLoading
{ canvasResizer }
{ !! canvasSize.width && (
<motion.div
whileHover={
isEditorPage &&
canvasMode === 'view'
? {
scale: 1.005,
transition: {
duration:
disableMotion ||
isResizing
? 0
: 0.5,
ease: 'easeOut',
},
}
: {}
}
initial={ false }
layout="position"
className="edit-site-layout__canvas"
transition={ {
type: 'tween',
duration:
disableMotion || isResizing
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
>
<ErrorBoundary>
<ResizableFrame
isReady={
! isEditorLoading
}
/>
</ResizableFrame>
) }
{ isListPage && <ListPage /> }
</ErrorBoundary>
</motion.div>
isFullWidth={ isEditing }
oversizedClassName="edit-site-layout__resizable-frame-oversized"
>
<Editor
isLoading={
isEditorLoading
}
/>
</ResizableFrame>
</ErrorBoundary>
</motion.div>
) }
</div>
) }
</div>
</>
) }
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
}
}

.edit-site-layout__main {
flex-grow: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}

.edit-site-layout__canvas-container {
position: relative;
flex-grow: 1;
Expand Down
Loading