[data view editor] Form state refactor - move all state logic into service and out of react state management#143604
Conversation
src/plugins/data_view_editor/public/components/form_fields/title_field.tsx
Outdated
Show resolved
Hide resolved
src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx
Outdated
Show resolved
Hide resolved
…kime/kibana into reduce_react_state_data_view_create
src/plugins/data_view_editor/public/components/form_fields/title_field.tsx
Outdated
Show resolved
Hide resolved
| showAllIndices: allowHidden, | ||
| }); | ||
| dataViewEditorService.setIndexPattern(title); | ||
| }, [dataViewEditorService, title]); |
| const isLoadingDataViewNames$ = useRef(new BehaviorSubject<boolean>(true)); | ||
| const existingDataViewNames$ = useRef(new BehaviorSubject<string[]>([])); | ||
| const isLoadingDataViewNames = useObservable(isLoadingDataViewNames$.current, true); | ||
| const existingDataViewNames = useObservable(dataViewEditorService.dataViewNames$); |
| // alernates between value and undefined so validation can treat new value as thought its a promise | ||
| rollupIndexForProvider$ = new Subject<string | undefined | null>(); | ||
|
|
||
| matchedIndices$ = new BehaviorSubject<MatchedIndicesSet>(matchedIndiciesDefault); |
There was a problem hiding this comment.
public observables for react code to subscribe to
|
|
||
| setIndexPattern = (indexPattern: string) => { | ||
| this.indexPattern = indexPattern; | ||
| this.loadIndices(); |
There was a problem hiding this comment.
simple state update that kicks off observable updates
| services: { dataViews, notifications, http }, | ||
| } = useKibana<DataViewEditorContext>(); | ||
|
|
||
| const dataViewEditorService = useRef( |
There was a problem hiding this comment.
The intention is to have a stable reference to a single service for the life of the component.
…kime/kibana into reduce_react_state_data_view_create
There was a problem hiding this comment.
Recent changes to the service initialization lgtm 👍
I started testing,
Noticed that you edit a data view, press save, then it goes into an indefinite "loading" state. In main it simply saves and closes the flyout. I assume that the culprit might cause other similar bugs
Also seem to be the same problem for editing and ad-hoc view, even after doing some changes,
|
@Dosant I resolved that issue - the index pattern field wasn't being updated and therefore an observable wasn't getting a new value which was necessary for validation. I added a line of code which generates the new value. I think there's a bit of a mismatch between form lib and using observables for state. In the long run I'd like to rectify this but I see a number of conversations around state management before that could happen. |
Dosant
left a comment
There was a problem hiding this comment.
Retested, seem to be working well
…kime/kibana into reduce_react_state_data_view_create
jughosta
left a comment
There was a problem hiding this comment.
LGTM 👍
Thanks for the refactoring! Left some suggestions which can be addressed later if relevant.
|
|
||
| // state | ||
| private indexPattern = ''; | ||
| private allowHidden = false; |
There was a problem hiding this comment.
Would be great if allowHidden becomes enabled when editing a saved data view for hidden indices.
Steps:
- Create a data view for hidden indices
- Open it in Edit mode and see that it can't find matching indices unless the switch is toggled manually again.
There was a problem hiding this comment.
I'll address these in a follow up PR.
| name: initialName = '', | ||
| }, | ||
| requireTimestampField = false, | ||
| }: DataViewEditorServiceConstructorArgs) { |
…kime/kibana into reduce_react_state_data_view_create
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsESLint disabled in files
ESLint disabled line counts
References to deprecated APIs
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |



Summary
This PR completes the data view editor state service. Of note:
useObservableuseRefso the service is created once per flyout creationIMO the diff isn't very helpful. It might be easier to review the changed files in completion.
Follow up to #142421