Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Lazy document to handle viewing PDF's without downloading. #253

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"typescript.validate.enable": false,
"javascript.validate.enable": false
}
6 changes: 3 additions & 3 deletions packages/controlled-vocabulary/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/controlled-vocabulary",
"version": "1.1.3",
"version": "1.1.4",
"description": "A package of components to allow user to configure dropdown elements. Use with the \"controlled_vocabulary\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,8 +12,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^1.1.3",
"@performant-software/shared-components": "^1.1.3",
"@performant-software/semantic-components": "^1.1.4",
"@performant-software/shared-components": "^1.1.4",
"i18next": "^21.9.2",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/geospatial/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/geospatial",
"version": "1.1.3",
"version": "1.1.4",
"description": "TODO: ADD",
"license": "MIT",
"main": "./build/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/semantic-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/semantic-components",
"version": "1.1.3",
"version": "1.1.4",
"description": "A package of shared components based on the Semantic UI Framework.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -12,7 +12,7 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/shared-components": "^1.1.3",
"@performant-software/shared-components": "^1.1.4",
"@react-google-maps/api": "^2.8.1",
"axios": "^0.26.1",
"i18next": "^19.4.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/semantic-ui/src/components/FacetSlider.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'rc-slider/assets/index.css';

.facet-slider > .ui.grid {
margin-top: 0em;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/semantic-ui/src/components/FacetSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, {
import { Grid } from 'semantic-ui-react';
import Facet, { type Props as FacetProps } from './Facet';
import { type RangeSliderProps } from '../types/InstantSearch';
import 'rc-slider/assets/index.css';

import './FacetSlider.css';

type Props = FacetProps & RangeSliderProps;
Expand All @@ -25,7 +25,7 @@ const FacetSlider = forwardRef(({ useRangeSlider, ...props }: Props, ref: HTMLEl
refine,
} = useRangeSlider(props);

const [valueView, setValueView] = useState<Array<number>>([range.min, range.max]);
const [valueView, setValueView] = useState < Array < number >> ([range.min, range.max]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we preserve the current spacing rules? I'm not sure if this is a Prettier/ESLint issue, or something else.


/**
* Sets the visibility variable based on the range min and max.
Expand Down Expand Up @@ -72,12 +72,12 @@ const FacetSlider = forwardRef(({ useRangeSlider, ...props }: Props, ref: HTMLEl
columns={2}
>
<Grid.Column>
{ valueView[0] }
{valueView[0]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a style guide I can use in VSCode? This I believe is the default ruleset of the VSCode formatter it is using as I do not have prettier activated right now...Though I think we should use it ;-)

</Grid.Column>
<Grid.Column
textAlign='right'
>
{ valueView[1] }
{valueView[1]}
</Grid.Column>
</Grid>
</div>
Expand Down
6 changes: 6 additions & 0 deletions packages/semantic-ui/src/components/LazyDocument.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.lazy-document.ui.segment .buttons {
display: flex;
flex-direction: column;
z-index: 1000;
}

.lazy-document.ui.segment .buttons .ui.button {
Expand All @@ -30,3 +31,8 @@
.lazy-document > .image.hidden {
display: none;
}

.pdf-container {
width: 200px;
height: 300px;
}
18 changes: 9 additions & 9 deletions packages/semantic-ui/src/components/LazyDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
import DownloadButton from './DownloadButton';
import LazyLoader from './LazyLoader';

import 'react-pdf/dist/esm/Page/AnnotationLayer.css';
import 'react-pdf/dist/esm/Page/TextLayer.css';
import './LazyDocument.css';

type Props = {
Expand Down Expand Up @@ -87,13 +85,13 @@ const LazyDocument = (props: Props) => {
onMouseEnter={() => setDimmer(true)}
onMouseLeave={() => setDimmer(false)}
>
{ !loaded && (
{!loaded && (
<LazyLoader
active
size={props.size}
/>
)}
{ !error && props.preview && (
{!error && props.preview && (
<Image
{...props.image}
className={getClassNames()}
Expand All @@ -109,7 +107,7 @@ const LazyDocument = (props: Props) => {
size={props.size}
/>
)}
{ !error && loaded && !props.preview && props.src && props.pdf && (
{!error && loaded && !props.preview && props.src && props.pdf && (
<Image
{...props.image}
className={getClassNames()}
Expand All @@ -121,11 +119,13 @@ const LazyDocument = (props: Props) => {
>
<Page
pageNumber={1}
renderTextLayer={false}
renderAnnotationLayer={false}
/>
</Document>
</Image>
)}
{ (error || (!props.preview && !(props.src && props.pdf))) && (
{(error || (!props.preview && !(props.src && props.pdf))) && (
<Image
{...props.image}
className={getClassNames('placeholder-image')}
Expand All @@ -137,20 +137,20 @@ const LazyDocument = (props: Props) => {
/>
</Image>
)}
{ (props.download || props.src || props.children) && props.dimmable && (
{(props.download || props.src || props.children) && props.dimmable && (
<Dimmer
active={dimmer}
>
<div
className='buttons'
>
{ props.download && (
{props.download && (
<DownloadButton
primary
url={props.download || props.src}
/>
)}
{ props.children }
{props.children}
</div>
</Dimmer>
)}
Expand Down
68 changes: 68 additions & 0 deletions packages/semantic-ui/src/components/ViewPDFButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// @flow

import React, { useMemo } from 'react';
import { Icon, Button } from 'semantic-ui-react';
import i18n from '../i18n/i18n';

type Props = {
basic?: boolean,
className?: string,
color?: string,
compact?: boolean,
primary?: boolean,
size?: string,
secondary?: boolean,
url: string,
};

const ViewPDFButton = (props: Props) => {
/**
* Sets the appropriate class names based on the formatting props.
*
* @type {string}
*/
const className = useMemo(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of these props can be passed to the Button component as props, instead of concatenting them as a class name. I'm wondering if this needs to be it's own component or can be done inline in the LazyDocument:

<Button
  basic
  content={...}
  primary
  icon='file pdf'
  onClick={...}
/>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy/paste of the DownloadButton component as a starting point. I switched from using an anchor to see if I could resolve an earlier issue. I use this button outside of LazyDocument in the ArchNet client so I think it makes sense to keep it as a functional component, but I could definitely refactor the classname stuff. Do not know if it is a priority right now.

const classNames = ['ui', 'button'];

if (props.basic) {
classNames.push('basic');
}

if (props.className) {
classNames.push(...props.className.split(' '));
}

if (props.color) {
classNames.push(props.color);
}

if (props.compact) {
classNames.push('compact');
}

if (props.primary) {
classNames.push('primary');
}

if (props.secondary) {
classNames.push('secondary');
}

if (props.size) {
classNames.push(props.size);
}

return classNames.join(' ');
}, [props.basic, props.color]);

return (
<Button className={className} onClick={() => window.open(props.url, '_blank')}>
<Icon
name='file pdf'
/>
{i18n.t('Common.buttons.pdf')}
</Button>
);
};

export default ViewPDFButton;
5 changes: 3 additions & 2 deletions packages/semantic-ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"save": "Save",
"search": "Search",
"show": "Show",
"upload": "Upload"
"upload": "Upload",
"pdf": "View PDF"
},
"errors": {
"save": "There was an error saving the record.",
Expand Down Expand Up @@ -331,4 +332,4 @@
},
"title": "XML"
}
}
}
1 change: 1 addition & 0 deletions packages/semantic-ui/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export { default as Toaster } from './components/Toaster';
export { default as VideoFrameSelector } from './components/VideoFrameSelector';
export { default as VideoPlayer } from './components/VideoPlayer';
export { default as VideoPlayerButton } from './components/VideoPlayerButton';
export { default as ViewPDFButton } from './components/ViewPDFButton';
export { default as ViewXML } from './components/ViewXML';

