-
Notifications
You must be signed in to change notification settings - Fork 34
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
fix: onchange for autocomplete in datafilters #2047
Conversation
Fix to add `onChange` event for Autocomplete in DataFilters for DataTable
] as string) ?? "" | ||
} | ||
onChange={(_, value) => { | ||
const label = |
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.
@benlister-okta Can we pull this logic up into the handleInputChange
?
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.
Never mind, don't think we can :( How about making another function like... getAutoCompleteLabel
or something like that? Generally, I just try to avoid having to much logic inside JSX
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.
It would be cleaner if we did for sure. I was exploring this today and the issue I run into is that due to the structure of Autocomplete's data which simulates a Select
, the check to see if the data is an object or a string is needed here, but not in the global handleInputChange
. I might be missing something, let's chat about this Monday!
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.
@bryancunningham-okta I pulled back my last change and went with your idea of moving the logic to a getAutoCompleteLabel
function. Looking at the changes I had in handleInputChange
, it felt like it was getting too complicated overall. Let me know what you think of this approach or if you think and could be further optimized.
Type checks in onChange for Autocomplete moved into handleInputChange
Created a new function called getAutoCompleteLabel to simplify the Autocomplete logic
@bryancunningham-okta @KevinGhadyani-Okta @jordankoschei-okta let me know if you have thoughts on this approach. I think abstracting the checks into the autocomplete-specific function will be cleaner than what I was trying to do previously. |
): string => { | ||
if (Array.isArray(value)) { | ||
// Iterating to find the label | ||
for (const valueElement of value) { |
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.
Is the value array ever more than one entry?
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 didn't explore this case but multi-select is an option for Autocomplete
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.
So, it could theoretically be something like this?
[{label: 'some label'}, 'another label']
return valueElement.label; | ||
} | ||
} | ||
} else if ( |
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.
We could probably just do
} else if (value?.label) {...
removes nested ternary and breaks out handleInputChange into 2 steps
Hey @bryancunningham-okta @jordankoschei-okta, @KevinGhadyani-Okta helped me refactor some of the logic for the Autocomplete filter's Also, I just realized I still haven't gained access to Aplitools so I need help with the failed visual regression test (I believe it timed out). |
value: undefined, | ||
}); | ||
|
||
updateFilters({ |
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.
Kevin and I also discussed splitting the logic for updating the filter value shown in the DataFilter UI and the actual value in the form components into 2 parts updateInputValue
and updateFilters
to separate concerns and make the code a little easier to read.
unnecessary dependency was included
Fix to add `onChange` event for Autocomplete in DataFilters for DataTable
Type checks in onChange for Autocomplete moved into handleInputChange
Created a new function called getAutoCompleteLabel to simplify the Autocomplete logic
removes nested ternary and breaks out handleInputChange into 2 steps
unnecessary dependency was included
useImperativeHandle( | ||
inputFocusRef, | ||
() => { | ||
const element = ref.current; |
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.
Why create a temp variable? I think inputRef.current?.focus()
is fine. The .current
will always exist, it just might be run depending on when it's run.
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.
@KevinGhadyani-Okta the scope of my PR was only to add logic for autocomplete in DataFilters
. I am not sure what the reason for using a temp variable here was originally, but because I am unfamiliar with this code, I am unsure how to test it. Do you think we should consider this change in a future PR since it adds scope?
|
||
const Radio = ({ | ||
inputFocusRef, |
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.
Is the plan that any bi-directional props (like blur()
and focus()
are gonna have separate ref props?
If not, we should instead make this more generic so consumers only have to worry about creating a single ref to pass.
I would rename this more generically such as inputRef
.
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 am also not certain on this one, I believe the updates to Radio in the PR are from a library update, not related to new functionality.
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.
Did a rough check. Are all these changes yours? Did you need to merge main
?
if (typeof valueElement !== "string") { | ||
return valueElement.label; | ||
} | ||
|
||
return; |
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 surprised this doesn't throw a typescript error because we're not returning the same thing. Either we're returning a string
or undefined
.
I wonder if it would be better to say "if it's a string, then return undefined
; otherwise, return valueElement.label
". I say that because I prefer the positive over the negative with if
statements:
if (typeof valueElement !== "string") { | |
return valueElement.label; | |
} | |
return; | |
if (typeof valueElement === "string") { | |
return undefined; | |
} | |
return valueElement.label; |
<Box | ||
sx={{ | ||
display: "flex", | ||
gap: 2, | ||
alignItems: "flex-end", | ||
}} | ||
> | ||
<Box sx={{ width: "100%" }}> |
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.
Were we going to add styled components in this PR or a followup?
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.
thanks for the reminder, PR is updated with this now.
value={ | ||
inputValues[filterPopoverCurrentFilter.id] ?? "" | ||
} | ||
onChange={(_, value) => { |
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.
It's fine to keep this labeled as event
even if we don't use it because if we do use it, the _
isn't very helpful:
onChange={(_, value) => { | |
onChange={(event, value) => { |
If it's an ESLint error, don't worry about it.
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.
changing to event gives an ESLint error
options={filterPopoverCurrentFilter.options.map( | ||
(option: { label: string }) => ({ | ||
label: option.label, | ||
}) | ||
)} |
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.
We need to memoize this value.
Right now, we're creating options
every time a re-render occurs which is anytime you click something in DataFilters
, but I don't think the options ever change once this is rendered unless we're removing selected filters?
I thought there was something @jordankoschei-okta did recently about making it so selected items stay in the Autocomplete
list.
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.
@KevinGhadyani-Okta Are you open to pairing on this? It looks like we use memo
elsewhere in this file but I am not familiar with how the library works.
Fix to add
onChange
event for Autocomplete in DataFilters for DataTable.Jira: OKTA-671006
Summary
OnChange
to trigger updates in theAutocomplete
filter inDataFilters
. This was previously placeholder/stub logic.Textfield
andNumber
filters where the user makes a selection and click a primary button to add the filter.Testing & Screenshots
N/A