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

Gallery View and image info dialog #1081 #1099 #1083 #1082 #1145

Merged
merged 35 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a65b74c
gallery view #1081 #1084
joshuadkitenge Nov 1, 2024
35408f8
Merge branch 'upload-images-#1062' into gallery-view-#1081
joshuadkitenge Nov 1, 2024
5dc385e
Merge branch 'upload-images-#1062' into gallery-view-#1081
joshuadkitenge Nov 1, 2024
23d092f
add primary images query #1081
joshuadkitenge Nov 4, 2024
55240cc
update images and add failed thumbnail in mock data #1081
joshuadkitenge Nov 4, 2024
a81f14a
invalidate images request on close #1081
joshuadkitenge Nov 4, 2024
ccd7280
Add pagination to thumbnail view #1099
joshuadkitenge Nov 4, 2024
2ede0d3
Merge branch 'develop' into gallery-view-#1081
joshuadkitenge Nov 4, 2024
0198cda
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Nov 4, 2024
c36b1ff
fix styling on thumbnail grid #1081
joshuadkitenge Nov 6, 2024
af56615
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Nov 6, 2024
180761a
Address review comments #1081
joshuadkitenge Nov 6, 2024
ebe72e7
Merge branch 'develop' into gallery-view-#1081
joshuadkitenge Nov 7, 2024
0c21d5d
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Nov 7, 2024
4e4a5e9
use MRT for cardView #1099
joshuadkitenge Nov 7, 2024
1e3868a
fix grid styling #1081
joshuadkitenge Nov 7, 2024
c08a488
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Nov 7, 2024
19de890
Add image information dialog #1083 #1082
joshuadkitenge Nov 8, 2024
7f87baa
closes dialog after test #1082 #1083
joshuadkitenge Nov 12, 2024
381cff1
change download_url to url #1081
joshuadkitenge Nov 21, 2024
7581df4
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Nov 21, 2024
9b6b97e
Merge branch 'add-pagination-to-thumbnail-view-#1099' into feature/im…
joshuadkitenge Nov 21, 2024
c704a36
improve styling #1081
joshuadkitenge Nov 22, 2024
c16564c
Remove react-photoswipe-gallery and use creat custom lightbox
joshuadkitenge Dec 4, 2024
23fd79c
fix image endpoint return value #1081
joshuadkitenge Dec 4, 2024
a089b7b
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Dec 4, 2024
a1962d1
Merge branch 'add-pagination-to-thumbnail-view-#1099' into feature/im…
joshuadkitenge Dec 4, 2024
42b6334
Merge branch 'feature/image-information-dialog-#1082-#1083' into cust…
joshuadkitenge Dec 4, 2024
66b6367
change alt text to description #1081
joshuadkitenge Dec 4, 2024
09d56c4
Merge branch 'gallery-view-#1081' into add-pagination-to-thumbnail-vi…
joshuadkitenge Dec 4, 2024
2ddc9fa
Merge branch 'add-pagination-to-thumbnail-view-#1099' into feature/im…
joshuadkitenge Dec 4, 2024
040390d
Merge branch 'feature/image-information-dialog-#1082-#1083' into cust…
joshuadkitenge Dec 4, 2024
9dadad5
address review comments
joshuadkitenge Dec 5, 2024
3323708
Merge branch 'develop' into custom-light-box
joshuadkitenge Dec 9, 2024
b72d8e1
Address review comment
joshuadkitenge Dec 9, 2024
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
194 changes: 194 additions & 0 deletions cypress/e2e/with_mock_data/items.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,200 @@ describe('Items', () => {

cy.findByText('Upload failed').should('exist');
});

it('falls back to placeholder thumbnail', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();
cy.findByText('The image cannot be loaded').should('exist');
});

