Skip to content

Commit

Permalink
Custom Data and Custom Fields (#1096)
Browse files Browse the repository at this point in the history
* save ppf admin changes

* fixed failing tests

* restoring EventCard test

* coverage increase

* increased coverage some more

* increase orgprofilefieldsettings' coverage
  • Loading branch information
JamarTG authored Dec 1, 2023
1 parent d23c7dc commit da70807
Show file tree
Hide file tree
Showing 16 changed files with 653 additions and 5 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"react-dom": "^17.0.2",
"react-google-recaptcha": "^2.1.0",
"react-i18next": "^11.18.1",
"react-icons": "^4.12.0",
"react-infinite-scroll-component": "^6.1.0",
"react-redux": "^7.2.5",
"react-router-dom": "^5.2.0",
Expand Down
14 changes: 13 additions & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,8 @@
"settings": "Settings",
"noData": "No data",
"otherSettings": "Other Settings",
"changeLanguage": "Change Language"
"changeLanguage": "Change Language",
"manageCustomFields": "Manage Custom Fields"
},
"deleteOrg": {
"deleteOrganization": "Delete Organization",
Expand Down Expand Up @@ -686,5 +687,16 @@
"userChatRoom": {
"selectContact": "Select a contact to start conversation",
"sendMessage": "Send Message"
},
"orgProfileField": {
"loading": "Loading...",
"noCustomField": "No custom fields available",
"customFieldName": "Field Name",
"enterCustomFieldName": "Enter Field name",
"customFieldType": "Field Type",
"saveChanges": "Save Changes",
"Remove Custom Field": "Remove Custom Field",
"fieldSuccessMessage": "Field added successfully",
"fieldRemovalSuccess": "Field removed successfully"
}
}
14 changes: 13 additions & 1 deletion public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@
"settings": "Réglages",
"noData": "Pas de données",
"otherSettings": "Autres paramètres",
"changeLanguage": "Changer la langue"
"changeLanguage": "Changer la langue",
"manageCustomFields": "Gérer les Champs Personnalisés"
},
"deleteOrg": {
"deleteOrganization": "Supprimer l'organisation",
Expand Down Expand Up @@ -664,5 +665,16 @@
"userChatRoom": {
"selectContact": "Sélectionnez un contact pour démarrer la conversation",
"sendMessage": "Envoyer le message"
},
"orgProfileField": {
"loading": "Chargement...",
"noCustomField": "Aucun champ personnalisé disponible",
"customFieldName": "Nom du champ",
"enterCustomFieldName": "Entrez le nom du champ",
"customFieldType": "Type de champ",
"saveChanges": "Enregistrer les modifications",
"Supprimer le champ personnalisé": "Supprimer le champ personnalisé",
"fieldSuccessMessage": "Champ ajouté avec succès",
"fieldRemovalSuccess": "Champ supprimé avec succès"
}
}
14 changes: 13 additions & 1 deletion public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@
"settings": "समायोजन",
"noData": "कोई डेटा नहीं",
"otherSettings": "अन्य सेटिंग्स",
"changeLanguage": "भाषा बदलें"
"changeLanguage": "भाषा बदलें",
"manageCustomFields": "कस्टम फ़ील्ड प्रबंधन करें"
},
"deleteOrg": {
"deleteOrganization": "संगठन हटाएं",
Expand Down Expand Up @@ -664,5 +665,16 @@
"userChatRoom": {
"selectContact": "बातचीत शुरू करने के लिए एक संपर्क चुनें",
"sendMessage": "मेसेज भेजें"
},
"ऑर्गप्रोफ़ाइलफ़ील्ड": {
"लोड हो रहा है": "लोड हो रहा है...",
"noCustomField": "कोई कस्टम फ़ील्ड उपलब्ध नहीं",
"customFieldName": "फ़ील्ड नाम",
"enterCustomFieldName": "फ़ील्ड नाम दर्ज करें",
"customFieldType": "फ़ील्ड प्रकार",
"saveChanges": "परिवर्तन सहेजें",
"कस्टम फ़ील्ड हटाएँ": "कस्टम फ़ील्ड हटाएँ",
"fieldSuccessMessage": "फ़ील्ड सफलतापूर्वक जोड़ा गया",
"fieldRemovalSuccess": "फ़ील्ड सफलतापूर्वक हटा दिया गया"
}
}
14 changes: 13 additions & 1 deletion public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@
"settings": "Ajustes",
"noData": "Sin datos",
"otherSettings": "Otras Configuraciones",
"changeLanguage": "Cambiar Idioma"
"changeLanguage": "Cambiar Idioma",
"manageCustomFields": "Gestionar Campos Personalizados"
},
"deleteOrg": {
"deleteOrganization": "Eliminar organización",
Expand Down Expand Up @@ -664,5 +665,16 @@
"userChatRoom": {
"selectContact": "Seleccione un contacto para iniciar una conversación",
"sendMessage": "Enviar mensaje"
},
"campoPerfildeOrganización": {
"cargando": "Cargando...",
"noCustomField": "No hay campos personalizados disponibles",
"customFieldName": "Nombre de campo",
"enterCustomFieldName": "Ingrese el nombre del campo",
"customFieldType": "Tipo de campo",
"saveChanges": "Guardar cambios",
"Eliminar campo personalizado": "Eliminar campo personalizado",
"fieldSuccessMessage": "Campo agregado exitosamente",
"fieldRemovalSuccess": "Campo eliminado exitosamente"
}
}
14 changes: 13 additions & 1 deletion public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@
"settings": "設置",
"noData": "沒有數據",
"otherSettings": "其他设置",
"changeLanguage": "更改语言"
"changeLanguage": "更改语言",
"manageCustomFields": "管理自定义字段"
},
"deleteOrg": {
"deleteOrganization": "删除组织",
Expand Down Expand Up @@ -664,5 +665,16 @@
"userChatRoom": {
"selectContact": "選擇聯絡人開始對話",
"sendMessage": "傳訊息"
},
"orgProfileField": {
"loading": "正在加载...",
"noCustomField": "没有可用的自定义字段",
"customFieldName": "字段名称",
"enterCustomFieldName": "输入字段名称",
"customFieldType": "字段类型",
"saveChanges": "保存更改",
"删除自定义字段": "删除自定义字段",
"fieldSuccessMessage": "字段添加成功",
"fieldRemovalSuccess": "字段删除成功"
}
}
26 changes: 26 additions & 0 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,29 @@ export const TOGGLE_PINNED_POST = gql`
}
}
`;