// Context
Expand Down
4 changes: 4 additions & 0 deletions packages/semantic-ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ module.exports = configure(__dirname, {
'./react-calendar/dist/Calendar.css$': path.resolve(
__dirname,
'../../node_modules/react-calendar/dist/Calendar.css'
),
'./rc-slider/assets/index.css$': path.resolve(
__dirname,
'../../node_modules/rc-slider/assets/index.css'
)
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/shared-components",
"version": "1.1.3",
"version": "1.1.4",
"description": "A package of shared, framework agnostic, components.",
"license": "MIT",
"main": "./build/index.js",
Expand Down
Binary file added packages/storybook/src/assets/test.pdf
Binary file not shown.
19 changes: 19 additions & 0 deletions packages/storybook/src/semantic-ui/LazyDocument.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import React, { useState } from 'react';
import { Card, Item } from 'semantic-ui-react';
import _ from 'underscore';
import FileInputButton from '../../../semantic-ui/src/components/FileInputButton';
import ViewPDFButton from '../../../semantic-ui/src/components/ViewPDFButton';
import image from '../assets/test-image.jpg';
import LazyDocument from '../../../semantic-ui/src/components/LazyDocument';
import portraitImage from '../assets/portrait-test-image.jpg';
import pdf from '../assets/test.pdf';

export default {
title: 'Components/Semantic UI/LazyDocument'
Expand Down Expand Up @@ -85,6 +87,23 @@ export const CardContent = () => (
</Card.Group>
);

export const ViewContent = () => (
<LazyDocument
pdf
src={pdf}
view
viewUrl={pdf}
>
<ViewPDFButton url={pdf} primary />
</LazyDocument>
);

export const DownloadContent = () => (
<LazyDocument
download={pdf}
/>
);

export const ListContent = () => (
<Item.Group>
<Item>
Expand Down
6 changes: 3 additions & 3 deletions packages/user-defined-fields/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/user-defined-fields",
"version": "1.1.3",
"version": "1.1.4",
"description": "A package of components used for allowing end users to define fields on models. Use with the \"user_defined_fields\" gem.",
"license": "MIT",
"main": "./build/index.js",
Expand All @@ -9,8 +9,8 @@
"build": "webpack --mode production && flow-copy-source -v src types"
},
"dependencies": {
"@performant-software/semantic-components": "^1.1.3",
"@performant-software/shared-components": "^1.1.3",
"@performant-software/semantic-components": "^1.1.4",
"@performant-software/shared-components": "^1.1.4",
"i18next": "^21.9.1",
"semantic-ui-react": "^2.1.2",
"underscore": "^1.13.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performant-software/visualize",
"version": "1.1.3",
"version": "1.1.4",
"description": "A package of components used for data visualization",
"license": "MIT",
"main": "./build/index.js",
Expand Down
4 changes: 2 additions & 2 deletions react-components.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"packages/user-defined-fields",
"packages/visualize"
],
"version": "1.1.3"
}
"version": "1.1.4"
}
Loading