Skip to content

Commit

Permalink
Updated photoCapture and inspectionGallery with thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
dlymonkai committed Jul 22, 2024
1 parent 9e335ba commit d995399
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const CreateInspection = i18nWrap(({ lang, onInspectionCreated }: CreateI
const { createInspection } = useMonkApi({
authToken: authToken ?? '',
apiDomain: config.apiDomain,
thumbnailDomain: config.thumbnailDomain,
});
const analytics = useAnalytics();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { i18nWrap, useI18nSync, useThumbnail } from '@monkvision/common';
import { i18nWrap, useI18nSync } from '@monkvision/common';
import { useMemo, useState } from 'react';
import { Image, ImageType } from '@monkvision/types';
import { InspectionGalleryItem, InspectionGalleryProps, NavigateToCaptureReason } from './types';
Expand Down Expand Up @@ -44,7 +44,6 @@ export const InspectionGallery = i18nWrap((props: InspectionGalleryProps) => {
captureMode: props.captureMode,
isFilterActive: currentFilter !== null,
});
const { getThumbnailUrl } = useThumbnail(props.thumbnailDomain);

const handleItemClick = (item: InspectionGalleryItem) => {
if (item.isAddDamage && props.captureMode) {
Expand Down Expand Up @@ -114,7 +113,6 @@ export const InspectionGallery = i18nWrap((props: InspectionGalleryProps) => {
<div style={itemStyle} key={getItemKey(item)}>
<InspectionGalleryItemCard
item={item}
getThumbnailUrl={getThumbnailUrl}
captureMode={props.captureMode}
onClick={() => handleItemClick(item)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { SightOverlay } from '../../SightOverlay';

export function InspectionGalleryItemCard({
item,
getThumbnailUrl,
captureMode,
onClick,
}: InspectionGalleryItemCardProps) {
Expand All @@ -24,7 +23,7 @@ export function InspectionGalleryItemCard({
statusIcon,
sightOverlay,
addDamageIcon,
} = useInspectionGalleryItemCardStyles({ item, captureMode, status, getThumbnailUrl });
} = useInspectionGalleryItemCardStyles({ item, captureMode, status });
const statusIconName = useInspectionGalleryItemStatusIconName({ item, captureMode });
const label = useInspectionGalleryItemLabel(item);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { IconName } from '../../../icons';
export interface InspectionGalleryItemCardProps {
item: InspectionGalleryItem;
captureMode: boolean;
getThumbnailUrl: (image: Image) => string;
onClick?: () => void;
}

Expand Down Expand Up @@ -56,14 +55,12 @@ export function useInspectionGalleryItemStatusIconName({
export interface UseInspectionGalleryItemCardStylesParams {
item: InspectionGalleryItem;
status: InteractiveStatus;
getThumbnailUrl: (image: Image) => string;
captureMode: boolean;
}

export function useInspectionGalleryItemCardStyles({
item,
status,
getThumbnailUrl,
captureMode,
}: UseInspectionGalleryItemCardStylesParams) {
const { palette } = useMonkTheme();
Expand Down Expand Up @@ -96,13 +93,6 @@ export function useInspectionGalleryItemCardStyles({
}
}

let backgroundImage = 'none';
if (!item.isAddDamage && item.isTaken) {
backgroundImage = item.image.path.startsWith('blob')
? `url(${item.image.path})`
: `url(${getThumbnailUrl(item.image)})`;
}

return {
cardStyle: {
...styles['card'],
Expand All @@ -113,7 +103,8 @@ export function useInspectionGalleryItemCardStyles({
previewStyle: {
...styles['preview'],
backgroundColor: colors.previewBackground,
backgroundImage,
backgroundImage:
!item.isAddDamage && item.isTaken ? `url(${item.image.thumbnailPath})` : 'none',
},
previewOverlayStyle: {
...styles['previewOverlay'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ export type InspectionGalleryProps = {
* The config used to communicate with the API.
*/
apiConfig: MonkApiConfig;
/**
* The API domain used to communicate with the resize micro service
*/
thumbnailDomain: string;
/**
* The language used by the InspectionGallery component.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const VehicleTypeSelection = i18nWrap((props: VehicleTypeSelectionProps)
const { getInspection } = useMonkApi({
authToken: props.authToken ?? '',
apiDomain: props.apiDomain ?? '',
thumbnailDomain: props.thumbnailDomain ?? '',
});
const loading = useLoadingState();
const { handleError, setTags, setUserId } = useMonitoring();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export interface PhotoCaptureProps
| 'enableAddDamage'
| 'sightGuidelines'
| 'enableSightGuidelines'
| 'thumbnailDomain'
>,
Partial<CompressionOptions>,
Partial<ComplianceOptions> {
Expand Down Expand Up @@ -132,7 +131,6 @@ export function PhotoCapture({
lang,
enforceOrientation,
validateButtonLabel,
thumbnailDomain,
...initialCameraConfig
}: PhotoCaptureProps) {
useI18nSync(lang);
Expand Down Expand Up @@ -286,7 +284,6 @@ export function PhotoCapture({
<InspectionGallery
inspectionId={inspectionId}
apiConfig={apiConfig}
thumbnailDomain={thumbnailDomain}
captureMode={true}
lang={lang}
showBackButton={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function createAddImageOptions(
upload: PictureUpload,
inspectionId: string,
siblingId: number,
enableThumbnail: boolean,
additionalTasks?: CaptureAppConfig['additionalTasks'],
compliance?: ComplianceOptions,
): AddImageOptions {
Expand All @@ -116,6 +117,7 @@ function createAddImageOptions(
tasks: additionalTasks ? uniq([...upload.tasks, ...additionalTasks]) : upload.tasks,
inspectionId,
compliance,
enableThumbnail,
};
}
return {
Expand All @@ -125,6 +127,7 @@ function createAddImageOptions(
firstShot: upload.mode === PhotoCaptureMode.ADD_DAMAGE_1ST_SHOT,
inspectionId,
compliance,
enableThumbnail,
};
}

Expand Down Expand Up @@ -153,6 +156,7 @@ export function useUploadQueue({
upload,
inspectionId,
siblingIdRef.current,
true,
additionalTasks,
complianceOptions,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ function createProps(): PhotoCaptureProps {
return {
sights: [sights['test-sight-1'], sights['test-sight-2'], sights['test-sight-3']],
inspectionId: 'test-inspection-test',
apiConfig: { apiDomain: 'test-api-domain-test', authToken: 'test-auth-token-test' },
thumbnailDomain: 'test-thumbnail-domain',
apiConfig: {
apiDomain: 'test-api-domain-test',
authToken: 'test-auth-token-test',
thumbnailDomain: 'test-thumbnail-domain',
},

additionalTasks: [TaskName.DASHBOARD_OCR],
tasksBySight: { 'test-sight-1': [TaskName.IMAGE_EDITING] },
startTasksOnComplete: [TaskName.COMPLIANCES],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function createParams(): PhotoCaptureSightsParams {
sights['test-sight-3'],
sights['test-sight-4'],
],
apiConfig: { apiDomain: 'test-api-domain', authToken: 'test-auth-token' },
apiConfig: {
apiDomain: 'test-api-domain',
authToken: 'test-auth-token',
thumbnailDomain: 'test-thumbnail-domain',
},
loading: {
start: jest.fn(),
onSuccess: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
function createParams(): UseStartTasksOnCompleteParams {
return {
inspectionId: 'test-inspection-id',
apiConfig: { apiDomain: 'test-api-domain', authToken: 'test-auth-token' },
apiConfig: {
apiDomain: 'test-api-domain',
authToken: 'test-auth-token',
thumbnailDomain: 'test-thumbnail-domain',
},
sights: [
sights['test-sight-1'],
sights['test-sight-2'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import { act } from '@testing-library/react';
function createParams(): UploadQueueParams {
return {
inspectionId: 'test-inspection-id',
apiConfig: { apiDomain: 'test-api-domain', authToken: 'test-auth-token' },
apiConfig: {
apiDomain: 'test-api-domain',
authToken: 'test-auth-token',
thumbnailDomain: 'test-thumbnail-domain',
},
complianceOptions: {
enableCompliance: true,
complianceIssues: [ComplianceIssue.INTERIOR_NOT_SUPPORTED],
Expand Down Expand Up @@ -84,6 +88,7 @@ describe('useUploadQueue hook', () => {
tasks: defaultUploadOptions.tasks,
compliance: initialProps.complianceOptions,
inspectionId: initialProps.inspectionId,
enableThumbnail: true,
});

unmount();
Expand All @@ -105,6 +110,7 @@ describe('useUploadQueue hook', () => {
uploadType: ImageUploadType.BEAUTY_SHOT,
picture: defaultUploadOptions.picture,
sightId: defaultUploadOptions.sightId,
enableThumbnail: true,
tasks: expect.arrayContaining([
TaskName.DAMAGE_DETECTION,
TaskName.IMAGE_EDITING,
Expand Down Expand Up @@ -142,6 +148,7 @@ describe('useUploadQueue hook', () => {
uploadType: ImageUploadType.CLOSE_UP_2_SHOT,
picture: upload1.picture,
siblingKey: expect.any(String),
enableThumbnail: true,
firstShot: true,
compliance: initialProps.complianceOptions,
inspectionId: initialProps.inspectionId,
Expand All @@ -165,6 +172,7 @@ describe('useUploadQueue hook', () => {
uploadType: ImageUploadType.CLOSE_UP_2_SHOT,
picture: upload2.picture,
siblingKey,
enableThumbnail: true,
firstShot: false,
compliance: initialProps.complianceOptions,
inspectionId: initialProps.inspectionId,
Expand Down

0 comments on commit d995399

Please sign in to comment.