it('displays and hides filters, applies and clears name filter on gallery view', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();
cy.findAllByText('stfc-logo-blue-text.png').should('have.length', 8);
cy.findByText('Show Filters').click();
cy.findByRole('button', { name: 'Clear Filters' }).should('be.disabled');
cy.findByLabelText('Filter by File name').type('logo1.png');
cy.findByAltText('test').should('not.exist');
cy.findByRole('button', { name: 'Clear Filters' }).click();
cy.findAllByText('stfc-logo-blue-text.png').should('have.length', 8);
cy.findByText('Hide Filters').click();
cy.findByText('Show Filters').should('exist');
});

it('opens information dialog from card view', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findAllByLabelText('Card Actions').first().click();
cy.findAllByText('Information').last().click();

cy.findByRole('dialog').within(() => {
cy.findByText('Image Information').should('exist');
cy.findByText('stfc-logo-blue-text').should('exist');
cy.findByText('stfc-logo-blue-text.png').should('exist');
cy.findByText('test').should('exist');
cy.findByText('No').should('exist');

cy.findByRole('button', { name: 'Close' }).click();
});

cy.findByText('Image information').should('not.exist');
});

it('opens full-size image when thumbnail is clicked and navigates to the next image', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findAllByAltText('test').first().click();
cy.findByTestId('galleryLightBox').within(() => {
cy.findByText('File name: stfc-logo-blue-text.png').should('exist');
cy.findByText('Title: stfc-logo-blue-text').should('exist');
cy.findByText('test').should('exist');

cy.findByAltText('test').should('exist');

cy.findByAltText('test')
.should('have.attr', 'src')
.and(
'include',
'http://localhost:3000/images/stfc-logo-blue-text.png?text=1'
);

cy.findByLabelText('Next').click();

cy.findByText('File name: logo1.png').should('exist');
cy.findByText('Title: logo1').should('exist');
cy.findByText('test').should('exist');

cy.findByAltText('test').should('exist');

cy.findByAltText('test')
.should('have.attr', 'src')
.and('include', 'http://localhost:3000/logo192.png?text=2');
cy.findByLabelText('Close').click();
});

cy.findByTestId('galleryLightBox').should('not.exist');
});

it('opens corrupted image, and navigates back to previous image (invalid url)', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findByText('The image cannot be loaded').click();
cy.findByTestId('galleryLightBox').within(() => {
cy.findByText('File name: stfc-logo-blue-text.png').should('exist');
cy.findByText('Title: stfc-logo-blue-text').should('exist');
cy.findByText('No description available').should('exist');

cy.findByText('The image cannot be loaded').should('exist');

cy.findByLabelText('Previous').click();

cy.findByText('File name: logo1.png').should('exist');
cy.findByText('Title: logo1').should('exist');
cy.findByText('test').should('exist');

cy.findByAltText('test').should('exist');

cy.findByAltText('test')
.should('have.attr', 'src')
.and('include', 'http://localhost:3000/logo192.png?text=2');
cy.findByLabelText('Close').click();
});

cy.findByTestId('galleryLightBox').should('not.exist');
});

it('opens corrupted image (network error)', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findAllByAltText('test').eq(3).click();
cy.findByTestId('galleryLightBox').within(() => {
cy.findByText('The image cannot be loaded', { timeout: 10000 }).should(
'exist'
);

cy.findByText('File name: stfc-logo-blue-text.png').should('exist');
cy.findByText('Title: stfc-logo-blue-text').should('exist');
cy.findByText('test').should('exist');

cy.findByLabelText('Close').click();
});

cy.findByTestId('galleryLightBox').should('not.exist');
});

it('opens information dialog in lightbox', () => {
cy.findByText('5YUQDDjKpz2z').click();
cy.findByText(
'High-resolution cameras for beam characterization. 1'
).should('exist');

cy.findByText('Gallery').click();

cy.findAllByAltText('test').first().click();
cy.findByTestId('galleryLightBox').within(() => {
cy.findByText('File name: stfc-logo-blue-text.png').should('exist');
cy.findByText('Title: stfc-logo-blue-text').should('exist');
cy.findByText('test').should('exist');

cy.findByAltText('test').should('exist');

cy.findByAltText('test')
.should('have.attr', 'src')
.and(
'include',
'http://localhost:3000/images/stfc-logo-blue-text.png?text=1'
);

cy.findByLabelText('Image Actions').click();
});

cy.findAllByText('Information').last().click();

cy.findByRole('dialog', { timeout: 10000 }).should('exist');

cy.findByRole('dialog').within(() => {
cy.findByText('Image Information').should('exist');
});

cy.findByRole('dialog').within(() => {
cy.findByRole('button', { name: 'Close' }).click();
});

cy.findByRole('dialog').should('not.exist');

cy.findByLabelText('Close').click();

cy.findByTestId('galleryLightBox').should('not.exist');
});
});

