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

Feat/mn 569/add damage part select #829

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion apps/demo-app/src/local-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "demo-app-dev",
"description": "Config for the dev Demo App.",
"allowSkipRetake": true,
"enableAddDamage": true,
"addDamage": "part_select",
"enableSightGuidelines": true,
"allowVehicleTypeSelection": true,
"allowManualLogin": true,
Expand Down
10 changes: 5 additions & 5 deletions apps/demo-app/test/pages/PhotoCapturePage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next';
import { render } from '@testing-library/react';
import { expectPropsOnChildMock } from '@monkvision/test-utils';
import { PhotoCapture } from '@monkvision/inspection-capture-web';
import { PhotoCapture, PhotoCaptureProps } from '@monkvision/inspection-capture-web';
import { useMonkAppState } from '@monkvision/common';
import { PhotoCapturePage } from '../../src/pages';

Expand All @@ -20,7 +20,7 @@ const appState = {
enforceOrientation: 'test-enforceOrientation-test',
maxUploadDurationWarning: 'test-maxUploadDurationWarning-test',
allowSkipRetake: 'test-allowSkipRetake-test',
enableAddDamage: 'test-enableAddDamage-test',
addDamage: 'test-addDamage-test',
enableCompliance: 'test-enableCompliance-test',
enableCompliancePerSight: 'test-enableCompliancePerSight-test',
complianceIssues: 'test-complianceIssues-test',
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('PhotoCapture page', () => {
enforceOrientation: appState.config.enforceOrientation,
maxUploadDurationWarning: appState.config.maxUploadDurationWarning,
allowSkipRetake: appState.config.allowSkipRetake,
enableAddDamage: appState.config.enableAddDamage,
addDamage: appState.config.addDamage,
enableCompliance: appState.config.enableCompliance,
enableCompliancePerSight: appState.config.enableCompliancePerSight,
complianceIssues: appState.config.complianceIssues,
Expand All @@ -62,7 +62,7 @@ describe('PhotoCapture page', () => {
customComplianceThresholds: appState.config.customComplianceThresholds,
customComplianceThresholdsPerSight: appState.config.customComplianceThresholdsPerSight,
additionalTasks: appState.config.additionalTasks,
});
} as unknown as PhotoCaptureProps);

unmount();
});
Expand All @@ -74,7 +74,7 @@ describe('PhotoCapture page', () => {
expect(appState.getCurrentSights).toHaveBeenCalled();
expectPropsOnChildMock(PhotoCapture, {
sights: appState.getCurrentSights(),
});
} as PhotoCaptureProps);

unmount();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export = {
SVGElement: jest.fn(() => <></>),
SwitchButton: jest.fn(() => <></>),
TakePictureButton: jest.fn(() => <></>),
VehiclePartSelection: jest.fn(() => <></>),
};
3 changes: 3 additions & 0 deletions configs/test-utils/src/__mocks__/@monkvision/common.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { InteractiveStatus } from '@monkvision/types';

const { vehiclePartLabels } = jest.requireActual('@monkvision/common');

function createMockLoadingState() {
return {
isLoading: false,
Expand Down Expand Up @@ -59,6 +61,7 @@ export = {
complianceIssueLabels,
imageStatusLabels,
getInspectionImages,
vehiclePartLabels,

/* Mocks */
useMonkTheme: jest.fn(() => createTheme()),
Expand Down
6 changes: 3 additions & 3 deletions configs/test-utils/src/expects/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
* If you want to test the children passed to the child component, you can add the `children` property to the props
* object.
*/
export function expectPropsOnChildMock(
Component: jest.Mock | FC<any> | ForwardedRef<any>,
props: { [key: string]: unknown },
export function expectPropsOnChildMock<T extends jest.Mock | FC<any> | ForwardedRef<any>>(
Component: T,
props: T extends (prop: infer P) => any ? Partial<P> : never,
): void {
expect(Component).toHaveBeenCalledWith(expect.objectContaining(props), expect.anything());
}
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/photo-capture-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ increase the detection rate. This feature is called `Add Damage`, and there two
take a close-up picture of the damage.

For now, only the 2-shot workflow is implemented in the PhotoCapture workflow. This feature is enabled by default in the
`PhotoCapture` component. To disable it, pass the `enableAddDamage` prop to `false`.
`PhotoCapture` component. To disable it, pass the `addDamage` prop to `AddDamage.DISABLED`.

## Using Compliance
The compliance is a feature that allows our AI models to analyze the quality of the pictures taken by the user, and if
Expand Down
3 changes: 2 additions & 1 deletion documentation/src/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SteeringWheelPosition,
TaskName,
VehicleType,
AddDamage,
} from '@monkvision/types';
import { sights } from '@monkvision/sights';
import { flatten } from '@monkvision/common';
Expand Down Expand Up @@ -270,7 +271,7 @@ export const LiveConfigSchema = z
maxUploadDurationWarning: z.number().positive().or(z.literal(-1)).optional(),
useAdaptiveImageQuality: z.boolean().optional(),
allowSkipRetake: z.boolean().optional(),
enableAddDamage: z.boolean().optional(),
addDamage: z.nativeEnum(AddDamage).optional(),
enableSightGuidelines: z.boolean().optional(),
sightGuidelines: z.array(SightGuidelineSchema).optional(),
enableTutorial: z.nativeEnum(PhotoCaptureTutorialOption).optional(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from 'react';
import { ImageStatus, Sight } from '@monkvision/types';
import { AddDamage, ImageStatus, Sight } from '@monkvision/types';
import { getInspectionImages, MonkState, useMonkState } from '@monkvision/common';
import { useInspectionPoll } from '@monkvision/network';
import { InspectionGalleryItem, InspectionGalleryProps } from '../types';
Expand Down Expand Up @@ -57,7 +57,7 @@ function getItems(
captureMode: boolean,
entities: MonkState,
inspectionSights?: Sight[],
enableAddDamage?: boolean,
addDamage?: AddDamage,
): InspectionGalleryItem[] {
const images = getInspectionImages(inspectionId, entities.images, captureMode);
const items: InspectionGalleryItem[] = images.map((image) => ({
Expand All @@ -73,7 +73,7 @@ function getItems(
items.push({ isTaken: false, isAddDamage: false, sightId: sight.id });
}
});
if (captureMode && enableAddDamage !== false) {
if (captureMode && (!addDamage || addDamage !== AddDamage.DISABLED)) {
items.push({ isAddDamage: true });
}
return items.sort((a, b) => compareGalleryItems(a, b, captureMode, inspectionSights));
Expand All @@ -93,15 +93,8 @@ export function useInspectionGalleryItems(props: InspectionGalleryProps): Inspec
const { state } = useMonkState();

const items = useMemo(
() =>
getItems(
props.inspectionId,
props.captureMode,
state,
inspectionSights,
props.enableAddDamage,
),
[props.inspectionId, props.captureMode, state, inspectionSights, props.enableAddDamage],
() => getItems(props.inspectionId, props.captureMode, state, inspectionSights, props.addDamage),
[props.inspectionId, props.captureMode, state, inspectionSights, props.addDamage],
);
const shouldFetch = useMemo(() => shouldContinueToFetch(items), items);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComplianceOptions, Image, Sight } from '@monkvision/types';
import { AddDamage, ComplianceOptions, Image, Sight } from '@monkvision/types';
import { MonkApiConfig } from '@monkvision/network';

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ export type InspectionGalleryProps = {
*
* @default true
*/
enableAddDamage?: boolean;
addDamage: AddDamage;
/**
* Custom label for validate button.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMonkTheme } from '@monkvision/common';
import {
PartSelectionOrientation,
VehicleModel,
Expand Down Expand Up @@ -68,6 +67,10 @@ function createGetAttributesCallback(
}

function getVehicleModel(vehicleType: VehicleType): VehicleModel {
if (vehicleType === VehicleType.SUV) {
// eslint-disable-next-line no-param-reassign
vehicleType = VehicleType.CUV;
}
Comment on lines +70 to +73
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer this :

cons type = vehicleType === VehicleType.SUV ? VehicleType.CUV : vehicleType;

over this :

if (vehicleType === VehicleType.SUV) {
  // eslint-disable-next-line no-param-reassign
  vehicleType = VehicleType.CUV;
}

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 would be string forward and don't need to create a new variable. because vehicleType is good variable name.

const detail = Object.entries(vehicles)
.filter(([type]) => type !== VehicleModel.AUDIA7)
.find(([, details]) => details.type === vehicleType)?.[1];
Expand All @@ -91,14 +94,13 @@ export function VehicleDynamicWireframe({
throw new Error(`No wireframe found for vehicle type ${vehicleType}`);
}
const overlay = wireframes[orientation];
const { utils } = useMonkTheme();

return (
<DynamicSVG
svg={overlay}
style={{
width: '100%',
color: utils.getColor('text-primary'),
height: '100%',
}}
getAttributes={createGetAttributesCallback(onClickPart, getPartAttributes)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { Styles } from '@monkvision/types';

export const styles: Styles = {
wrapper: {
position: 'absolute',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
inset: '0 0 0 0',
gap: '30px',
flexGrow: 1,
maxHeight: '100%',
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ export function VehiclePartSelection({
part: VehiclePart,
) => ({
style: {
// TODO: need to finalize the color for the selected parts.
fill: selectedParts.includes(part) ? palette.primary.xlight : undefined,
stroke: palette.primary.light,
fill: selectedParts.includes(part) ? palette.primary.base : undefined,
stroke: palette.text.primary,
display: 'block',
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/common-ui-web/src/icons/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const MonkIconAssetsMap: IconAssetsMap = {
'zoom-out':
'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#000" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 0 0 1.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 0 0-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 0 0 5.34-1.48l.27.28v.79l4.26 4.25c.41.41 1.07.41 1.48 0l.01-.01c.41-.41.41-1.07 0-1.48L15.5 14Zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14Zm-2-5h4c.28 0 .5.22.5.5s-.22.5-.5.5h-4c-.28 0-.5-.22-.5-.5s.22-.5.5-.5Z"/></svg>',
'rotate-left':
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7.8 13.5c-.1-4.6.9-7 2.5-8.9l-1.9-.9c-.6-.6-.2-1.7.7-1.7h5.6c.5 0 1 .4 1 1v5.6c0 .9-1.1 1.3-1.7.7l-1.9-1.9c-1.2 1.4-1.9 3.1-1.9 5.1 0 3.1 1.7 5.9 4.5 7.2.6.3.8.9.6 1.5-.3.7-1.1 1-1.7.7C10 20.4 9.7 19 8.3 16Z"/></svg>',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#000" d="M7.8 13.5c-.1-4.6.9-7 2.5-8.9l-1.9-.9c-.6-.6-.2-1.7.7-1.7h5.6c.5 0 1 .4 1 1v5.6c0 .9-1.1 1.3-1.7.7l-1.9-1.9c-1.2 1.4-1.9 3.1-1.9 5.1 0 3.1 1.7 5.9 4.5 7.2.6.3.8.9.6 1.5-.3.7-1.1 1-1.7.7C10 20.4 9.7 19 8.3 16Z"/></svg>',
'rotate-right':
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16.2 13.5c.1-4.6-.9-7-2.5-8.9l1.9-.9c.6-.6.2-1.7-.7-1.7H9.3c-.5 0-1 .4-1 1v5.6c0 .9 1.1 1.3 1.7.7l1.9-1.9c1.2 1.4 1.9 3.1 1.9 5.1 0 2.1-1.7 4.9-4.5 6.2-.6.3-.8.9-.6 1.5.2.5.9.9 1.5.6 3.6-1.5 4.3-2.8 5.3-5.1z"/></svg>',
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#000" d="M16.2 13.5c.1-4.6-.9-7-2.5-8.9l1.9-.9c.6-.6.2-1.7-.7-1.7H9.3c-.5 0-1 .4-1 1v5.6c0 .9 1.1 1.3 1.7.7l1.9-1.9c1.2 1.4 1.9 3.1 1.9 5.1 0 2.1-1.7 4.9-4.5 6.2-.6.3-.8.9-.6 1.5.2.5.9.9 1.5.6 3.6-1.5 4.3-2.8 5.3-5.1z"/></svg>',
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
useImageLabelIcon,
} from '../../../../src/components/ImageDetailedView/ImageDetailedViewOverlay/hooks';
import { Image, ImageStatus } from '@monkvision/types';
import { Button, Icon } from '../../../../src';
import { Button, Icon, IconName } from '../../../../src';
import { useObjectTranslation } from '@monkvision/common';

function createProps(): ImageDetailedViewOverlayProps {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('ImageDetailedViewOverlay component', () => {
it('should display the image label with the proper icon', () => {
const props = createProps();
props.image.label = { en: 'test', fr: 'fr', de: 'test-de', nl: 'test-nl' };
const icon = 'hello-test-icon';
const icon = 'hello-test-icon' as IconName;
const primaryColor = 'test-primary-test';
(useImageLabelIcon as jest.Mock).mockImplementationOnce(() => ({ icon, primaryColor }));
const label = 'valid-test-label';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('InspectionGalleryItemCard component', () => {
const { unmount } = render(<InspectionGalleryItemCard {...props} />);

expect(useInspectionGalleryItemStatusIconName).toHaveBeenCalled();
expectPropsOnChildMock(Icon, { icon: useInspectionGalleryItemStatusIconName({} as any) });
expectPropsOnChildMock(Icon, { icon: useInspectionGalleryItemStatusIconName({} as any)! });
Copy link
Contributor

Choose a reason for hiding this comment

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

Even in tests, I really don't like using !, try to find a better solution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of this, we need to specify the exact type using the 'as' keyword to inform TypeScript about a different type But that also have it downsights.


unmount();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { renderHook } from '@testing-library/react-hooks';
import { sights } from '@monkvision/sights';
import { ComplianceIssue, ComplianceOptions, Image, ImageStatus } from '@monkvision/types';
import {
AddDamage,
ComplianceIssue,
ComplianceOptions,
Image,
ImageStatus,
} from '@monkvision/types';
import { createEmptyMonkState, useMonkState } from '@monkvision/common';
import { useInspectionPoll } from '@monkvision/network';
import { useInspectionGalleryItems } from '../../../../src/components/InspectionGallery/hooks';
Expand All @@ -19,6 +25,7 @@ function createProps(): InspectionGalleryProps {
},
refreshIntervalMs: 1234,
captureMode: true,
addDamage: AddDamage.TWO_SHOT,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('LiveConfigAppProvider component', () => {
});

it('should fetch the live config and pass it to the MonkAppStateProvider component', async () => {
const config = { hello: 'world' };
const config = { hello: 'world' } as unknown as CaptureAppConfig;
(MonkApi.getLiveConfig as jest.Mock).mockImplementationOnce(() => Promise.resolve(config));
const id = 'test-id-test';
const { unmount } = render(<LiveConfigAppProvider id={id} />);
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/i18n/utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ describe('Monkvision i18n utils', () => {
}>;

it('should wrap the component in a I18nextProvider with the given instance', () => {
const instance = { test: 'test' };
const Wrapped = i18nWrap(TestComponent, instance as unknown as i18n);
const instance = { test: 'test' } as unknown as i18n;
const Wrapped = i18nWrap(TestComponent, instance);

const { unmount } = render(<Wrapped />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DeviceOrientation,
PhotoCaptureTutorialOption,
Sight,
AddDamage,
} from '@monkvision/types';
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -59,7 +60,7 @@ export interface PhotoCaptureProps
| 'showCloseButton'
| 'enforceOrientation'
| 'allowSkipRetake'
| 'enableAddDamage'
| 'addDamage'
| 'sightGuidelines'
| 'enableSightGuidelines'
| 'enableTutorial'
Expand Down Expand Up @@ -129,7 +130,7 @@ export function PhotoCapture({
customComplianceThresholdsPerSight,
useLiveCompliance = false,
allowSkipRetake = false,
enableAddDamage = true,
addDamage = AddDamage.PART_SELECT,
sightGuidelines,
enableTutorial = PhotoCaptureTutorialOption.FIRST_TIME_ONLY,
allowSkipTutorial = true,
Expand Down Expand Up @@ -261,14 +262,15 @@ export function PhotoCapture({
onSelectSight: sightState.selectSight,
onRetakeSight: sightState.retakeSight,
onAddDamage: addDamageHandle.handleAddDamage,
onAddDamageParts: addDamageHandle.handleAddParts,
onCancelAddDamage: addDamageHandle.handleCancelAddDamage,
onRetry: sightState.retryLoadingInspection,
loading,
onClose,
inspectionId,
showCloseButton,
images,
enableAddDamage,
addDamage,
sightGuidelines,
enableSightGuidelines,
currentTutorialStep,
Expand Down Expand Up @@ -310,7 +312,7 @@ export function PhotoCapture({
onBack={handleGalleryBack}
onNavigateToCapture={handleNavigateToCapture}
onValidate={handleGalleryValidate}
enableAddDamage={enableAddDamage}
addDamage={addDamage}
validateButtonLabel={validateButtonLabel}
isInspectionCompleted={sightState.isInspectionCompleted}
{...complianceOptions}
Expand Down
Loading