Skip to content

Commit

Permalink
"see-original" action with Modal window
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmaguitar committed Sep 20, 2024
1 parent c046c58 commit ab230e1
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
import { getTopicsElementsFormat } from './utils';
import { useState, useMemo } from '@wordpress/element';
import { Spinner, withNotices } from '@wordpress/components';
import {
SelectControl,
Button,
__experimentalText as Text,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Spinner,
withNotices,
} from '@wordpress/components';

import { __ } from '@wordpress/i18n';
import apiFetch from '@wordpress/api-fetch';

Expand Down Expand Up @@ -189,9 +198,42 @@ const App = withNotices( ( { noticeOperations, noticeUI } ) => {
{
id: 'see-original',
label: __( 'See Original' ),
callback: ( [ item ] ) => {
const urlImage = item.urls.raw;
window.open( urlImage, '_blank' );
modalHeader: __( 'See Original Image', 'action label' ),
RenderModal: ( { items: [ item ], closeModal } ) => {
const [ size, setSize ] = useState( 'raw' );
return (
<VStack spacing="5">
<Text>
{ `Select the size you want to open for "${ item.slug }"` }
</Text>
<HStack justify="left">
<SelectControl
__nextHasNoMarginBottom
label="Size"
value={ size }
options={ Object.keys( item.urls )
.filter( ( url ) => url !== 'small_s3' )
.map( ( url ) => ( {
label: url,
value: url,
} ) ) }
onChange={ setSize }
/>
</HStack>
<HStack justify="right">
<Button
__next40pxDefaultSize
variant="primary"
onClick={ () => {
closeModal();
window.open( item.urls[ size ], '_blank' );
} }
>
Open image from original location
</Button>
</HStack>
</VStack>
);
},
},
];
Expand Down

0 comments on commit ab230e1

Please sign in to comment.