Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now edge property field types aren't overwritten on plugin load #581

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,6 @@ export default class BreadcrumbsPlugin extends Plugin {
this.settings = migrate_old_settings(this.settings);
await this.saveSettings();

// Set the edge_fields & BC-meta-fields to the right Properties type
try {
const all_properties =
this.app.metadataTypeManager.getAllProperties();

for (const field of this.settings.edge_fields) {
if (all_properties[field.label]?.type === "multitext") continue;
this.app.metadataTypeManager.setType(field.label, "multitext");
}

for (const [field, { property_type }] of Object.entries(
METADATA_FIELDS_MAP,
)) {
if (all_properties[field]?.type === property_type) continue;
this.app.metadataTypeManager.setType(field, property_type);
}
} catch (error) {
log.error("metadataTypeManager.setType error >", error);
}

this.addSettingTab(new BreadcrumbsSettingTab(this.app, this));

// API
Expand Down Expand Up @@ -90,6 +70,26 @@ export default class BreadcrumbsPlugin extends Plugin {
this.app.workspace.onLayoutReady(async () => {
log.debug("on:layout-ready");

// Set the edge_fields & BC-meta-fields to the right Properties type
try {
const all_properties =
this.app.metadataTypeManager.getAllProperties();

for (const field of this.settings.edge_fields) {
if (all_properties[field.label]?.type) continue;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type will always be there, so this if branch will always continue. I understand what you intend to do, but don't think this achieves it.
Maybe try something like if (!["text", "multitext"].includes(all_properties[field.label]?.type)) { continue }. In other words, if the field type has already been set to something other than "text" (the default), or "multitext" (the BC target), then skip it. The assumption being that the user overrode that field

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't type only be there if the property has already been set? Meaning that if the properties.yaml doesn't contain the property field yet, a type won't be set, and it will then run this.app.metadataTypeManager.setType(field.label, "multitext");.

However the only two types that make sense here are text or multitext, so I'd be fine with changing this to your suggestion, I can modify it.

this.app.metadataTypeManager.setType(field.label, "multitext");
}

for (const [field, { property_type }] of Object.entries(
METADATA_FIELDS_MAP,
)) {
if (all_properties[field]?.type === property_type) continue;
this.app.metadataTypeManager.setType(field, property_type);
}
} catch (error) {
log.error("metadataTypeManager.setType error >", error);
}

// Wait for DV and metadataCache before refreshing
await dataview_plugin.await_if_enabled(this);

Expand Down