Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/techmatters/flex-plugins
Browse files Browse the repository at this point in the history
…into alejandro/nz/adding_translations
  • Loading branch information
janorivera committed Aug 9, 2024
2 parents c23d76f + 50f2986 commit 3a6ca20
Show file tree
Hide file tree
Showing 18 changed files with 356 additions and 39,412 deletions.
11 changes: 10 additions & 1 deletion plugin-hrm-form/src/___tests__/states/resources/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ const testStore = (stateChanges: Partial<ReferrableResourceSearchState> = {}) =>
});

const nonInitialState: ReferrableResourceSearchState = {
filterOptions: initialState.filterOptions,
filterOptions: {
...initialState.filterOptions,
region: [{ label: '', value: undefined }],
city: [{ label: '', value: undefined }],
},
currentPage: 2,
status: ResourceSearchStatus.ResultPending,
parameters: {
Expand All @@ -69,6 +73,11 @@ const nonInitialState: ReferrableResourceSearchState = {
{ name: '6', id: '6', attributes: {} },
],
suggesters: { names: ['something else entirely'] },
referenceLocations: {
cityOptions: [],
provinceOptions: [],
regionOptions: [],
},
};

describe('actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,19 @@ const toCsv = (...args: string[]) => {
const extractPrimaryLocation = (attributes: Attributes, language: Language) => {
const address1 = getAttributeValue(attributes, language, 'primaryLocationAddress1');
const address2 = getAttributeValue(attributes, language, 'primaryLocationAddress2');
const county = getAttributeValue(attributes, language, 'primaryLocationCounty');
const city = getAttributeData(attributes, language, 'primaryLocationCity')?.info?.name;
const county =
getAttributeData(attributes, language, 'primaryLocationRegion')?.info?.name ??
getAttributeValue(attributes, language, 'primaryLocationCounty');
const city =
getAttributeData(attributes, language, 'primaryLocationRegionCity')?.info?.name ??
getAttributeValue(attributes, language, 'primaryLocationCity');
const province = getAttributeData(attributes, language, 'primaryLocationProvince')?.info?.name;
const postalCode = getAttributeValue(attributes, language, 'primaryLocationPostalCode');
const phone = getAttributeValue(attributes, language, 'primaryLocationPhone');
// eslint-disable-next-line prefer-named-capture-group
const formattedPhone = phone?.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');

return `${toCsv(address1, address2)}${toCsv(county, city)}${toCsv(province, postalCode)}${formattedPhone}`;
return `${toCsv(address1, address2)}${toCsv(city, county)}${toCsv(province, postalCode)}${formattedPhone}`;
};

const extractMainContact = (mainContact: Attributes, language: Language) => {
Expand Down Expand Up @@ -176,8 +180,11 @@ const extractSiteLocation = (site: Attributes) => {
return {
address1: getAttributeValue(location, '', 'address1'),
address2: getAttributeValue(location, '', 'address2'),
city: getAttributeData(location, '', 'city')?.info?.name || '',
county: getAttributeValue(location, '', 'county'),
city:
getAttributeData(location, '', 'region-city')?.info?.name ||
getAttributeData(location, '', 'city')?.info?.name ||
'',
county: getAttributeData(location, '', 'region')?.info?.name || getAttributeValue(location, '', 'county'),
postalCode: getAttributeValue(location, '', 'postalCode'),
province: getAttributeData(location, '', 'province')?.info?.name || '',
country: getAttributeValue(location, '', 'country'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ import {
FormSelect,
FormSelectWrapper,
Row,
StyledNextStepButton,
SearchFormTopRule,
StyledNextStepButton,
} from '../../../styles';
import {
SearchFormClearButton,
ResourcesSearchFormArea,
ResourcesSearchFormContainer,
ResourcesSearchFormFilterHeader,
ResourcesSearchFormSectionHeader,
ResourcesSearchFormSettingBox,
ResourcesSearchTitle,
SearchFormClearButton,
} from '../styles';
import {
ReferrableResourceSearchState,
Expand All @@ -58,6 +58,11 @@ import { getAseloFeatureFlags, getTemplateStrings } from '../../../hrmConfig';
import asyncDispatch from '../../../states/asyncDispatch';
import SearchAutoComplete from './SearchAutoComplete';
import { namespace, referrableResourcesBase } from '../../../states/storeNamespaces';
import {
loadReferenceLocationsAsyncAction,
ReferenceLocationList,
ReferenceLocationState,
} from '../../../states/resources/referenceLocations';

const NO_AGE_SELECTED = -1;
const NO_LOCATION_SELECTED = '__NO_LOCATION_SELECTED__';
Expand All @@ -78,6 +83,7 @@ const mapStateToProps = (state: RootState) => {
const {
parameters: { generalSearchTerm, pageSize, filterSelections },
filterOptions,
referenceLocations,
} = state[namespace][referrableResourcesBase].search;
const { suggestSearch } = state[namespace][referrableResourcesBase];
return {
Expand All @@ -86,6 +92,7 @@ const mapStateToProps = (state: RootState) => {
filterSelections,
filterOptions,
suggestSearch,
referenceLocations,
};
};

Expand All @@ -112,6 +119,17 @@ const mapDispatchToProps = (dispatch: Dispatch<AnyAction>) => {
leading: true,
trailing: true,
}),
loadReferenceLocations: (referenceLocations: ReferenceLocationState) => {
if (!referenceLocations.provinceOptions?.length) {
searchAsyncDispatch(loadReferenceLocationsAsyncAction(ReferenceLocationList.Provinces));
}
if (!referenceLocations.regionOptions?.length) {
searchAsyncDispatch(loadReferenceLocationsAsyncAction(ReferenceLocationList.Regions));
}
if (!referenceLocations.cityOptions?.length) {
searchAsyncDispatch(loadReferenceLocationsAsyncAction(ReferenceLocationList.Cities));
}
},
};
};

Expand All @@ -130,6 +148,8 @@ const SearchResourcesForm: React.FC<Props> = ({
filterSelections,
suggestSearch,
updateSuggestSearch,
loadReferenceLocations,
referenceLocations,
}) => {
const firstElement = useRef(null);
const strings = getTemplateStrings();
Expand All @@ -156,6 +176,11 @@ const SearchResourcesForm: React.FC<Props> = ({
setGeneralSearchTermBoxText(generalSearchTerm);
}, [generalSearchTerm, setGeneralSearchTermBoxText]);

useEffect(() => {
loadReferenceLocations(referenceLocations);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const locationDropdown = (locationFilterName: LocationFilterName, optionList: FilterOption[]) => {
const capitalizedLocationFilterName = locationFilterName.charAt(0).toUpperCase() + locationFilterName.slice(1);
return (
Expand Down
24 changes: 18 additions & 6 deletions plugin-hrm-form/src/services/ResourceService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ export type Attributes = {
[key: string]: AttributeData[] | Attributes;
};

export type ReferrableResourceAttributeValue =
| string
| string[]
| { id: string; value: string }[]
| { info: string; value: string; language: string }[];

export type ReferrableResource = {
id: string;
name: string;
attributes: Record<string, Attributes>;
};

export type ReferenceAttributeStringValue = {
value: string;
id: string;
info: any;
language: string;
};

export const referrableResourcesEnabled = () => Boolean(getReferrableResourceConfig().resourcesBaseUrl);

export const getResource = async (resourceId: string): Promise<ReferrableResource> => {
Expand Down Expand Up @@ -70,3 +71,14 @@ export const searchResources = async (
export const suggestSearch = async (prefix: string): Promise<TaxonomyLevelNameCompletion> => {
return fetchResourceApi(`suggest?prefix=${prefix}`);
};

export const getReferenceAttributeList = async (
list: string,
language?: string,
valueStartsWith?: string,
): Promise<ReferenceAttributeStringValue[]> => {
const queryItems = Object.entries({ valueStartsWith, language }).filter(([, value]) => value);
const queryString = queryItems.map(([k, v]) => `${k}=${v}`).join('&');
// Lists can contain slashes, but we only want them as one path section
return fetchResourceApi(`reference-attributes/${encodeURIComponent(list)}?${queryString}`);
};
Loading

0 comments on commit 3a6ca20

Please sign in to comment.