Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: add editable alcohol data table with full history and inline editing
Adam Eivy5148f5d70678
diff --git a/.changelog/v1.11.x.md b/.changelog/v1.11.x.mdnew file mode 100644index 0000000000..0c690ed7bf--- /dev/null+++ b/.changelog/v1.11.x.md@@ -0,0 +1,14 @@+# Release v1.11.x - Changelog++Released: YYYY-MM-DD++## Overview++Alcohol data table: view and edit all imported drink entries with inline editing, pagination, and standard drink recalculation.++## Features++- **Full editable alcohol data table** replacing the 7-day recent drinks view — browse all 700+ daily entries grouped by date with day totals, inline edit any drink (name, oz, ABV, count), and see standard drinks recalculate in real-time+- **Paginated display**: shows 50 days at a time with "Load More" for full history, scrollable with sticky header+- **Update drink API**: `PUT /api/meatspace/alcohol/log/:date/:index` with partial update schema (any combination of name, oz, abv, count)+- 3 new tests for drink update logic with standard drink recalculation verificationdiff --git a/client/src/components/meatspace/tabs/AlcoholTab.jsx b/client/src/components/meatspace/tabs/AlcoholTab.jsxindex 718ffbd39a..4de66b82df 100644--- a/client/src/components/meatspace/tabs/AlcoholTab.jsx+++ b/client/src/components/meatspace/tabs/AlcoholTab.jsx@@ -1,5 +1,5 @@import { useState, useEffect, useCallback } from 'react';-import { Beer, Plus, Trash2, AlertTriangle, TrendingDown, TrendingUp } from 'lucide-react';+import { Beer, Plus, Trash2, AlertTriangle, TrendingDown, TrendingUp, Pencil, Check, X } from 'lucide-react';import * as api from '../../../services/api';import BrailleSpinner from '../../BrailleSpinner';import AlcoholChart from '../AlcoholChart';@@ -27,11 +27,20 @@ const RISK_BG = {high: 'bg-port-error/10 border-port-error/30'};+const DAYS_PER_PAGE = 50;++function computeStdDrinks(oz, abv, count) {+ const pureOz = (oz || 0) * (count || 1) * ((abv || 0) / 100);+ return Math.round((pureOz / 0.6) * 100) / 100;+}+export default function AlcoholTab() {const [summary, setSummary] = useState(null);+ const [allEntries, setAllEntries] = useState(null);const [loading, setLoading] = useState(true);const [logging, setLogging] = useState(false);const [refreshKey, setRefreshKey] = useState(0);+ const [visibleDays, setVisibleDays] = useState(DAYS_PER_PAGE);// Form stateconst [name, setName] = useState('');@@ -40,15 +49,23 @@ export default function AlcoholTab() {const [count, setCount] = useState(1);const [date, setDate] = useState('');- const fetchSummary = useCallback(async () => {- const data = await api.getAlcoholSummary().catch(() => null);- setSummary(data);+ // Inline edit state+ const [editingKey, setEditingKey] = useState(null); // "date:index"+ const [editForm, setEditForm] = useState({ name: '', oz: '', abv: '', count: 1 });++ const fetchData = useCallback(async () => {+ const [summaryData, entries] = await Promise.all([+ api.getAlcoholSummary().catch(() => null),+ api.getDailyAlcohol().catch(() => [])+ ]);+ setSummary(summaryData);+ setAllEntries(entries);setLoading(false);}, []);useEffect(() => {- fetchSummary();- }, [fetchSummary, refreshKey]);+ fetchData();+ }, [fetchData, refreshKey]);const handleQuickAdd = async (drink) => {setLogging(true);@@ -87,6 +104,34 @@ export default function AlcoholTab() {setRefreshKey(k => k + 1);};+ const startEdit = (entryDate, index, drink) => {+ setEditingKey(`${entryDate}:${index}`);+ setEditForm({+ name: drink.name || '',+ oz: String(drink.oz || ''),+ abv: String(drink.abv || ''),+ count: drink.count || 1+ });+ };++ const cancelEdit = () => {+ setEditingKey(null);+ };++ const saveEdit = async () => {+ if (!editingKey) return;+ const [entryDate, indexStr] = editingKey.split(':');+ const index = parseInt(indexStr, 10);+ await api.updateAlcoholDrink(entryDate, index, {+ name: editForm.name,+ oz: parseFloat(editForm.oz),+ abv: parseFloat(editForm.abv),+ count: parseInt(editForm.count, 10) || 1+ }).catch(() => null);+ setEditingKey(null);+ setRefreshKey(k => k + 1);+ };+if (loading) {return (<div className="flex items-center justify-center h-64">@@ -95,6 +140,9 @@ export default function AlcoholTab() {);}+ const visibleEntries = allEntries?.slice(0, visibleDays) || [];+ const hasMore = allEntries?.length > visibleDays;+return (<div className="space-y-6">{/* Rolling Averages Summary */}@@ -243,43 +291,158 @@ export default function AlcoholTab() {</form></div>- {/* Recent Drinks */}- {summary?.recentEntries?.length > 0 && (+ {/* All Drink Entries */}+ {allEntries?.length > 0 && (<div className="bg-port-card border border-port-border rounded-xl p-6"><h3 className="text-sm font-medium text-gray-400 uppercase tracking-wider mb-4">- Recent Drinks (7 days)+ All Drink Entries ({allEntries.length} days)</h3>- <div className="space-y-3">- {summary.recentEntries.map(entry => (- <div key={entry.date} className="border border-port-border rounded-lg p-3">- <div className="flex items-center justify-between mb-2">- <span className="text-sm font-medium text-gray-300">{entry.date}</span>- <span className={`text-sm font-bold ${- entry.alcohol.standardDrinks > (summary.thresholds?.dailyMax || 2) ? 'text-port-error' : 'text-port-accent'- }`}>- {entry.alcohol.standardDrinks} std drinks- </span>- </div>- <div className="space-y-1">- {entry.alcohol.drinks.map((drink, idx) => (- <div key={idx} className="flex items-center justify-between text-xs">- <span className="text-gray-400">- {drink.name || 'Unnamed'} — {drink.oz}oz @ {drink.abv}%- {drink.count > 1 && ` (x${drink.count})`}- </span>- <button- onClick={() => handleRemove(entry.date, idx)}- className="text-gray-600 hover:text-port-error transition-colors p-1"- title="Remove drink"+ <div className="max-h-[70vh] overflow-y-auto rounded-lg border border-port-border">+ <table className="w-full text-sm">+ <thead className="sticky top-0 bg-port-card z-10">+ <tr className="border-b border-port-border text-left text-xs text-gray-500 uppercase">+ <th className="px-3 py-2">Date</th>+ <th className="px-3 py-2">Name</th>+ <th className="px-3 py-2 text-right">Oz</th>+ <th className="px-3 py-2 text-right">ABV%</th>+ <th className="px-3 py-2 text-right">Count</th>+ <th className="px-3 py-2 text-right">Std Drinks</th>+ <th className="px-3 py-2 text-right w-20">Actions</th>+ </tr>+ </thead>+ <tbody>+ {visibleEntries.map(entry => {+ const drinks = entry.alcohol?.drinks || [];+ return drinks.map((drink, idx) => {+ const key = `${entry.date}:${idx}`;+ const isEditing = editingKey === key;+ const stdDrinks = computeStdDrinks(drink.oz, drink.abv, drink.count);+ return (+ <tr+ key={key}+ className={`border-b border-port-border/50 hover:bg-port-border/20 ${+ idx === 0 ? 'border-t border-port-border' : ''+ }`}>- <Trash2 size={12} />- </button>- </div>- ))}- </div>- </div>- ))}+ <td className="px-3 py-1.5">+ {idx === 0 ? (+ <div>+ <span className="text-gray-300 font-medium">{entry.date}</span>+ <span className={`ml-2 text-xs font-bold ${+ entry.alcohol.standardDrinks > (summary?.thresholds?.dailyMax || 2) ? 'text-port-error' : 'text-port-accent'+ }`}>+ ({entry.alcohol.standardDrinks} total)+ </span>+ </div>+ ) : (+ <span className="text-gray-700"> </span>+ )}+ </td>+ {isEditing ? (+ <>+ <td className="px-3 py-1.5">+ <input+ type="text"+ value={editForm.name}+ onChange={e => setEditForm(f => ({ ...f, name: e.target.value }))}+ className="w-full px-2 py-1 bg-port-bg border border-port-border rounded text-xs text-white"+ />+ </td>+ <td className="px-3 py-1.5">+ <input+ type="number"+ step="0.1"+ min="0.1"+ value={editForm.oz}+ onChange={e => setEditForm(f => ({ ...f, oz: e.target.value }))}+ className="w-16 px-2 py-1 bg-port-bg border border-port-border rounded text-xs text-white text-right"+ />+ </td>+ <td className="px-3 py-1.5">+ <input+ type="number"+ step="0.1"+ min="0"+ max="100"+ value={editForm.abv}+ onChange={e => setEditForm(f => ({ ...f, abv: e.target.value }))}+ className="w-16 px-2 py-1 bg-port-bg border border-port-border rounded text-xs text-white text-right"+ />+ </td>+ <td className="px-3 py-1.5">+ <input+ type="number"+ min="1"+ max="100"+ value={editForm.count}+ onChange={e => setEditForm(f => ({ ...f, count: e.target.value }))}+ className="w-14 px-2 py-1 bg-port-bg border border-port-border rounded text-xs text-white text-right"+ />+ </td>+ <td className="px-3 py-1.5 text-right text-gray-500 text-xs">+ {computeStdDrinks(parseFloat(editForm.oz), parseFloat(editForm.abv), parseInt(editForm.count) || 1)}+ </td>+ <td className="px-3 py-1.5 text-right">+ <div className="flex items-center justify-end gap-1">+ <button+ onClick={saveEdit}+ className="p-1 text-port-success hover:text-port-success/80 transition-colors"+ title="Save"+ >+ <Check size={14} />+ </button>+ <button+ onClick={cancelEdit}+ className="p-1 text-gray-500 hover:text-gray-300 transition-colors"+ title="Cancel"+ >+ <X size={14} />+ </button>+ </div>+ </td>+ </>+ ) : (+ <>+ <td className="px-3 py-1.5 text-gray-400">{drink.name || 'Unnamed'}</td>+ <td className="px-3 py-1.5 text-right text-gray-300">{drink.oz}</td>+ <td className="px-3 py-1.5 text-right text-gray-300">{drink.abv}%</td>+ <td className="px-3 py-1.5 text-right text-gray-300">{drink.count > 1 ? drink.count : 1}</td>+ <td className="px-3 py-1.5 text-right text-gray-400">{stdDrinks}</td>+ <td className="px-3 py-1.5 text-right">+ <div className="flex items-center justify-end gap-1">+ <button+ onClick={() => startEdit(entry.date, idx, drink)}+ className="p-1 text-gray-600 hover:text-port-accent transition-colors"+ title="Edit drink"+ >+ <Pencil size={12} />+ </button>+ <button+ onClick={() => handleRemove(entry.date, idx)}+ className="p-1 text-gray-600 hover:text-port-error transition-colors"+ title="Remove drink"+ >+ <Trash2 size={12} />+ </button>+ </div>+ </td>+ </>+ )}+ </tr>+ );+ });+ })}+ </tbody>+ </table></div>+ {hasMore && (+ <button+ onClick={() => setVisibleDays(v => v + DAYS_PER_PAGE)}+ className="mt-3 w-full py-2 text-sm text-port-accent hover:text-port-accent/80 border border-port-border rounded-lg hover:bg-port-border/20 transition-colors"+ >+ Load More ({allEntries.length - visibleDays} days remaining)+ </button>+ )}</div>)}diff --git a/client/src/services/api.js b/client/src/services/api.jsindex a947410cdd..b72ed6a9c3 100644--- a/client/src/services/api.js+++ b/client/src/services/api.js@@ -1283,6 +1283,10 @@ export const logAlcoholDrink = (data) => request('/meatspace/alcohol/log', {method: 'POST',body: JSON.stringify(data)});+export const updateAlcoholDrink = (date, index, data) => request(`/meatspace/alcohol/log/${date}/${index}`, {+ method: 'PUT',+ body: JSON.stringify(data)+});export const removeAlcoholDrink = (date, index) => request(`/meatspace/alcohol/log/${date}/${index}`, {method: 'DELETE'});diff --git a/package-lock.json b/package-lock.jsonindex 606bfc290c..e8c8b84619 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "portos",- "version": "1.10.1",+ "version": "1.11.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "portos",- "version": "1.10.1",+ "version": "1.11.0","license": "MIT","dependencies": {"express": "^4.21.2",diff --git a/package.json b/package.jsonindex 28b7cee676..d13d3acc0d 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portos",- "version": "1.10.1",+ "version": "1.11.0","private": true,"description": "Local dev machine App OS portal","author": "Adam Eivy (@antic|@atomantic)",diff --git a/server/lib/meatspaceValidation.js b/server/lib/meatspaceValidation.jsindex ab9097e370..cb218c1e18 100644--- a/server/lib/meatspaceValidation.js+++ b/server/lib/meatspaceValidation.js@@ -40,6 +40,13 @@ export const drinkLogSchema = z.object({date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional()});+export const drinkUpdateSchema = z.object({+ name: z.string().max(200).optional(),+ oz: z.number().min(0.1).max(1000).optional(),+ abv: z.number().min(0).max(100).optional(),+ count: z.number().int().min(1).max(100).optional()+});+// =============================================================================// BLOOD TESTS// =============================================================================diff --git a/server/routes/meatspace.js b/server/routes/meatspace.jsindex 00d67b5ebf..786393a66b 100644--- a/server/routes/meatspace.js+++ b/server/routes/meatspace.js@@ -5,6 +5,7 @@ import {configUpdateSchema,lifestyleUpdateSchema,drinkLogSchema,+ drinkUpdateSchema,bloodTestSchema,bodyEntrySchema,epigeneticTestSchema,@@ -118,6 +119,20 @@ router.post('/alcohol/log', asyncHandler(async (req, res) => {res.status(201).json(result);}));+/**+ * PUT /api/meatspace/alcohol/log/:date/:index+ * Update a specific drink entry+ */+router.put('/alcohol/log/:date/:index', asyncHandler(async (req, res) => {+ const { date, index } = req.params;+ const data = validateRequest(drinkUpdateSchema, req.body);+ const result = await alcoholService.updateDrink(date, parseInt(index, 10), data);+ if (!result) {+ throw new ServerError('Drink entry not found', { status: 404, code: 'NOT_FOUND' });+ }+ res.json(result);+}));+/*** DELETE /api/meatspace/alcohol/log/:date/:index* Remove a specific drink entrydiff --git a/server/services/meatspaceAlcohol.js b/server/services/meatspaceAlcohol.jsindex ff6feab5a7..707a66123a 100644--- a/server/services/meatspaceAlcohol.js+++ b/server/services/meatspaceAlcohol.js@@ -189,6 +189,28 @@ export async function logDrink({ name, oz, abv, count = 1, date }) {return { drink, standardDrinks, date: targetDate, dayTotal: entry.alcohol.standardDrinks };}+export async function updateDrink(date, index, updates) {+ const log = await loadDailyLog();+ const entry = log.entries.find(e => e.date === date);+ if (!entry?.alcohol?.drinks?.[index]) return null;++ const drink = entry.alcohol.drinks[index];+ if (updates.name !== undefined) drink.name = updates.name;+ if (updates.oz !== undefined) drink.oz = updates.oz;+ if (updates.abv !== undefined) drink.abv = updates.abv;+ if (updates.count !== undefined) drink.count = updates.count;++ // Recalculate total+ entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {+ return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);+ }, 0);+ entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;++ await saveDailyLog(log);+ console.log(`📝 Updated drink on ${date}[${index}]: ${drink.name || 'unnamed'} ${drink.oz}oz @ ${drink.abv}%`);+ return { drink, dayTotal: entry.alcohol.standardDrinks };+}+export async function removeDrink(date, index) {const log = await loadDailyLog();const entry = log.entries.find(e => e.date === date);diff --git a/server/services/meatspaceAlcohol.test.js b/server/services/meatspaceAlcohol.test.jsindex c5ee907b5f..c67ad6b14f 100644--- a/server/services/meatspaceAlcohol.test.js+++ b/server/services/meatspaceAlcohol.test.js@@ -104,6 +104,70 @@ describe('computeStandardDrinks', () => {});});+// =============================================================================+// UPDATE DRINK TESTS (inline logic mirroring updateDrink service)+// =============================================================================++describe('updateDrink logic', () => {+ it('updates oz and recalculates standard drinks for the day', () => {+ // Simulate a day entry with two drinks+ const entry = {+ date: '2024-06-15',+ alcohol: {+ drinks: [+ { name: 'Beer', oz: 12, abv: 5, count: 1 },+ { name: 'Wine', oz: 5, abv: 12, count: 1 }+ ],+ standardDrinks: 2 // 1 + 1+ }+ };++ // Update first drink oz from 12 to 24 (doubling it)+ const drink = entry.alcohol.drinks[0];+ drink.oz = 24;++ // Recalculate total (same logic as updateDrink)+ entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {+ return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);+ }, 0);+ entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;++ // 24oz @ 5% = 2 std drinks, 5oz @ 12% = 1 std drink => total 3+ expect(entry.alcohol.standardDrinks).toBe(3);+ expect(drink.oz).toBe(24);+ });++ it('updates abv and recalculates correctly', () => {+ const entry = {+ date: '2024-06-15',+ alcohol: {+ drinks: [+ { name: 'Mystery', oz: 12, abv: 5, count: 1 }+ ],+ standardDrinks: 1+ }+ };++ // Change ABV from 5% to 10%+ entry.alcohol.drinks[0].abv = 10;++ entry.alcohol.standardDrinks = entry.alcohol.drinks.reduce((sum, d) => {+ return sum + computeStandardDrinks((d.oz || 0) * (d.count || 1), d.abv || 0);+ }, 0);+ entry.alcohol.standardDrinks = Math.round(entry.alcohol.standardDrinks * 100) / 100;++ // 12oz @ 10% = 1.2 pure oz / 0.6 = 2+ expect(entry.alcohol.standardDrinks).toBe(2);+ });++ it('updates name without affecting calculations', () => {+ const drink = { name: 'Old Name', oz: 12, abv: 5, count: 1 };+ drink.name = 'New IPA';+ expect(drink.name).toBe('New IPA');+ expect(computeStandardDrinks(drink.oz * drink.count, drink.abv)).toBe(1);+ });+});+// =============================================================================// ROLLING AVERAGES TESTS// =============================================================================