IO-3092 Address PR concerns.

This commit is contained in:
Patrick Fic
2025-02-27 13:54:16 -08:00
parent f13a70a22f
commit ace0039429
6 changed files with 96 additions and 83 deletions

View File

@@ -17,6 +17,7 @@ import JobsDocumentsGalleryReassign from "./jobs-document-imgproxy-gallery.reass
import JobsDocumentsDeleteButton from "./jobs-documents-imgproxy-gallery.delete.component";
import JobsDocumentsGallerySelectAllComponent from "./jobs-documents-imgproxy-gallery.selectall.component";
import i18n from "i18next";
import { isFunction } from "lodash";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
@@ -40,19 +41,19 @@ function JobsDocumentsImgproxyComponent({
downloadIdentifier,
ignoreSizeLimit
}) {
const [galleryImages, setgalleryImages] = useState({ images: [], other: [] });
const [galleryImages, setGalleryImages] = useState({ images: [], other: [] });
const { t } = useTranslation();
const [modalState, setModalState] = useState({ open: false, index: 0 });
const fetchThumbnails = () => {
fetchImgproxyThumbnails({ setStateCallback: setgalleryImages, jobId });
fetchImgproxyThumbnails({ setStateCallback: setGalleryImages, jobId });
};
useEffect(() => {
if (data) {
fetchThumbnails();
}
}, [data, setgalleryImages]);
}, [data]);
const hasMediaAccess = HasFeatureAccess({ bodyshop, featureName: "media" });
const hasMobileAccess = HasFeatureAccess({ bodyshop, featureName: "mobile" });
@@ -65,7 +66,7 @@ function JobsDocumentsImgproxyComponent({
onClick={() => {
//Handle any doc refresh.
refetch && refetch();
isFunction(refetch) && refetch();
//Do the imgproxy refresh too
fetchThumbnails();
@@ -73,7 +74,7 @@ function JobsDocumentsImgproxyComponent({
>
<SyncOutlined />
</Button>
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setgalleryImages} />
<JobsDocumentsGallerySelectAllComponent galleryImages={galleryImages} setGalleryImages={setGalleryImages} />
<JobsDocumentsDownloadButton galleryImages={galleryImages} identifier={downloadIdentifier} />
<JobsDocumentsDeleteButton
galleryImages={galleryImages}
@@ -122,7 +123,7 @@ function JobsDocumentsImgproxyComponent({
// );
}}
onSelect={(index, image) => {
setgalleryImages({
setGalleryImages({
...galleryImages,
images: galleryImages.images.map((g, idx) =>
index === idx ? { ...g, isSelected: !g.isSelected } : g
@@ -148,7 +149,7 @@ function JobsDocumentsImgproxyComponent({
window.open(galleryImages.other[index].source, "_blank", "toolbar=0,location=0,menubar=0");
}}
onSelect={(index) => {
setgalleryImages({
setGalleryImages({
...galleryImages,
other: galleryImages.other.map((g, idx) => (index === idx ? { ...g, isSelected: !g.isSelected } : g))
});
@@ -160,6 +161,7 @@ function JobsDocumentsImgproxyComponent({
<Lightbox
toolbarButtons={[
<EditFilled
key="edit"
onClick={() => {
const newWindow = window.open(
`${window.location.protocol}//${window.location.host}/edit?documentId=${
@@ -202,7 +204,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(JobsDocumentsImgprox
export const fetchImgproxyThumbnails = async ({ setStateCallback, jobId, imagesOnly }) => {
const result = await axios.post("/media/imgproxy/thumbnails", { jobid: jobId });
let documents = result.data.reduce(
const documents = result.data.reduce(
(acc, value) => {
if (value.type.startsWith("image")) {
acc.images.push({
@@ -259,9 +261,6 @@ export const fetchImgproxyThumbnails = async ({ setStateCallback, jobId, imagesO
},
{ images: [], other: [] }
);
if (imagesOnly) {
setStateCallback(documents.images);
} else {
setStateCallback(documents);
}
setStateCallback(imagesOnly ? documents.images : documents);
};