fix: isolate Today summary drafts by account
This commit is contained in:
parent
b3a359760c
commit
abc736d32e
|
|
@ -1,16 +1,27 @@
|
|||
function createTodaySummary({ storage = null, getLogin = () => '', share = null, copy = null } = {}) {
|
||||
let draft = null;
|
||||
let draftKey = '';
|
||||
|
||||
const storageKey = () => {
|
||||
const login = String(getLogin() || '').trim().toLowerCase();
|
||||
return login ? 'stackchain.today-summary-draft.v1.' + login : '';
|
||||
};
|
||||
const syncAccount = () => {
|
||||
const key = storageKey();
|
||||
if (key !== draftKey) {
|
||||
draft = null;
|
||||
draftKey = key;
|
||||
}
|
||||
};
|
||||
const copyRows = rows => rows.map(row => ({ ...row }));
|
||||
const snapshot = () => draft ? {
|
||||
...draft,
|
||||
worked:copyRows(draft.worked),
|
||||
tomorrow:copyRows(draft.tomorrow),
|
||||
} : null;
|
||||
const snapshot = () => {
|
||||
syncAccount();
|
||||
return draft ? {
|
||||
...draft,
|
||||
worked:copyRows(draft.worked),
|
||||
tomorrow:copyRows(draft.tomorrow),
|
||||
} : null;
|
||||
};
|
||||
const persist = () => {
|
||||
const key = storageKey();
|
||||
if (storage && key && draft) storage.setItem(key, JSON.stringify(draft));
|
||||
|
|
@ -58,6 +69,7 @@ function createTodaySummary({ storage = null, getLogin = () => '', share = null,
|
|||
|
||||
return {
|
||||
begin(worked, tomorrow) {
|
||||
draftKey = storageKey();
|
||||
draft = {
|
||||
worked:(worked || []).filter(row => row?.identity).slice(0, 20).map(row => cleanRow(row, true)),
|
||||
tomorrow:(tomorrow || []).filter(row => row?.identity).slice(0, 20).map(row => cleanRow(row, false)),
|
||||
|
|
@ -69,10 +81,12 @@ function createTodaySummary({ storage = null, getLogin = () => '', share = null,
|
|||
},
|
||||
snapshot,
|
||||
restore() {
|
||||
draftKey = storageKey();
|
||||
draft = load();
|
||||
return Boolean(draft);
|
||||
},
|
||||
choose(section, identity, include) {
|
||||
syncAccount();
|
||||
const row = draft?.[section]?.find(candidate => candidate.identity === identity);
|
||||
if (!row || typeof include !== 'boolean') return false;
|
||||
row.include = include;
|
||||
|
|
@ -80,12 +94,14 @@ function createTodaySummary({ storage = null, getLogin = () => '', share = null,
|
|||
return true;
|
||||
},
|
||||
includeActuals(include) {
|
||||
syncAccount();
|
||||
if (!draft || typeof include !== 'boolean') return false;
|
||||
draft.include_actuals = include;
|
||||
persist();
|
||||
return true;
|
||||
},
|
||||
setNote(note) {
|
||||
syncAccount();
|
||||
if (!draft) return false;
|
||||
draft.note = String(note || '').trim().slice(0, 1000);
|
||||
persist();
|
||||
|
|
@ -93,6 +109,7 @@ function createTodaySummary({ storage = null, getLogin = () => '', share = null,
|
|||
},
|
||||
discard,
|
||||
text() {
|
||||
syncAccount();
|
||||
if (!draft) return '';
|
||||
const sections = [];
|
||||
const worked = selectedLines(draft.worked, draft.include_actuals);
|
||||
|
|
|
|||
|
|
@ -153,3 +153,21 @@ summary.begin([{{
|
|||
process.stdout.write(JSON.stringify({{text:summary.text()}}));
|
||||
"""
|
||||
assert run_node(script)["text"] == "Today\n- Ship mobile capture"
|
||||
|
||||
|
||||
def test_summary_draft_is_not_visible_after_the_confirmed_account_changes():
|
||||
script = f"""
|
||||
const createSummary = require({json.dumps(str(TODAY_SUMMARY))});
|
||||
const values = new Map();
|
||||
const storage = {{
|
||||
getItem:key => values.has(key) ? values.get(key) : null,
|
||||
setItem:(key,value) => values.set(key,value),
|
||||
removeItem:key => values.delete(key),
|
||||
}};
|
||||
let login='timmy';
|
||||
const summary=createSummary({{storage,getLogin:()=>login}});
|
||||
summary.begin([{{identity:'issue:acme/mobile:41:',title:'Private work',actual_minutes:42}}], []);
|
||||
login='alexander';
|
||||
process.stdout.write(JSON.stringify({{snapshot:summary.snapshot(),text:summary.text()}}));
|
||||
"""
|
||||
assert run_node(script) == {"snapshot": None, "text": ""}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user