-
Notifications
You must be signed in to change notification settings - Fork 2
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
Proposal for new editors system #1166
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good for the most part, however I'd really like to reduce the API surface to a minimum before merging this in (instead of thinking about all the what-if use-cases).
One more major thing to address is the addition of core-quantity
peer dep.
I like the iconName
-> React.ReactNode
mapping for abstract iconSpec
types. However, let's do this in a separate PR.
apps/test-app/src/frontend/appui/frontstages/EditorFrontstage.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editorsRegistry/EditorsRegistryContext.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/CommittingEditor.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed most of the stuff in components-react
and imodel-components-react
.
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Metadata.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Values.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/values/Metadata.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/enum/UseEnumEditorProps.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/text/UseTextEditorProps.ts
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/newEditors/editors/numeric/FormattedNumericInput.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/editors/NewColorEditor.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/EditorRenderer.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors-registry/DefaultEditors.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/FormattedNumericInput.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/FormattedNumericInput.tsx
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/editors/NumericEditor.tsx
Outdated
Show resolved
Hide resolved
ui/components-react/src/components-react/new-editors/interop/EditorInterop.ts
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/editors/NewWeightEditor.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/QuantityEditor.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/QuantityInput.tsx
Outdated
Show resolved
Hide resolved
ui/imodel-components-react/src/imodel-components-react/inputs/newEditors/UseQuantityInfo.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the legacy APIs be deprecated in this PR? Or are you planning to do that separately?
I want to do that in separate PR. Have an issue for that #1224. |
...-image-check-box-UiAbstract-CheckBoxImages-default-visual-in-New-system-1-chromium-linux.png
Outdated
Show resolved
Hide resolved
...-snapshots/Editor-Primitive-boolean-toggle-default-visual-in-New-system-1-chromium-linux.png
Outdated
Show resolved
Hide resolved
@saskliutas I have a more meta question about this PR more than anything specific to the implementation. Should this new set of editors live inside of the AppUI components package or be split out of AppUI into its own separate package? Is there anything technically that would prevent this today, such as existing dependencies in other components within the package? I have the same question generally for a lot of the things in components react given the way we are not splitting major components into their own individual packages with their own release version and cadence. |
I think there is nothing preventing from moving editors into a separate package. Only uncomfortable part is that I am using React context to allow supplying custom editors so that new editors package would have to be a peerDependency in other packages delivering components using editors. As majority of packages delivering widgets already has peerDependecy on |
Proposal for new editor system
Proposal for the new editors system. This would replace existing editors system in order to simplify requirements for custom editors. Also it removes static EditorManager in favor of editors registry controlled through React context.
API overview:
EditorsRegistry - Application should use it to register their on custom editors or custom editors provided by some dependencies so that they would be accessible to all components in the application that uses editors system:
EditorsRegistryProvider
- adds supplied editors to the registry hold inReact
context. It supports nesting multipleEditorsRegistryProvider
to allow registering custom editors specific for some component that have higher priority than the ones registered near the root of the application.useEditor
- hook to get the editor that should be used to edit the supplied value. First it looks for applicable editor in EditorsRegistry and if none was found it fallbacks to the default editors.EditorRenderer
- wrapper around EditorRegistry that provides a convenient way to render editors for specific value.useCommittableValue
- custom React hooks that provides a convenient way to addcancel/commit
actions onEsc
/Enter
key click to the editor.Value
- type for all values that are supported by editors.ValueMetadata
- type for additional metadata that can be supplied to editors alongside value itself. It can be extended when implementing custom editors. (E.g. passing available choices and icons to the enum editor that is rendered as button group)createEditorSpec
- an utility function to that provides a convenient way to defined editor spec for typed editors.PropertyRecordEditor
- React component that allows to use existingPropertyRecord
type with the new editors system.Usage
Some examples of the new editors system usage.
Rendering editor and registering custom editors
Defining component that renders value editor:
Defining component that renders value editor with
Commit
/Cancel
actions:Registering custom editors to be available through out all application:
Registering custom editors that should be available only for specific component:
Defining custom editors
The goal of the new editors system is to remove the need for static editor registration and provide more convenient API for implementing custom editors. Current API has quite a lot optional properties that do not make sense (
propertyRecord
is optional but if it isundefined
there is no way to figure out what to render):Custom editor using old editor system and react class components:
Custom editor using old system and react functional components:
Custom boolean editor using new system:
The new system removes all the code that was associated with class components and accessing values through editor
ref
. It is not clear if that was used/useful so the chosen approach is to add something similar later if that is still needed. Majority of that was used byEditorContainer
that is replaced byuseCommittableValue
hook in the new system.Units supports
New editors system was aimed to provide better support for units. There is base component that should help with that
FormattedNumericInput
. It should be easy to write an editor on top of it that would know how to findParser
/Formatter
for specific unit.TODO
PropertyEditorParams
fromPropertyRecord
. Need to find a way how to sunset thosePropertyEditorParams
in the future but in mean time if should be possible to maintain what is already there in the old system.PropertyEditorParams
. The initial approach is to maintain internal registry (iconName: string) => ReactNode that would hold currently used icons. Open for suggestions on this one.CommitingEditor
as general solutions for committing entered values only on Enter/Blur or each components should have it's own logic to handle such workflows?