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

Decouple './client/multi-currency-setup' #9348

Merged
merged 22 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a22e41c
Move client/data/multi-currency/* to multi-currency/client/data/*
lovo-h Aug 22, 2024
0675fbf
Connect new MCCY data store: wc/payments/mccy
lovo-h Aug 22, 2024
fd9059b
Ensure non-MCCY reference the correct MCCY data files
lovo-h Aug 22, 2024
a9fffde
Remove unused MCCY test code
lovo-h Aug 22, 2024
ffb71c8
WebPack config: Add 'multi-currency' dir and alias with 'mccy'
lovo-h Aug 22, 2024
ae3b87d
Added a data interface layer where functions are shared
lovo-h Aug 23, 2024
489e423
Move ./client/multi-currency-setup to ./multi-currency/client/setup
lovo-h Aug 27, 2024
8c0868e
Add interface layer: components, functions, & data
lovo-h Aug 27, 2024
6041e39
Use the 'functions' interface to inject dependencies into MCCY
lovo-h Aug 27, 2024
635f3cd
Use the 'components' interface to inject dependencies into MCCY
lovo-h Aug 27, 2024
64a47cd
Use the 'data' interface to inject dependencies into MCCY
lovo-h Aug 27, 2024
b93903a
Update multi-currency-setup's stale references to MCCY data files
lovo-h Aug 27, 2024
3586349
Export MultiCurrencySetupPage from MCCY to main codebase
lovo-h Aug 27, 2024
69a556f
Add temporary dependency on MCCY + TODOs
lovo-h Aug 27, 2024
62eefc4
Fix tests: useStoreSettings imported from client
lovo-h Aug 27, 2024
1f01897
Update 'mccy' alias to 'multi-currency'
lovo-h Aug 28, 2024
588ab57
Merge branch 'migrate/data-multi-currency' into migrate/setup-multi-c…
lovo-h Aug 28, 2024
10de47f
Update 'mccy' alias reference to 'multi-currency'
lovo-h Aug 28, 2024
0d01922
Merge branch 'multi-currency-v2' into migrate/setup-multi-currency
lovo-h Aug 29, 2024
1424558
De-duplicate WizardTaskItem
lovo-h Aug 30, 2024
3b3e995
Code cleanup: Place imports in correct section, fix typo
lovo-h Aug 30, 2024
4996381
Ensure getMultiCurrencyState refers to top level state
lovo-h Aug 30, 2024
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
2 changes: 2 additions & 0 deletions client/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export * from './charges/hooks';
export * from './timeline/hooks';
export * from './disputes/hooks';
export * from './settings/hooks';
// TODO: Needs to be migrated. At the moment, there exist dependencies on these files.
export * from 'multi-currency/data';
export * from './card-readers/hooks';
export * from './capital/hooks';
export * from './documents/hooks';
Expand Down
2 changes: 1 addition & 1 deletion client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import DisputesPage from 'disputes';
import RedirectToTransactionDetails from 'disputes/redirect-to-transaction-details';
import DisputeEvidencePage from 'disputes/evidence';
import AdditionalMethodsPage from 'wcpay/additional-methods-setup';
import MultiCurrencySetupPage from 'wcpay/multi-currency-setup';
import { MultiCurrencySetupPage } from 'multi-currency/interface/components';
import CardReadersPage from 'card-readers';
import CapitalPage from 'capital';
import OverviewPage from 'overview';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ jest.mock( 'multi-currency/interface/data', () => ( {
useEnabledCurrencies: jest.fn().mockReturnValue( {} ),
} ) );

jest.mock( 'multi-currency/interface/data', () => ( {
useCurrencies: jest.fn().mockReturnValue( { isLoading: true } ),
useEnabledCurrencies: jest.fn().mockReturnValue( {} ),
} ) );

jest.mock( '@wordpress/data', () => ( {
useDispatch: jest
.fn()
Expand Down
2 changes: 1 addition & 1 deletion multi-currency/client/data/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal Dependencies
*/
import { recordEvent } from 'multi-currency/interface/data';
import { recordEvent } from 'multi-currency/interface/functions';
import TYPES from './action-types';
import { NAMESPACE, STORE_NAME } from './constants';

