-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[App Search] Schema: Set up server routes, grand foray into shared/connected Kea logic #99548
Conversation
- values & actions shared between both default source engine & meta engine pages
- significantly different actions (no updating) & API response from source engines, hence the separate files + fix typing issue - without Partial<>, all 4 enum types are expected instead of 1-4 - for some reason this causes an error in a separate a util file, not sure why (Typescript issue?)
interface MetaEngineSchemaValues extends SchemaBaseValues { | ||
fields: MetaEngineSchemaApiResponse['fields']; | ||
conflictingFields: MetaEngineSchemaApiResponse['conflictingFields']; | ||
conflictingFieldsCount: number; | ||
hasConflicts: boolean; | ||
} | ||
|
||
interface MetaEngineSchemaActions extends SchemaBaseActions { | ||
loadMetaEngineSchema(): void; | ||
onMetaEngineSchemaLoad(response: MetaEngineSchemaApiResponse): MetaEngineSchemaApiResponse; | ||
} | ||
|
||
export const MetaEngineSchemaLogic = kea< |
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.
Hopefully comparing the two different logic files between source engines & meta engines helps illustrate why I chose to separate them - they're all in 1 file right now in the standalone UI and it's pretty hard to grok as a result. Hoping this is at least tidier.
It's honestly weird because the Meta Engine view, aside from the schema
data, is almost completely different from the default/indexed schema view - it has no actual actions to take for example.
Some day I'll have a breakthrough genius idea on how to better organize our meta engine vs indexed engine logic/views/etc., but that day is not today 🙃
x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/types.ts
Show resolved
Hide resolved
@@ -31,7 +31,7 @@ export type Schema = Record<string, SchemaType>; | |||
|
|||
// This is a mapping of schema field types ("text", "number", "geolocation", "date") | |||
// to the names of source engines which utilize that type | |||
export type SchemaConflictFieldTypes = Record<SchemaType, string[]>; | |||
export type SchemaConflictFieldTypes = Partial<Record<SchemaType, string[]>>; |
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.
Not sure how I didn't run into a type error with this before now, but without the Partial<>
Typescript yells if you have just e.g. { text: ['some-engine'], number: ['another-engine'] }
- it wants all the keys from SchemaType otherwise 🤷
...terprise_search/public/applications/app_search/components/schema/schema_meta_engine_logic.ts
Show resolved
Hide resolved
...k/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
Show resolved
Hide resolved
...k/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
Show resolved
Hide resolved
mostRecentIndexJob: { | ||
percentageComplete: 100, | ||
numDocumentsWithErrors: 10, | ||
activeReindexJobId: 'some-id', | ||
isActive: false, | ||
hasErrors: true, | ||
}, |
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.
FYI that a large majority of this data we're no longer using after 7.12/the document storage refactor - percentageComplete
will always come back as 100 and isActive
as false. I still kept it in here as an example, but def would be nice to clean up our APIs some day
/** | ||
* Unfortunately, we can't mount({ schema: ... }) & have to use an action to set schema | ||
* because of the separate connected logic file - our LogicMounter test helper sets context | ||
* for only the currently tested file | ||
*/ | ||
const mountAndSetSchema = ({ schema, ...values }: { schema: Schema; [key: string]: unknown }) => { | ||
mount(values); | ||
SchemaLogic.actions.setSchema(schema); | ||
}; |
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.
Just want to flag this as one very unfortunate hiccup in the connect
approach to sharing state... our LogicMounter
test helper automatically uses the current path to populate values, so we can't populate connected logics' values. So doing this:
mount({ schema: {} }); // belongs to SchemaBaseLogic, not SchemaLogic
does nothing and doesn't actually correctly set the value. I used this as a workaround in this file for now, but not sure if we should try to come up with a better/more elegant solution or just want for .extend()
type support 🤷
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.
That's interesting. How would this look if we bypassed the helper? 🤔
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.
I assume something like this:
resetContext({
defaults: {
enterprise_search: {
app_search: {
some_base_logic: {
someSharedValue: 'hello',
},
some_extended_logic: {
someSpecificValue: 'world',
},
},
},
},
});
Looking at it that way, I can definitely see the potential of extending our test mount helper to mount with separate files, but it would be fairly tricky and be a more complex API/usage than our current helper
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.
Ahhh ok, that clears it up for me, thanks for posting that.
connect: { | ||
values: [SchemaBaseLogic, ['dataLoading', 'schema']], | ||
actions: [SchemaBaseLogic, ['loadSchema', 'setSchema']], | ||
}, |
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.
FWIW though, I do actually kind of like that shared values/actions are so explicitly listed rather than .extend()
being somewhat magical / invisible & having to dive into another file to see what's shared. Tradeoffs everywhere I guess!
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.
I feel the same way. 💯
@elasticmachine merge upstream |
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.
I really like the base logic, it keeps things DRY without adding a ton of overhead.
Just a few questions and comments.
x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/types.ts
Show resolved
Hide resolved
x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/types.ts
Show resolved
Hide resolved
...enterprise_search/public/applications/app_search/components/schema/schema_base_logic.test.ts
Show resolved
Hide resolved
...gins/enterprise_search/public/applications/app_search/components/schema/schema_base_logic.ts
Outdated
Show resolved
Hide resolved
...gins/enterprise_search/public/applications/app_search/components/schema/schema_logic.test.ts
Show resolved
Hide resolved
...k/plugins/enterprise_search/public/applications/app_search/components/schema/schema_logic.ts
Outdated
Show resolved
Hide resolved
...terprise_search/public/applications/app_search/components/schema/schema_meta_engine_logic.ts
Show resolved
Hide resolved
...terprise_search/public/applications/app_search/components/schema/schema_meta_engine_logic.ts
Outdated
Show resolved
Hide resolved
...ise_search/public/applications/app_search/components/schema/schema_meta_engine_logic.test.ts
Outdated
Show resolved
Hide resolved
...terprise_search/public/applications/app_search/components/schema/schema_meta_engine_logic.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.
@JasonStoltz check it out!!! 82a711c
-31 lines! This is so much simpler/cleaner haha. Thanks for showing me the light!! It somehow never occurred to me the shared action itself could continue to be extended via reducers 🤦♀️ Seriously so cool.
@@ -23,6 +23,9 @@ describe('SchemaBaseLogic', () => { | |||
some_text_field: SchemaType.Text, | |||
some_number_field: SchemaType.Number, | |||
}; | |||
const MOCK_RESPONSE = { | |||
schema: MOCK_SCHEMA, | |||
} as any; |
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.
I'm being a bit lazy and using any
in this test file to avoid the whole SchemaApiResponse | MetaEngineSchemaApiResponse
typing shenanigans. I could cast as unknown as SchemaApiResponse
if folks prefer me to stop taking shortcuts 😅
onSchemaLoad( | ||
response: SchemaApiResponse | MetaEngineSchemaApiResponse | ||
): SchemaApiResponse | MetaEngineSchemaApiResponse; |
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.
Typing comments continued - this is mostly here as dev documentation. I override/extend the onSchemaLoad
action typing in each individual extended logic file (see below comments).
@@ -35,7 +35,6 @@ interface SchemaValues extends SchemaBaseValues { | |||
} | |||
|
|||
interface SchemaActions extends SchemaBaseActions { | |||
loadIndexedEngineSchema(): void; | |||
onSchemaLoad(response: SchemaApiResponse): SchemaApiResponse; |
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.
See above comment - this fixes the onSchemaLoad
type differences between source & meta engines
@@ -18,8 +18,7 @@ interface MetaEngineSchemaValues extends SchemaBaseValues { | |||
} | |||
|
|||
interface MetaEngineSchemaActions extends SchemaBaseActions { | |||
loadMetaEngineSchema(): void; | |||
onMetaEngineSchemaLoad(response: MetaEngineSchemaApiResponse): MetaEngineSchemaApiResponse; | |||
onSchemaLoad(response: MetaEngineSchemaApiResponse): MetaEngineSchemaApiResponse; |
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.
See above comment - this fixes the onSchemaLoad
type differences between source & meta engines
actions: { | ||
loadMetaEngineSchema: true, | ||
onMetaEngineSchemaLoad: (response) => response, | ||
actions: [SchemaBaseLogic, ['loadSchema', 'onSchemaLoad']], |
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.
I cleaned up setSchema
from this list since meta engines isn't using that action (bad copypasta on my part)
loadMetaEngineSchema: () => { | ||
actions.loadSchema(actions.onMetaEngineSchemaLoad); | ||
}, | ||
}), |
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.
Doh I forgot to include this comment in the batch just now, but just wanted to reiterate that it's SUPER cool I was able to drop the actions
and listeners
block for MetaEngineSchemaLogic totally. Thanks again Jason, you're a genius! 🧠
💚 Build SucceededMetrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
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.
Great work! Glad that worked out for you.
…nnected Kea logic (elastic#99548) * Set up server API routes * Set up types * Set up shared/base Schema logic file - values & actions shared between both default source engine & meta engine pages * Add default/indexed engine SchemaLogic * Add MetaEnginesSchemaLogic - significantly different actions (no updating) & API response from source engines, hence the separate files + fix typing issue - without Partial<>, all 4 enum types are expected instead of 1-4 - for some reason this causes an error in a separate a util file, not sure why (Typescript issue?) * Update Schema & MetaEngineSchema views with loaders * PR feedback: comment nit * PR feedback: Remove unnecessary async/awaits * PR feedback: Simplify loadSchema to be shared by base logic Much clean, such simple Co-authored-by: Kibana Machine <[email protected]>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…nnected Kea logic (#99548) (#99833) * Set up server API routes * Set up types * Set up shared/base Schema logic file - values & actions shared between both default source engine & meta engine pages * Add default/indexed engine SchemaLogic * Add MetaEnginesSchemaLogic - significantly different actions (no updating) & API response from source engines, hence the separate files + fix typing issue - without Partial<>, all 4 enum types are expected instead of 1-4 - for some reason this causes an error in a separate a util file, not sure why (Typescript issue?) * Update Schema & MetaEngineSchema views with loaders * PR feedback: comment nit * PR feedback: Remove unnecessary async/awaits * PR feedback: Simplify loadSchema to be shared by base logic Much clean, such simple Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Constance <[email protected]>
- Missed this in elastic#99548
* Add schema add field modal to page * Add SchemaCallouts component * Add empty state * Add SchemaTable component - Main update functionality is covered by the shared SchemaFieldTypeSelect component + Readd 'Recently added' i18n strings removed in https://github.com/elastic/kibana/pull/98955/files/d93e31dd415ba61354ab3714cd2728d60efa6ddc#r624038044 squash with table * Add final update types button behavior + expand tests more explicitly & cleanly * Fix i18n just throw my body in the trash * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/views/schema.test.tsx Co-authored-by: Jason Stoltzfus <[email protected]> * [Misc] Add missing SchemaBaseLogic state check - Missed this in #99548 * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/components/empty_state.tsx Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Jason Stoltzfus <[email protected]>
* Add schema add field modal to page * Add SchemaCallouts component * Add empty state * Add SchemaTable component - Main update functionality is covered by the shared SchemaFieldTypeSelect component + Readd 'Recently added' i18n strings removed in https://github.com/elastic/kibana/pull/98955/files/d93e31dd415ba61354ab3714cd2728d60efa6ddc#r624038044 squash with table * Add final update types button behavior + expand tests more explicitly & cleanly * Fix i18n just throw my body in the trash * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/views/schema.test.tsx Co-authored-by: Jason Stoltzfus <[email protected]> * [Misc] Add missing SchemaBaseLogic state check - Missed this in elastic#99548 * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/components/empty_state.tsx Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Jason Stoltzfus <[email protected]>
* Add schema add field modal to page * Add SchemaCallouts component * Add empty state * Add SchemaTable component - Main update functionality is covered by the shared SchemaFieldTypeSelect component + Readd 'Recently added' i18n strings removed in https://github.com/elastic/kibana/pull/98955/files/d93e31dd415ba61354ab3714cd2728d60efa6ddc#r624038044 squash with table * Add final update types button behavior + expand tests more explicitly & cleanly * Fix i18n just throw my body in the trash * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/views/schema.test.tsx Co-authored-by: Jason Stoltzfus <[email protected]> * [Misc] Add missing SchemaBaseLogic state check - Missed this in #99548 * Update x-pack/plugins/enterprise_search/public/applications/app_search/components/schema/components/empty_state.tsx Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Jason Stoltzfus <[email protected]> Co-authored-by: Constance <[email protected]> Co-authored-by: Jason Stoltzfus <[email protected]>
Summary
Whoof, a lot going on here! There (currently) isn't any changed UI/UX to test this with, but if you go to the schema pages of an engine or meta engine you can see the XHR call getting made on page load and inspect the API response.
This PR is also a semi-experimental foray into sharing some base values/actions between 2 separate-but-similar logic files. Indexed vs Meta Engines is generally a good candidate for this and there's some other meta engine logic where I might attempt something similar later if this is well-received by y'all.
Strongly recommend following along by commit!
Checklist