Skip to content

CHI-3295: TTop level NPM workspaces #2960

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
wants to merge 17 commits into
base: CHI-3295-update_prepopulate_logic
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
3 changes: 1 addition & 2 deletions .github/actions/build-and-upload-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ runs:
shell: bash
# Build flex plugin
- name: Run build command
run: ENABLE_MONITORING=true twilio flex:plugins:build -l debug || true
working-directory: ./plugin-hrm-form
run: ENABLE_MONITORING=true npm run build:plugin || true
shell: bash
- name: Check bundle was built
if: ${{ hashFiles('plugin-hrm-form/build/plugin-hrm-form.js') == '' }}
Expand Down
12 changes: 6 additions & 6 deletions .github/actions/install-flex-plugin/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ runs:
- name: Install the Twilio CLI and plugins
run: npm install -g twilio-cli && twilio plugins:install @twilio-labs/[email protected]
shell: bash
- name: Install hrm-form-definitions Packages
- name: Install All Packages
run: npm ci
working-directory: ${{ inputs.path }}/hrm-form-definitions
shell: bash
- name: Install plugin-hrm-form Packages
run: npm ci
working-directory: ${{ inputs.path }}/plugin-hrm-form
working-directory: ${{ inputs.path }}
shell: bash
- name: Build hrm-form-definitions module
run: npm run build -w hrm-form-definitions
working-directory: ${{ inputs.path }}
shell: bash
4 changes: 2 additions & 2 deletions .github/actions/run-e2e-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ runs:
aws-region: us-east-1

- name: Install e2e-tests dependencies
run: npm ci
working-directory: ${{ inputs.path }}/e2e-tests
run: npm ci -w e2e-tests
working-directory: ${{ inputs.path }}
shell: bash

- name: Setup dependencies for playwright/browsers
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/webchat-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ jobs:

# Build and compile Webchat
- name: Run build command
run: CONFIG=as-development npm run build
working-directory: ./webchat
run: CONFIG=as-development npm run build -w webchat

lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"eslint-import-resolver-typescript": "^2.7.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"hrm-form-definitions": "file:../hrm-form-definitions",
"@tech-matters/hrm-form-definitions": "1.0.0",
"mock-socket": "^9.1.5",
"npm-run-all": "^4.1.5",
"playwright-core": "^1.30.0",
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/ui-tests/aselo-service-mocks/hrm/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import flexContext from '../../flex-in-a-box/global-context';
import { addSeconds, subHours } from 'date-fns';
// eslint-disable-next-line import/no-extraneous-dependencies
import { DefinitionVersionId } from 'hrm-form-definitions';
import { DefinitionVersionId } from '@tech-matters/hrm-form-definitions';
// eslint-disable-next-line import/no-extraneous-dependencies
import { Page } from '@playwright/test';
import context from '../global-context';
Expand Down
7 changes: 3 additions & 4 deletions hrm-form-definitions/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hrm-form-definitions",
"name": "@tech-matters/hrm-form-definitions",
"version": "1.0.0",
"description": "Module to manage form definitions in the Aselo HRM Twilio plugin",
"main": "dist/index.js",
Expand All @@ -15,8 +15,8 @@
"@babel/preset-typescript": "^7.16.5",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.8",
"@types/react": "^17.0.38",
"@types/node": "^18.16.2",
"@types/react": "^17.0.47",
"@typescript-eslint/eslint-plugin": "^4.28.3",
"@typescript-eslint/parser": "^4.28.3",
"babel-core": "^6.26.3",
Expand All @@ -32,7 +32,6 @@
"jest-each": "^28.1.1",
"jest-junit": "^16.0.0",
"prettier": "^2.3.2",
"react-hook-form": "^6.11.0",
"ts-jest": "^27.1.2",
"ts-node": "^10.1.0",
"typescript": "^4.3.5"
Expand Down
7 changes: 3 additions & 4 deletions hrm-form-definitions/src/formDefinition/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

/* eslint-disable import/no-unused-modules */
// eslint-disable-next-line import/no-extraneous-dependencies
import { RegisterOptions } from 'react-hook-form';
import { OneToManyConfigSpecs, OneToOneConfigSpec } from './insightsConfig';
import { CallTypeKeys } from './callTypes';
import { LayoutVersion } from './layoutVersion';
Expand Down Expand Up @@ -61,8 +60,8 @@ type ItemBase = {
label: string;
type: FormInputType;
metadata?: Record<string, any>;
} & IsPIIFlag &
RegisterOptions;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the RegisterOptions portion removed here? 🤔

required?: { value: boolean, message: string };
} & IsPIIFlag;

