Skip to content
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

DRAFT/PROTOTYPE: React multiselect for user assignment #1184

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import Select from 'react-select'
import { useEffect } from 'react';
import accessibleAutocomplete from 'accessible-autocomplete'

Expand Down Expand Up @@ -26,28 +27,29 @@ function AssignUserForm({ assignmentType, users }) {
return (
<>
<form action={assignUsersUrl} method="POST" data-testid={"assign-user-form"}>
<input type="hidden" value={CSRF_TOKEN} name="csrfmiddlewaretoken"/>
<input type="hidden" value={CSRF_TOKEN} name="csrfmiddlewaretoken" />
<div className="govuk-form-group">
<label className="govuk-label" htmlFor={elementId}>
{label}
</label>
<div id={`${elementName}-hint`} className="govuk-hint">
{hint}
</div>
<select
{/* See scss/components for style overrides */}
<Select
required={true}
unstyled
isMulti
className="react-select-container"
classNamePrefix="react-select"
id={elementId}
name={elementName}
data-testid='assign-user-select'
>
<option value="">Select a user</option>
{users.map(user =>
<option key={user.pk} value={user.pk}>{user.name}</option>
)}
</select>
options={users}
/>
</div>
<div className="govuk-form-group">
<input type="hidden" name="assignment_type" value={assignmentType}/>
<input type="hidden" name="assignment_type" value={assignmentType} />
</div>
<button type="submit" className="govuk-button" data-prevent-double-click="true">Save</button>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,27 @@ function WorkbasketUserAssignment({ action, assignment, users, buttonId, formId
const [showForm, setShowForm] = useState(null);
const assignmentType = assignment == "workers" ? "WORKBASKET_WORKER" : "WORKBASKET_REVIEWER";

const removeFormDiv = () => {
const possibleFormDivs = [
document.getElementById("assign-workers-form"),
document.getElementById("unassign-workers-form"),
document.getElementById("assign-reviewers-form"),
document.getElementById("unassign-reviewers-form"),
];
possibleFormDivs.forEach(form => {
if (form) {
const assignmentRow = form.previousSibling;
assignmentRow.classList.remove("govuk-summary-list__row--no-border");
form.remove();
}
});
}

const createFormDiv = () => {
const formDiv = document.createElement("div");
formDiv.id = formId;
const formDiv = document.getElementById(formId);
formDiv.className = "govuk-!-margin-top-4";
const assignmentButton = document.getElementById(buttonId);
const assignmentRow = assignmentButton.closest(".govuk-summary-list__row");
assignmentRow.classList.add("govuk-summary-list__row--no-border");
assignmentRow.after(formDiv);
setShowForm(formDiv);
}

const handleClick = (e) => {
e.preventDefault();
const isShown = document.getElementById(formId);
removeFormDiv();
if(showForm && isShown) {
if (showForm && isShown) {
setShowForm(null);
return;
}
createFormDiv();
}
}

function UserForm({ action }) {
if (action === "Assign")
return <AssignUserForm assignmentType={assignmentType} users={users}/>;
return <AssignUserForm assignmentType={assignmentType} users={users} />;
else
return <UnassignUserForm users={users}/>;
return <UnassignUserForm users={users} />;
}

return (
Expand All @@ -75,7 +53,7 @@ function WorkbasketUserAssignment({ action, assignment, users, buttonId, formId
</button>

{showForm !== null && createPortal(
<UserForm action={action}/>,
<UserForm action={action} />,
showForm
)}
</>
Expand Down
26 changes: 26 additions & 0 deletions common/static/common/scss/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,29 @@
}

}

.react-select__control {
@extend .govuk-select;
}

.react-select__menu {
@extend .govuk-body;
background-color: govuk-colour("white");
border: 1px solid govuk-colour("mid-grey");
}

.react-select__option {
padding: 4px;

&:hover {
background-color: govuk-colour("light-grey");
}
}

.react-select__multi-value {
margin-right: 4px;
padding: 0 4px;
background-color: govuk-colour("light-grey");
border: 1px solid govuk-colour("dark-grey");
border-radius: 5px;
}
Loading
Loading