// Handles custom organization fields
export const ADD_CUSTOM_FIELD = gql`
mutation ($organizationId: ID!, $type: String!, $name: String!) {
addOrganizationCustomField(
organizationId: $organizationId
type: $type
name: $name
) {
name
type
}
}
`;

export const REMOVE_CUSTOM_FIELD = gql`
mutation ($organizationId: ID!, $customFieldId: ID!) {
removeOrganizationCustomField(
organizationId: $organizationId
customFieldId: $customFieldId
) {
type
name
}
}
`;
10 changes: 10 additions & 0 deletions src/GraphQl/Queries/Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,3 +843,13 @@ export const IS_SAMPLE_ORGANIZATION_QUERY = gql`
isSampleOrganization(id: $isSampleOrganizationId)
}
`;

export const ORGANIZATION_CUSTOM_FIELDS = gql`
query ($customFieldsByOrganizationId: ID!) {
customFieldsByOrganization(id: $customFieldsByOrganizationId) {
_id
type
name
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type { Dispatch, SetStateAction } from 'react';
import React from 'react';
import { act, render } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom';
import EditOrgCustomFieldDropDown from './EditCustomFieldDropDown';
import type { InterfaceCustomFieldData } from 'components/OrgProfileFieldSettings/OrgProfileFieldSettings';
import userEvent from '@testing-library/user-event';
import availableFieldTypes from 'utils/fieldTypes';

async function wait(ms = 100): Promise<void> {
await act(() => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
});
}

describe('Testing Custom Field Dropdown', () => {
test('Component Should be rendered properly', async () => {
const customFieldData = {
type: 'Number',
name: 'Age',
};

const setCustomFieldData: Dispatch<
SetStateAction<InterfaceCustomFieldData>
> = (val) => {
{
val;
}
};
const props = {
customFieldData: customFieldData as InterfaceCustomFieldData,
setCustomFieldData: setCustomFieldData,
parentContainerStyle: 'parentContainerStyle',
btnStyle: 'btnStyle',
btnTextStyle: 'btnTextStyle',
};

const { getByTestId, getByText } = render(
<BrowserRouter>
<EditOrgCustomFieldDropDown {...props} />
</BrowserRouter>
);

expect(getByText('Number')).toBeInTheDocument();

act(() => {
userEvent.click(getByTestId('toggleBtn'));
});

await wait();

availableFieldTypes.forEach(async (_, index) => {
act(() => {
userEvent.click(getByTestId(`dropdown-btn-${index}`));
});
});
});
});
53 changes: 53 additions & 0 deletions src/components/EditCustomFieldDropDown/EditCustomFieldDropDown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import type { SetStateAction, Dispatch } from 'react';
import { Dropdown } from 'react-bootstrap';
import availableFieldTypes from 'utils/fieldTypes';
import type { InterfaceCustomFieldData } from 'components/OrgProfileFieldSettings/OrgProfileFieldSettings';

interface InterfaceEditCustomFieldDropDownProps {
customFieldData: InterfaceCustomFieldData;
setCustomFieldData: Dispatch<SetStateAction<InterfaceCustomFieldData>>;
parentContainerStyle?: string;
btnStyle?: string;
btnTextStyle?: string;
}
[];

const EditOrgCustomFieldDropDown = (
props: InterfaceEditCustomFieldDropDownProps
): JSX.Element => {
return (
<Dropdown
title="Edit Custom Field"
className={`${props?.parentContainerStyle ?? ''}`}
>
<Dropdown.Toggle
variant="outline-success"
className={`${props?.btnStyle ?? ''}`}
data-testid="toggleBtn"
>
{props.customFieldData.type || 'None'}
</Dropdown.Toggle>
<Dropdown.Menu>
{availableFieldTypes.map((customFieldType, index: number) => (
<Dropdown.Item
key={`dropdown-item-${index}`}
className={`dropdown-item`}
data-testid={`dropdown-btn-${index}`}
onClick={(): void => {
props.setCustomFieldData({
...props.customFieldData,
type: customFieldType,
});
}}
disabled={props.customFieldData.type == customFieldType}
>
{customFieldType}
</Dropdown.Item>
))}
</Dropdown.Menu>
</Dropdown>
);
};

export default EditOrgCustomFieldDropDown;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.customDataTable {
width: 100%;
border-collapse: collapse;
}

.customDataTable th,
.customDataTable td {
padding: 8px;
text-align: left;
}

.customDataTable th {
background-color: #f2f2f2;
}
form {
display: flex;
flex-direction: column;
gap: 10px;
}

.saveButton {
width: 10em;
align-self: self-end;
}
Loading

0 comments on commit da70807

Please sign in to comment.