Skip to content

Commit

Permalink
improving refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGB committed Jan 24, 2023
1 parent 55e741d commit 40b6e79
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/stateManagement/data/handlers/DataviewUpdaterHandlerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { UpdaterData } from "cdm/EmitterModel";
import { TableColumn } from "cdm/FolderModel";
import { FilterSettings, LocalSettings } from "cdm/SettingsModel";
import { DataState, TableActionResponse } from "cdm/TableStateInterface";
import { DATAVIEW_UPDATER_OPERATIONS, MetadataColumns } from "helpers/Constants";
import { DATAVIEW_UPDATER_OPERATIONS, MetadataColumns, SourceDataTypes } from "helpers/Constants";
import tableFilter from "helpers/TableFiltersHelper";
import { TFile } from "obsidian";
import { DataviewService } from "services/DataviewService";
import { LOGGER } from "services/Logger";
import NoteInfo from "services/NoteInfo";
import { AbstractTableAction } from "stateManagement/AbstractTableAction";
import { DatabaseView } from "views/DatabaseView";

export default class DataviewUpdaterHandlerAction extends AbstractTableAction<DataState> {
handle(tableActionResponse: TableActionResponse<DataState>): TableActionResponse<DataState> {
Expand All @@ -19,10 +21,11 @@ export default class DataviewUpdaterHandlerAction extends AbstractTableAction<Da
ddbbConfig: LocalSettings,
filterConfig: FilterSettings
) => {

const { op, file, oldPath } = updaterData;
if (!this.checkIfFileIsInSource(file, view)) return;
set((updater) => {
const { rows } = updater;
const { op, file, oldPath } = updaterData;

const pathToOperate = oldPath ? oldPath : file.path;
const indexToOperate = updater.rows.findIndex((row) => row.__note__.filepath === pathToOperate);
const isFileInDDBB = indexToOperate !== -1;
Expand Down Expand Up @@ -78,4 +81,14 @@ export default class DataviewUpdaterHandlerAction extends AbstractTableAction<Da
tableActionResponse.implementation = implementation;
return this.goNext(tableActionResponse);
}

private checkIfFileIsInSource(file: TFile, view: DatabaseView): boolean {
switch (view.diskConfig.yaml.config.source_data) {
case SourceDataTypes.CURRENT_FOLDER:
return file.parent.path.startsWith(view.file.parent.path);
case SourceDataTypes.CURRENT_FOLDER_WITHOUT_SUBFOLDERS:
return file.parent.path === view.file.parent.path;
}
return true;
}
}

0 comments on commit 40b6e79

Please sign in to comment.