From 7e2b6b1f4ed0fe68578060818be99000e41b9777 Mon Sep 17 00:00:00 2001
From: DecafDev <40307803+decaf-dev@users.noreply.github.com>
Date: Sat, 6 Jul 2024 12:36:49 -0600
Subject: [PATCH 1/4] feat: add duplicate rule button
---
...filter-modal.ts => custom-filter-modal.ts} | 12 +--
.../app/components/custom-filter.svelte | 6 +-
.../app/components/group-tag-list.svelte | 4 +-
src/svelte/app/index.svelte | 26 ++---
.../filters/custom/filter-by-groups.ts | 10 +-
.../components/content-filter.svelte | 1 +
.../components/display-name-utils.ts | 0
.../components/file-name-filter.svelte | 1 +
.../components/filter-rule-list.svelte | 8 +-
.../components/filter-rule.svelte | 28 +++++-
.../components/folder-filter.svelte | 1 +
.../components/group-edit-view.svelte | 5 +-
.../components/group-list-item.svelte | 0
.../components/group-list.svelte | 6 +-
.../components/property-filter.svelte | 1 +
.../index.svelte | 96 +++++++++++++++----
.../utils.ts | 0
src/types/index.ts | 9 +-
18 files changed, 154 insertions(+), 60 deletions(-)
rename src/obsidian/{properties-filter-modal.ts => custom-filter-modal.ts} (57%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/content-filter.svelte (98%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/display-name-utils.ts (100%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/file-name-filter.svelte (97%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/filter-rule-list.svelte (91%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/filter-rule.svelte (87%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/folder-filter.svelte (99%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/group-edit-view.svelte (94%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/group-list-item.svelte (100%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/group-list.svelte (93%)
rename src/svelte/{properties-filter-app => custom-filter-app}/components/property-filter.svelte (99%)
rename src/svelte/{properties-filter-app => custom-filter-app}/index.svelte (84%)
rename src/svelte/{properties-filter-app => custom-filter-app}/utils.ts (100%)
diff --git a/src/obsidian/properties-filter-modal.ts b/src/obsidian/custom-filter-modal.ts
similarity index 57%
rename from src/obsidian/properties-filter-modal.ts
rename to src/obsidian/custom-filter-modal.ts
index 8930802..aecface 100644
--- a/src/obsidian/properties-filter-modal.ts
+++ b/src/obsidian/custom-filter-modal.ts
@@ -1,14 +1,12 @@
import { Modal } from "obsidian";
-import PropertiesFilterApp from "../svelte/properties-filter-app/index.svelte";
+import CustomFilterApp from "../svelte/custom-filter-app/index.svelte";
import VaultExplorerPlugin from "src/main";
-export default class PropertiesFilterModal extends Modal {
- component: PropertiesFilterApp | null;
+export default class CustomFilterModal extends Modal {
+ component: CustomFilterApp | null;
plugin: VaultExplorerPlugin;
- constructor(
- plugin: VaultExplorerPlugin,
- ) {
+ constructor(plugin: VaultExplorerPlugin) {
super(plugin.app);
this.plugin = plugin;
this.component = null;
@@ -17,7 +15,7 @@ export default class PropertiesFilterModal extends Modal {
onOpen(): void {
const { contentEl } = this;
- this.component = new PropertiesFilterApp({
+ this.component = new CustomFilterApp({
target: contentEl,
});
}
diff --git a/src/svelte/app/components/custom-filter.svelte b/src/svelte/app/components/custom-filter.svelte
index 0538948..9268f47 100644
--- a/src/svelte/app/components/custom-filter.svelte
+++ b/src/svelte/app/components/custom-filter.svelte
@@ -1,13 +1,13 @@
@@ -32,6 +32,7 @@
on:ruleValueChange
on:ruleToggle
on:ruleDeleteClick
+ on:ruleDuplicateClick
on:propertyNameChange
on:propertyTypeChange
on:propertyValueDataChange
@@ -53,6 +54,7 @@
on:ruleOperatorChange
on:ruleValueChange
on:ruleToggle
+ on:ruleDuplicateClick
on:ruleDeleteClick
/>
{/if}
@@ -72,6 +74,7 @@
on:ruleOperatorChange
on:ruleValueChange
on:ruleToggle
+ on:ruleDuplicateClick
on:ruleDeleteClick
on:folderSubfoldersToggle
/>
@@ -91,6 +94,7 @@
on:ruleOperatorChange
on:ruleValueChange
on:ruleToggle
+ on:ruleDuplicateClick
on:ruleDeleteClick
/>
{/if}
diff --git a/src/svelte/properties-filter-app/components/filter-rule.svelte b/src/svelte/custom-filter-app/components/filter-rule.svelte
similarity index 87%
rename from src/svelte/properties-filter-app/components/filter-rule.svelte
rename to src/svelte/custom-filter-app/components/filter-rule.svelte
index 7856c87..435c3b9 100644
--- a/src/svelte/properties-filter-app/components/filter-rule.svelte
+++ b/src/svelte/custom-filter-app/components/filter-rule.svelte
@@ -23,6 +23,7 @@
import { createEventDispatcher } from "svelte";
import Wrap from "src/svelte/shared/components/wrap.svelte";
import License from "src/svelte/shared/services/license";
+ import { Menu } from "obsidian";
export let index: number;
export let id: string;
@@ -42,6 +43,27 @@
enablePremiumFeatures = isRegistered;
});
+ function handleActionsClick(e: CustomEvent) {
+ const nativeEvent = e.detail.nativeEvent as MouseEvent;
+
+ const menu = new Menu();
+ menu.setUseNativeMenu(true);
+
+ menu.addItem((item) => {
+ item.setTitle("Duplicate");
+ item.onClick(() => handleDuplicateClick());
+ });
+ menu.addItem((item) => {
+ item.setTitle("Delete");
+ item.onClick(() => handleDeleteClick());
+ });
+ menu.showAtMouseEvent(nativeEvent);
+ }
+
+ function handleDuplicateClick() {
+ dispatch("ruleDuplicateClick", { id });
+ }
+
function handleDeleteClick() {
dispatch("ruleDeleteClick", { id });
}
@@ -134,9 +156,9 @@
handleToggle()} />
handleDeleteClick()}
+ ariaLabel="Rule actions"
+ iconId="ellipsis-vertical"
+ on:click={handleActionsClick}
/>
diff --git a/src/svelte/properties-filter-app/components/folder-filter.svelte b/src/svelte/custom-filter-app/components/folder-filter.svelte
similarity index 99%
rename from src/svelte/properties-filter-app/components/folder-filter.svelte
rename to src/svelte/custom-filter-app/components/folder-filter.svelte
index eba07fc..2782c2f 100644
--- a/src/svelte/properties-filter-app/components/folder-filter.svelte
+++ b/src/svelte/custom-filter-app/components/folder-filter.svelte
@@ -108,6 +108,7 @@
{condition}
{isEnabled}
on:ruleDeleteClick
+ on:ruleDuplicateClick
on:ruleTypeChange
on:ruleConditionChange
on:ruleOperatorChange
diff --git a/src/svelte/properties-filter-app/components/group-edit-view.svelte b/src/svelte/custom-filter-app/components/group-edit-view.svelte
similarity index 94%
rename from src/svelte/properties-filter-app/components/group-edit-view.svelte
rename to src/svelte/custom-filter-app/components/group-edit-view.svelte
index c260474..4ad05e2 100644
--- a/src/svelte/properties-filter-app/components/group-edit-view.svelte
+++ b/src/svelte/custom-filter-app/components/group-edit-view.svelte
@@ -3,7 +3,7 @@
import IconButton from "src/svelte/shared/components/icon-button.svelte";
import Stack from "src/svelte/shared/components/stack.svelte";
- import { FilterGroup } from "src/types";
+ import { TFilterGroup } from "src/types";
import FilterRuleList from "./filter-rule-list.svelte";
import { createEventDispatcher } from "svelte";
@@ -11,7 +11,7 @@
import Spacer from "src/svelte/shared/components/spacer.svelte";
const dispatch = createEventDispatcher();
- export let selectedGroup: FilterGroup;
+ export let selectedGroup: TFilterGroup;
function handleFilterAddClick() {
const newFilter = createPropertyFilter();
@@ -44,6 +44,7 @@
on:ruleValueChange
on:ruleToggle
on:ruleDeleteClick
+ on:ruleDuplicateClick
on:propertyTypeChange
on:propertyNameChange
on:propertyMatchWhenPropertyDNEChange
diff --git a/src/svelte/properties-filter-app/components/group-list-item.svelte b/src/svelte/custom-filter-app/components/group-list-item.svelte
similarity index 100%
rename from src/svelte/properties-filter-app/components/group-list-item.svelte
rename to src/svelte/custom-filter-app/components/group-list-item.svelte
diff --git a/src/svelte/properties-filter-app/components/group-list.svelte b/src/svelte/custom-filter-app/components/group-list.svelte
similarity index 93%
rename from src/svelte/properties-filter-app/components/group-list.svelte
rename to src/svelte/custom-filter-app/components/group-list.svelte
index 0deab38..601bd44 100644
--- a/src/svelte/properties-filter-app/components/group-list.svelte
+++ b/src/svelte/custom-filter-app/components/group-list.svelte
@@ -1,10 +1,10 @@