From 92cd077a861820c9d3a53b85bec2cb7ed44940fe Mon Sep 17 00:00:00 2001
From: Chris Beer <cabeer@stanford.edu>
Date: Thu, 28 Feb 2019 14:59:25 -0800
Subject: [PATCH] Collapse ValidationCanvas into our ManifestoCanvas wrapper

---
 src/components/ValidationCanvas.js         | 35 ----------------------
 src/components/WindowSideBarCanvasPanel.js |  9 +++---
 src/components/index.js                    |  1 -
 src/lib/ManifestoCanvas.js                 | 30 +++++++++++++++++++
 4 files changed, 35 insertions(+), 40 deletions(-)
 delete mode 100644 src/components/ValidationCanvas.js

diff --git a/src/components/ValidationCanvas.js b/src/components/ValidationCanvas.js
deleted file mode 100644
index dc3ed584e..000000000
--- a/src/components/ValidationCanvas.js
+++ /dev/null
@@ -1,35 +0,0 @@
-import ManifestoCanvas from '../lib/ManifestoCanvas';
-
-/**
- */
-export class ValidationCanvas extends ManifestoCanvas {
-  /**
-   * checks whether the canvas has a valid height
-   */
-  get hasValidHeight() {
-    return (
-      typeof this.canvas.getHeight() === 'number'
-      && this.canvas.getHeight() > 0
-    );
-  }
-
-  /**
-   * checks whether the canvas has a valid height
-   */
-  get hasValidWidth() {
-    return (
-      typeof this.canvas.getHeight() === 'number'
-      && this.canvas.getHeight() > 0
-    );
-  }
-
-  /**
-   * checks whether the canvas has valid dimensions
-   */
-  get hasValidDimensions() {
-    return (
-      this.hasValidHeight
-      && this.hasValidWidth
-    );
-  }
-}
diff --git a/src/components/WindowSideBarCanvasPanel.js b/src/components/WindowSideBarCanvasPanel.js
index ed05c9d4a..58ff4ee62 100644
--- a/src/components/WindowSideBarCanvasPanel.js
+++ b/src/components/WindowSideBarCanvasPanel.js
@@ -5,7 +5,7 @@ import Typography from '@material-ui/core/Typography';
 import List from '@material-ui/core/List';
 import ListItem from '@material-ui/core/ListItem';
 import { CanvasThumbnail } from './CanvasThumbnail';
-import { ValidationCanvas } from './ValidationCanvas';
+import ManifestoCanvas from '../lib/ManifestoCanvas';
 import { getIdAndLabelOfCanvases } from '../state/selectors';
 
 /**
@@ -35,8 +35,9 @@ export class WindowSideBarCanvasPanel extends Component {
         <List>
           {
             canvasesIdAndLabel.map((canvas, canvasIndex) => {
-              const validationCanvas = new ValidationCanvas(canvases[canvasIndex]);
-              const isValid = validationCanvas.hasValidDimensions;
+              const { width, height } = config.canvasNavigation;
+              const manifestoCanvas = new ManifestoCanvas(canvases[canvasIndex]);
+              const isValid = manifestoCanvas.hasValidDimensions;
               const onClick = () => { setCanvas(windowId, canvasIndex); }; // eslint-disable-line require-jsdoc, max-len
 
               return (
@@ -47,7 +48,7 @@ export class WindowSideBarCanvasPanel extends Component {
                     <CanvasThumbnail
                       className={classNames(classes.clickable)}
                       isValid={isValid}
-                      imageUrl={validationCanvas.thumbnail(config.canvasNavigation.height)}
+                      imageUrl={manifestoCanvas.thumbnail(config.canvasNavigation.height)}
                       onClick={onClick}
                       style={{
                         cursor: 'pointer',
diff --git a/src/components/index.js b/src/components/index.js
index e624b5872..72c49d7c4 100644
--- a/src/components/index.js
+++ b/src/components/index.js
@@ -10,7 +10,6 @@ export * from './NestedMenu';
 export * from './OpenSeadragonViewer';
 export * from './SanitizedHtml';
 export * from './ThumbnailNavigation';
-export * from './ValidationCanvas';
 export * from './ViewerNavigation';
 export * from './Window';
 export * from './WindowList';
diff --git a/src/lib/ManifestoCanvas.js b/src/lib/ManifestoCanvas.js
index 7952804d2..7f243436b 100644
--- a/src/lib/ManifestoCanvas.js
+++ b/src/lib/ManifestoCanvas.js
@@ -52,4 +52,34 @@ export default class ManifestoCanvas {
 
     return this.canonicalImageUri.replace(/\/full\/.*\/0\//, `/full/${width},/0/`);
   }
+
+  /**
+   * checks whether the canvas has a valid height
+   */
+  get hasValidHeight() {
+    return (
+      typeof this.canvas.getHeight() === 'number'
+      && this.canvas.getHeight() > 0
+    );
+  }
+
+  /**
+   * checks whether the canvas has a valid height
+   */
+  get hasValidWidth() {
+    return (
+      typeof this.canvas.getHeight() === 'number'
+      && this.canvas.getHeight() > 0
+    );
+  }
+
+  /**
+   * checks whether the canvas has valid dimensions
+   */
+  get hasValidDimensions() {
+    return (
+      this.hasValidHeight
+      && this.hasValidWidth
+    );
+  }
 }
-- 
GitLab