mirror of
https://github.com/inventree/InvenTree.git
synced 2026-04-01 00:51:06 +00:00
[UI Update image fix (#11557)
* Improve thumbnail selector - Center image - Better descriptive text * Updated playwrigth testing
This commit is contained in:
@@ -82,8 +82,14 @@ const removeModal = (apiPath: string, setImage: (image: string) => void) =>
|
|||||||
),
|
),
|
||||||
labels: { confirm: t`Remove`, cancel: t`Cancel` },
|
labels: { confirm: t`Remove`, cancel: t`Cancel` },
|
||||||
onConfirm: async () => {
|
onConfirm: async () => {
|
||||||
await api.patch(apiPath, { image: null });
|
api.patch(apiPath, { image: null }).then(() => {
|
||||||
setImage(backup_image);
|
setImage(backup_image);
|
||||||
|
showNotification({
|
||||||
|
title: t`Image removed`,
|
||||||
|
message: t`The image has been removed successfully`,
|
||||||
|
color: 'green'
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Trans } from '@lingui/react/macro';
|
|||||||
import {
|
import {
|
||||||
AspectRatio,
|
AspectRatio,
|
||||||
Button,
|
Button,
|
||||||
|
Center,
|
||||||
Divider,
|
Divider,
|
||||||
Group,
|
Group,
|
||||||
Pagination,
|
Pagination,
|
||||||
@@ -21,6 +22,7 @@ import { Suspense, useState } from 'react';
|
|||||||
|
|
||||||
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
|
||||||
import { apiUrl } from '@lib/functions/Api';
|
import { apiUrl } from '@lib/functions/Api';
|
||||||
|
import { showNotification } from '@mantine/notifications';
|
||||||
import { IconX } from '@tabler/icons-react';
|
import { IconX } from '@tabler/icons-react';
|
||||||
import { api } from '../../App';
|
import { api } from '../../App';
|
||||||
import { Thumbnail } from '../../components/images/Thumbnail';
|
import { Thumbnail } from '../../components/images/Thumbnail';
|
||||||
@@ -71,7 +73,8 @@ function PartThumbComponent({
|
|||||||
color = hoverColor;
|
color = hoverColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
const src: string | undefined = element?.image ? element?.image : undefined;
|
const src: string | undefined = element?.image || undefined;
|
||||||
|
const imageName = element.image?.split('/')?.at(-1) ?? '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
@@ -82,11 +85,13 @@ function PartThumbComponent({
|
|||||||
onClick={() => selectImage(element.image)}
|
onClick={() => selectImage(element.image)}
|
||||||
>
|
>
|
||||||
<Stack justify='space-between'>
|
<Stack justify='space-between'>
|
||||||
<AspectRatio ratio={1}>
|
<Center>
|
||||||
<Thumbnail size={120} src={src} align='center' />
|
<AspectRatio ratio={1}>
|
||||||
</AspectRatio>
|
<Thumbnail size={120} src={src} align='center' />
|
||||||
|
</AspectRatio>
|
||||||
|
</Center>
|
||||||
<Text size='xs'>
|
<Text size='xs'>
|
||||||
{element.image.split('/')[1]} ({element.count})
|
{imageName || element.image} ({element.count})
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Paper>
|
</Paper>
|
||||||
@@ -114,6 +119,11 @@ async function setNewImage(
|
|||||||
if (response.data.image.includes(image)) {
|
if (response.data.image.includes(image)) {
|
||||||
setImage(response.data.image);
|
setImage(response.data.image);
|
||||||
modals.closeAll();
|
modals.closeAll();
|
||||||
|
showNotification({
|
||||||
|
title: t`Image updated`,
|
||||||
|
message: t`The image has been updated successfully`,
|
||||||
|
color: 'green'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,6 +207,7 @@ export function PartThumbTable({ pk, setImage }: Readonly<ThumbTableProps>) {
|
|||||||
<Group justify='left' gap='xs'>
|
<Group justify='left' gap='xs'>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={t`Search...`}
|
placeholder={t`Search...`}
|
||||||
|
aria-label='part-thumb-search'
|
||||||
value={filterInput}
|
value={filterInput}
|
||||||
onChange={(event) => {
|
onChange={(event) => {
|
||||||
setFilterInput(event.currentTarget.value);
|
setFilterInput(event.currentTarget.value);
|
||||||
|
|||||||
@@ -65,6 +65,38 @@ test('Parts - Tabs', async ({ browser }) => {
|
|||||||
await loadTab(page, 'Build Orders');
|
await loadTab(page, 'Build Orders');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Parts - Image Selection', async ({ browser }) => {
|
||||||
|
const page = await doCachedLogin(browser, { url: 'part/911/details' });
|
||||||
|
|
||||||
|
// Select a new image from the available images
|
||||||
|
await page
|
||||||
|
.getByRole('tabpanel', { name: 'Part Details' })
|
||||||
|
.locator('img')
|
||||||
|
.hover();
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'action-button-select-from-' })
|
||||||
|
.click();
|
||||||
|
await page.getByRole('textbox', { name: 'part-thumb-search' }).fill('red');
|
||||||
|
await page
|
||||||
|
.locator('div')
|
||||||
|
.filter({ hasText: /^chair_red\.png \(1\)$/ })
|
||||||
|
.nth(1)
|
||||||
|
.click();
|
||||||
|
await page.getByRole('button', { name: 'Select' }).click();
|
||||||
|
await page.getByText('The image has been updated successfully').waitFor();
|
||||||
|
|
||||||
|
// Now remove the associated image
|
||||||
|
await page
|
||||||
|
.getByRole('tabpanel', { name: 'Part Details' })
|
||||||
|
.locator('img')
|
||||||
|
.hover();
|
||||||
|
await page
|
||||||
|
.getByRole('button', { name: 'action-button-delete-image' })
|
||||||
|
.click();
|
||||||
|
await page.getByRole('button', { name: 'Remove' }).click();
|
||||||
|
await page.getByText('The image has been removed successfully').waitFor();
|
||||||
|
});
|
||||||
|
|
||||||
test('Parts - Manufacturer Parts', async ({ browser }) => {
|
test('Parts - Manufacturer Parts', async ({ browser }) => {
|
||||||
const page = await doCachedLogin(browser, { url: 'part/84/' });
|
const page = await doCachedLogin(browser, { url: 'part/84/' });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user