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

release-7.4.13.123 blocker fixes #550

Open
wants to merge 5 commits into
base: release-7.4.13.123
Choose a base branch
from
Open
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
Expand Up @@ -23,7 +23,7 @@ import {BasicInfoContainer} from './BasicInfoContainer/BasicInfoContainer';
import ContentContainer from './ContentContainer/ContentContainer';
import DefinitionOfTermsContainer from './DefinitionOfTermsContainer/DefinitionOfTermsContainer';
import {SettingsContainer} from './SettingsContainer/SettingsContainer';
import {getEmailNotificationRoles} from './SettingsContainer/rolesUtils';
import {getEmailNotificationRoles} from './SettingsContainer/rolesUtil';

import './EditNotificationTemplate.scss';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
import React, {useEffect, useState} from 'react';

import {NotificationTemplateError} from '../EditNotificationTemplate';
import {getCheckedChildren} from './rolesUtils';
import {
getCheckedChildren,
handleMultiSelectRoleItemsChange,
} from './rolesUtil';

interface PrimaryRecipientProps {
emailNotificationRoles: MultiSelectItem[];
Expand All @@ -45,30 +48,6 @@ export function PrimaryRecipient({
const [recipient] = values.recipients as EmailRecipients[];
const [toRolesList, setToRolesList] = useState<MultiSelectItem[]>([]);

const handleMultiSelectItemsChange = (itemsGroup: MultiSelectItem[]) => {
const newRecipients: EmailNotificationRecipients[] = [];

if (itemsGroup.length) {
itemsGroup.forEach((itemGroup) => {
itemGroup.children.forEach((child) => {
if (child.checked) {
newRecipients.push({['roleName']: child.value});
}
});
});
}

setValues({
...values,
recipients: [
{
...recipient,
to: newRecipients,
},
],
});
};

useEffect(() => {
if (emailNotificationRoles.length && !toRolesList.length) {
setToRolesList(emailNotificationRoles);
Expand Down Expand Up @@ -171,7 +150,19 @@ export function PrimaryRecipient({
)}
selectAllOption
setOptions={(items) => {
handleMultiSelectItemsChange(items);
const newRecipients =
handleMultiSelectRoleItemsChange(items);

setValues({
...values,
recipients: [
{
...recipient,
to: newRecipients,
},
],
});

setToRolesList(items);
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
} from 'frontend-js-components-web';
import React, {useEffect, useState} from 'react';

import {getCheckedChildren} from './rolesUtils';
import {
getCheckedChildren,
handleMultiSelectRoleItemsChange,
} from './rolesUtil';

interface SecondaryRecipientsProps {
emailNotificationRoles: MultiSelectItem[];
Expand All @@ -38,22 +41,6 @@ export function SecondaryRecipient({
const [ccRolesList, setCCRolesList] = useState<MultiSelectItem[]>([]);
const [recipient] = values.recipients as EmailRecipients[];

const handleMultiSelectItemsChange = (itemsGroup: MultiSelectItem[]) => {
const newRecipients: EmailNotificationRecipients[] = [];

if (itemsGroup.length) {
itemsGroup.forEach((itemGroup) => {
itemGroup.children.forEach((child) => {
if (child.checked) {
newRecipients.push({['roleName']: child.value});
}
});
});
}

return newRecipients;
};

useEffect(() => {
if (emailNotificationRoles.length && !ccRolesList.length) {
setCCRolesList(emailNotificationRoles);
Expand Down Expand Up @@ -200,9 +187,10 @@ export function SecondaryRecipient({
selectAllOption
setOptions={(items) => {
const newRecipients =
handleMultiSelectItemsChange(
handleMultiSelectRoleItemsChange(
items
);

setValues({
...values,
recipients: [
Expand All @@ -212,6 +200,7 @@ export function SecondaryRecipient({
},
],
});

setCCRolesList(items);
}}
/>
Expand Down Expand Up @@ -318,9 +307,10 @@ export function SecondaryRecipient({
selectAllOption
setOptions={(items) => {
const newRecipients =
handleMultiSelectItemsChange(
handleMultiSelectRoleItemsChange(
items
);

setValues({
...values,
recipients: [
Expand All @@ -330,6 +320,7 @@ export function SecondaryRecipient({
},
],
});

setBCCRolesList(items);
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {fetch} from 'frontend-js-web';
import React, {useEffect, useState} from 'react';

import {HEADERS} from '../../util/constants';
import {getRoles, getUserNotificationRoles} from './rolesUtils';
import {getRoles, getUserNotificationRoles} from './rolesUtil';

interface User {
alternateName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface Roles {
totalCount: number;
}
interface RolesGroup {
accountRoles: LabelValueObject[];
organizationRoles: LabelValueObject[];
regularRoles: LabelValueObject[];
accountRoles: LabelNameObject[];
organizationRoles: LabelNameObject[];
regularRoles: LabelNameObject[];
}

const roleGroupLabels = {
Expand All @@ -46,17 +46,14 @@ export async function getEmailNotificationRoles(baseResourceURL: string) {
const roles = [] as MultiSelectItem[];

(
Object.entries(rolesResponse) as [
keyof RolesGroup,
LabelValueObject[],
][]
Object.entries(rolesResponse) as [keyof RolesGroup, LabelNameObject[]][]
).forEach(([roleGroupKey, roleValues]) => {
roles.push({
children: roleValues.map(({label, value}) => {
children: roleValues.map(({label, name}) => {
return {
checked: false,
label,
value,
value: name,
};
}),
label: roleGroupLabels[roleGroupKey],
Expand Down Expand Up @@ -117,3 +114,21 @@ export function getCheckedChildren(
};
});
}

export function handleMultiSelectRoleItemsChange(
itemsGroup: MultiSelectItem[]
) {
const newRecipients: EmailNotificationRecipients[] = [];

if (itemsGroup.length) {
itemsGroup.forEach((itemGroup) => {
itemGroup.children.forEach((child) => {
if (child.checked) {
newRecipients.push({['roleName']: child.value});
}
});
});
}

return newRecipients;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
*/

import '@testing-library/jest-dom/extend-expect';
import {MultiSelectItem} from '@liferay/object-js-components-web';

import {
getCheckedChildren,
getUserNotificationRoles,
} from '../components/SettingsContainer/rolesUtils';
handleMultiSelectRoleItemsChange,
} from '../components/SettingsContainer/rolesUtil';

it('Assert role names checked items', () => {
const children = [
Expand Down Expand Up @@ -137,3 +139,80 @@ it('Assert roles in User Notification', () => {
},
]);
});

it('verify that handleMultiSelectRoleItemsChange generates new recipients in the correct data structure', () => {
const itemsGroupMock = [
{
children: [
{
checked: true,
label: 'Account Administrator',
value: 'Account Administrator',
},
{
checked: false,
label: 'Account Member',
value: 'Account Member',
},
{
checked: true,
label: 'Account Supplier',
value: 'Account Supplier',
},
{
checked: true,
label: 'Buyer',
value: 'Buyer',
},
],
label: 'Account Roles',
value: 'accountRoles',
},
{
children: [
{
checked: false,
label: 'Administrator',
value: 'Administrator',
},
{
checked: false,
label: 'Owner',
value: 'Owner',
},
{
checked: true,
label: 'Power User',
value: 'Power User',
},
{
checked: true,
label: 'Supplier',
value: 'Supplier',
},
],
label: 'Regular Roles',
value: 'regularRoles',
},
] as MultiSelectItem[];

const newRecipients = handleMultiSelectRoleItemsChange(itemsGroupMock);

expect(newRecipients).toStrictEqual([
{
roleName: 'Account Administrator',
},
{
roleName: 'Account Supplier',
},
{
roleName: 'Buyer',
},
{
roleName: 'Power User',
},
{
roleName: 'Supplier',
},
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,11 @@ private void _verifyPortalUpgradeExtProperties() throws IOException {
private static File _jarDir;
private static final List<String> _reflectionOpens = Arrays.asList(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.base/sun.net.www.protocol.http=ALL-UNNAMED",
"--add-opens=java.base/sun.net.www.protocol.https=ALL-UNNAMED",
"--add-opens=java.base/sun.util.calendar=ALL-UNNAMED",
"--add-opens=jdk.zipfs/jdk.nio.zipfs=ALL-UNNAMED");

Expand Down