-
Notifications
You must be signed in to change notification settings - Fork 18
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
searchLocalStorageDataClasses #718
base: main
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 so far. Depending on where we're heading with this, see FYI comments.
typeof value === 'string' && | ||
value.toLowerCase().includes(lowerCaseSearchTerm) | ||
|
||
recordKeys.forEach(({ className: entity, recordKey }) => { |
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 we're mixing and renaming
className
andentity
/entities
for the same thing. Can we stick to either one or the other for better readability?
@@ -10,6 +10,8 @@ interface RawDataItem { | |||
[key: string]: unknown | |||
} | |||
|
|||
const recordKeys: Set<{ recordKey: string; className: string }> = new Set() |
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 Making this a Set is misleading b/c the seemingly same key, e.g.
recordKeys.add({ recordKey: "foo", className: "bar" })
will be added multiple times to the set. How about making it an Array instead?
@@ -25,6 +27,7 @@ export function provideLocalStorageDataClass( | |||
} = {}, | |||
) { | |||
const recordKey = `localDataClass-${scrivitoTenantId()}-${className}` | |||
recordKeys.add({ className, recordKey }) |
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 The
recordKey
can be recomputed easily from theclassName
. How about reducing redundancy and just storing the list of class names? - FYI Taking it one step further: Looking at the intended usage the caller of
searchLocalStorageDataClasses
knows all class names. If this is true for all callers we could rid of the list of keys completely by taking the list of class names as an argument.
Object.entries(restoreRecord(recordKey)).forEach(([_id, item]) => { | ||
if (Object.values(item).some(matchesSearchTerm)) { | ||
results.push({ | ||
_id, |
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 We may end up with multiple results sharing the same
_id
, e.g., after copy-pasting to add a new local-storage data class. Not sure which implications this will have later on.
search: string, | ||
blackListEntities: string[] = [], | ||
): Array<{ _id: string; entity: string; title: string }> { | ||
const results: Array<{ _id: string; entity: string; title: 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.
- FYI For a reader with a functional programming background something like this could be more readable (actually this is what I translate the logic of the function to in my head when reading the code):
return entities.flatMap((entity) =>
Object.entries(restoreRecord(recordKeyForClassName(entity)))
.filter(([, item]) => Object.values(item).some(matchesSearchTerm))
.map(([_id, item]) => ({
_id,
entity,
title: ensureString(item.title) || ensureString(item.keyword),
})),
)
}) | ||
}) | ||
|
||
return results |
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 The results will be "sorted" by the runtime order of entities. Assuming an actual backend would sort by relevance, could we apply some sorting, e.g., by the number of matches per item?
This is a preparation of the upcoming CRM search.
Intended use searchLocalStorageDataClasses...poc_crm_search .
Example deployment: https://edit.scrivito.com/d0a154d76edf2a7bd991fc658e700a1d~https://poc-crm-search.scrivito-portal-app.pages.dev/en/search-02fffe06aa9f09d9?_scrivito_workspace_id=p6d384dda43ac613&_scrivito_display_mode=view