这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@d51x
Copy link
Contributor

@d51x d51x commented Oct 10, 2023

Sometimes it is necessary to make copies of the rule for later editing.

Added ability to copy a rule.
After "copy rule" new rule is opened
If original rule is disabled, then copied rule also disabled

Original rule

image

Copied rule

Opened as New rule with pre-filled values

image

Signed-off-by: Dmitry P. (d51x) <dimonich110@gmail.com>
@d51x d51x requested a review from a team as a code owner October 10, 2023 19:42
@relativeci
Copy link

relativeci bot commented Oct 10, 2023

Job #1219: Bundle Size — 15.79MiB (+0.21%).

e9a661a(current) vs b7270d2 main#1158(baseline)

Warning

Bundle contains 16 duplicate packages – View duplicate packages

Warning

Bundle introduced 13 new packages: @jsep-plugin/regex, @jsep-plugin/arrow, @jsep-plugin/object and 10 more – View changed packages

Bundle metrics  Change 10 changes Regression 5 regressions Improvement 1 improvement
                 Current
Job #1219
     Baseline
Job #1158
Regression  Initial JS 1.85MiB(+10.95%) 1.67MiB
Regression  Initial CSS 608.95KiB(+0.01%) 608.89KiB
Change  Cache Invalidation 93.81% 93.95%
Change  Chunks 217(-0.91%) 219
Change  Assets 683(-0.87%) 689
Change  Modules 2987(+75.71%) 1700
Regression  Duplicate Modules 173(+92.22%) 90
Improvement  Duplicate Code 1.61%(-17.44%) 1.95%
Regression  Packages 152(+10.14%) 138
Regression  Duplicate Packages 16(+6.67%) 15
Bundle size by type  Change 3 changes Regression 3 regressions
                 Current
Job #1219
     Baseline
Job #1158
Regression  JS 9.28MiB (+0.25%) 9.25MiB
Regression  Other 4.74MiB (+0.2%) 4.73MiB
Regression  CSS 860.19KiB (+0.08%) 859.49KiB
Not changed  Fonts 526.1KiB 526.1KiB
Not changed  Media 295.6KiB 295.6KiB
Not changed  IMG 140.74KiB 140.74KiB
Not changed  HTML 1.23KiB 1.23KiB

View job #1219 reportView d51x:rule_copy branch activity

@rkoshak
Copy link

rkoshak commented Oct 10, 2023

I wonder if the new rule should be created initially disabled regardless of the state of the old rule. For example, if the rule is triggered by a system runlevel/system started trigger, the new rule will immediately run as soon as it's created as a copy which could be undesirable. Simply making a copy shouldn't cause "stuff" to happen.

Also, since the rule's UID cannot be changed once it's created, it would be desireable if the user could choose the UID of the newly created rule. Because one needs the UID of a rule to call it from another rule, and some error messages use the rule UID in the error, having the ability to choose our own UID on creation/copy is kind of important.

Could this be used perhaps as a way to create a copy of an unmanaged rule (i.e. rule defined in a text file instead of through the UI)? I would expect not but if there is enough data there to recreate the rule as a managed rule that could be a cool way to import text file rules into the UI.

@d51x
Copy link
Contributor Author

d51x commented Oct 11, 2023

I wonder if the new rule should be created initially disabled regardless of the state of the old rule. For example, if the rule is triggered by a system runlevel/system started trigger, the new rule will immediately run as soon as it's created as a copy which could be undesirable. Simply making a copy shouldn't cause "stuff" to happen.

Also, since the rule's UID cannot be changed once it's created, it would be desireable if the user could choose the UID of the newly created rule. Because one needs the UID of a rule to call it from another rule, and some error messages use the rule UID in the error, having the ability to choose our own UID on creation/copy is kind of important.

Could this be used perhaps as a way to create a copy of an unmanaged rule (i.e. rule defined in a text file instead of through the UI)? I would expect not but if there is enough data there to recreate the rule as a managed rule that could be a cool way to import text file rules into the UI.

UID of copied rule is new (unique)

@rkoshak
Copy link

rkoshak commented Oct 11, 2023

UID of copied rule is new (unique)

Yes but the end user should be allowed to change it before the new rule is created.

@d51x
Copy link
Contributor Author

d51x commented Oct 11, 2023

UID of copied rule is new (unique)

Yes but the end user should be allowed to change it before the new rule is created.
don't understand.... "copy rule" feature makes uniq id for new rule automatically. why change it?

@JustinGeorgi
Copy link
Contributor

don't understand.... "copy rule" feature makes uniq id for new rule automatically. why change it?

Many users do not use the automatically generated random UIDs but prefer to give rules more descriptive identifiable names. If this feature is going to be useful for all users then it needs to not create the rule as a saved configuration already but open the rule in the rule creation wizard so the user can, if they want to change the UID.

@rkoshak
Copy link

rkoshak commented Oct 11, 2023

I listed some examples above for why a user would want to change the UID. In brief:

  • makes it easier to identify rules when wanting to call a rule from another rule
  • the rule UID sometimes is the only identifier in an error message, using meaningful UIDs makes it easier to map an error to a specific rule

It's a lot easier to work with a rule with a UID of door-open-detection than with a UID 51f0c47a62.

Signed-off-by: Dmitry P. (d51x) <dimonich110@gmail.com>
@d51x
Copy link
Contributor Author

d51x commented Oct 11, 2023

the implementation of the copy rule has been changed
the form opens as for a new rule
user can change rule ID
the rule is not saved until the user clicks the Save button

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!
This has been on my "I want to implement it list" for a long time, thanks for doing that!

I just fixed some places you forgot to replace createMode with isNewRule.

Wrt to disabling a copied rule by default: Since a newly created rule is enabled by default, I would do the same for a copied rule. However technically it would be possible to create the new rule right after creating it, that would not solve the problem with start level trigger triggering. Seems like it is not possible to create the rule already disabled.

@florian-h05 florian-h05 added enhancement New feature or request main ui Main UI labels Oct 22, 2023
@florian-h05 florian-h05 added this to the 4.1 milestone Oct 22, 2023
@florian-h05 florian-h05 changed the title Rules: copy rule Add copy rule functionality Oct 22, 2023
@florian-h05 florian-h05 merged commit 0a8c9a7 into openhab:main Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request main ui Main UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants