mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Editing summary columns widget options
Summary: - Allowing changing description and all widget options (except choices) for summary columns - Making text error in toast notification selectable Test Plan: Added new tests Reviewers: georgegevoian Reviewed By: georgegevoian Subscribers: georgegevoian Differential Revision: https://phab.getgrist.com/D4346
This commit is contained in:
@@ -4,6 +4,7 @@ files: test_summary.py and test_summary2.py.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import unittest
|
||||
|
||||
import actions
|
||||
import summary
|
||||
@@ -960,49 +961,49 @@ class Address:
|
||||
old = '{"widget":"Spinner","alignment":"center"}'
|
||||
self.assertTrue(widgetOptions(new, old))
|
||||
|
||||
# Can update but must leave other options.
|
||||
new = '{"widget":"TextBox","cant":"center"}'
|
||||
old = '{"widget":"Spinner","cant":"center"}'
|
||||
# Can update but must leave choices options.
|
||||
new = '{"widget":"TextBox","choices":"center"}'
|
||||
old = '{"widget":"Spinner","choices":"center"}'
|
||||
self.assertTrue(widgetOptions(new, old))
|
||||
|
||||
# Can't add protected property when old was empty.
|
||||
new = '{"widget":"TextBox","cant":"new"}'
|
||||
new = '{"widget":"TextBox","choices":"new"}'
|
||||
old = None
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can't remove when there was a protected property.
|
||||
new = None
|
||||
old = '{"widget":"TextBox","cant":"old"}'
|
||||
old = '{"widget":"TextBox","choices":"old"}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can't update by omitting.
|
||||
new = '{"widget":"TextBox"}'
|
||||
old = '{"widget":"TextBox","cant":"old"}'
|
||||
old = '{"widget":"TextBox","choices":"old"}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can't update by changing.
|
||||
new = '{"widget":"TextBox","cant":"new"}'
|
||||
old = '{"widget":"TextBox","cant":"old"}'
|
||||
new = '{"widget":"TextBox","choices":"new"}'
|
||||
old = '{"widget":"TextBox","choices":"old"}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can't update by adding.
|
||||
new = '{"widget":"TextBox","cant":"new"}'
|
||||
new = '{"widget":"TextBox","choices":"new"}'
|
||||
old = '{"widget":"TextBox"}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can update objects
|
||||
new = '{"widget":"TextBox","alignment":{"prop":1},"cant":{"prop":1}}'
|
||||
old = '{"widget":"TextBox","alignment":{"prop":2},"cant":{"prop":1}}'
|
||||
new = '{"widget":"TextBox","alignment":{"prop":1},"choices":{"prop":1}}'
|
||||
old = '{"widget":"TextBox","alignment":{"prop":2},"choices":{"prop":1}}'
|
||||
self.assertTrue(widgetOptions(new, old))
|
||||
|
||||
# Can't update objects
|
||||
new = '{"widget":"TextBox","cant":{"prop":1}}'
|
||||
old = '{"widget":"TextBox","cant":{"prop":2}}'
|
||||
new = '{"widget":"TextBox","choices":{"prop":1}}'
|
||||
old = '{"widget":"TextBox","choices":{"prop":2}}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can't update lists
|
||||
new = '{"widget":"TextBox","cant":[1, 2]}'
|
||||
old = '{"widget":"TextBox","cant":[2, 1]}'
|
||||
new = '{"widget":"TextBox","choices":[1, 2]}'
|
||||
old = '{"widget":"TextBox","choices":[2, 1]}'
|
||||
self.assertFalse(widgetOptions(new, old))
|
||||
|
||||
# Can update lists
|
||||
@@ -1011,7 +1012,10 @@ class Address:
|
||||
self.assertTrue(widgetOptions(new, old))
|
||||
|
||||
# Can update without changing list.
|
||||
new = '{"widget":"TextBox","dontChange":[1, 2]}'
|
||||
old = '{"widget":"Spinner","dontChange":[1, 2]}'
|
||||
new = '{"widget":"TextBox","choices":[1, 2]}'
|
||||
old = '{"widget":"Spinner","choices":[1, 2]}'
|
||||
self.assertTrue(widgetOptions(new, old))
|
||||
# pylint: enable=R0915
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -192,8 +192,8 @@ def allowed_summary_change(key, updated, original):
|
||||
"""
|
||||
Checks if summary group by column can be modified.
|
||||
"""
|
||||
# Conditional styles are allowed
|
||||
if updated == original or key == 'rules':
|
||||
allowed_fields_to_change = {'rules', 'description'}
|
||||
if updated == original or key in allowed_fields_to_change:
|
||||
return True
|
||||
elif key == 'widgetOptions':
|
||||
try:
|
||||
@@ -201,18 +201,12 @@ def allowed_summary_change(key, updated, original):
|
||||
original_options = json.loads(original or '{}')
|
||||
except ValueError:
|
||||
return False
|
||||
# Unfortunately all widgetOptions are allowed to change, except choice items. But it is
|
||||
# better to list those that can be changed.
|
||||
# TODO: move choice items to separate column
|
||||
allowed_to_change = {'widget', 'dateFormat', 'timeFormat', 'isCustomDateFormat', 'alignment',
|
||||
'fillColor', 'textColor', 'isCustomTimeFormat', 'isCustomDateFormat',
|
||||
'numMode', 'numSign', 'decimals', 'maxDecimals', 'currency',
|
||||
'fontBold', 'fontItalic', 'fontUnderline', 'fontStrikethrough',
|
||||
'rulesOptions'}
|
||||
# Can do anything, but those options must be the same
|
||||
must_be_the_same = {'choices', 'choiceOptions'}
|
||||
# Helper function to remove protected keys from dictionary.
|
||||
def trim(options):
|
||||
return {k: v for k, v in options.items() if k not in allowed_to_change}
|
||||
return trim(updated_options) == trim(original_options)
|
||||
def protected_options(options):
|
||||
return {k: v for k, v in options.items() if k in must_be_the_same}
|
||||
return protected_options(updated_options) == protected_options(original_options)
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user