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

Bug/906 administration cascade duplication #924

Merged
merged 3 commits into from
Jan 15, 2024
Merged
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
18 changes: 15 additions & 3 deletions frontend/src/components/filters/AdministrationDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,25 @@ const AdministrationDropdown = ({
if (!e) {
return;
}
const { data: selectedAdm } = await api.get(`administration/${e}`);
let admItems = null;
if (Array.isArray(e)) {
const multiadministration = await Promise.all(
e.map(async (ID) => {
const apiResponse = await api.get(`administration/${ID}`);
return apiResponse.data;
})
);
admItems = multiadministration;
} else {
const { data: selectedAdm } = await api.get(`administration/${e}`);
admItems = [selectedAdm];
}
store.update((s) => {
s.administration.length = index + 1;
s.administration = s.administration.concat(selectedAdm);
s.administration = s.administration.concat(admItems);
});
if (onChange) {
const _values = allowMultiple && Array.isArray(e) ? e : null;
const _values = allowMultiple && Array.isArray(e) ? e : [e];
onChange(_values);
}
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/pages/mobile-assignment/AddAssignment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const AddAssignment = () => {
const [loading, setLoading] = useState(false);
const [preload, setPreload] = useState(true);
const [level, setLevel] = useState(userAdmLevel);
const [selectedAdministrations, setSelectedAdministrations] = useState([]);

const lowestLevel = levels
.slice()
Expand All @@ -55,7 +56,6 @@ const AddAssignment = () => {
const text = useMemo(() => {
return uiText[activeLang];
}, [activeLang]);

const pageTitle = id ? text.mobileEditText : text.mobileAddText;
const descriptionData = (
<p>{id ? text.mobilePanelEditDesc : text.mobilePanelAddDesc}</p>
Expand Down Expand Up @@ -129,7 +129,7 @@ const AddAssignment = () => {
const payload = {
name: values.name,
administrations:
values.administrations || selectedAdm.map((a) => a?.id),
selectedAdministrations || selectedAdm.map((a) => a?.id),
forms: values.forms,
};
if (id) {
Expand Down Expand Up @@ -265,7 +265,7 @@ const AddAssignment = () => {
maxLevel={level}
onChange={(values) => {
if (values) {
form.setFieldsValue({ administrations: values });
setSelectedAdministrations(values);
}
}}
persist={id ? true : false}
Expand Down