Update default values (#327)

* feat: add default value to properties

* feat: rename to File system

* refactor: update value

* chore: update guardgen
This commit is contained in:
DecafDev 2024-09-10 00:50:41 -06:00 committed by GitHub
parent b63126791b
commit 19ef005f84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 52 deletions

View file

@ -7,10 +7,9 @@ export const HOVER_LINK_SOURCE_ID = "vault-explorer-preview";
export const DEFAULT_SETTINGS: VaultExplorerPluginSettings = {
properties: {
favorite: "",
url: "",
image: "",
coverImageFit: "",
url: "url",
image: "image",
coverImageFit: "image-fit",
createdDate: "",
modifiedDate: "",
custom1: "",

View file

@ -1,4 +1,4 @@
import { App } from "obsidian"
import { App } from "obsidian";
import { ObsidianProperty, ObsidianPropertyType } from "./types";
/**
@ -6,17 +6,34 @@ import { ObsidianProperty, ObsidianPropertyType } from "./types";
* NOTE: This is an undocumented API function and may break in future versions of Obsidian
*/
export const getAllObsidianProperties = (app: App) => {
const properties = (app as any).metadataTypeManager.getAllProperties() as Record<string, ObsidianProperty>;
return Object.values(properties).sort((a: ObsidianProperty, b: ObsidianProperty) => a.name.localeCompare(b.name));
const properties = (
app as any
).metadataTypeManager.getAllProperties() as Record<
string,
ObsidianProperty
>;
return Object.values(properties).sort(
(a: ObsidianProperty, b: ObsidianProperty) =>
a.name.localeCompare(b.name)
);
};
export const getObsidianPropertiesByType = (app: App, type: ObsidianPropertyType) => {
export const getObsidianPropertiesByType = (
app: App,
type: ObsidianPropertyType
) => {
return getAllObsidianProperties(app).filter((p) => p.type === type);
}
};
export const getDropdownOptionsForProperties = (properties: ObsidianProperty[]) => {
return properties.reduce((acc: Record<string, string>, cur: ObsidianProperty) => {
acc[cur.name] = cur.name;
return acc;
}, { "": "Select a property" });
}
export const getDropdownOptionsForProperties = (
properties: ObsidianProperty[],
defaultValue: Record<string, string> = { "": "Select a property" }
) => {
return properties.reduce(
(acc: Record<string, string>, cur: ObsidianProperty) => {
acc[cur.name] = cur.name;
return acc;
},
defaultValue
);
};

View file

@ -446,26 +446,6 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
new Setting(containerEl).setName("Built-in properties").setHeading();
new Setting(containerEl)
.setName("Favorite property")
.setDesc(
"Property used to mark a note as a favorite. This must be a checkbox property."
)
.addDropdown((dropdown) =>
dropdown
.addOptions(
getDropdownOptionsForProperties(checkboxProperties)
)
.setValue(this.plugin.settings.properties.favorite)
.onChange(async (value) => {
this.plugin.settings.properties.favorite = value;
await this.plugin.saveSettings();
EventManager.getInstance().emit(
PluginEvent.PROPERTY_SETTING_CHANGE
);
})
);
new Setting(containerEl)
.setName("Cover image property")
.setDesc(
@ -473,7 +453,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
)
.addDropdown((dropdown) =>
dropdown
.addOptions(getDropdownOptionsForProperties(textProperties))
.addOptions(
getDropdownOptionsForProperties(textProperties, {
image: "image",
})
)
.setValue(this.plugin.settings.properties.image)
.onChange(async (value) => {
this.plugin.settings.properties.image = value;
@ -491,7 +475,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
)
.addDropdown((dropdown) =>
dropdown
.addOptions(getDropdownOptionsForProperties(textProperties))
.addOptions(
getDropdownOptionsForProperties(textProperties, {
"image-fit": "image-fit",
})
)
.setValue(this.plugin.settings.properties.coverImageFit)
.onChange(async (value) => {
this.plugin.settings.properties.coverImageFit = value;
@ -509,7 +497,11 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
)
.addDropdown((dropdown) =>
dropdown
.addOptions(getDropdownOptionsForProperties(textProperties))
.addOptions(
getDropdownOptionsForProperties(textProperties, {
url: "url",
})
)
.setValue(this.plugin.settings.properties.url)
.onChange(async (value) => {
this.plugin.settings.properties.url = value;
@ -525,7 +517,7 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
text: "Property used to store a creation date. This must be a date or datetime property.",
});
creationDateDesc.createDiv({
text: "If set to 'Select a property', the file's created at date will be used.",
text: "If set, the property will be preferred over the file's creation date.",
});
new Setting(containerEl)
@ -554,7 +546,7 @@ export default class VaultExplorerSettingsTab extends PluginSettingTab {
text: "Property used to store a modification date. This must be a date or datetime property.",
});
modificationDateDesc.createDiv({
text: "If set to 'Select a property', the file's modified at date will be used.",
text: "If set, the property will be preferred over the file's modification date.",
});
new Setting(containerEl)

View file

@ -754,14 +754,6 @@
const { properties } = plugin.settings;
const { coverImageFit: coverImageFitProperty } = properties;
//If the favorite property is not set, return
if (coverImageFitProperty === "") {
new Notice(
"Vault Explorer: Please set a cover image fit property in the plugin settings to use this feature",
);
return;
}
const file = plugin.app.vault.getFileByPath(filePath);
if (!file) {
Logger.error({

View file

@ -13,7 +13,6 @@ export function isVaultExplorerPluginSettings(obj: unknown): obj is VaultExplore
(typedObj["properties"] !== null &&
typeof typedObj["properties"] === "object" ||
typeof typedObj["properties"] === "function") &&
typeof typedObj["properties"]["favorite"] === "string" &&
typeof typedObj["properties"]["url"] === "string" &&
typeof typedObj["properties"]["image"] === "string" &&
typeof typedObj["properties"]["coverImageFit"] === "string" &&

View file

@ -1,7 +1,6 @@
/** @see {isVaultExplorerPluginSettings} ts-auto-guard:type-guard */
export interface VaultExplorerPluginSettings {
properties: {
favorite: string;
url: string;
image: string;
coverImageFit: string;

View file

@ -9,7 +9,7 @@
"modifiedDate": "modification",
"createdDate": "creation",
"image": "image",
"coverImageFit": ""
"coverImageFit": "image-fit"
},
"filters": {
"search": {
@ -18,7 +18,7 @@
},
"sort": {
"isEnabled": true,
"value": "file-name-asc"
"value": "modified-desc"
},
"custom": {
"isEnabled": true,