refactor(views/board): use single point for obtaining status attribute

This commit is contained in:
Elian Doran
2025-07-21 14:40:35 +03:00
parent ff01656268
commit 86911100df
2 changed files with 17 additions and 10 deletions

View File

@@ -14,18 +14,23 @@ export default class BoardApi {
private _parentNoteId: string, private _parentNoteId: string,
private viewStorage: ViewModeStorage<BoardData>, private viewStorage: ViewModeStorage<BoardData>,
private byColumn: ColumnMap, private byColumn: ColumnMap,
private persistedData: BoardData) {} private persistedData: BoardData,
private _statusAttribute: string) {}
get columns() { get columns() {
return this._columns; return this._columns;
} }
get statusAttribute() {
return this._statusAttribute;
}
getColumn(column: string) { getColumn(column: string) {
return this.byColumn.get(column); return this.byColumn.get(column);
} }
async changeColumn(noteId: string, newColumn: string) { async changeColumn(noteId: string, newColumn: string) {
await attributes.setLabel(noteId, "status", newColumn); await attributes.setLabel(noteId, this._statusAttribute, newColumn);
} }
openNote(noteId: string) { openNote(noteId: string) {
@@ -62,7 +67,7 @@ export default class BoardApi {
await executeBulkActions(noteIds, [ await executeBulkActions(noteIds, [
{ {
name: "updateLabelValue", name: "updateLabelValue",
labelName: "status", labelName: this._statusAttribute,
labelValue: newValue labelValue: newValue
} }
]); ]);
@@ -82,7 +87,7 @@ export default class BoardApi {
await executeBulkActions(noteIds, [ await executeBulkActions(noteIds, [
{ {
name: "deleteLabel", name: "deleteLabel",
labelName: "status" labelName: this._statusAttribute
} }
]); ]);
@@ -106,8 +111,10 @@ export default class BoardApi {
} }
static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) { static async build(parentNote: FNote, viewStorage: ViewModeStorage<BoardData>) {
const statusAttribute = "status"; // This should match the attribute used for grouping
let persistedData = await viewStorage.restore() ?? {}; let persistedData = await viewStorage.restore() ?? {};
const { byColumn, newPersistedData } = await getBoardData(parentNote, "status", persistedData); const { byColumn, newPersistedData } = await getBoardData(parentNote, statusAttribute, persistedData);
const columns = Array.from(byColumn.keys()) || []; const columns = Array.from(byColumn.keys()) || [];
if (newPersistedData) { if (newPersistedData) {
@@ -115,7 +122,7 @@ export default class BoardApi {
viewStorage.store(persistedData); viewStorage.store(persistedData);
} }
return new BoardApi(columns, parentNote.noteId, viewStorage, byColumn, persistedData); return new BoardApi(columns, parentNote.noteId, viewStorage, byColumn, persistedData, statusAttribute);
} }
} }

View File

@@ -425,7 +425,7 @@ export default class BoardView extends ViewMode<BoardData> {
if (newNote) { if (newNote) {
// Set the status label to place it in the correct column // Set the status label to place it in the correct column
await attributeService.setLabel(newNote.noteId, "status", column); await this.api?.changeColumn(newNote.noteId, column);
// Refresh the board to show the new item // Refresh the board to show the new item
await this.renderList(); await this.renderList();
@@ -540,8 +540,8 @@ export default class BoardView extends ViewMode<BoardData> {
async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) { async onEntitiesReloaded({ loadResults }: EventData<"entitiesReloaded">) {
// Check if any changes affect our board // Check if any changes affect our board
const hasRelevantChanges = const hasRelevantChanges =
// React to changes in "status" attribute for notes in this board // React to changes in status attribute for notes in this board
loadResults.getAttributeRows().some(attr => attr.name === "status" && this.noteIds.includes(attr.noteId!)) || loadResults.getAttributeRows().some(attr => attr.name === this.api?.statusAttribute && this.noteIds.includes(attr.noteId!)) ||
// React to changes in note title // React to changes in note title
loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)) || loadResults.getNoteIds().some(noteId => this.noteIds.includes(noteId)) ||
// React to changes in branches for subchildren (e.g., moved, added, or removed notes) // React to changes in branches for subchildren (e.g., moved, added, or removed notes)