type NonSaveable = {
saveable: false;
Expand Down Expand Up @@ -396,7 +395,7 @@ export type DefinitionVersion = {
/**
* @deprecated - this is the legacy prepopulation configuration. Use prepopulationMappings for all new code
*/
prepopulateKeys?: {
prepopulateKeys: {
survey: {
ChildInformationTab: string[];
CallerInformationTab: string[];
Expand Down
1 change: 1 addition & 0 deletions lambdas/account-scoped/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@aws-sdk/client-ssm": "^3.716.0",
"@twilio-labs/serverless-runtime-types": "^4.0.1",
"@tech-matters/hrm-form-definitions": "1.0.0",
"date-fns": "^4.1.0",
"lodash": "^4.17.21",
"twilio": "^5.4.0"
Expand Down
72 changes: 18 additions & 54 deletions lambdas/account-scoped/src/hrm/populateHrmContactFormFromTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,62 +17,13 @@
import { capitalize } from 'lodash';
import { startOfDay, format } from 'date-fns';
import { TaskSID } from '../twilioTypes';
import { FormInputType, DefinitionVersion, FormItemDefinition, loadDefinition } from "@tech-matters/hrm-form-definitions";

type MapperFunction = (options: string[]) => (value: string) => string;

// When we move this into the flex repo we can depend on hrm-form-definitions for these types & enums
export enum FormInputType {
Input = 'input',
SearchInput = 'search-input',
NumericInput = 'numeric-input',
Email = 'email',
RadioInput = 'radio-input',
ListboxMultiselect = 'listbox-multiselect',
Select = 'select',
DependentSelect = 'dependent-select',
Checkbox = 'checkbox',
MixedCheckbox = 'mixed-checkbox',
Textarea = 'textarea',
DateInput = 'date-input',
TimeInput = 'time-input',
FileUpload = 'file-upload',
Button = 'button',
CopyTo = 'copy-to',
CustomContactComponent = 'custom-contact-component',
}

export type FormItemDefinition = {
type: FormInputType;
name: string;
unknownOption?: string;
options?: { value: string }[];
initialChecked?: boolean;
initializeWithCurrent?: boolean;
} & (
| {
type: Exclude<FormInputType, FormInputType.DependentSelect>;
defaultOption?: {
value: string;
};
}
| {
type: FormInputType.DependentSelect;
defaultOption: {
value: string;
};
}
);

// Exported for testing purposes
export type PrepopulateKeys = {
preEngagement: {
ChildInformationTab: string[];
CallerInformationTab: string[];
CaseInformationTab: string[];
};
survey: { ChildInformationTab: string[]; CallerInformationTab: string[] };
};

type PrepopulateKeys = Exclude<DefinitionVersion['prepopulateKeys'], undefined>
type ChannelTypes =
| 'voice'
| 'sms'
Expand Down Expand Up @@ -340,6 +291,7 @@ const getValuesFromPreEngagementData = (
};

const loadedConfigJsons: Record<string, any> = {};
const loadedDefinitions: Record<string, DefinitionVersion> = {};

const loadConfigJson = async (
formDefinitionRootUrl: URL,
Expand All @@ -363,21 +315,31 @@ const loadConfigJson = async (
return loadedConfigJsons[section];
};

const loadDefinitionForVersion = async (
formDefinitionRootUrl: URL,
) => {
const rootAsString = formDefinitionRootUrl.toString()
if (!loadedDefinitions[rootAsString]) {
loadedDefinitions[rootAsString] = await loadDefinition(`${formDefinitionRootUrl}/${rootAsString}`)
}
return loadedDefinitions[rootAsString];
}

const populateInitialValues = async (contact: HrmContact, formDefinitionRootUrl: URL) => {
const tabNamesAndRawJsonSections: [string, Record<string, FormValue>][] = [
['CaseInformationTab', contact.rawJson.caseInformation],
['ChildInformationTab', contact.rawJson.childInformation],
['CallerInformationTab', contact.rawJson.callerInformation],
];

const defintionsAndJsons: [FormItemDefinition[], Record<string, FormValue>][] =
const definitionsAndJsons: [FormItemDefinition[], Record<string, FormValue>][] =
await Promise.all(
tabNamesAndRawJsonSections.map(async ([tabbedFormsSection, rawJsonSection]) => [
await loadConfigJson(formDefinitionRootUrl, `tabbedForms/${tabbedFormsSection}`),
rawJsonSection,
]),
);
for (const [tabFormDefinition, rawJson] of defintionsAndJsons) {
for (const [tabFormDefinition, rawJson] of definitionsAndJsons) {
for (const formItemDefinition of tabFormDefinition) {
rawJson[formItemDefinition.name] = getInitialValue(formItemDefinition);
}
Expand Down Expand Up @@ -431,12 +393,14 @@ export const populateHrmContactFormFromTask = async (
contact: HrmContact,
formDefinitionRootUrl: URL,
): Promise<HrmContact> => {

const { memory, preEngagementData, firstName, language } = taskAttributes;
const answers = { ...memory, firstName, language };
await populateInitialValues(contact, formDefinitionRootUrl);
if (!memory && !firstName && !preEngagementData) return contact;
const definition = await loadDefinitionForVersion(formDefinitionRootUrl)
const { preEngagement: preEngagementKeys, survey: surveyKeys }: PrepopulateKeys =
await loadConfigJson(formDefinitionRootUrl, 'PrepopulateKeys');
definition.prepopulateKeys;

const isValidSurvey = Boolean(answers?.aboutSelf); // determines if the memory has valid values or if it was aborted
const isAboutSelf = answers.aboutSelf === 'Yes';
Expand Down
4 changes: 2 additions & 2 deletions lambdas/account-scoped/tests/testHrmValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import {
FormInputType,
FormItemDefinition,
} from '../src/hrm/populateHrmContactFormFromTask';
} from '@tech-matters/hrm-form-definitions';
import { FormDefinitionSet } from './testHrmTypes';

const BASE_PERSON_FORM_DEFINITION: FormItemDefinition[] = [
Expand Down Expand Up @@ -65,7 +65,7 @@ const BASE_PERSON_FORM_DEFINITION: FormItemDefinition[] = [
name: 'otherGender',
type: FormInputType.Input,
},
];
] as FormItemDefinition[];
export const BASE_FORM_DEFINITION: FormDefinitionSet = {
childInformation: BASE_PERSON_FORM_DEFINITION,
callerInformation: BASE_PERSON_FORM_DEFINITION,
Expand Down
Loading
Loading