-
Notifications
You must be signed in to change notification settings - Fork 6
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
[#8895] Refactor search profile, update alerts and add delete modal #6059
[#8895] Refactor search profile, update alerts and add delete modal #6059
Conversation
31b6202
to
b6e14f2
Compare
b6e14f2
to
dca7159
Compare
return () => document.removeEventListener('keydown', handleKeyDown) | ||
}, []) | ||
|
||
useEffect(() => { |
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'd add a null check before calling showModal()
useEffect(() => {
if (dialogRef.current) {
dialogRef.current.showModal()
}
}, [])
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! Have added 👍
onClose() | ||
} | ||
|
||
useEffect(() => { |
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 save some performance and drop this useEffect
, and add onKeyDown as dialog attribute/prop. see comment below
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.
Nice, that's now removed.
}, []) | ||
|
||
return ( | ||
<dialog className="kiezradar__modal" ref={dialogRef} aria-modal="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.
<dialog
className="kiezradar__modal"
ref={dialogRef}
aria-modal="true" //can't remember whether we still need this
aria-labelledby="modal-title"
onKeyDown={(event) => {
if (event.key === 'Escape') closeModal()
}}
>
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.
also, since we have a title we might add a aria-labelledby="modal-title"
and the id="modal-title"
to the h3 (adds more context than aria-modal alone)
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.
Added that 👍
const [isEditing, setIsEditing] = useState(false) | ||
const [loading, setLoading] = useState(false) | ||
const [error, setError] = useState(null) | ||
const [profile, setProfile] = useState(profile_) | ||
const [deleteModal, setDeleteModal] = useState(null) | ||
|
||
const handleDelete = async () => { |
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.
what about const handleDelete = useCallback(async () => {
... and handleSubmit? to prevent unnecessary re-renders
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.
Oh cool, yes! Both using useCallback
now.
profile.project_types, | ||
profile.status.map((status) => ({ name: statusNames[status.name] })), | ||
profile.organisations | ||
searchProfile.districts, |
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.
what about destructuring to avoid redundancy ? const { id, name, query_text, districts, topics, project_types, status, organisations, plans_only, notification } = searchProfile;
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.
Tried this, but the linter complains:
const {
query_text,
districts,
topics,
project_types,
status,
organisations,
plans_only
} = searchProfile
87:5 error Identifier 'query_text' is not in camel case camelcase
90:5 error Identifier 'project_types' is not in camel case camelcase
93:5 error Identifier 'plans_only' is not in camel case camelcase
99:5 error Identifier 'project_types' is not in camel case camelcase
106:6 error Identifier 'query_text' is not in camel case camelcase
108:6 error Identifier 'plans_only' is not in camel case camelcase
Let's keep as is for now (and not alias to camelCase, as that is misleading what named properties are actually returned from a search profile).
Side note: I am always battling with this linter before pushing 🙈, mainly around formatting. Maybe in the future, Liquid can change to Prettier formatting, which formats on save in most editors.
</div> | ||
{error && <Alert type="danger" title={errorText} message={error} />} | ||
{isEditing && ( | ||
<form className="form--base panel--heavy search-profile__form" onSubmit={handleSubmit}> |
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.
what do you think of adding <fieldset disabled={loading}>
below <form>
to prevent submitting multiple times?
onKeyDown={(e) => { | ||
if (e.key === 'Enter') { | ||
e.preventDefault() | ||
e.target.form.requestSubmit() |
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 probably should avoid directly handling the DOM here 🤔 💭
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.
sorry a string of meetings interrupted my review 🫠 i think i was going to suggest useRef here..
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 turns out by adding type="button
to <button className="link" onClick={() => setIsEditing(false)}>
means we no longer need onKeyDown
as the browser now natively handles it 🎉
Unsure why doing this fixed it, as it is not the submit button, but prior to this, if we didn't have onKeyDown
, Chrome was complaining:
"Form submission canceled because the form is not connected"
dca7159
to
8d96330
Compare
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 ✨
Describe your changes
This PR refactors the search profile, to have a similar pattern of updating the alerts as the
Kiezradars
component where most of the state is in the parent.It also updates the search profile alert text and adds the delete modal when deleting search profiles.
Tasks