Skip to content

Commit

Permalink
Use global ramda (#920)
Browse files Browse the repository at this point in the history
* Update webpack config

* Update imports in domains

* Update imports in form builder

* Trigger lockfile change

* debug event edit page content

* Update wp-env docker image

* Update .wp-env.json

* destroy wp env docker

* debug

* Run e2e in parallel

* Update pr-checks.yml

* Update deps

* downgrade jest

* Revert "downgrade jest"

This reverts commit 7bd3cbf.

* Revert "Update deps"

This reverts commit da58577.

* Fix vendor scripts

* Update pr-checks.yml

* Restore config

* Update package.json

* Update index.js

* Restore package.json

* Update yarn.lock

* Restore typeform
  • Loading branch information
manzoorwanijk committed Jun 10, 2021
1 parent 4344c86 commit b3e67b7
Show file tree
Hide file tree
Showing 57 changed files with 224 additions and 214 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ jobs:
if: ${{ ! fromJson(env.run_after_build) }}
run: yarn && yarn build

# Since we map the barista build directory to core/assets, vendor scripts are not present
# we need to copy them manually
- name: Copy vendor assets
run: mkdir -p build/vendor/ && cp node_modules/ramda/dist/* build/vendor/

- name: Install WordPress
run: yarn wp-env start

Expand Down
3 changes: 3 additions & 0 deletions config/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ function requestToExternal(request) {

case 'react-dom':
return 'ReactDOM';

case 'ramda':
return 'R';
}

if (BUNDLED_PACKAGES.includes(request)) {
Expand Down
5 changes: 2 additions & 3 deletions domains/core/admin/blocks/src/adapters/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback, useMemo } from 'react';

import ReactSelect from 'react-select';
import { find, propEq } from 'ramda';
import * as R from 'ramda';

import type { SelectProps } from './types';

Expand All @@ -11,7 +10,7 @@ const Select: React.FC<SelectProps> = ({ value, options, label, onChange, id, ..
* Lets create it from options array by finding the option with the same value
*/
const reactSelectValue = useMemo(() => {
return find(propEq('value', value), options);
return R.find(R.propEq('value', value), options);
}, [options, value]);

const reactSelectOnChange = useCallback(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo, useCallback } from 'react';
import { pick } from 'ramda';
import * as R from 'ramda';

import { CalendarOutlined, ControlOutlined, ProfileOutlined } from '@eventespresso/icons';
import { startAndEndDateFixer, useDatetimeItem, hooks } from '@eventespresso/edtr-services';
Expand Down Expand Up @@ -53,7 +53,7 @@ const useDateFormConfig = (id: EntityId, config?: EspressoFormProps): DateFormCo
return hooks.applyFilters(
'eventEditor.dateForm.initalValues',
{
...pick<Partial<Datetime>, keyof Datetime>(FIELD_NAMES, datetime || {}),
...R.pick<Partial<Datetime>, keyof Datetime>(FIELD_NAMES, datetime || {}),
startDate,
endDate,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo } from 'react';
import { pick } from 'ramda';
import * as R from 'ramda';

import { isTrashed } from '@eventespresso/predicates';
import { useDatetimeItem, useDatetimeMutator, useDeleteRelatedTickets, useEventId } from '@eventespresso/edtr-services';
Expand Down Expand Up @@ -30,7 +30,7 @@ const useActions = (datetimeId: EntityId): Actions => {
});

const copyDate = useCallback(() => {
const newDatetime = pick(
const newDatetime = R.pick(
['capacity', 'description', 'endDate', 'isPrimary', 'name', 'order', 'reserved', 'sold', 'startDate'],
datetime
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useCallback } from 'react';
import { __ } from '@eventespresso/i18n';
import { pick } from 'ramda';
import * as R from 'ramda';

import { CalendarOutlined, ControlOutlined, ProfileOutlined } from '@eventespresso/icons';
import { intervalsToOptions, Intervals, DATE_INTERVALS } from '@eventespresso/dates';
Expand All @@ -13,7 +13,7 @@ import { useMemoStringify } from '@eventespresso/hooks';
type DateFormConfig = EspressoFormProps<BulkEditFormShape>;

const unitOptions = intervalsToOptions(
pick<Intervals, keyof Intervals>(['months', 'weeks', 'days', 'hours', 'minutes'], DATE_INTERVALS),
R.pick<Intervals, keyof Intervals>(['months', 'weeks', 'days', 'hours', 'minutes'], DATE_INTERVALS),
true
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react';
import classNames from 'classnames';
import { parseISO } from 'date-fns';
import { filter, pipe } from 'ramda';
import * as R from 'ramda';

import { addZebraStripesOnMobile, CellData } from '@eventespresso/ui-components';
import { filterCellByStartOrEndDate, useDatetimes, useLazyDatetime } from '@eventespresso/edtr-services';
Expand Down Expand Up @@ -133,9 +133,9 @@ const useBodyRowGenerator = (): DatesTableBodyRowGen => {
Boolean
);

const filterCells = filter(filterCellByStartOrEndDate(displayStartOrEndDate));
const filterCells = R.filter(filterCellByStartOrEndDate(displayStartOrEndDate));

const cells = pipe(filterCells, addZebraStripes)(cellsData);
const cells = R.pipe(filterCells, addZebraStripes)(cellsData);

return {
cells,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from 'react';
import { omit, pick } from 'ramda';
import * as R from 'ramda';

import { useRelations } from '@eventespresso/services';
import { useDefaultTicketIds } from '@eventespresso/edtr-services';
Expand All @@ -16,13 +16,13 @@ const useInvalidDataAlert = (showAlert: VoidFunction): Callback => {
const hasOrphanEntities = useCallback(() => {
const data = getData();
// remove default tickets from TAM relations
const newData = { ...data, tickets: omit(defaultTicketIds, data.tickets || {}) };
const newData = { ...data, tickets: R.omit(defaultTicketIds, data.tickets || {}) };
// simplify the data for loop
const entries = Object.entries(pick(TAM_ENTITIES, newData));
const entries = Object.entries(R.pick(TAM_ENTITIES, newData));

for (const [, entityRelations] of entries) {
for (const [, relations] of Object.entries(entityRelations)) {
const tamRelations = pick(TAM_ENTITIES, relations);
const tamRelations = R.pick(TAM_ENTITIES, relations);
// flatten the relations
const relatedIds = Object.values(tamRelations).flat();
if (!relatedIds.length) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { head } from 'ramda';
import * as R from 'ramda';
import { renderHook, act } from '@testing-library/react-hooks';

import { relationalData } from '@eventespresso/edtr-services/src/context/test';
Expand Down Expand Up @@ -39,8 +39,8 @@ describe('useAssignmentManager', () => {
expect(result.current.getData()).toHaveProperty('datetimes');
expect(result.current.getData()).toHaveProperty('tickets');
expect(result.current.getData()).not.toHaveProperty('prices');
expect(head(Object.values(result.current.getData().tickets))).toHaveProperty('datetimes');
expect(head(Object.values(result.current.getData().tickets))).not.toHaveProperty('prices');
expect(R.head(Object.values(result.current.getData().tickets))).toHaveProperty('datetimes');
expect(R.head(Object.values(result.current.getData().tickets))).not.toHaveProperty('prices');
});

it('returns assigned tickets to a given datetimeId', () => {
Expand All @@ -55,9 +55,9 @@ describe('useAssignmentManager', () => {
expect(result.current.getAssignedTickets({ datetimeId })).toEqual([]);
});

const datetimeId = head(Object.keys(initArgs.data.datetimes));
const datetimeId = R.head(Object.keys(initArgs.data.datetimes));
const assignedTickets = initArgs.data.datetimes[datetimeId].tickets;
const ticketId = head(assignedTickets);
const ticketId = R.head(assignedTickets);

// sane value for datetimeId
expect(result.current.getAssignedTickets({ datetimeId })).toEqual(assignedTickets);
Expand All @@ -84,9 +84,9 @@ describe('useAssignmentManager', () => {
expect(result.current.getAssignedDates({ ticketId })).toEqual([]);
});

const ticketId = head(Object.keys(initArgs.data.tickets));
const ticketId = R.head(Object.keys(initArgs.data.tickets));
const assignedDatetimes = initArgs.data.tickets[ticketId].datetimes;
const datetimeId = head(assignedDatetimes);
const datetimeId = R.head(assignedDatetimes);

// sane value for ticketId
expect(result.current.getAssignedDates({ ticketId })).toEqual(assignedDatetimes);
Expand Down Expand Up @@ -132,9 +132,9 @@ describe('useAssignmentManager', () => {
result.current.initialize(initArgs);
});

const ticketId = head(Object.keys(initArgs.data.tickets));
const ticketId = R.head(Object.keys(initArgs.data.tickets));
const assignedDatetimes = initArgs.data.tickets[ticketId].datetimes;
const datetimeId = head(assignedDatetimes);
const datetimeId = R.head(assignedDatetimes);

// they are married for now
expect(result.current.getAssignedDates({ ticketId })).toEqual(assignedDatetimes);
Expand All @@ -156,9 +156,9 @@ describe('useAssignmentManager', () => {
result.current.initialize(initArgs);
});

const ticketId = head(Object.keys(initArgs.data.tickets));
const ticketId = R.head(Object.keys(initArgs.data.tickets));
const assignedDatetimes = initArgs.data.tickets[ticketId].datetimes;
const datetimeId = head(assignedDatetimes);
const datetimeId = R.head(assignedDatetimes);

// they are married for now
expect(result.current.getAssignedDates({ ticketId })).toEqual(assignedDatetimes);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { head } from 'ramda';
import * as R from 'ramda';
import { renderHook, act } from '@testing-library/react-hooks';

import { actWait } from '@eventespresso/utils/src/test';
Expand All @@ -24,9 +24,9 @@ describe('useDataStateManager', () => {
result.current.initialize({ ...props, data: relationalData });
});

const ticketId = head(Object.keys(result.current.getData().tickets));
const ticketId = R.head(Object.keys(result.current.getData().tickets));
const assignedDatetimes = result.current.getData().tickets[ticketId].datetimes;
const datetimeId = head(assignedDatetimes);
const datetimeId = R.head(assignedDatetimes);

// they are old childhood friends
expect(result.current.getAssignmentStatus({ datetimeId, ticketId })).toBe('OLD');
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('useDataStateManager', () => {
result.current.initialize({ ...props, data: relationalData });
});

const datetimeId = head(Object.keys(result.current.getData().datetimes));
const datetimeId = R.head(Object.keys(result.current.getData().datetimes));
const assignedTickets = result.current.getData().datetimes[datetimeId].tickets;

// it has tickets by default
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('useDataStateManager', () => {
expect(result.current.hasOrphanTickets()).toBe(false);
expect(result.current.hasOrphanEntities()).toBe(false);

const datetimeId = head(Object.keys(result.current.getData().datetimes));
const datetimeId = R.head(Object.keys(result.current.getData().datetimes));
const assignedTickets = result.current.getData().datetimes[datetimeId].tickets;

// lets remove all the assigned tickets for the datetimeId
Expand All @@ -124,7 +124,7 @@ describe('useDataStateManager', () => {
expect(result.current.hasOrphanDates()).toBe(true);
expect(result.current.hasOrphanEntities()).toBe(true);

const ticketId = head(Object.keys(result.current.getData().tickets));
const ticketId = R.head(Object.keys(result.current.getData().tickets));
const assignedDates = result.current.getData().tickets[ticketId].datetimes;

assignedDates.forEach((datetimeId) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assocPath } from 'ramda';
import * as R from 'ramda';
import { renderHook, act } from '@testing-library/react-hooks';
import { formatISO } from 'date-fns';

Expand All @@ -9,7 +9,7 @@ import TestWrapper from './TestWrapper';
import { nodes as datetimes } from '@eventespresso/edtr-services/src/apollo/queries/datetimes/test/data';
import { useFilterState } from '../../filters';

const datetimesWithATrashedOne = assocPath([1, 'isTrashed'], true, datetimes);
const datetimesWithATrashedOne = R.assocPath([1, 'isTrashed'], true, datetimes);

describe('useFilteredDatetimes', () => {
it('returns filtered dates for default filter state', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assocPath } from 'ramda';
import * as R from 'ramda';
import { renderHook, act } from '@testing-library/react-hooks';

import { actWait } from '@eventespresso/utils/src/test';
Expand All @@ -8,7 +8,7 @@ import TestWrapper from './TestWrapper';
import { nodes as tickets } from '@eventespresso/edtr-services/src/apollo/queries/tickets/test/data';
import { useFilterState } from '../../filters';

const ticketsWithATrashedOne = assocPath([1, 'isTrashed'], true, tickets);
const ticketsWithATrashedOne = R.assocPath([1, 'isTrashed'], true, tickets);

describe('useFilteredTickets', () => {
it('returns filtered tickets for default filter state', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useMemo, useState } from 'react';
import { pick, map, mapObjIndexed, isEmpty } from 'ramda';
import * as R from 'ramda';

import { useRelationsManager, RelationFunctionProps } from '@eventespresso/services';

Expand Down Expand Up @@ -120,10 +120,10 @@ const useAssignmentManager = (): AM => {
) {
// only the realtions for the given single entity
// for which TAM has been opened
relationalEntityToUse = pick([entity.id], relationalEntity);
relationalEntityToUse = R.pick([entity.id], relationalEntity);
// if it's for a new date or ticket,
// there will obviously be no entry of it in existing relations
if (isEmpty(relationalEntityToUse)) {
if (R.isEmpty(relationalEntityToUse)) {
const newRelationKey = entityType === 'datetimes' ? 'tickets' : 'datetimes';
// initialize to empty relations
relationalEntityToUse[entity.id] = {
Expand All @@ -133,9 +133,9 @@ const useAssignmentManager = (): AM => {
}

// Now loop through all the relational entities
return map((relation) => {
return R.map((relation) => {
// pick only TAM relations, i.e. filter out tickets to prices relations
return pick(TAM_ENTITIES, relation);
return R.pick(TAM_ENTITIES, relation);
}, relationalEntityToUse);
}, []);

Expand All @@ -145,10 +145,10 @@ const useAssignmentManager = (): AM => {
const initialize = useCallback<AM['initialize']>(
({ data, assignmentType, entity }) => {
// pick only datetimes and tickets from relational data
let newData = pick(TAM_ENTITIES, data);
let newData = R.pick(TAM_ENTITIES, data);

// Remove other relations from newData
newData = mapObjIndexed((relationalEntity, entityType) => {
newData = R.mapObjIndexed((relationalEntity, entityType) => {
return removeNonTAMRelations({ assignmentType, entity, entityType, relationalEntity });
}, newData);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useCallback, useMemo, useState } from 'react';
import { omit } from 'ramda';
import * as R from 'ramda';

import { EntityId } from '@eventespresso/data';
import { useRelations } from '@eventespresso/services';
Expand Down Expand Up @@ -92,7 +92,7 @@ const useDataStateManager = (props: BaseProps): DataStateManager => {
if (!initialized) {
const data = relations.getData();
// remove default tickets from TAM relations
const newData = { ...data, tickets: omit(defaultTicketIds, data.tickets || {}) };
const newData = { ...data, tickets: R.omit(defaultTicketIds, data.tickets || {}) };
// initialize with existing data
initialize({ data: newData, ...props });
// now check if there are any orphaned entities in the initial data and save the result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react';
import { any } from 'ramda';
import * as R from 'ramda';

import { useRelations } from '@eventespresso/services';
import { UpdateTicketInput, useDatetimes, useTickets, useBulkEditTickets } from '@eventespresso/edtr-services';
Expand Down Expand Up @@ -46,7 +46,7 @@ const useOnSubmitAssignments = (): Callback => {
});
Object.entries(ticketsWithChangedQuantity).forEach(([id, quantity]) => {
// if it's already in uniqueInputs
if (any<UpdateTicketInput>(entityHasGuid(id), uniqueInputs)) {
if (R.any<UpdateTicketInput>(entityHasGuid(id), uniqueInputs)) {
return;
}
uniqueInputs.push({ id, quantity });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { mapObjIndexed, pickBy, isEmpty } from 'ramda';
import * as R from 'ramda';

import { AssignmentManager, TAMPossibleRelation, TAMRelationalData, TAMRelationalEntity } from '../types';

Expand All @@ -14,14 +14,14 @@ const useValidation = (assignmentManager: AssignmentManager): TAMPossibleRelatio

useEffect(() => {
// may be the data is not initialized yet
if (isEmpty(TAMData)) {
if (R.isEmpty(TAMData)) {
return;
}
// loop through TAM data to find entities with no relations
// See the data shape, please check the shape of TAMRelationalData
const newTAMData: TAMPossibleRelation = mapObjIndexed((relationalEntity, entity) => {
const newTAMData: TAMPossibleRelation = R.mapObjIndexed((relationalEntity, entity) => {
const relation: keyof TAMPossibleRelation = entity === 'datetimes' ? 'tickets' : 'datetimes';
const emptyRelationalEntities = pickBy<TAMRelationalEntity, TAMRelationalEntity>(
const emptyRelationalEntities = R.pickBy<TAMRelationalEntity, TAMRelationalEntity>(
(relations: TAMPossibleRelation) => {
const relatedIds = relations?.[relation] || [];
return relatedIds.length === 0;
Expand Down
Loading

0 comments on commit b3e67b7

Please sign in to comment.