it('delete an item', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/api/api.types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,14 @@ export interface ImagePost {
description?: string | null;
}

export interface Image
export interface APIImage
joshuadkitenge marked this conversation as resolved.
Show resolved Hide resolved
extends Required<Omit<ImagePost, 'upload_file'>>,
CreatedModifiedMixin {
id: string;
primary: boolean;
thumbnail_base64: string;
}

export interface ImageGet extends APIImage {
joshuadkitenge marked this conversation as resolved.
Show resolved Hide resolved
url: string;
}
53 changes: 53 additions & 0 deletions src/api/images.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { renderHook, waitFor } from '@testing-library/react';
import ImagesJSON from '../mocks/Images.json';
import { hooksWrapperWithProviders } from '../testUtils';
import { useGetImage, useGetImages } from './images';

describe('images api functions', () => {
afterEach(() => {
vi.clearAllMocks();
});

describe('useGetImages', () => {
it('sends request to fetch image data and returns successful response', async () => {
const { result } = renderHook(() => useGetImages('1'), {
wrapper: hooksWrapperWithProviders(),
});

await waitFor(() => {
expect(result.current.isSuccess).toBeTruthy();
});

expect(result.current.data?.length).toEqual(20);
});

it('sends request to fetch primary image data and returns successful response', async () => {
const { result } = renderHook(() => useGetImages('1', true), {
wrapper: hooksWrapperWithProviders(),
});

await waitFor(() => {
expect(result.current.isSuccess).toBeTruthy();
});

expect(result.current.data?.length).toEqual(1);
});
});

describe('useGetImage', () => {
it('sends request to fetch image data and returns successful response', async () => {
const { result } = renderHook(() => useGetImage('1'), {
wrapper: hooksWrapperWithProviders(),
});

await waitFor(() => {
expect(result.current.isSuccess).toBeTruthy();
});

expect(result.current.data).toEqual({
...ImagesJSON[1],
url: 'http://localhost:3000/images/stfc-logo-blue-text.png?text=1',
});
});
});
});
46 changes: 46 additions & 0 deletions src/api/images.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { storageApi } from './api';
import { APIImage, ImageGet } from './api.types';

export const getImage = async (id: string): Promise<ImageGet> => {
return storageApi.get(`/images/${id}`).then((response) => {
return response.data;
});
};

export const useGetImage = (
id?: string
): UseQueryResult<ImageGet, AxiosError> => {
return useQuery({
queryKey: ['Image', id],
queryFn: () => getImage(id ?? ''),
enabled: !!id,
});
};

const getImages = async (
entityId: string,
primary?: boolean
): Promise<APIImage[]> => {
const queryParams = new URLSearchParams();
queryParams.append('entity_id', entityId);

if (primary !== undefined) queryParams.append('primary', String(primary));
return storageApi
.get(`/images`, {
params: queryParams,
})
.then((response) => response.data);
};

export const useGetImages = (
entityId?: string,
primary?: boolean
): UseQueryResult<APIImage[], AxiosError> => {
return useQuery({
queryKey: ['Images', entityId, primary],
queryFn: () => getImages(entityId ?? '', primary),
enabled: !!entityId,
});
};
1 change: 0 additions & 1 deletion src/common/actionMenu.component.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@testing-library/jest-dom';
import { screen, waitFor } from '@testing-library/react';
import userEvent, { UserEvent } from '@testing-library/user-event';
import { vi } from 'vitest';
Expand Down
Loading
Loading