Skip to content

Commit

Permalink
Fix dataviews storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Feb 14, 2024
1 parent 99c7e35 commit 74034eb
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions packages/dataviews/src/stories/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ import { useState, useMemo, useCallback } from '@wordpress/element';
/**
* Internal dependencies
*/
import { DataViews, LAYOUT_GRID, LAYOUT_TABLE } from '../index';

import { DataViews } from '../index';
import { DEFAULT_VIEW, actions, data } from './fixtures';

const LAYOUT_GRID = 'grid';
const LAYOUT_TABLE = 'table';

const meta = {
title: 'DataViews (Experimental)/DataViews',
component: DataViews,
};
export default meta;

const defaultConfigPerViewType = {
[ LAYOUT_TABLE ]: {},
[ LAYOUT_TABLE ]: {
primaryField: 'title',
},
[ LAYOUT_GRID ]: {
mediaField: 'image',
primaryField: 'title',
Expand Down Expand Up @@ -100,23 +104,19 @@ export const Default = ( props ) => {
};
}, [ view ] );
const onChangeView = useCallback(
( viewUpdater ) => {
let updatedView =
typeof viewUpdater === 'function'
? viewUpdater( view )
: viewUpdater;
if ( updatedView.type !== view.type ) {
updatedView = {
...updatedView,
( newView ) => {
if ( newView.type !== view.type ) {
newView = {
...newView,
layout: {
...defaultConfigPerViewType[ updatedView.type ],
...defaultConfigPerViewType[ newView.type ],
},
};
}

setView( updatedView );
setView( newView );
},
[ view, setView ]
[ view.type, setView ]
);
return (
<DataViews
Expand All @@ -131,7 +131,5 @@ export const Default = ( props ) => {
};
Default.args = {
actions,
getItemId: ( item ) => item.id,
isLoading: false,
supportedLayouts: [ LAYOUT_TABLE, LAYOUT_GRID ],
};

0 comments on commit 74034eb

Please sign in to comment.