-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/ProjectMirador/research-a…
…nd-demos into history
- Loading branch information
Showing
13 changed files
with
246 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
minimal_redux_poc/__tests__/integration/mirador/window_actions.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
describe('Window actions', () => { | ||
beforeAll(async () => { | ||
await page.goto('http://127.0.0.1:4488/__tests__/integration/mirador/'); | ||
}); | ||
it('opens a window and closes it', async () => { | ||
await expect(page).toFill('#manifestURL', 'https://purl.stanford.edu/sn904cj3429/iiif/manifest'); | ||
await expect(page).toClick('#fetchBtn'); | ||
// TODO: Refactor the app so we get rid of the wait | ||
await page.waitFor(1000); | ||
await expect(page).toClick('li button'); | ||
await expect(page).toMatchElement('.mirador-window'); | ||
await expect(page).toClick('.mirador-window-close'); | ||
await expect(page).not.toMatchElement('.mirador-window'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import fetch from 'node-fetch'; | ||
import OpenSeaDragon from 'openseadragon'; | ||
import ns from '../config/css-ns'; | ||
import WindowTopBar from './WindowTopBar'; | ||
|
||
/** | ||
* Represents a Window in the mirador workspace | ||
* @param {object} window | ||
*/ | ||
class Window extends Component { | ||
/** | ||
* @param {Object} props [description] | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
|
||
this.miradorInstanceRef = React.createRef(); | ||
} | ||
/** | ||
* React lifecycle event | ||
*/ | ||
componentDidMount() { | ||
if (!this.miradorInstanceRef.current) { | ||
return false; | ||
} | ||
const viewer = OpenSeaDragon({ | ||
id: this.miradorInstanceRef.current.id, | ||
showNavigationControl: false, | ||
}); | ||
const that = this; | ||
fetch(`${this.props.manifest.manifestation.getSequences()[0].getCanvases()[0].getImages()[0].getResource().getServices()[0].id}/info.json`) | ||
.then(response => response.json()) | ||
.then((json) => { | ||
viewer.addTiledImage({ | ||
tileSource: json, | ||
success: (event) => { | ||
const tiledImage = event.item; | ||
|
||
/** | ||
* A callback for the tile after its drawn | ||
* @param {[type]} e event object | ||
*/ | ||
const tileDrawnHandler = (e) => { | ||
if (e.tiledImage === tiledImage) { | ||
viewer.removeHandler('tile-drawn', tileDrawnHandler); | ||
that.miradorInstanceRef.current.style.display = 'block'; | ||
} | ||
}; | ||
viewer.addHandler('tile-drawn', tileDrawnHandler); | ||
}, | ||
}); | ||
}) | ||
.catch(error => console.log(error)); | ||
return false; | ||
} | ||
|
||
/** | ||
* Fetches IIIF thumbnail URL | ||
*/ | ||
thumbnail() { | ||
const thumb = this.props.manifest.manifestation.getThumbnail() || { id: 'http://placekitten.com/200/300' }; | ||
return thumb.id; | ||
} | ||
|
||
/** | ||
* Return style attributes | ||
*/ | ||
styleAttributes() { | ||
return { width: `${this.props.window.xywh[2]}px`, height: `${this.props.window.xywh[3]}px` }; | ||
} | ||
|
||
/** | ||
* Renders things | ||
* @param {object} props (from react/redux) | ||
*/ | ||
render() { | ||
return ( | ||
<div className={ns('window')} style={this.styleAttributes()}> | ||
<WindowTopBar | ||
windowId={this.props.window.id} | ||
manifest={this.props.manifest} | ||
/> | ||
<img src={this.thumbnail()} alt="" /> | ||
<div | ||
className={ns('osd-container')} | ||
style={{ display: 'none' }} | ||
id={`${this.props.window.id}-osd`} | ||
ref={this.miradorInstanceRef} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Window.propTypes = { | ||
window: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types | ||
manifest: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
}; | ||
|
||
Window.defaultProps = { | ||
manifest: null, | ||
}; | ||
|
||
/** | ||
* mapStateToProps - used to hook up connect to action creators | ||
* @memberof Window | ||
* @private | ||
*/ | ||
const mapStateToProps = ({ windows, manifests }, props) => { | ||
const window = windows.find(win => props.id === win.id); | ||
return { | ||
window, | ||
manifest: manifests[window.manifestId], | ||
}; | ||
}; | ||
|
||
export default connect(mapStateToProps)(Window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { actions } from 'mirador3-core'; | ||
import { ns } from '../config/css-ns'; | ||
|
||
|
||
/** | ||
* WindowTopBar | ||
*/ | ||
class WindowTopBarComponent extends React.Component { | ||
/** | ||
* render - description | ||
* @return {type} description | ||
*/ | ||
render() { | ||
return ( | ||
<div className={ns('window-top-bar')}> | ||
<h3>{this.props.manifest.manifestation.getLabel().map(label => label.value)[0]}</h3> | ||
<button | ||
type="button" | ||
className={ns('window-close')} | ||
aria-label="Close Window" | ||
onClick={() => this.props.removeWindow(this.props.windowId)} | ||
> | ||
× | ||
</button> | ||
</div> | ||
); | ||
} | ||
} | ||
// | ||
// /** | ||
// * mapStateToProps - used to hook up connect to action creators | ||
// * @memberof Window | ||
// * @private | ||
// */ | ||
// const mapStateToProps = ({ windows, manifests }, props) => { | ||
// const window = windows.find(win => props.windowId === win.id); | ||
// return { | ||
// window, | ||
// // | ||
// manifest: manifests[window.manifestId], | ||
// }; | ||
// }; | ||
|
||
/** | ||
* mapDispatchToProps - used to hook up connect to action creators | ||
* @memberof ManifestListItem | ||
* @private | ||
*/ | ||
const mapDispatchToProps = dispatch => ({ | ||
removeWindow: windowId => ( | ||
dispatch(actions.removeWindow(windowId)) | ||
), | ||
}); | ||
|
||
WindowTopBarComponent.propTypes = { | ||
manifest: PropTypes.object, // eslint-disable-line react/forbid-prop-types | ||
removeWindow: PropTypes.func.isRequired, | ||
windowId: PropTypes.string.isRequired, | ||
}; | ||
|
||
WindowTopBarComponent.defaultProps = { | ||
manifest: null, | ||
}; | ||
|
||
|
||
export const WindowTopBar = connect(null, mapDispatchToProps)(WindowTopBarComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/mirador3-common/src/components/test/WindowTopBar.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { actions, store } from 'mirador3-core'; | ||
import { WindowTopBar } from '../WindowTopBar'; | ||
import fixture from './fixtures/24.json'; | ||
|
||
describe('Window', () => { | ||
let wrapper; | ||
let window; | ||
beforeEach(() => { | ||
store.dispatch(actions.receiveManifest('foo', fixture)); | ||
store.dispatch(actions.addWindow({ manifestId: 'foo' })); | ||
const manifest = store.getState().manifests.foo; | ||
[window] = store.getState().windows; | ||
wrapper = shallow(<WindowTopBar store={store} manifest={manifest} windowId={window.id} />) | ||
.dive(); | ||
}); | ||
|
||
it('renders without an error', () => { | ||
expect(wrapper.find('div.mirador-window-top-bar h3').text()).toBe('Test 24 Manifest: Image with IIIF Service - adapted with real image'); | ||
expect(wrapper.find('button.mirador-window-close')); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters