Documents Gallery Package Fixes

This commit is contained in:
Patrick Fic
2023-01-17 13:59:44 -08:00
parent 8fd9614f69
commit 713b3f4f6d
4 changed files with 154 additions and 66 deletions

View File

@@ -46,6 +46,7 @@
"react-grid-layout": "^1.3.4", "react-grid-layout": "^1.3.4",
"react-i18next": "^12.1.1", "react-i18next": "^12.1.1",
"react-icons": "^4.7.1", "react-icons": "^4.7.1",
"react-image-lightbox": "^5.1.4",
"react-number-format": "^5.1.2", "react-number-format": "^5.1.2",
"react-redux": "^8.0.5", "react-redux": "^8.0.5",
"react-resizable": "^3.0.4", "react-resizable": "^3.0.4",

View File

@@ -1,7 +1,7 @@
import { EditFilled, FileExcelFilled, SyncOutlined } from "@ant-design/icons"; import { EditFilled, FileExcelFilled, SyncOutlined } from "@ant-design/icons";
import { Button, Card, Col, Row, Space } from "antd"; import { Button, Card, Col, Row, Space } from "antd";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import Gallery from "react-grid-gallery"; import { Gallery } from "react-grid-gallery";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import DocumentsUploadComponent from "../documents-upload/documents-upload.component"; import DocumentsUploadComponent from "../documents-upload/documents-upload.component";
import { DetermineFileType } from "../documents-upload/documents-upload.utility"; import { DetermineFileType } from "../documents-upload/documents-upload.utility";
@@ -10,7 +10,8 @@ import JobsDocumentsDownloadButton from "./jobs-document-gallery.download.compon
import JobsDocumentsGalleryReassign from "./jobs-document-gallery.reassign.component"; import JobsDocumentsGalleryReassign from "./jobs-document-gallery.reassign.component";
import JobsDocumentsDeleteButton from "./jobs-documents-gallery.delete.component"; import JobsDocumentsDeleteButton from "./jobs-documents-gallery.delete.component";
import JobsDocumentsGallerySelectAllComponent from "./jobs-documents-gallery.selectall.component"; import JobsDocumentsGallerySelectAllComponent from "./jobs-documents-gallery.selectall.component";
import Lightbox from "react-image-lightbox";
import "react-image-lightbox/style.css";
function JobsDocumentsComponent({ function JobsDocumentsComponent({
data, data,
jobId, jobId,
@@ -23,11 +24,7 @@ function JobsDocumentsComponent({
}) { }) {
const [galleryImages, setgalleryImages] = useState({ images: [], other: [] }); const [galleryImages, setgalleryImages] = useState({ images: [], other: [] });
const { t } = useTranslation(); const { t } = useTranslation();
const [index, setIndex] = useState(0); const [modalState, setModalState] = useState({ open: false, index: 0 });
const onCurrentImageChange = (index) => {
setIndex(index);
};
useEffect(() => { useEffect(() => {
let documents = data.reduce( let documents = data.reduce(
@@ -35,10 +32,12 @@ function JobsDocumentsComponent({
const fileType = DetermineFileType(value.type); const fileType = DetermineFileType(value.type);
if (value.type.startsWith("image")) { if (value.type.startsWith("image")) {
acc.images.push({ acc.images.push({
src: GenerateSrcUrl(value), // src: GenerateSrcUrl(value),
thumbnail: GenerateThumbUrl(value), // thumbnail: GenerateThumbUrl(value),
thumbnailHeight: 225, fullsize: GenerateSrcUrl(value),
thumbnailWidth: 225, src: GenerateThumbUrl(value),
height: 225,
width: 225,
isSelected: false, isSelected: false,
key: value.key, key: value.key,
extension: value.extension, extension: value.extension,
@@ -62,8 +61,8 @@ function JobsDocumentsComponent({
const fileName = value.key.split("/").pop(); const fileName = value.key.split("/").pop();
acc.other.push({ acc.other.push({
source: GenerateSrcUrl(value), source: GenerateSrcUrl(value),
src: "", //src: "",
thumbnail: thumb, src: thumb,
tags: [ tags: [
{ {
value: fileName, value: fileName,
@@ -85,8 +84,8 @@ function JobsDocumentsComponent({
] ]
: []), : []),
], ],
thumbnailHeight: 225, height: 225,
thumbnailWidth: 225, width: 225,
isSelected: false, isSelected: false,
extension: value.extension, extension: value.extension,
@@ -148,35 +147,15 @@ function JobsDocumentsComponent({
<Card title={t("jobs.labels.documents-images")}> <Card title={t("jobs.labels.documents-images")}>
<Gallery <Gallery
images={galleryImages.images} images={galleryImages.images}
backdropClosesModal={true} onClick={(index, item) => {
currentImageWillChange={onCurrentImageChange} setModalState({ open: true, index: index });
customControls={[ // window.open(
<Button // item.fullsize,
key="edit-button" // "_blank",
style={{ // "toolbar=0,location=0,menubar=0"
float: "right", // );
zIndex: "5",
}}
onClick={() => {
const newWindow = window.open(
`${window.location.protocol}//${window.location.host}/edit?documentId=${galleryImages.images[index].id}`,
"_blank",
"noopener,noreferrer"
);
if (newWindow) newWindow.opener = null;
}}
>
<EditFilled />
</Button>,
]}
onClickImage={(props) => {
window.open(
props.target.src,
"_blank",
"toolbar=0,location=0,menubar=0"
);
}} }}
onSelectImage={(index, image) => { onSelect={(index, image) => {
setgalleryImages({ setgalleryImages({
...galleryImages, ...galleryImages,
images: galleryImages.images.map((g, idx) => images: galleryImages.images.map((g, idx) =>
@@ -191,8 +170,6 @@ function JobsDocumentsComponent({
<Card title={t("jobs.labels.documents-other")}> <Card title={t("jobs.labels.documents-other")}>
<Gallery <Gallery
images={galleryImages.other} images={galleryImages.other}
backdropClosesModal={true}
enableLightbox={false}
thumbnailStyle={() => { thumbnailStyle={() => {
return { return {
backgroundImage: <FileExcelFilled />, backgroundImage: <FileExcelFilled />,
@@ -201,14 +178,14 @@ function JobsDocumentsComponent({
cursor: "pointer", cursor: "pointer",
}; };
}} }}
onClickThumbnail={(index) => { onClick={(index) => {
window.open( window.open(
galleryImages.other[index].source, galleryImages.other[index].source,
"_blank", "_blank",
"toolbar=0,location=0,menubar=0" "toolbar=0,location=0,menubar=0"
); );
}} }}
onSelectImage={(index) => { onSelect={(index) => {
setgalleryImages({ setgalleryImages({
...galleryImages, ...galleryImages,
other: galleryImages.other.map((g, idx) => other: galleryImages.other.map((g, idx) =>
@@ -220,6 +197,53 @@ function JobsDocumentsComponent({
</Card> </Card>
</Col> </Col>
</Row> </Row>
{modalState.open && (
<Lightbox
toolbarButtons={[
<EditFilled
onClick={() => {
const newWindow = window.open(
`${window.location.protocol}//${
window.location.host
}/edit?documentId=${
galleryImages.images[modalState.index].id
}`,
"_blank",
"noopener,noreferrer"
);
if (newWindow) newWindow.opener = null;
}}
/>,
]}
mainSrc={galleryImages.images[modalState.index].fullsize}
nextSrc={
galleryImages.images[
(modalState.index + 1) % galleryImages.images.length
].fullsize
}
prevSrc={
galleryImages.images[
(modalState.index + galleryImages.images.length - 1) %
galleryImages.images.length
].fullsize
}
onCloseRequest={() => setModalState({ open: false, index: 0 })}
onMovePrevRequest={() =>
setModalState({
...modalState,
index:
(modalState.index + galleryImages.images.length - 1) %
galleryImages.images.length,
})
}
onMoveNextRequest={() =>
setModalState({
...modalState,
index: (modalState.index + 1) % galleryImages.images.length,
})
}
/>
)}
</div> </div>
); );
} }

View File

@@ -1,7 +1,7 @@
import { SyncOutlined, FileExcelFilled } from "@ant-design/icons"; import { SyncOutlined, FileExcelFilled } from "@ant-design/icons";
import { Alert, Button, Card, Space } from "antd"; import { Alert, Button, Card, Space } from "antd";
import React, { useEffect } from "react"; import React, { useEffect, useState } from "react";
import Gallery from "react-grid-gallery"; import { Gallery } from "react-grid-gallery";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { createStructuredSelector } from "reselect"; import { createStructuredSelector } from "reselect";
@@ -18,6 +18,8 @@ import JobsDocumentsLocalDeleteButton from "./jobs-documents-local-gallery.delet
import JobsLocalGalleryDownloadButton from "./jobs-documents-local-gallery.download"; import JobsLocalGalleryDownloadButton from "./jobs-documents-local-gallery.download";
import JobsDocumentsLocalGalleryReassign from "./jobs-documents-local-gallery.reassign.component"; import JobsDocumentsLocalGalleryReassign from "./jobs-documents-local-gallery.reassign.component";
import JobsDocumentsLocalGallerySelectAllComponent from "./jobs-documents-local-gallery.selectall.component"; import JobsDocumentsLocalGallerySelectAllComponent from "./jobs-documents-local-gallery.selectall.component";
import Lightbox from "react-image-lightbox";
import "react-image-lightbox/style.css";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop, bodyshop: selectBodyshop,
@@ -49,6 +51,7 @@ export function JobsDocumentsLocalGallery({
vendorid, vendorid,
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [modalState, setModalState] = useState({ open: false, index: 0 });
useEffect(() => { useEffect(() => {
if (job) { if (job) {
if (invoice_number) { if (invoice_number) {
@@ -58,6 +61,7 @@ export function JobsDocumentsLocalGallery({
} }
} }
}, [job, invoice_number, getJobMedia, getBillMedia]); }, [job, invoice_number, getJobMedia, getBillMedia]);
let optimized; let optimized;
const jobMedia = const jobMedia =
allMedia && allMedia[job.id] allMedia && allMedia[job.id]
@@ -70,12 +74,20 @@ export function JobsDocumentsLocalGallery({
) { ) {
acc.images.push({ acc.images.push({
...val, ...val,
fullsize: val.src,
src: val.thumbnail,
height: val.thumbnailHeight,
width: val.thumbnailWidth,
...(val.optimized && { src: val.optimized, fullsize: val.src }), ...(val.optimized && { src: val.optimized, fullsize: val.src }),
}); });
if (val.optimized) optimized = true; if (val.optimized) optimized = true;
} else { } else {
acc.other.push({ acc.other.push({
...val, ...val,
fullsize: val.src,
src: val.thumbnail,
height: val.thumbnailHeight,
width: val.thumbnailWidth,
tags: [{ value: val.filename, title: val.filename }], tags: [{ value: val.filename, title: val.filename }],
}); });
} }
@@ -120,8 +132,7 @@ export function JobsDocumentsLocalGallery({
<Card title={t("jobs.labels.documents-images")}> <Card title={t("jobs.labels.documents-images")}>
<Gallery <Gallery
images={jobMedia.images} images={jobMedia.images}
backdropClosesModal={true} onSelect={(index, image) => {
onSelectImage={(index, image) => {
toggleMediaSelected({ jobid: job.id, filename: image.filename }); toggleMediaSelected({ jobid: job.id, filename: image.filename });
}} }}
{...(optimized && { {...(optimized && {
@@ -133,24 +144,23 @@ export function JobsDocumentsLocalGallery({
/>, />,
], ],
})} })}
onClickImage={(props) => { onClick={(index, item) => {
const media = allMedia[job.id].find( setModalState({ open: true, index: index });
(m) => m.optimized === props.target.src // const media = allMedia[job.id].find(
); // (m) => m.optimized === item.src
// );
window.open( // window.open(
media ? media.src : props.target.src, // media ? media.fullsize : item.fullsize,
"_blank", // "_blank",
"toolbar=0,location=0,menubar=0" // "toolbar=0,location=0,menubar=0"
); // );
}} }}
/> />
</Card> </Card>
<Card title={t("jobs.labels.documents-other")}> <Card title={t("jobs.labels.documents-other")}>
<Gallery <Gallery
images={jobMedia.other} images={jobMedia.other}
backdropClosesModal={true}
enableLightbox={false}
thumbnailStyle={() => { thumbnailStyle={() => {
return { return {
backgroundImage: <FileExcelFilled />, backgroundImage: <FileExcelFilled />,
@@ -159,18 +169,48 @@ export function JobsDocumentsLocalGallery({
cursor: "pointer", cursor: "pointer",
}; };
}} }}
onClickThumbnail={(index) => { onClick={(index) => {
window.open( window.open(
jobMedia.other[index].src, jobMedia.other[index].fullsize,
"_blank", "_blank",
"toolbar=0,location=0,menubar=0" "toolbar=0,location=0,menubar=0"
); );
}} }}
onSelectImage={(index, image) => { onSelect={(index, image) => {
toggleMediaSelected({ jobid: job.id, filename: image.filename }); toggleMediaSelected({ jobid: job.id, filename: image.filename });
}} }}
/> />
</Card> </Card>
{modalState.open && (
<Lightbox
mainSrc={jobMedia.images[modalState.index].fullsize}
nextSrc={
jobMedia.images[(modalState.index + 1) % jobMedia.images.length]
.fullsize
}
prevSrc={
jobMedia.images[
(modalState.index + jobMedia.images.length - 1) %
jobMedia.images.length
].fullsize
}
onCloseRequest={() => setModalState({ open: false, index: 0 })}
onMovePrevRequest={() =>
setModalState({
...modalState,
index:
(modalState.index + jobMedia.images.length - 1) %
jobMedia.images.length,
})
}
onMoveNextRequest={() =>
setModalState({
...modalState,
index: (modalState.index + 1) % jobMedia.images.length,
})
}
/>
)}
</div> </div>
); );
} }

View File

@@ -5888,6 +5888,11 @@ executable@^4.1.1:
dependencies: dependencies:
pify "^2.2.0" pify "^2.2.0"
exenv@^1.2.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
integrity sha512-Z+ktTxTwv9ILfgKCk32OX3n/doe+OcLTRtqK9pcL+JsP3J1/VW8Uvl4ZjLlKqeW4rzK4oesDOGMEMRIZqtP4Iw==
exifr@^7.1.3: exifr@^7.1.3:
version "7.1.3" version "7.1.3"
resolved "https://registry.yarnpkg.com/exifr/-/exifr-7.1.3.tgz#f6218012c36dbb7d843222011b27f065fddbab6f" resolved "https://registry.yarnpkg.com/exifr/-/exifr-7.1.3.tgz#f6218012c36dbb7d843222011b27f065fddbab6f"
@@ -10317,6 +10322,14 @@ react-icons@^4.7.1:
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.7.1.tgz#0f4b25a5694e6972677cb189d2a72eabea7a8345" resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.7.1.tgz#0f4b25a5694e6972677cb189d2a72eabea7a8345"
integrity sha512-yHd3oKGMgm7zxo3EA7H2n7vxSoiGmHk5t6Ou4bXsfcgWyhfDKMpyKfhHR6Bjnn63c+YXBLBPUql9H4wPJM6sXw== integrity sha512-yHd3oKGMgm7zxo3EA7H2n7vxSoiGmHk5t6Ou4bXsfcgWyhfDKMpyKfhHR6Bjnn63c+YXBLBPUql9H4wPJM6sXw==
react-image-lightbox@^5.1.4:
version "5.1.4"
resolved "https://registry.yarnpkg.com/react-image-lightbox/-/react-image-lightbox-5.1.4.tgz#5b847dcb79e9efdf9d7cd5621a92e0f156d2cf30"
integrity sha512-kTiAODz091bgT7SlWNHab0LSMZAPJtlNWDGKv7pLlLY1krmf7FuG1zxE0wyPpeA8gPdwfr3cu6sPwZRqWsc3Eg==
dependencies:
prop-types "^15.7.2"
react-modal "^3.11.1"
react-is@^16.10.2, react-is@^16.12.0, react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0: react-is@^16.10.2, react-is@^16.12.0, react-is@^16.13.1, react-is@^16.6.0, react-is@^16.7.0:
version "16.13.1" version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
@@ -10332,11 +10345,21 @@ react-is@^18.0.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
react-lifecycles-compat@^3.0.4: react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
version "3.0.4" version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA== integrity sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==
react-modal@^3.11.1:
version "3.16.1"
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.16.1.tgz#34018528fc206561b1a5467fc3beeaddafb39b2b"
integrity sha512-VStHgI3BVcGo7OXczvnJN7yT2TWHJPDXZWyI/a0ssFNhGZWsPmB8cF0z33ewDXq4VfYMO1vXgiv/g8Nj9NDyWg==
dependencies:
exenv "^1.2.0"
prop-types "^15.7.2"
react-lifecycles-compat "^3.0.0"
warning "^4.0.3"
react-number-format@^5.1.2: react-number-format@^5.1.2:
version "5.1.3" version "5.1.3"
resolved "https://registry.yarnpkg.com/react-number-format/-/react-number-format-5.1.3.tgz#5534f5141cea29e0fe889f76c73dfad11ddf2e17" resolved "https://registry.yarnpkg.com/react-number-format/-/react-number-format-5.1.3.tgz#5534f5141cea29e0fe889f76c73dfad11ddf2e17"