Repository navigation
feat: add the edit form model and form edit mode to Core (#364) - #509
Open
michaelstonis wants to merge 5 commits into
Open
michaelstonis wants to merge 5 commits into
michaelstonis wants to merge 5 commits into
Conversation
Comment on lines
+358
to
+369
| foreach (var column in dataSource.DisplayColumns) | ||
| { | ||
| if (!IsFormColumn(column)) continue; | ||
| int columnIndex = IndexOf(columns, column); | ||
| var kind = KindOf(column); | ||
| var value = ReadValue(item, column); | ||
| bool readOnly = gridReadOnly || column.IsReadOnly || !CanWrite(item, column) || | ||
| kind == KumikoEditFormFieldKind.Time && value is TimeSpan span && (span < TimeSpan.Zero || span >= TimeSpan.FromDays(1)); | ||
| var choices = kind == KumikoEditFormFieldKind.Choice ? ChoicesOf(column) : Array.Empty<KumikoEditFormChoice>(); | ||
| string label = string.IsNullOrEmpty(column.Header) ? column.PropertyName : column.Header; | ||
| fields.Add(new KumikoEditFormField(column, columnIndex, kind, label, readOnly, value, choices, culture)); | ||
| } |
Compute the sample join dates in double, drop the always-true pattern in KumikoEditFormField.Text and make the hosts' first-editor fields readonly.
Accessor, setter and nested-path fields, choice selectors and member paths, offset dates and times, setters that throw, sources that cannot take a new record, form commands and notifications, and edit triggers on rows that are not records. Brings branch coverage back over the ratchet.
| public void ANewItem_ACopiedOrTypedSourceCannotTake_IsNotAdded() | ||
| { | ||
| var title = new KumikoColumn { Header = "Title", PropertyName = nameof(Meeting.Title) }; | ||
| var copied = SourceOf(new[] { new Meeting() }.Select(m => m), title); // an IEnumerable: the grid keeps a copy |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #364.
Changes
A form edit mode: the grid can edit, or add, a record in a host-native form built from its columns instead of cell by cell. The rules for the form live in Core's editing layer, so the MAUI and Uno hosts share them and only build the native views.
Core (
KumikoUI.Core.Editing)KumikoEditMode { InCell, Form }andEditSession.EditMode. In form mode,EditSession.BeginEditopens no cell editor. It raisesEditSession.EditFormRequested(KumikoEditFormRequestedEventArgs:RowIndex,ColumnIndex,Column,Item,DataSource) and returns false. Every existing trigger already goes throughBeginEdit(double tap, Enter, F2, typing, the row menu's Edit), soKumikoInputControlleris unchanged. Boolean cells still toggle in place. Switching to form mode commits an open cell edit.EditSession.CreateEditForm(source, item, isNewItem)returns aKumikoEditFormwith these members:Item,IsNewItem,DataSource,Fields,GetField(name)(also exposed as an indexer,[Name]),Title,FirstEditableField,IsOpen,Error,HasErrors,TryCommit()/TryCommit(out invalidFields),Cancel(),SaveCommand,CancelCommand,ClosedandPropertyChanged.KumikoEditFormField(INotifyPropertyChanged) hasColumn,Label,Kind(KumikoEditFormFieldKind: Text, Numeric, Boolean, Date, DateTime, Time, Choice),IsReadOnly,IsThreeState,MinDate/MaxDate,Use24HourTime,Choices(KumikoEditFormChoice:Label,Value),OriginalValue, the pendingValue,Text,SelectedChoiceIndex,IsDirty,ErrorandHasError.How fields are built: one field per visible column, in on-screen order. Image, progress bar, selection and action-button (interactive renderer) columns are skipped, and so are columns with nothing to read or write. Template columns are edited as text. A field is read-only when its column is read-only, when the grid is read-only, when the property has no setter, or when a time column holds a duration.
What
TryCommitdoes:KumikoValueConverter, in the grid's culture). A date edited alone keeps its time of day, and a time keeps the date of aDateTime.CellValidatorwith the item's view row (-1 for a new or hidden item). A warning is shown once and accepted on the second save, as in a cell.BeginUpdatebatch (one view rebuild), insideIEditableObject.BeginEdit/EndEditwhen the item implements it.IDataErrorInfo/INotifyDataErrorInfo). On an error, every original value is written back andCancelEditis called.KumikoSource.TryAddItem.CellValueChangedonce per changed field, so apps that save on that event keep working.A refused commit sets
Erroron each refused field and writes nothing.Cancelwrites nothing.KumikoEditFormOpeningEventArgs(Form,Handled,Cancel) andKumikoEditFormClosedEventArgs(Form,Committed).New
KumikoStrings:EditFormTitle,EditFormNewTitle,EditFormSave,EditFormCancel,EditFormNoValue,EditFormChecked,EditFormUnchecked,EditFormCannotAdd,AnnounceEditFormSaved.Small internal additions:
KumikoValuePath.CanWrite(item).EditSessionbecamepartial, with the new members inEditSession.Form.cs.TargetType,ValidateItemandMoreSeverewent from private to internal so the form can reuse them.Hosts (same surface on MAUI and Uno)
EditMode,EditFormTemplate(DataTemplate),EditFormOpening,EditFormClosed,ActiveEditForm,ShowEditForm(object item)andShowNewItemForm(object newItem). BothShowmethods work in either mode. They return false when the grid is read-only, when another form is open, when an open cell edit is refused, or when the opening event cancels.KumikoEditFormPageis pushed modally with the grid'sNavigation.Entry(numeric keyboard for numbers),CheckBox, a three-wayPickerfor three-state Booleans,DatePicker,TimePickerandPicker.KumikoEditFormDialog(ContentDialog) opens in the grid'sXamlRoot.TextBox(number input scope for numbers),CheckBox(IsThreeState),CalendarDatePicker,TimePickerandComboBox.SemanticProperties.Description/AutomationProperties.Name). The first editable field takes focus on open, and focus returns to the grid on close. "Saved", or the first error, is announced.KumikoStyle.EditFormTemplatereplaces the generated fields; the title, form message and buttons stay.EditFormOpening.Handledreplaces the whole UI.Samples and docs
Acceptance criteria
KumikoEditFormbuilds fields from columns, converts and validates all fields, writes them as one change, and supports new items. Not done yet: the issue also lists DataAnnotations (Editing: validate commits against DataAnnotations attributes, trim-safe through the source generator #352),RowValidating(Editing: add row-level edit transactions with IEditableObject, RowValidating and row cancel #351), one undo step (Editing: undo and redo committed cell edits with Ctrl/Cmd+Z and Ctrl/Cmd+Y #363), the per-cell read-only resolver (Editing: add a per-cell read-only resolver honored by every edit path #358) and theAddingNewItemfactory (Rows: add an in-grid new-item row that creates and edits an item in place #348), and none of these have landed.TryCommitmarks where the DataAnnotations check goes. New items come from the caller (ShowNewItemForm(newItem)) until Rows: add an in-grid new-item row that creates and edits an item in place #348 adds a factory.EditMode = Formopens the form from the usual edit triggers;ShowEditFormandShowNewItemFormwork in both modes; Cancel writes nothing. A trigger on a read-only column opens nothing, because the input controller stops beforeBeginEdit, and changing that would mean editingKumikoInputController.EditFormTemplateandEditFormOpening.Handledreplace them.tests/KumikoUI.Core.Tests/Editing; host tests intests/KumikoUI.Maui.Testsandtests/KumikoUI.Uno.Tests. The Uno tests cover the dialog with check box and choice fields plus the date and clock mappings:TextBoxand the date and time pickers cannot be created without a running Uno app.PublicAPI.Unshipped.txtupdated (Core, Maui, Uno).Verification
dotnet build src/KumikoUI.Core: 0 warnings, 0 errors. A Release build passeseng/TypeNameCheck("No public type name collides").dotnet build src/KumikoUI.SkiaSharp: 0 warnings.dotnet build src/KumikoUI.Maui -f net10.0-maccatalyst: 0 warnings.dotnet build src/KumikoUI.Uno -f net10.0-desktop: no new warnings.dotnet test tests/KumikoUI.Core.Tests: 4383 passed, 5 skipped. New:Editing/EditFormTests(22 tests) and theLocalizationTeststable.dotnet test tests/KumikoUI.Maui.Tests: 458 passed, including 9 newKumikoDataGridEditFormTests.dotnet test tests/KumikoUI.Uno.Tests: 328 passed, including 7 newKumikoEditFormDialogTests.dotnet test tests/KumikoUI.SkiaSharp.Tests: 42 passed.dotnet build samples/SampleApp.Uno -f net10.0-desktop: succeeded.dotnet build samples/SampleApp.Maui -f net10.0-maccatalyst -p:KumikoDevFlow=false: succeeded. With DevFlow on, this machine's restore fails with NU1605, a Microsoft.Maui.Controls version conflict. The conflict is the same without this change.dotnet run --project eng/DocsSnippets -c Release, thendotnet build tests/KumikoUI.Docs.Snippets.Uno -f net10.0-desktop -c Releaseanddotnet build tests/KumikoUI.Docs.Snippets.Maui -f net10.0-maccatalyst -c Release: both succeeded.