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

Disable option for AddDamage feature #727

Merged
merged 1 commit into from
May 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function PhotoCapturePage() {
enforceOrientation={DeviceOrientation.LANDSCAPE}
allowSkipRetake={false}
useLiveCompliance={true}
enableAddDamage={false}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export interface PhotoCaptureProps
* @default false
*/
allowSkipRetake?: boolean;
/**
* Boolean indicating if `Add Damage` feature should be enabled or not. If disabled, the `Add Damage` button will be hidden.
*
* @default true
*/
enableAddDamage?: boolean;
}

enum PhotoCaptureScreen {
Expand All @@ -109,6 +115,7 @@ export function PhotoCapture({
enableCompliance = true,
useLiveCompliance = false,
allowSkipRetake = false,
enableAddDamage = true,
complianceIssues,
lang,
enforceOrientation,
Expand Down Expand Up @@ -204,6 +211,7 @@ export function PhotoCapture({
inspectionId,
showCloseButton,
images,
enableAddDamage,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ export interface PhotoCaptureHUDProps extends CameraHUDProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating if `Add Damage` feature should be enabled or not. If disabled, the `Add Damage` button will be hidden.
*
* @default true
*/
enableAddDamage?: boolean;
}

/**
Expand All @@ -102,6 +108,7 @@ export function PhotoCaptureHUD({
handle,
cameraPreview,
images,
enableAddDamage,
}: PhotoCaptureHUDProps) {
const { t } = useTranslation();
const [showCloseModal, setShowCloseModal] = useState(false);
Expand Down Expand Up @@ -135,6 +142,7 @@ export function PhotoCaptureHUD({
error={loading.error ?? handle.error}
streamDimensions={handle.dimensions}
images={images}
enableAddDamage={enableAddDamage}
/>
</div>
<PhotoCaptureHUDButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export interface PhotoCaptureHUDPreviewProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating if `Add Damage` feature should be enabled or not. If disabled, the `Add Damage` button will be hidden.
*
* @default true
*/
enableAddDamage?: boolean;
}

/**
Expand All @@ -71,6 +77,7 @@ export function PhotoCaptureHUDPreview(params: PhotoCaptureHUDPreviewProps) {
onAddDamage={params.onAddDamage}
streamDimensions={params.streamDimensions}
images={params.images}
enableAddDamage={params.enableAddDamage}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Button } from '@monkvision/common-ui-web';
import { CSSProperties } from 'react';
import { useTranslation } from 'react-i18next';
import { usePhotoCaptureHUDButtonBackground } from '../../hooks';

Expand All @@ -10,18 +11,30 @@ export interface AddDamageButtonProps {
* Callback called when the user presses the button.
*/
onAddDamage?: () => void;
/**
* Boolean indicating whether the Add Damage feature is enabled. If disabled, the `Add Damage` button will be hidden.
*
* @default true
*/
enableAddDamage?: boolean;
}

function getButtonStyle(enableAddDamage?: boolean): CSSProperties {
return { visibility: enableAddDamage ? 'visible' : 'hidden' };
}

/**
* Custom button displayed in the PhotoCapture Camera HUD that allows user to enter add damage mode.
*/
export function AddDamageButton({ onAddDamage }: AddDamageButtonProps) {
export function AddDamageButton({ onAddDamage, enableAddDamage }: AddDamageButtonProps) {
const { t } = useTranslation();
const primaryColor = usePhotoCaptureHUDButtonBackground();

return (
<Button
icon='add'
style={getButtonStyle(enableAddDamage)}
disabled={!enableAddDamage}
onClick={onAddDamage}
data-testid='monk-test-btn'
primaryColor={primaryColor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export interface PhotoCaptureHUDSightPreviewProps {
* The current images taken by the user (ignoring retaken pictures etc.).
*/
images: Image[];
/**
* Boolean indicating whether the Add Damage feature is disabled. If disabled, the `Add Damage` button will be hidden.
*
* @default true
*/
enableAddDamage?: boolean;
}

/**
Expand All @@ -53,6 +59,7 @@ export function PhotoCaptureHUDPreviewSight({
sightsTaken,
streamDimensions,
images,
enableAddDamage,
}: PhotoCaptureHUDSightPreviewProps) {
const style = usePhotoCaptureHUDSightPreviewStyle();
const aspectRatio = `${streamDimensions?.width}/${streamDimensions?.height}`;
Expand All @@ -68,7 +75,7 @@ export function PhotoCaptureHUDPreviewSight({
totalSights={sights.length}
sightsTaken={sightsTaken.length}
/>
<AddDamageButton onAddDamage={onAddDamage} />
<AddDamageButton onAddDamage={onAddDamage} enableAddDamage={enableAddDamage} />
</div>
<SightSlider
sights={sights}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const styles: Styles = {
scrollbarWidth: 'none',
maxWidth: '60vw',
zIndex: '9',
bottom: '0',
bottom: '10px',
right: `${PHOTO_CAPTURE_HUD_BUTTONS_BAR_WIDTH * 2}px`,
left: '0',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function createProps(): PhotoCaptureProps {
showCloseButton: true,
lang: 'de',
allowSkipRetake: true,
enableAddDamage: true,
};
}

Expand Down Expand Up @@ -233,6 +234,7 @@ describe('PhotoCapture component', () => {
showCloseButton: props.showCloseButton,
onOpenGallery: expect.any(Function),
images,
enableAddDamage: props.enableAddDamage,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,15 @@ describe('AddDamageButton component', () => {

unmount();
});

it('should be disabled and not visible when enableAddDamage is false', () => {
const onAddDamage = jest.fn();
const { unmount } = render(
<AddDamageButton onAddDamage={onAddDamage} enableAddDamage={false} />,
);

expectPropsOnChildMock(Button, { style: { visibility: 'hidden' }, disabled: true });

unmount();
});
});