Interactive interface for browsing global, full-resolution satellite imagery
WV-4036 Modernize GifPanelGrid, GifPanel, ResolutionTable, and VectorMetaTabl… (#6871)
vicgonzalez255337f62b0594
diff --git a/web/js/components/animation-widget/gif-panel-grid.js b/web/js/components/animation-widget/gif-panel-grid.jsindex bb1a7fd97..c247b9919 100644--- a/web/js/components/animation-widget/gif-panel-grid.js+++ b/web/js/components/animation-widget/gif-panel-grid.js@@ -1,4 +1,3 @@-import React from 'react';import PropTypes from 'prop-types';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';import MonospaceDate from '../util/monospace-date';@@ -7,22 +6,21 @@ import MonospaceDate from '../util/monospace-date';* A table that updates with image* data*- * @class ResolutionTable- * @extends React.Component+ * @function GifPanelGrid*/-export default class GifPanelGrid extends React.Component {- renderImageSize() {- const { valid, maxGifSize, requestSize } = this.props;- const roundedSize = requestSize.toFixed(2);- if (!valid) {- return (- <div id="gif-size" className="gif-size gif-size-invalid grid-child">- <FontAwesomeIcon icon="times" fixedWidth widthAuto />- <span>{`${maxGifSize} MB ~${roundedSize} MB`}</span>- </div>- );- }- return (+export default function GifPanelGrid({+ startDate, endDate, speed, increment, valid, height,+ width, maxImageDimensionSize, maxGifSize, requestSize,+}) {+ const roundedSize = requestSize.toFixed(2);+ const imageSize = !valid+ ? (+ <div id="gif-size" className="gif-size gif-size-invalid grid-child">+ <FontAwesomeIcon icon="times" fixedWidth widthAuto />+ <span>{`${maxGifSize} MB ~${roundedSize} MB`}</span>+ </div>+ )+ : (<div id="gif-size" className="gif-size grid-child"><span>{`${maxGifSize} MB / ~${roundedSize} MB`}@@ -30,65 +28,58 @@ export default class GifPanelGrid extends React.Component {</span></div>);- }- render() {- const {- startDate, endDate, speed, increment, valid, height, width, maxImageDimensionSize,- } = this.props;- const imageSize = this.renderImageSize();- return (- <div className="gif-download-grid">- <div className="grid-child label">- <span>Start Date: </span>- </div>- <div className="grid-child">- <MonospaceDate date={startDate} />- {' '}- </div>- <div className="grid-child label">- <span>End Date: </span>- </div>- <div className="grid-child">- <MonospaceDate date={endDate} />- </div>- <div className="grid-child label">- <span>Speed: </span>- </div>- <div className="grid-child">- <span>{`${speed} Frames Per Second`}</span>- </div>- <div className="grid-child label">- <span>Increment:</span>- </div>- <div className="grid-child">- <span>{increment}</span>- </div>- <div className="grid-child label">- <span>Max / Raw Size:</span>- </div>- {imageSize}- <div className="grid-child label">- <span>Max Dimension: </span>- </div>- <div- className={- valid- ? 'grid-child gif-max-size'- : 'grid-child gif-max-size gif-size-invalid'- }- >- <span>{`${maxImageDimensionSize}px`}</span>- </div>- <div className="grid-child label">- <span>Image Dimensions:</span>- </div>- <div className="grid-child" id="wv-image-width">- <span>{`${width}px x ${height}px`}</span>- </div>+ return (+ <div className="gif-download-grid">+ <div className="grid-child label">+ <span>Start Date: </span></div>- );- }+ <div className="grid-child">+ <MonospaceDate date={startDate} />+ {' '}+ </div>+ <div className="grid-child label">+ <span>End Date: </span>+ </div>+ <div className="grid-child">+ <MonospaceDate date={endDate} />+ </div>+ <div className="grid-child label">+ <span>Speed: </span>+ </div>+ <div className="grid-child">+ <span>{`${speed} Frames Per Second`}</span>+ </div>+ <div className="grid-child label">+ <span>Increment:</span>+ </div>+ <div className="grid-child">+ <span>{increment}</span>+ </div>+ <div className="grid-child label">+ <span>Max / Raw Size:</span>+ </div>+ {imageSize}+ <div className="grid-child label">+ <span>Max Dimension: </span>+ </div>+ <div+ className={+ valid+ ? 'grid-child gif-max-size'+ : 'grid-child gif-max-size gif-size-invalid'+ }+ >+ <span>{`${maxImageDimensionSize}px`}</span>+ </div>+ <div className="grid-child label">+ <span>Image Dimensions:</span>+ </div>+ <div className="grid-child" id="wv-image-width">+ <span>{`${width}px x ${height}px`}</span>+ </div>+ </div>+ );}GifPanelGrid.propTypes = {endDate: PropTypes.string,diff --git a/web/js/components/animation-widget/gif-panel.js b/web/js/components/animation-widget/gif-panel.jsindex 790a0a41a..7eb18b77a 100644--- a/web/js/components/animation-widget/gif-panel.js+++ b/web/js/components/animation-widget/gif-panel.js@@ -1,4 +1,4 @@-import React from 'react';+import { useState } from 'react';import PropTypes from 'prop-types';import SelectionList from '../util/selector';import GifPanelGrid from './gif-panel-grid';@@ -23,97 +23,83 @@ const isFileSizeValid = function(requestSize, imgHeight, imgWidth) {* A react component, Builds a rather specific* interactive widget*- * @class resolutionSelection- * @extends React.Component+ * @function GifPanel*/-export default class GifPanel extends React.Component {- constructor(props) {- super(props);- this.state = {- speed: props.speed,- resolutions: props.resolutions,- resolution: props.resolution,- increment: props.increment,- };- this.handleChange = this.handleChange.bind(this);- }+export default function GifPanel({+ projId,+ lonlats,+ startDate,+ endDate,+ onCheck,+ showDates = true,+ numberOfFrames,+ firstLabel = 'Resolution (per pixel):',+ onClick,+ onDownloadClick,+ speed: speedProp,+ resolutions: resolutionsProp,+ resolution: resolutionProp,+ increment: incrementProp,+}) {+ const [speed] = useState(speedProp);+ const [resolutions] = useState(resolutionsProp);+ const [resolution, setResolution] = useState(resolutionProp);+ const [increment] = useState(incrementProp);- handleChange(type, value) {- this.setState({- resolution: value,- });- }+ const handleChange = (type, value) => {+ setResolution(value);+ };- render() {- const {- projId,- lonlats,- startDate,- endDate,- onCheck,- showDates,- numberOfFrames,- firstLabel,- onClick,- onDownloadClick,- } = this.props;- const {- resolution, resolutions, speed, increment,- } = this.state;- const dimensions = getDimensions(projId, lonlats, resolution);- const { height } = dimensions;- const { width } = dimensions;- const requestSize = ((width * height * 24) / 8388608).toFixed(2) * numberOfFrames;- const valid = isFileSizeValid(requestSize, height, width);- return (- <div className="gif-dialog">- <div className="animation-gif-dialog-wrapper">- <div className="gif-selector-case">- {firstLabel}- <SelectionList- id="gif-resolution"- optionArray={resolutions}- value={resolution}- optionName="resolution"- onChange={this.handleChange}- />- </div>- <GifPanelGrid- width={width}- height={height}- requestSize={requestSize}- maxGifSize={MAX_GIF_SIZE}- maxImageDimensionSize={MAX_IMAGE_DIMENSION_SIZE}- valid={valid}- onClick={onDownloadClick}- startDate={startDate}- endDate={endDate}- speed={speed}- increment={increment}- />- <Button- onClick={() => onClick(width, height)}- text="Create GIF"- valid={valid}- />- <Checkbox- id="wv-checkbox-gif"- classNames="wv-checkbox-gif"- title="Check box to remove dates from Animating GIF"- checked={showDates}- onCheck={onCheck}- label="Include Date Stamps"+ const dimensions = getDimensions(projId, lonlats, resolution);+ const { height } = dimensions;+ const { width } = dimensions;+ const requestSize = ((width * height * 24) / 8388608).toFixed(2) * numberOfFrames;+ const valid = isFileSizeValid(requestSize, height, width);++ return (+ <div className="gif-dialog">+ <div className="animation-gif-dialog-wrapper">+ <div className="gif-selector-case">+ {firstLabel}+ <SelectionList+ id="gif-resolution"+ optionArray={resolutions}+ value={resolution}+ optionName="resolution"+ onChange={handleChange}/></div>+ <GifPanelGrid+ width={width}+ height={height}+ requestSize={requestSize}+ maxGifSize={MAX_GIF_SIZE}+ maxImageDimensionSize={MAX_IMAGE_DIMENSION_SIZE}+ valid={valid}+ onClick={onDownloadClick}+ startDate={startDate}+ endDate={endDate}+ speed={speed}+ increment={increment}+ />+ <Button+ onClick={() => onClick(width, height)}+ text="Create GIF"+ valid={valid}+ />+ <Checkbox+ id="wv-checkbox-gif"+ classNames="wv-checkbox-gif"+ title="Check box to remove dates from Animating GIF"+ checked={showDates}+ onCheck={onCheck}+ label="Include Date Stamps"+ /></div>- );- }+ </div>+ );}-GifPanel.defaultProps = {- firstLabel: 'Resolution (per pixel):',- showDates: true,-};GifPanel.propTypes = {endDate: PropTypes.string,firstLabel: PropTypes.string,diff --git a/web/js/components/image-download/grid.js b/web/js/components/image-download/grid.jsindex 2f4a65402..0711b0f8c 100644--- a/web/js/components/image-download/grid.js+++ b/web/js/components/image-download/grid.js@@ -1,4 +1,3 @@-import React from 'react';import PropTypes from 'prop-types';import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';import Button from '../util/button';@@ -7,24 +6,22 @@ import Button from '../util/button';* A table that updates with image* data*- * @class ResolutionTable- * @extends React.Component+ * @function ResolutionTable*/-export default class ResolutionTable extends React.Component {- renderImageSize() {- const { fileSize, validSize } = this.props;- if (!validSize) {- return (- <div- id="wv-image-size"- className="wv-image-size wv-image-size-invalid grid-child"- >- <FontAwesomeIcon icon="times" fixedWidth widthAuto />- <span>{`~${fileSize}MB`}</span>- </div>- );- }- return (+export default function ResolutionTable({+ fileSize, height, maxImageSize, onClick, validLayers, validSize, width, isSnapshotInProgress,+}) {+ const imageSize = !validSize+ ? (+ <div+ id="wv-image-size"+ className="wv-image-size wv-image-size-invalid grid-child"+ >+ <FontAwesomeIcon icon="times" fixedWidth widthAuto />+ <span>{`~${fileSize}MB`}</span>+ </div>+ )+ : (<div id="wv-image-size" className="wv-image-size grid-child"><span>{`~${fileSize} MB`}@@ -32,54 +29,46 @@ export default class ResolutionTable extends React.Component {</span></div>);- }-- render() {- const imageSize = this.renderImageSize();- const {- width, height, maxImageSize, onClick, validLayers, validSize, isSnapshotInProgress,- } = this.props;- const isDownloadDisabled = !validSize || !validLayers || isSnapshotInProgress;- const buttonText = isSnapshotInProgress ? 'Creating...' : 'Download';+ const isDownloadDisabled = !validSize || !validLayers || isSnapshotInProgress;+ const buttonText = isSnapshotInProgress ? 'Creating...' : 'Download';- return (- <div className="wv-image-download-grid">- <div className="grid-child grid-head">- <span>Raw Size</span>- </div>- <div className="grid-child grid-head">- <span>Maximum</span>- </div>- {imageSize}- <div- className={- validSize- ? 'grid-child wv-image-max-size'- : 'grid-child wv-image-max-size wv-image-size-invalid'- }- >- <span>{maxImageSize}</span>- </div>- <div- className="grid-child wv-image-dimensions"- id="wv-image-dimensions"- >- <span>{`${width} x ${height}px`}</span>- </div>- <div className="grid-child wv-image-button">- <Button- text={buttonText}- onClick={() => {- onClick(width, height);- }}- valid={!isDownloadDisabled}- disabled={isDownloadDisabled}- />- </div>+ return (+ <div className="wv-image-download-grid">+ <div className="grid-child grid-head">+ <span>Raw Size</span></div>- );- }+ <div className="grid-child grid-head">+ <span>Maximum</span>+ </div>+ {imageSize}+ <div+ className={+ validSize+ ? 'grid-child wv-image-max-size'+ : 'grid-child wv-image-max-size wv-image-size-invalid'+ }+ >+ <span>{maxImageSize}</span>+ </div>+ <div+ className="grid-child wv-image-dimensions"+ id="wv-image-dimensions"+ >+ <span>{`${width} x ${height}px`}</span>+ </div>+ <div className="grid-child wv-image-button">+ <Button+ text={buttonText}+ onClick={() => {+ onClick(width, height);+ }}+ valid={!isDownloadDisabled}+ disabled={isDownloadDisabled}+ />+ </div>+ </div>+ );}ResolutionTable.propTypes = {fileSize: PropTypes.string,diff --git a/web/js/components/vector-metadata/table.js b/web/js/components/vector-metadata/table.jsindex 70144f52d..038a4fd7e 100644--- a/web/js/components/vector-metadata/table.js+++ b/web/js/components/vector-metadata/table.js@@ -4,87 +4,83 @@ import { Table } from 'reactstrap';import VectorMetaTooltip from './tooltip';import util from '../../util/util';-export default class VectorMetaTable extends React.Component {- shouldComponentUpdate(nextProps) {- const { id, title } = this.props;- if (- id &&- title && nextProps.id && nextProps.title &&- id === nextProps.id && title === nextProps.title) {- return false;- }- return true;- }-- render() {- const { metaArray } = this.props;+function VectorMetaTable({ id, metaArray, title }) {+ return (+ <div>+ {metaArray.map((obj, metaIndex) => {+ const metaFeatures = obj.features;+ const metaLegend = obj.legend;+ const title = obj.featureTitle;+ return (+ <div key={util.encodeId(`${title}_${metaIndex}`)}>+ <Table size="sm">+ <thead>+ <tr>+ <th>{title || `${obj.title} ${metaIndex + 1}`}</th>+ </tr>+ </thead>+ <tbody>+ {metaLegend.map((properties, index) => {+ const {+ Function, ValueMap, DataType, Title, Identifier, Units, Description,+ } = properties;- return (- <div>- {metaArray.map((obj, metaIndex) => {- const metaFeatures = obj.features;- const metaLegend = obj.legend;- const title = obj.featureTitle;- return (- <div key={util.encodeId(`${title}_${metaIndex}`)}>- <Table size="sm">- <thead>- <tr>- <th>{title || `${obj.title} ${metaIndex + 1}`}</th>- </tr>- </thead>- <tbody>- {metaLegend.map((properties, index) => {- const {- Function, ValueMap, DataType, Title, Identifier, Units, Description,- } = properties;+ const isIntegerToStyle = Function !== 'Identify' && (DataType === 'int');+ const metaFeaturesIdentifierValue = metaFeatures[Identifier]+ ? metaFeatures[Identifier]+ : null;+ const metaFeaturesResult = isIntegerToStyle+ ? metaFeatures[Identifier].toLocaleString('en')+ : metaFeaturesIdentifierValue;+ const value = ValueMap+ ? ValueMap[metaFeatures[Identifier]]+ : metaFeaturesResult;+ const id = util.cleanId(String(`${title}-${metaIndex + index}`));- const isIntegerToStyle = Function !== 'Identify' && (DataType === 'int');- const metaFeaturesIdentifierValue = metaFeatures[Identifier]- ? metaFeatures[Identifier]- : null;- const metaFeaturesResult = isIntegerToStyle- ? metaFeatures[Identifier].toLocaleString('en')- : metaFeaturesIdentifierValue;- const value = ValueMap- ? ValueMap[metaFeatures[Identifier]]- : metaFeaturesResult;- const id = util.cleanId(String(`${title}-${metaIndex + index}`));-- if (!value) return undefined;- return (- <tr key={`vector-row-${id}`}>- <td>- {Description- ? (- <VectorMetaTooltip id={id} index={index} description={Description} />- )- : undefined}- <div className="vector-feature-name-cell">{Title || Identifier}</div>- </td>- <td>- <span>{value}</span>- {Units && (- <span>- {' '}- {Units}- </span>- )}- </td>- </tr>- );- })}- </tbody>- </Table>- </div>- );- })}- </div>- );- }+ if (!value) return undefined;+ return (+ <tr key={`vector-row-${id}`}>+ <td>+ {Description+ ? (+ <VectorMetaTooltip id={id} index={index} description={Description} />+ )+ : undefined}+ <div className="vector-feature-name-cell">{Title || Identifier}</div>+ </td>+ <td>+ <span>{value}</span>+ {Units && (+ <span>+ {' '}+ {Units}+ </span>+ )}+ </td>+ </tr>+ );+ })}+ </tbody>+ </Table>+ </div>+ );+ })}+ </div>+ );}+VectorMetaTable.propTypes = {id: PropTypes.number,metaArray: PropTypes.oneOfType([PropTypes.array, PropTypes.oneOf(['null'])]),title: PropTypes.string,};++export default React.memo(VectorMetaTable, (prevProps, nextProps) => {+ if (+ prevProps.id &&+ prevProps.title && nextProps.id && nextProps.title &&+ prevProps.id === nextProps.id && prevProps.title === nextProps.title) {+ return true;+ }+ return false;+});