Expand Down
19 changes: 19 additions & 0 deletions multi-currency/client/interface/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Dependencies from WooPayments to MCCY.
*/
// wcpay/additional-methods-setup/*
export { default as CollapsibleBody } from 'wcpay/additional-methods-setup/wizard/collapsible-body';
export { default as Wizard } from 'wcpay/additional-methods-setup/wizard/wrapper';
export { default as WizardTask } from 'wcpay/additional-methods-setup/wizard/task';
export { default as WizardTaskItem } from 'wcpay/additional-methods-setup/wizard/task-item';
export { default as WizardTaskList } from 'wcpay/additional-methods-setup/wizard/task-list';
// wcpay/components/*
export { default as Page } from 'wcpay/components/page';
export { default as Search } from 'wcpay/components/search';
export { LoadableBlock } from 'wcpay/components/loadable';

/**
* Dependencies from MCCY to WooPayments.
*/
// multi-currency/setup
export { default as MultiCurrencySetupPage } from 'multi-currency/setup';
7 changes: 4 additions & 3 deletions multi-currency/client/interface/data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* Importing 'tracks' from WooPayments and exporting.
* Dependencies from WooPayments to MCCY.
*/
export { recordEvent } from 'wcpay/tracks';
// wcpay/data
export { useSettings, useMultiCurrency } from 'wcpay/data';

/**
* Importing data from MCCY and exporting.
* Dependencies from MCCY to WooPayments.
*/
export { useCurrencies, useEnabledCurrencies } from 'multi-currency/data';
9 changes: 9 additions & 0 deletions multi-currency/client/interface/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Dependencies from WooPayments to MCCY.
*/
// wcpay/tracks
export { recordEvent } from 'wcpay/tracks';
// wcpay/settings
export { default as WCPaySettingsContext } from 'wcpay/settings/wcpay-settings-context';
// wcpay/additional-methods-setup/*
export { default as WizardTaskContext } from 'wcpay/additional-methods-setup/wizard/task/context';
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
/**
* Internal dependencies
*/
import Page from 'components/page';
import MultiCurrencySetup from './tasks/multi-currency-setup';
import WCPaySettingsContext from '../settings/wcpay-settings-context';
import { Page } from 'multi-currency/interface/components';
import { WCPaySettingsContext } from 'multi-currency/interface/functions';

const MultiCurrencySetupPage = () => {
const { isSetupCompleted } = window.wcpaySettings.multiCurrencySetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,26 @@ import _ from 'lodash';
/**
* Internal dependencies
*/
import WizardTaskContext from '../../../additional-methods-setup/wizard/task/context';
import CollapsibleBody from '../../../additional-methods-setup/wizard/collapsible-body';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import {
CollapsibleBody,
Search,
LoadableBlock,
} from 'multi-currency/interface/components';
import WizardTaskItem from '../../wizard/task-item';
Copy link
Member

Choose a reason for hiding this comment

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

Question: It seems like we have a pretty similar WizardTaskItem from interface/components. I wonder if we should use only one? And adapt V1 to have a visibleDescription prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call out. De-duplicated in 1424558.


import {
useCurrencies,
useAvailableCurrencies,
useEnabledCurrencies,
useDefaultCurrency,
} from 'wcpay/data';
} from 'multi-currency/data';

// eslint-disable-next-line max-len
import EnabledCurrenciesModalCheckboxList from '../../../multi-currency/multi-currency-settings/enabled-currencies-list/modal-checkbox-list';
import EnabledCurrenciesModalCheckbox from '../../../multi-currency/multi-currency-settings/enabled-currencies-list/modal-checkbox';
import Search from 'components/search';

import { LoadableBlock } from '../../../components/loadable';
// TODO: Migrate to 'multi-currency/settings/enabled-currencies-list/modal-checkbox-list'.
import EnabledCurrenciesModalCheckboxList from 'wcpay/multi-currency/multi-currency-settings/enabled-currencies-list/modal-checkbox-list';
// TODO: Migrate to 'multi-currency/settings/enabled-currencies-list/modal-checkbox'.
import EnabledCurrenciesModalCheckbox from 'wcpay/multi-currency/multi-currency-settings/enabled-currencies-list/modal-checkbox';

import { recommendedCurrencyCodes, numberWords } from './constants';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ import { useSelect } from '@wordpress/data';
* Internal dependencies
*/
import AddCurrenciesTask from '..';
import { useSettings } from 'multi-currency/interface/data';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import {
useCurrencies,
useAvailableCurrencies,
useDefaultCurrency,
useEnabledCurrencies,
useSettings,
} from 'wcpay/data';
} from 'multi-currency/data';

import WizardTaskContext from '../../../../additional-methods-setup/wizard/task/context';
import { recommendedCurrencyCodes } from '../constants';
import { __ } from '@wordpress/i18n';

