Skip to content
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
4 changes: 3 additions & 1 deletion README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ Uploads become WebP images with a maximum long edge of 1920 pixels, without enla

Items are sorted by latest update by default.

New items reuse the most recently added item's category, locations, brand, style and variant settings in the current area. Enter a new name, barcode, tags and photos; the private checkbox is not carried over.

The background moves subtly as you scroll, and item cards slide into view on their first entrance. The first screen appears immediately. Both effects respect the system's reduced-motion preference.

The first visit downloads the interface. If a module fails to load after login, the page reloads once to fetch the current application; if it fails again, use Reload to try again.

Click the app name at the top-left to unlock the private area. Locking or refreshing hides it again.
Click the app name at the top-left to unlock the private area and show only private items. Click it again to return to ordinary items. Refreshing hides the private area again.

## Development

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ docker compose up -d

物品默认按最近更新排列。

新增物品沿用当前区域最近新增物品的分类、位置、品牌、款式及规格设置;名称、条码、标签、图片和隐私勾选重新填写。

滚动时背景轻微视差移动,物品卡片首次滚入视野时滑入显示。首屏内容直接显示,系统开启“减少动态效果”时关闭这两种动效。

首次打开会下载界面程序。若文件加载失败,登录后会自动重新加载最新页面一次;仍失败可点击“重新加载”重试。

点击左上角“物品管理”输入隐私区密码;解锁后可设置隐私物品、分类和位置;物品的隐私开关位于“标签”右侧。锁定或刷新后重新隐藏。
点击左上角“物品管理”输入隐私区密码;解锁后只显示隐私物品,也可设置隐私物品、分类和位置;物品的隐私开关位于“标签”右侧。再次点击收起,恢复普通物品;刷新后重新隐藏。

## 开发

Expand Down
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itemmanager/desktop",
"version": "26.8.0",
"version": "26.9.0",
"private": true,
"description": "物品管理桌面客户端",
"author": "MCJ",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "itemmanager-workspace",
"version": "26.8.0",
"version": "26.9.0",
"private": true,
"license": "MIT",
"packageManager": "pnpm@11.7.0",
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@itemmanager/web",
"version": "26.8.0",
"version": "26.9.0",
"private": true,
"license": "MIT",
"packageManager": "pnpm@11.7.0",
Expand Down
14 changes: 8 additions & 6 deletions web/src/renderer/features/items/ItemEditorModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function createVariantRow(row = { color: '', size: '', isPackaged: false }) {
return { ...row, rowKey: ++variantRowSequence };
}

function normalizeItem(item, categories, locations, mode = 'edit') {
function normalizeItem(item, categories, locations, mode = 'edit', defaultsFromItem = null) {
if (item) {
return {
...(mode === 'copy' ? {} : { id: item.id }),
Expand All @@ -53,8 +53,9 @@ function normalizeItem(item, categories, locations, mode = 'edit') {
};
}

const empty = createEmptyItemDraft(categories, locations);
return { ...empty, imagePaths: [], imagePath: '', variants: getItemVariants(empty).map(createVariantRow), locationIds: [empty.locationId || ''], isPrivate: false };
const empty = createEmptyItemDraft(categories, locations, mode === 'create' ? defaultsFromItem : null);
const locationIds = getItemLocationIds(empty);
return { ...empty, imagePaths: [], imagePath: '', variants: getItemVariants(empty).map(createVariantRow), locationIds: locationIds.length ? locationIds : [''], isPrivate: false };
}

function buildCategorySelection(categories, categoryId) {
Expand All @@ -80,6 +81,7 @@ export default function ItemEditorModal({
open,
mode = 'edit',
item = null,
defaultsFromItem = null,
categories = [],
locations = [],
availableTags = [],
Expand All @@ -90,7 +92,7 @@ export default function ItemEditorModal({
onDelete,
onCopy
}) {
const [draft, setDraft] = useState(() => normalizeItem(item, categories, locations, mode));
const [draft, setDraft] = useState(() => normalizeItem(item, categories, locations, mode, defaultsFromItem));
const [dirtyDraft, setDirtyDraft] = useState(false);
const [tagInput, setTagInput] = useState('');
const [imageFeedback, setImageFeedback] = useState({ type: '', message: '' });
Expand Down Expand Up @@ -144,7 +146,7 @@ export default function ItemEditorModal({
} else {
browserEditorSessionRef.current = null;
}
setDraft(normalizeItem(item, categories, locations, mode));
setDraft(normalizeItem(item, categories, locations, mode, defaultsFromItem));
setDirtyDraft(false);
setActiveTab('edit');
setTagInput('');
Expand All @@ -153,7 +155,7 @@ export default function ItemEditorModal({
replacePendingImages([]);
stagedBrowserUploadRef.current.clear();
stagedImageCopyRef.current.clear();
}, [open, item, categories, locations, mode, imageAccess]);
}, [open, item, categories, locations, mode, imageAccess, defaultsFromItem]);

const categorySelection = useMemo(
() => buildCategorySelection(categories, draft.categoryId),
Expand Down
5 changes: 4 additions & 1 deletion web/src/renderer/features/items/ItemsGalleryPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function ItemsGalleryPage({
setModalState({
open: true,
mode: 'create',
itemId: null
itemId: null,
// Reverse the stable tie order for older records without creation dates.
defaultsFromItem: sortItemGalleryItems([...allItems].reverse(), 'created-desc')[0] || null
});
}

Expand Down Expand Up @@ -257,6 +259,7 @@ export default function ItemsGalleryPage({

<ItemEditorModal
canManagePrivacy={canManagePrivacy}
defaultsFromItem={modalState.mode === 'create' ? modalState.defaultsFromItem : null}
open={modalState.open}
mode={modalState.mode}
item={modalState.mode === 'copy' ? modalState.copyItem : modalState.mode === 'edit' ? editingItem : null}
Expand Down
25 changes: 22 additions & 3 deletions web/src/renderer/features/items/item-gallery-selectors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalizeItemDetail } from './item-detail-text';
import { formatItemVariants, getItemQuantity, getItemVariants, hasItemPackaging } from '../../../../shared/item-variants.mjs';
import { formatItemVariants, getItemQuantity, getItemVariants, getVariantQuantity, hasItemPackaging } from '../../../../shared/item-variants.mjs';
import { collectDescendantIds, getChildEntries, getItemLocationIds, getNodeLineage, normalizeTagCodes, toText } from '../../lib/project-data';

export function formatCompactPath(path) {
Expand Down Expand Up @@ -45,14 +45,14 @@ export function sortItemGalleryItems(items = [], sort = 'updated-desc') {
.map(({ item }) => item);
}

export function createEmptyItemDraft(categories = [], locations = []) {
export function createEmptyItemDraft(categories = [], locations = [], previousItem = null) {
const firstMainCategory = getChildEntries(categories, null)[0] || null;
const firstSubCategory = firstMainCategory ? getChildEntries(categories, firstMainCategory.id)[0] || null : null;
const level1Location = getChildEntries(locations, null)[0] || null;
const level2Location = level1Location ? getChildEntries(locations, level1Location.id)[0] || null : null;
const level3Location = level2Location ? getChildEntries(locations, level2Location.id)[0] || null : null;

return {
const empty = {
barcode: '',
code: '',
name: '',
Expand All @@ -65,6 +65,25 @@ export function createEmptyItemDraft(categories = [], locations = []) {
imagePath: '',
tags: []
};
if (!previousItem) return empty;

const locationIds = getItemLocationIds(previousItem).filter(id => locations.some(location => location.id === id));
const rows = getItemVariants(previousItem);
const variants = (rows.length ? rows : getItemVariants(empty)).map(row => ({
color: row.color, size: row.size, quantity: getVariantQuantity(row), isPackaged: row.isPackaged, imageId: ''
}));
return {
...empty,
brand: toText(previousItem.brand),
specification: toText(previousItem.specification),
categoryId: categories.some(category => category.id === previousItem.categoryId) ? previousItem.categoryId : null,
locationId: locationIds[0] || null,
locationIds,
variants,
quantity: getItemQuantity({ variants }),
isPackaged: variants.some(row => row.isPackaged),
isPrivate: false
};
}

export function buildTagChips(items = []) {
Expand Down
12 changes: 9 additions & 3 deletions web/src/renderer/features/web/WebApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
import AppShell from '../layout/AppShell';
import { applyItemGalleryFilters } from '../items/item-gallery-selectors';
import { createProjectStore, useProjectStore } from '../../store/project-store';
import { sanitizeProject, syncProjectItems } from '../../lib/project-data';
import { isItemPrivate, sanitizeProject, syncProjectItems } from '../../lib/project-data';
import { createWebApi } from './api';
import { ImageAccessProvider } from './ImageAccessContext';
import './web.css';
Expand Down Expand Up @@ -226,7 +226,13 @@ export default function WebApp({ fetchImpl, bootstrap }) {
}

const project = state.currentProject;
const visibleItems = useMemo(() => project ? applyItemGalleryFilters(project.items, project.categories, project.locations, state.itemFilters, state.search) : [], [project, state.itemFilters, state.search]);
// Keep the complete authorized project in the store for every save. The
// unlocked view displays only its private items, including inherited privacy.
const viewProject = useMemo(() => !project || !privacyOpen ? project : {
...project,
items: project.items.filter(item => isItemPrivate(item, project))
}, [project, privacyOpen]);
const visibleItems = useMemo(() => viewProject ? applyItemGalleryFilters(viewProject.items, viewProject.categories, viewProject.locations, state.itemFilters, state.search) : [], [viewProject, state.itemFilters, state.search]);

if (!authenticated) return <main className="web-login-page">
<form className="dialog-card web-login-card" onSubmit={login}>
Expand Down Expand Up @@ -257,7 +263,7 @@ export default function WebApp({ fetchImpl, bootstrap }) {
</div> : null}
{project ? <ImageAccessProvider api={api} key={privacyEpoch}>
<AppShell
project={project} canManagePrivacy={privacyOpen} interactionDisabled={busy} catalogSaveOnConfirm
project={viewProject} canManagePrivacy={privacyOpen} interactionDisabled={busy} catalogSaveOnConfirm
selectedSection={state.selectedSection} selectedCatalogMode={state.selectedCatalogMode}
selectedCatalogNodeId={state.selectedCatalogNodeIds[state.selectedCatalogMode]} selectedItemId={state.selectedItemId}
visibleItems={visibleItems} search={state.search} filters={state.itemFilters}
Expand Down
1 change: 1 addition & 0 deletions web/src/renderer/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ button:not(:disabled):hover {

.item-gallery-card__content {
display: grid;
grid-template-rows: auto 0.864rem 14px;
min-width: 0;
gap: 2px;
padding: 0 1px;
Expand Down
81 changes: 81 additions & 0 deletions web/tests/renderer/item-create-defaults.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { cleanup, render, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { afterEach, describe, expect, it, vi } from 'vitest';
import ItemsGalleryPage from '../../src/renderer/features/items/ItemsGalleryPage';
import { createEmptyItemDraft } from '../../src/renderer/features/items/item-gallery-selectors';

const categories = [{ id: 'first', name: '办公', level: 1 }, { id: 'clothes', name: '服装', level: 1 }];
const locations = [{ id: 'desk', name: '书桌', level: 1 }, { id: 'closet', name: '衣柜', level: 1 }];
const previous = {
id: 'previous', name: '上一件', brand: '品牌', specification: '印花 镂空', categoryId: 'clothes',
locationIds: ['closet', 'desk'], isPrivate: true, barcode: 'CODE', tags: ['YF-001'],
imagePaths: ['photo-one', 'photo-two'], createdAt: '2026-10-28T00:00:00Z',
variants: [{ color: '蓝色', size: 'XL', quantity: 3, isPackaged: true, imageId: 'photo-one' },
{ color: '白色', size: 'M', quantity: 1, isPackaged: false, imageId: 'photo-two' }]
};
afterEach(() => { cleanup(); vi.restoreAllMocks(); });

describe('new item defaults from saved items', () => {
it('reuses selections and specification rows without identity, photos, tags or privacy flags', () => {
const snapshot = structuredClone(previous);
const draft = createEmptyItemDraft(categories, locations, previous);
expect(draft).toMatchObject({ name: '', barcode: '', tags: [], imagePath: '', isPrivate: false,
brand: '品牌', specification: '印花 镂空', categoryId: 'clothes', locationIds: ['closet', 'desk'],
variants: [{ color: '蓝色', size: 'XL', quantity: 3, isPackaged: true, imageId: '' },
{ color: '白色', size: 'M', quantity: 1, isPackaged: false, imageId: '' }] });
expect(draft).not.toHaveProperty('id');
expect(draft).not.toHaveProperty('createdAt');
draft.variants[0].color = '红色';
draft.locationIds.pop();
expect(previous).toEqual(snapshot);
});

it('does not reintroduce unavailable private categories or locations', () => {
const draft = createEmptyItemDraft(categories, locations, { ...previous, categoryId: 'hidden-category', locationIds: ['hidden-place', 'desk'] });
expect(draft.categoryId).toBeNull();
expect(draft.locationIds).toEqual(['desk']);
expect(draft.isPrivate).toBe(false);
});

it('opens a fresh item using the most recently added record instead of the last edited record', async () => {
const old = { ...previous, id: 'old', name: '旧物品', categoryId: 'first', createdAt: '2025-01-01T00:00:00Z', updatedAt: '2026-10-29T23:00:00Z' };
const newest = { ...previous, id: 'newest', name: '新物品', isPrivate: false };
const onCreateItem = vi.fn().mockResolvedValue(undefined);
render(<ItemsGalleryPage allItems={[newest, old]} items={[old]} categories={categories} locations={locations}
onCreateItem={onCreateItem} canManagePrivacy />);
const user = userEvent.setup();
await user.click(screen.getByRole('button', { name: '新增物品', exact: true }));
expect(screen.getByLabelText('名称')).toHaveValue('');
expect(screen.getByLabelText('主分类')).toHaveValue('clothes');
expect(screen.getByLabelText('颜色1')).toHaveValue('蓝色');
expect(screen.getByLabelText('尺码1')).toHaveValue('XL');
expect(screen.getByLabelText('数量1')).toHaveValue(3);
expect(screen.getByLabelText('包装1')).toBeChecked();
expect(screen.getAllByLabelText('一级位置').map(select => select.value)).toEqual(['closet', 'desk']);
expect(screen.getByLabelText('隐私区')).not.toBeChecked();
expect(screen.queryByRole('button', { name: /放大规格/ })).not.toBeInTheDocument();
await user.type(screen.getByLabelText('名称'), '下一件');
await user.click(within(screen.getByRole('dialog')).getByRole('button', { name: '保存', exact: true }));
expect(onCreateItem).toHaveBeenCalledWith(expect.objectContaining({ name: '下一件', isPrivate: false,
categoryId: 'clothes', locationIds: ['closet', 'desk'], imagePaths: [], tags: [] }));
expect(onCreateItem.mock.calls[0][0]).not.toHaveProperty('id');
expect(onCreateItem.mock.calls[0][0]).not.toHaveProperty('createdAt');
});

it('does not remember canceled changes or the source privacy checkbox', async () => {
vi.spyOn(window, 'confirm').mockReturnValue(true);
const onCreateItem = vi.fn();
render(<ItemsGalleryPage allItems={[previous]} items={[previous]} categories={categories} locations={locations}
onCreateItem={onCreateItem} canManagePrivacy />);
const user = userEvent.setup();
await user.click(screen.getByRole('button', { name: '新增物品', exact: true }));
await user.clear(screen.getByLabelText('颜色1'));
await user.type(screen.getByLabelText('颜色1'), '未保存颜色');
await user.click(screen.getByLabelText('隐私区'));
await user.click(within(screen.getByRole('dialog')).getByRole('button', { name: '取消', exact: true }));
await user.click(screen.getByRole('button', { name: '新增物品', exact: true }));
expect(screen.getByLabelText('颜色1')).toHaveValue('蓝色');
expect(screen.getByLabelText('隐私区')).not.toBeChecked();
expect(onCreateItem).not.toHaveBeenCalled();
});
});
Loading
Loading