Skip to content

Commit

Permalink
DataViews: fix storybook (#58842)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Feb 14, 2024
1 parent 61aa8f5 commit abdde7a
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions packages/dataviews/src/stories/index.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ 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';
import { LAYOUT_GRID, LAYOUT_TABLE } from '../constants';

const meta = {
title: 'DataViews (Experimental)/DataViews',
Expand All @@ -17,7 +17,9 @@ const meta = {
export default meta;

const defaultConfigPerViewType = {
[ LAYOUT_TABLE ]: {},
[ LAYOUT_TABLE ]: {
primaryField: 'title',
},
[ LAYOUT_GRID ]: {
mediaField: 'image',
primaryField: 'title',
Expand Down Expand Up @@ -100,23 +102,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 +129,5 @@ export const Default = ( props ) => {
};
Default.args = {
actions,
getItemId: ( item ) => item.id,
isLoading: false,
supportedLayouts: [ LAYOUT_TABLE, LAYOUT_GRID ],
};

1 comment on commit abdde7a

@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 in abdde7a.
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/7901253435
📝 Reported issues:

Please sign in to comment.