// TODO: Remove this while we have a dependency on 'wcpay/multi-currency/preview-modal'.
jest.mock( 'wcpay/data', () => ( {
useStoreSettings: jest.fn(),
} ) );
jest.mock( 'multi-currency/data', () => ( {
useCurrencies: jest.fn(),
useAvailableCurrencies: jest.fn(),
useDefaultCurrency: jest.fn(),
useEnabledCurrencies: jest.fn(),
} ) );
jest.mock( 'multi-currency/interface/data', () => ( {
useSettings: jest.fn(),
} ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { Card, CardBody } from '@wordpress/components';
/**
* Internal dependencies
*/
import Wizard from '../../additional-methods-setup/wizard/wrapper';
import WizardTask from '../../additional-methods-setup/wizard/task';
import WizardTaskList from '../../additional-methods-setup/wizard/task-list';
import {
Wizard,
WizardTask,
WizardTaskList,
} from 'multi-currency/interface/components';
import StoreSettingsTask from './store-settings-task';
import SetupCompleteTask from './setup-complete-task';
import AddCurrenciesTask from './add-currencies-task';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import { useDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import CollapsibleBody from '../../../additional-methods-setup/wizard/collapsible-body';
import WizardTaskItem from '../../wizard/task-item';
import WizardTaskContext from '../../../additional-methods-setup/wizard/task/context';
import {
CollapsibleBody,
WizardTaskItem,
} from 'multi-currency/interface/components';
import { WizardTaskContext } from 'multi-currency/interface/functions';

import './index.scss';

import { useDefaultCurrency } from 'wcpay/data';
import { useDefaultCurrency } from 'multi-currency/data';

const SetupComplete = () => {
const { isActive } = useContext( WizardTaskContext );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import { render } from '@testing-library/react';
/**
* Internal dependencies
*/
import WizardTaskContext from '../../../../additional-methods-setup/wizard/task/context';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import SetupCompleteTask from '../../setup-complete-task';

jest.mock( '@wordpress/data', () => ( {
useDispatch: jest.fn().mockReturnValue( { updateOptions: jest.fn() } ),
} ) );

// TODO: Remove this while we have a dependency on 'wcpay/multi-currency/preview-modal'.
jest.mock( 'wcpay/data', () => ( {
useStoreSettings: jest.fn(),
} ) );
jest.mock( 'multi-currency/data', () => ( {
useDefaultCurrency: jest.fn().mockReturnValue( {
code: 'USD',
rate: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import interpolateComponents from '@automattic/interpolate-components';
/**
* Internal dependencies
*/
import WizardTaskContext from '../../../additional-methods-setup/wizard/task/context';
import CollapsibleBody from '../../../additional-methods-setup/wizard/collapsible-body';
import { CollapsibleBody } from 'multi-currency/interface/components';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import { useSettings, useMultiCurrency } from 'multi-currency/interface/data';
import WizardTaskItem from '../../wizard/task-item';
import PreviewModal from '../../../multi-currency/preview-modal';
// TODO: Migrate to 'multi-currency/preview-modal'.
import PreviewModal from 'wcpay/multi-currency/preview-modal';
import './index.scss';

import { useStoreSettings, useSettings, useMultiCurrency } from 'wcpay/data';
import { useStoreSettings } from 'multi-currency/data';

const StoreSettingsTask = () => {
const { storeSettings, submitStoreSettingsUpdate } = useStoreSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import { render, screen, fireEvent } from '@testing-library/react';
/**
* Internal dependencies
*/
import WizardTaskContext from '../../../../additional-methods-setup/wizard/task/context';
import {
useCurrencies,
useStoreSettings,
useSettings,
useMultiCurrency,
} from 'wcpay/data';
import { useCurrencies, useStoreSettings } from 'multi-currency/data';
import { useSettings, useMultiCurrency } from 'multi-currency/interface/data';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import StoreSettingsTask from '..';

jest.mock( 'wcpay/data', () => ( {
jest.mock( 'multi-currency/data', () => ( {
useStoreSettings: jest.fn(),
useCurrencies: jest.fn(),
useSettings: jest.fn(),
useMultiCurrency: jest.fn(),
} ) );
jest.mock( 'multi-currency/interface/data', () => ( {
useSettings: jest.fn(),
useMultiCurrency: jest.fn(),
} ) );

const changeableSettings = [
'enable_storefront_switcher',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Icon, check } from '@wordpress/icons';
/**
* Internal dependencies
*/
import WizardTaskContext from '../../additional-methods-setup/wizard/task/context';
import { WizardTaskContext } from 'multi-currency/interface/functions';
import './task-item.scss';

const WizardTaskItem = ( {
Expand Down