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

Refactoring of GridViewDataSet #1548

Open
wants to merge 48 commits into
base: main
Choose a base branch
from
Open

Refactoring of GridViewDataSet #1548

wants to merge 48 commits into from

Conversation

tomasherceg
Copy link
Member

Another attempt to make GridViewDataSet extensible and loadable on the client side.

Copy link
Member

@exyi exyi left a comment

Choose a reason for hiding this comment

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

Other significant unsolved problems are:

  • The dataset translations will only work in the context of DataSetClientSideLoad, not in ad-hoc staticCommand
  • Async LoadFromQueryable (and the IPagingOptionsLoadingPostProcessor interface), I will make a separate PR for that

@@ -125,6 +128,7 @@
<ItemGroup>
<!-- the wildcard would not work in Target.Inputs, it only works in Include -->
<TypescriptFile Include="Resources/Scripts/**/*.ts" />
<UpToDateCheckInput Include="Resources/Scripts/**/*.ts" />
Copy link
Member

Choose a reason for hiding this comment

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

What do these changes do?

writer.AddAttribute("onclick", KnockoutHelper.GenerateClientPostBackScript(
nameof(Click), clickBinding, this,
new PostbackScriptOptions(commandArgs: BindingHelper.GetParametrizedCommandArgs(this, ClickArguments))),
append: true, appendSeparator: ";");
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should consider moving the postback script generation to the base class, this is somewhat arcane if someone want to make a custom button

@@ -11,11 +9,11 @@ public interface IRefreshableGridViewDataSet : IBaseGridViewDataSet
/// Gets whether the data should be refreshed. This property is set to true automatically
/// when paging, sorting or other options change.
/// </summary>
bool IsRefreshRequired { get; }
bool IsRefreshRequired { get; set; }

/// <summary>
/// Requests to reload data into the <see cref="IRefreshableGridViewDataSet" />.
/// </summary>
void RequestRefresh();
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this method if are adding the IsRefreshRequired setter?

I actually think it's more obvious what dataset.IsRefreshRequired = true than dataset.RequestRefresh() - it's clear that it's no magic request, just a boolean flag

public TRowEditOptions RowEditOptions { get; set; }


IList IBaseGridViewDataSet.Items => Items is List<T> list ? list : Items.ToList();
Copy link
Member

Choose a reason for hiding this comment

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

I'd either throw an exception or change the return type IReadonlyList (or return a readonly list). E.g. deleting from the Items returned by this property might do nothing and I'd not want to debug this.

(dataSource as IPageableGridViewDataSet<IPagingFirstPageCapability>)?.PagingOptions.GoToFirstPage();
(dataSource as IRefreshableGridViewDataSet)?.RequestRefresh();
}),
new IdBindingProperty($"{this.GetDotvvmUniqueId().GetValue()}_sortBinding")
Copy link
Member

Choose a reason for hiding this comment

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

We used to simply call the SortChanged without the additional paging+refresh, why is this needed? Since we now have the Button CommandParameters, we wouldn't have to touch the SortChanged binding and we could thus simply allow staticCommands here.

src/Framework/Framework/Controls/DataPager.cs Outdated Show resolved Hide resolved
{
if (IsPropertySet(VisibleProperty))
throw new Exception("Visible can't be set on a DataPager when HideWhenOnlyOnePage is true. You can wrap it in an element that hide that or set HideWhenOnlyOnePage to false");
list.SetProperty(HtmlGenericControl.VisibleProperty, hasMoreThanOnePage);
Copy link
Member

Choose a reason for hiding this comment

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

I know this error is not new, but we can combine the Visible bindings now

if (property.GetCustomAttribute<ProtectAttribute>() is ProtectAttribute protect && protect.Settings == ProtectMode.EncryptData)
{
throw new Exception($"Cannot sort by an property '{prop}' that is encrypted.");
}
Copy link
Member

Choose a reason for hiding this comment

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

We do allow sorting by private properties through?


await r.RunCommand((CommandBindingExpression)nextPage.command, nextPage.control);
Assert.AreEqual(1, (int)r.ViewModel.Customers.PagingOptions.PageIndex);
}
Copy link
Member

Choose a reason for hiding this comment

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

TODO: add staticCommand datapager (just that it generates something reasonable, we have UI test for it); add AppendableDataPager

tomasherceg and others added 24 commits April 27, 2024 12:43
who knows if it works...
Creates a nested data context with _index and _collection extension parameters
* introduced symbolic parameters for $gridViewDataSet.loadData function.
   we need to substitute this loadData function on a single element, so
   we cannot use dotvvm-gridviewdataset to change the data context.
* refactored PostbackOptions to a record to allow using `with { ... }` syntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants