feat(packing): change the sharing of a whole list at once (#2961)

The list menu on desktop and phone gets "Sharing for Whole List": pick
Shared, Personal or Shared with people once and every item of yours in
that list moves there through the existing per-item sharing write. Items
other people added stay as they are, and the dialog says so up front.
This commit is contained in:
Maurice
2026-11-13 09:29:55 +01:00
parent 3f68c8a50e
commit 308daec14e
43 changed files with 1126 additions and 10 deletions
@@ -2,12 +2,16 @@ import { describe, expect, it } from 'vitest';
import { buildPackingItem } from '../../../tests/helpers/factories';
import {
agreedSharing,
categorySharingSplit,
formatWeight,
groupPackingItems,
isLastCustomItemInCategory,
isPackingPlaceholder,
itemOrderWithCategoryMoved,
itemsToReshare,
packingCategoryOrder,
packingItemSharing,
packingItemWeight,
packingProgress,
packingStatusFiltered,
@@ -15,7 +19,7 @@ import {
} from './packingListModel';
import { PACKING_PLACEHOLDER_NAME } from './packingListPanel.constants';
// FE-PACK-MODEL-001 to FE-PACK-MODEL-009
// FE-PACK-MODEL-001 to FE-PACK-MODEL-013
const shared = buildPackingItem({ id: 1, name: 'Tent', category: 'Camp', checked: 1 });
const mine = buildPackingItem({ id: 2, name: 'Socks', category: 'Clothes', is_private: 1 });
@@ -102,3 +106,46 @@ describe('packingListModel', () => {
expect(itemOrderWithCategoryMoved(items, items, 'Other', 'Camp', 'Other')).toEqual([4, 1, 3]);
});
});
describe('packingListModel: sharing a whole list (#2961)', () => {
const recipients = (...ids: number[]) => ids.map((user_id) => ({ user_id, username: `u${user_id}` }));
const common = buildPackingItem({ id: 10, category: 'Camp', owner_id: 1 });
const personal = buildPackingItem({ id: 11, category: 'Camp', is_private: 1, owner_id: 1 });
const sharedTwo = buildPackingItem({
id: 12,
category: 'Camp',
is_private: 1,
owner_id: 1,
recipients: recipients(3, 2),
});
const legacy = buildPackingItem({ id: 13, category: 'Camp', owner_id: null });
const theirs = buildPackingItem({ id: 14, category: 'Camp', owner_id: 2 });
it('FE-PACK-MODEL-010: an item reads as common, personal or shared with its people in order', () => {
expect(packingItemSharing(common)).toEqual({ visibility: 'common', recipientIds: [] });
expect(packingItemSharing(personal)).toEqual({ visibility: 'personal', recipientIds: [] });
expect(packingItemSharing(sharedTwo)).toEqual({ visibility: 'shared', recipientIds: [2, 3] });
});
it('FE-PACK-MODEL-011: my items and unowned ones can be moved, the ones of others are only counted', () => {
const split = categorySharingSplit([common, legacy, theirs, personal], 1);
expect(split.own.map((i) => i.id)).toEqual([10, 13, 11]);
expect(split.othersCount).toBe(1);
expect(categorySharingSplit([theirs], 1)).toEqual({ own: [], othersCount: 1 });
});
it('FE-PACK-MODEL-012: the tier the items agree on, or none when they differ', () => {
expect(agreedSharing([common, legacy])).toEqual({ visibility: 'common', recipientIds: [] });
const sameTwo = buildPackingItem({ category: 'Camp', is_private: 1, owner_id: 1, recipients: recipients(2, 3) });
expect(agreedSharing([sharedTwo, sameTwo])).toEqual({ visibility: 'shared', recipientIds: [2, 3] });
expect(agreedSharing([common, personal])).toBeNull();
expect(agreedSharing([])).toBeNull();
});
it('FE-PACK-MODEL-013: only the items not yet at the target tier need a write', () => {
const items = [common, personal, sharedTwo];
expect(itemsToReshare(items, { visibility: 'personal', recipientIds: [] }).map((i) => i.id)).toEqual([10, 12]);
expect(itemsToReshare(items, { visibility: 'shared', recipientIds: [3, 2] }).map((i) => i.id)).toEqual([10, 11]);
expect(itemsToReshare(items, { visibility: 'common', recipientIds: [] }).map((i) => i.id)).toEqual([11, 12]);
});
});