From 5d99b267bfde0f19ad8bb0a665d40225a89180e8 Mon Sep 17 00:00:00 2001 From: rjchow Date: Wed, 15 Nov 2023 15:21:14 +0800 Subject: [PATCH 1/6] fix: fixed all instances of no-use-before-define lint rule violations --- packages/js/api/.eslintrc.js | 1 - plugins/woocommerce-admin/.eslintrc.js | 1 - .../client/activity-panel/activity-panel.js | 26 ++++---- .../activity-panel/highlight-tooltip/index.js | 57 +++++++++--------- .../client/activity-panel/panel.js | 5 +- .../settings/historical-data/actions.js | 40 ++++++------- .../client/homescreen/layout.js | 26 ++++---- .../woocommerce-admin/client/layout/index.js | 34 +++++------ .../client/marketing/data/actions.js | 46 +++++++------- .../feedback-modal/feedback-modal.tsx | 60 +++++++++---------- .../client/profile-wizard/steps/industry.js | 30 +++++----- .../client/store-management-links/index.js | 44 +++++++------- 12 files changed, 184 insertions(+), 186 deletions(-) diff --git a/packages/js/api/.eslintrc.js b/packages/js/api/.eslintrc.js index 88928d13f94..cd7cb2ef99f 100644 --- a/packages/js/api/.eslintrc.js +++ b/packages/js/api/.eslintrc.js @@ -5,7 +5,6 @@ module.exports = { rules: { // These warning rules are stop gaps for eslint issues that need to be fixed later. '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-unused-vars': 'off', }, diff --git a/plugins/woocommerce-admin/.eslintrc.js b/plugins/woocommerce-admin/.eslintrc.js index 3f6f69444a3..5fb8e1f3958 100644 --- a/plugins/woocommerce-admin/.eslintrc.js +++ b/plugins/woocommerce-admin/.eslintrc.js @@ -10,7 +10,6 @@ module.exports = { files: [ 'client/**/*.js', 'client/**/*.jsx', 'client/**/*.tsx' ], rules: { 'react/react-in-jsx-scope': 'off', - '@typescript-eslint/no-use-before-define': 'warn', }, }, ], diff --git a/plugins/woocommerce-admin/client/activity-panel/activity-panel.js b/plugins/woocommerce-admin/client/activity-panel/activity-panel.js index a3ecf8cef0a..be9fb12ac5d 100644 --- a/plugins/woocommerce-admin/client/activity-panel/activity-panel.js +++ b/plugins/woocommerce-admin/client/activity-panel/activity-panel.js @@ -73,6 +73,19 @@ export const ActivityPanel = ( { isEmbedded, query } ) => { const { updateUserPreferences, ...userData } = useUserPreferences(); const activeSetupList = useActiveSetupTasklist(); + const closePanel = () => { + setIsPanelClosing( true ); + setIsPanelOpen( false ); + }; + + const clearPanel = () => { + if ( ! isPanelOpen ) { + setIsPanelClosing( false ); + setIsPanelSwitching( false ); + setCurrentTab( '' ); + } + }; + useEffect( () => { return addHistoryListener( () => { closePanel(); @@ -217,19 +230,6 @@ export const ActivityPanel = ( { isEmbedded, query } ) => { setIsPanelSwitching( panelSwitching ); }; - const closePanel = () => { - setIsPanelClosing( true ); - setIsPanelOpen( false ); - }; - - const clearPanel = () => { - if ( ! isPanelOpen ) { - setIsPanelClosing( false ); - setIsPanelSwitching( false ); - setCurrentTab( '' ); - } - }; - const isHomescreen = () => { return query.page === 'wc-admin' && ! query.path; }; diff --git a/plugins/woocommerce-admin/client/activity-panel/highlight-tooltip/index.js b/plugins/woocommerce-admin/client/activity-panel/highlight-tooltip/index.js index b9459b5298f..769fdfd5824 100644 --- a/plugins/woocommerce-admin/client/activity-panel/highlight-tooltip/index.js +++ b/plugins/woocommerce-admin/client/activity-panel/highlight-tooltip/index.js @@ -43,6 +43,30 @@ function HighlightTooltip( { ); const [ node, setNode ] = useState( null ); const [ anchorRect, setAnchorRect ] = useState( null ); + const showTooltip = ( container ) => { + const element = document.getElementById( id ); + if ( element && useAnchor ) { + setAnchorRect( element.getBoundingClientRect() ); + } + if ( container ) { + container.classList.add( SHOW_CLASS ); + } + setShowHighlight( true ); + onShow(); + }; + + const triggerShowTooltip = ( container ) => { + let timeoutId = null; + if ( delay > 0 ) { + timeoutId = setTimeout( () => { + timeoutId = null; + showTooltip( container ); + }, delay ); + } else if ( ! showHighlight ) { + showTooltip( container ); + } + return timeoutId; + }; useEffect( () => { const element = document.getElementById( id ); @@ -93,11 +117,6 @@ function HighlightTooltip( { } }, [ show ] ); - useLayoutEffect( () => { - window.addEventListener( 'resize', updateSize ); - return () => window.removeEventListener( 'resize', updateSize ); - }, [] ); - function updateSize() { if ( useAnchor ) { const element = document.getElementById( id ); @@ -105,30 +124,10 @@ function HighlightTooltip( { } } - const triggerShowTooltip = ( container ) => { - let timeoutId = null; - if ( delay > 0 ) { - timeoutId = setTimeout( () => { - timeoutId = null; - showTooltip( container ); - }, delay ); - } else if ( ! showHighlight ) { - showTooltip( container ); - } - return timeoutId; - }; - - const showTooltip = ( container ) => { - const element = document.getElementById( id ); - if ( element && useAnchor ) { - setAnchorRect( element.getBoundingClientRect() ); - } - if ( container ) { - container.classList.add( SHOW_CLASS ); - } - setShowHighlight( true ); - onShow(); - }; + useLayoutEffect( () => { + window.addEventListener( 'resize', updateSize ); + return () => window.removeEventListener( 'resize', updateSize ); + }, [] ); const triggerClose = () => { setShowHighlight( false ); diff --git a/plugins/woocommerce-admin/client/activity-panel/panel.js b/plugins/woocommerce-admin/client/activity-panel/panel.js index 248cae36de7..f1000786ccc 100644 --- a/plugins/woocommerce-admin/client/activity-panel/panel.js +++ b/plugins/woocommerce-admin/client/activity-panel/panel.js @@ -22,6 +22,9 @@ export const Panel = ( { } ) => { const panelClass = 'woocommerce-layout__activity-panel-wrapper'; + const focusOnMountRef = useFocusOnMount(); + const containerRef = useRef( null ); + const handleFocusOutside = ( event ) => { const isClickOnModalOrSnackbar = event.relatedTarget && @@ -50,9 +53,7 @@ export const Panel = ( { } }; - const focusOnMountRef = useFocusOnMount(); const useFocusOutsideProps = useFocusOutside( handleFocusOutside ); - const containerRef = useRef( null ); const mergedContainerRef = useCallback( ( node ) => { containerRef.current = node; diff --git a/plugins/woocommerce-admin/client/analytics/settings/historical-data/actions.js b/plugins/woocommerce-admin/client/analytics/settings/historical-data/actions.js index 3c7579a2294..68aaa2d1065 100644 --- a/plugins/woocommerce-admin/client/analytics/settings/historical-data/actions.js +++ b/plugins/woocommerce-admin/client/analytics/settings/historical-data/actions.js @@ -28,6 +28,26 @@ function HistoricalDataActions( { setImportStarted, updateImportation, } ) { + const makeQuery = ( path, errorMessage, importStarted = false ) => { + updateImportation( path, importStarted ) + .then( ( response ) => { + if ( response.status === 'success' ) { + createNotice( 'success', response.message ); + } else { + createNotice( 'error', errorMessage ); + setImportStarted( false ); + stopImport(); + } + } ) + .catch( ( error ) => { + if ( error && error.message ) { + createNotice( 'error', error.message ); + setImportStarted( false ); + stopImport(); + } + } ); + }; + const onStartImport = () => { const path = addQueryArgs( '/wc-analytics/reports/import', @@ -53,26 +73,6 @@ function HistoricalDataActions( { makeQuery( path, errorMessage ); }; - const makeQuery = ( path, errorMessage, importStarted = false ) => { - updateImportation( path, importStarted ) - .then( ( response ) => { - if ( response.status === 'success' ) { - createNotice( 'success', response.message ); - } else { - createNotice( 'error', errorMessage ); - setImportStarted( false ); - stopImport(); - } - } ) - .catch( ( error ) => { - if ( error && error.message ) { - createNotice( 'error', error.message ); - setImportStarted( false ); - stopImport(); - } - } ); - }; - const deletePreviousData = () => { const path = '/wc-analytics/reports/import/delete'; const errorMessage = __( diff --git a/plugins/woocommerce-admin/client/homescreen/layout.js b/plugins/woocommerce-admin/client/homescreen/layout.js index 229a9e373b4..65f0d040333 100644 --- a/plugins/woocommerce-admin/client/homescreen/layout.js +++ b/plugins/woocommerce-admin/client/homescreen/layout.js @@ -97,6 +97,19 @@ export const Layout = ( { const shouldStickColumns = isWideViewport.current && twoColumns; const shouldShowMobileAppModal = query.mobileAppModal ?? false; + const renderTaskList = () => { + return ( + }> + { activeSetupTaskList && isDashboardShown && ( + <> + + + ) } + + + ); + }; + const renderColumns = () => { return ( <> @@ -124,19 +137,6 @@ export const Layout = ( { ); }; - const renderTaskList = () => { - return ( - }> - { activeSetupTaskList && isDashboardShown && ( - <> - - - ) } - - - ); - }; - return ( <> { isDashboardShown && ( diff --git a/plugins/woocommerce-admin/client/layout/index.js b/plugins/woocommerce-admin/client/layout/index.js index 9107f7929c0..dfdcb10d019 100644 --- a/plugins/woocommerce-admin/client/layout/index.js +++ b/plugins/woocommerce-admin/client/layout/index.js @@ -108,23 +108,6 @@ const WithReactRouterProps = ( { children } ) => { } ); }; -/** - * Wraps _Layout with WithReactRouterProps for non-embedded page renders - * We need this because the hooks fail for embedded page renders as there is no Router context above it. - * - * @param {Object} props React component props - */ -const LayoutSwitchWrapper = ( props ) => { - if ( props.isEmbedded ) { - return <_Layout { ...props } />; - } - return ( - - <_Layout { ...props } /> - - ); -}; - function _Layout( { activePlugins, installedPlugins, @@ -287,6 +270,23 @@ _Layout.propTypes = { } ).isRequired, }; +/** + * Wraps _Layout with WithReactRouterProps for non-embedded page renders + * We need this because the hooks fail for embedded page renders as there is no Router context above it. + * + * @param {Object} props React component props + */ +const LayoutSwitchWrapper = ( props ) => { + if ( props.isEmbedded ) { + return <_Layout { ...props } />; + } + return ( + + <_Layout { ...props } /> + + ); +}; + const dataEndpoints = getAdminSetting( 'dataEndpoints' ); const Layout = compose( withPluginsHydration( { diff --git a/plugins/woocommerce-admin/client/marketing/data/actions.js b/plugins/woocommerce-admin/client/marketing/data/actions.js index 01f30d909b9..e3bfd36af41 100644 --- a/plugins/woocommerce-admin/client/marketing/data/actions.js +++ b/plugins/woocommerce-admin/client/marketing/data/actions.js @@ -62,6 +62,29 @@ export function setError( category, error ) { }; } +export function* loadInstalledPluginsAfterActivation( activatedPluginSlug ) { + try { + const response = yield apiFetch( { + path: `${ API_NAMESPACE }/overview/installed-plugins`, + } ); + + if ( response ) { + yield receiveInstalledPlugins( response ); + yield removeActivatingPlugin( activatedPluginSlug ); + } else { + throw new Error(); + } + } catch ( error ) { + yield handleFetchError( + error, + __( + 'There was an error loading installed extensions.', + 'woocommerce' + ) + ); + } +} + export function* activateInstalledPlugin( pluginSlug ) { const { createNotice } = dispatch( 'core/notices' ); yield receiveActivatingPlugin( pluginSlug ); @@ -102,29 +125,6 @@ export function* activateInstalledPlugin( pluginSlug ) { return true; } -export function* loadInstalledPluginsAfterActivation( activatedPluginSlug ) { - try { - const response = yield apiFetch( { - path: `${ API_NAMESPACE }/overview/installed-plugins`, - } ); - - if ( response ) { - yield receiveInstalledPlugins( response ); - yield removeActivatingPlugin( activatedPluginSlug ); - } else { - throw new Error(); - } - } catch ( error ) { - yield handleFetchError( - error, - __( - 'There was an error loading installed extensions.', - 'woocommerce' - ) - ); - } -} - export function* installAndActivateRecommendedPlugin( recommendedPluginSlug, category diff --git a/plugins/woocommerce-admin/client/marketplace/components/feedback-modal/feedback-modal.tsx b/plugins/woocommerce-admin/client/marketplace/components/feedback-modal/feedback-modal.tsx index a3131c5eece..218e873f20e 100644 --- a/plugins/woocommerce-admin/client/marketplace/components/feedback-modal/feedback-modal.tsx +++ b/plugins/woocommerce-admin/client/marketplace/components/feedback-modal/feedback-modal.tsx @@ -82,36 +82,6 @@ export default function FeedbackModal(): JSX.Element { }; const { createNotice } = useDispatch( 'core/notices' ); - function maybeShowSnackbar() { - // Don't show if we're still loading content - if ( isLoading ) { - return; - } - - // Don't show if the user has already given feedback or otherwise suppressed - if ( isDismissedForever() ) { - return; - } - - // Don't show if we've already shown today or user has declined today - const today = new Date().toDateString(); - if ( - today === - localStorage.getItem( LOCALSTORAGE_KEY_LAST_REQUESTED_DATE ) - ) { - return; - } - - const timer = setTimeout( showSnackbar, SNACKBAR_TIMEOUT ); - - // Without this, navigating between screens will create a series of snackbars - dismissToday(); - - return () => { - clearTimeout( timer ); - }; - } - function showSnackbar() { createNotice( 'success', @@ -167,6 +137,36 @@ export default function FeedbackModal(): JSX.Element { ); } + function maybeShowSnackbar() { + // Don't show if we're still loading content + if ( isLoading ) { + return; + } + + // Don't show if the user has already given feedback or otherwise suppressed + if ( isDismissedForever() ) { + return; + } + + // Don't show if we've already shown today or user has declined today + const today = new Date().toDateString(); + if ( + today === + localStorage.getItem( LOCALSTORAGE_KEY_LAST_REQUESTED_DATE ) + ) { + return; + } + + const timer = setTimeout( showSnackbar, SNACKBAR_TIMEOUT ); + + // Without this, navigating between screens will create a series of snackbars + dismissToday(); + + return () => { + clearTimeout( timer ); + }; + } + useEffect( maybeShowSnackbar, [ isLoading ] ); // We don't want the "How easy was it to find an extension?" dialog to appear forever: diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/industry.js b/plugins/woocommerce-admin/client/profile-wizard/steps/industry.js index c6f23f081ed..37c97f39c4e 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/industry.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/industry.js @@ -27,21 +27,6 @@ import { getAdminSetting } from '~/utils/admin-settings'; const onboarding = getAdminSetting( 'onboarding', {} ); -const Loader = ( props ) => { - if ( props.isLoading ) { - return ( -
- -
- ); - } - - return ; -}; - class Industry extends Component { constructor( props ) { const profileItems = get( props, 'profileItems', {} ); @@ -313,6 +298,21 @@ class Industry extends Component { } } +const Loader = ( props ) => { + if ( props.isLoading ) { + return ( +
+ +
+ ); + } + + return ; +}; + export default compose( withSelect( ( select ) => { const { diff --git a/plugins/woocommerce-admin/client/store-management-links/index.js b/plugins/woocommerce-admin/client/store-management-links/index.js index 0cd1c4d31cf..e7d170212b7 100644 --- a/plugins/woocommerce-admin/client/store-management-links/index.js +++ b/plugins/woocommerce-admin/client/store-management-links/index.js @@ -25,6 +25,28 @@ import { QuickLinkCategory } from './quick-link-category'; import { QuickLink } from './quick-link'; import { getAdminSetting } from '~/utils/admin-settings'; +export function getLinkTypeAndHref( { path, tab = null, type, href = null } ) { + return ( + { + 'wc-admin': { + href: `admin.php?page=wc-admin&path=%2F${ path }`, + linkType: 'wc-admin', + }, + 'wp-admin': { + href: path, + linkType: 'wp-admin', + }, + 'wc-settings': { + href: `admin.php?page=wc-settings&tab=${ tab }`, + linkType: 'wp-admin', + }, + }[ type ] || { + href, + linkType: 'external', + } + ); +} + export function getItemsByCategory( shopUrl ) { return [ { @@ -112,28 +134,6 @@ export function getItemsByCategory( shopUrl ) { ]; } -export function getLinkTypeAndHref( { path, tab = null, type, href = null } ) { - return ( - { - 'wc-admin': { - href: `admin.php?page=wc-admin&path=%2F${ path }`, - linkType: 'wc-admin', - }, - 'wp-admin': { - href: path, - linkType: 'wp-admin', - }, - 'wc-settings': { - href: `admin.php?page=wc-settings&tab=${ tab }`, - linkType: 'wp-admin', - }, - }[ type ] || { - href, - linkType: 'external', - } - ); -} - export const generateExtensionLinks = ( links ) => { return links.reduce( ( acc, { icon, href, title } ) => { const url = new URL( href, window.location.href ); From 420d219c2cb2429b51c4d92bca48ca237107e2cb Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 15 Nov 2023 10:52:50 +0000 Subject: [PATCH 2/6] Add changefile(s) from automation for the following project(s): @woocommerce/eslint-plugin, @woocommerce/components, @woocommerce/api, woocommerce --- .../41452-dev-fix-no-use-before-define-lint-violations | 4 ++++ .../41452-dev-fix-no-use-before-define-lint-violations | 4 ++++ .../41452-dev-fix-no-use-before-define-lint-violations | 4 ++++ .../41452-dev-fix-no-use-before-define-lint-violations | 4 ++++ 4 files changed, 16 insertions(+) create mode 100644 packages/js/api/changelog/41452-dev-fix-no-use-before-define-lint-violations create mode 100644 packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations create mode 100644 packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations create mode 100644 plugins/woocommerce/changelog/41452-dev-fix-no-use-before-define-lint-violations diff --git a/packages/js/api/changelog/41452-dev-fix-no-use-before-define-lint-violations b/packages/js/api/changelog/41452-dev-fix-no-use-before-define-lint-violations new file mode 100644 index 00000000000..20293a171a1 --- /dev/null +++ b/packages/js/api/changelog/41452-dev-fix-no-use-before-define-lint-violations @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fixed all violations of no-use-before-define eslint rule \ No newline at end of file diff --git a/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations b/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations new file mode 100644 index 00000000000..20293a171a1 --- /dev/null +++ b/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fixed all violations of no-use-before-define eslint rule \ No newline at end of file diff --git a/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations b/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations new file mode 100644 index 00000000000..20293a171a1 --- /dev/null +++ b/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fixed all violations of no-use-before-define eslint rule \ No newline at end of file diff --git a/plugins/woocommerce/changelog/41452-dev-fix-no-use-before-define-lint-violations b/plugins/woocommerce/changelog/41452-dev-fix-no-use-before-define-lint-violations new file mode 100644 index 00000000000..20293a171a1 --- /dev/null +++ b/plugins/woocommerce/changelog/41452-dev-fix-no-use-before-define-lint-violations @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fixed all violations of no-use-before-define eslint rule \ No newline at end of file From 69f1b43160c31262513306c9e02c68c4c472856a Mon Sep 17 00:00:00 2001 From: rjchow Date: Thu, 16 Nov 2023 19:21:21 +0800 Subject: [PATCH 3/6] Fix no-use-before-define lint rule violation --- .../dev-lint-violation-no-use-before-define | 4 + .../repositories/rest/orders/transformer.ts | 188 +++++++++--------- 2 files changed, 98 insertions(+), 94 deletions(-) create mode 100644 packages/js/api/changelog/dev-lint-violation-no-use-before-define diff --git a/packages/js/api/changelog/dev-lint-violation-no-use-before-define b/packages/js/api/changelog/dev-lint-violation-no-use-before-define new file mode 100644 index 00000000000..44dbeb2a883 --- /dev/null +++ b/packages/js/api/changelog/dev-lint-violation-no-use-before-define @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +Fix no-use-before-define lint rule violation diff --git a/packages/js/api/src/repositories/rest/orders/transformer.ts b/packages/js/api/src/repositories/rest/orders/transformer.ts index 4424130e4e3..501e40c8132 100644 --- a/packages/js/api/src/repositories/rest/orders/transformer.ts +++ b/packages/js/api/src/repositories/rest/orders/transformer.ts @@ -23,100 +23,6 @@ import { } from '../../../models'; import { createMetaDataTransformer } from '../shared'; -/** - * Creates a transformer for an order object. - * - * @return {ModelTransformer} The created transformer. - */ -export function createOrderTransformer(): ModelTransformer< Order > { - return new ModelTransformer( [ - new IgnorePropertyTransformation( [ 'date_created', 'date_modified' ] ), - new ModelTransformerTransformation( - 'billing', - BillingOrderAddress, - createBillingAddressTransformer() - ), - new ModelTransformerTransformation( - 'shipping', - ShippingOrderAddress, - createShippingAddressTransformer() - ), - new ModelTransformerTransformation( - 'taxLines', - OrderTaxRate, - createOrderTaxRateTransformer() - ), - new ModelTransformerTransformation( - 'refunds', - OrderRefundLine, - createOrderRefundLineTransformer() - ), - new ModelTransformerTransformation( - 'couponLines', - OrderCouponLine, - createOrdeCouponLineTransformer() - ), - new ModelTransformerTransformation( - 'feeLines', - OrderFeeLine, - createOrderFeeLineTransformer() - ), - new ModelTransformerTransformation( - 'lineItems', - OrderLineItem, - createOrderLineItemTransformer() - ), - new ModelTransformerTransformation( - 'shippingLines', - OrderShippingLine, - createOrderShippingItemTransformer() - ), - new ModelTransformerTransformation( - 'metaData', - MetaData, - createMetaDataTransformer() - ), - - new PropertyTypeTransformation( { - status: PropertyType.String, - currency: PropertyType.String, - discountTotal: PropertyType.String, - discountTax: PropertyType.String, - shippingTotal: PropertyType.String, - shippingTax: PropertyType.String, - cartTax: PropertyType.String, - total: PropertyType.String, - totalTax: PropertyType.String, - pricesIncludeTax: PropertyType.Boolean, - customerId: PropertyType.Integer, - customerNote: PropertyType.String, - paymentMethod: PropertyType.String, - transactionId: PropertyType.String, - setPaid: PropertyType.Boolean, - } ), - new KeyChangeTransformation< Order >( { - discountTotal: 'discount_total', - discountTax: 'discount_tax', - shippingTotal: 'shipping_total', - shippingTax: 'shipping_tax', - cartTax: 'cart_tax', - totalTax: 'total_tax', - pricesIncludeTax: 'prices_include_tax', - customerId: 'customer_id', - customerNote: 'customer_note', - paymentMethod: 'payment_method', - transactionId: 'transaction_id', - setPaid: 'set_paid', - lineItems: 'line_items', - taxLines: 'tax_lines', - shippingLines: 'shipping_lines', - feeLines: 'fee_lines', - couponLines: 'coupon_lines', - metaData: 'meta_data', - } ), - ] ); -} - /** * Creates a transformer for an order address object. * @@ -328,3 +234,97 @@ function createOrderShippingItemTransformer(): ModelTransformer< OrderShippingLi } ), ] ); } + +/** + * Creates a transformer for an order object. + * + * @return {ModelTransformer} The created transformer. + */ +export function createOrderTransformer(): ModelTransformer< Order > { + return new ModelTransformer( [ + new IgnorePropertyTransformation( [ 'date_created', 'date_modified' ] ), + new ModelTransformerTransformation( + 'billing', + BillingOrderAddress, + createBillingAddressTransformer() + ), + new ModelTransformerTransformation( + 'shipping', + ShippingOrderAddress, + createShippingAddressTransformer() + ), + new ModelTransformerTransformation( + 'taxLines', + OrderTaxRate, + createOrderTaxRateTransformer() + ), + new ModelTransformerTransformation( + 'refunds', + OrderRefundLine, + createOrderRefundLineTransformer() + ), + new ModelTransformerTransformation( + 'couponLines', + OrderCouponLine, + createOrdeCouponLineTransformer() + ), + new ModelTransformerTransformation( + 'feeLines', + OrderFeeLine, + createOrderFeeLineTransformer() + ), + new ModelTransformerTransformation( + 'lineItems', + OrderLineItem, + createOrderLineItemTransformer() + ), + new ModelTransformerTransformation( + 'shippingLines', + OrderShippingLine, + createOrderShippingItemTransformer() + ), + new ModelTransformerTransformation( + 'metaData', + MetaData, + createMetaDataTransformer() + ), + + new PropertyTypeTransformation( { + status: PropertyType.String, + currency: PropertyType.String, + discountTotal: PropertyType.String, + discountTax: PropertyType.String, + shippingTotal: PropertyType.String, + shippingTax: PropertyType.String, + cartTax: PropertyType.String, + total: PropertyType.String, + totalTax: PropertyType.String, + pricesIncludeTax: PropertyType.Boolean, + customerId: PropertyType.Integer, + customerNote: PropertyType.String, + paymentMethod: PropertyType.String, + transactionId: PropertyType.String, + setPaid: PropertyType.Boolean, + } ), + new KeyChangeTransformation< Order >( { + discountTotal: 'discount_total', + discountTax: 'discount_tax', + shippingTotal: 'shipping_total', + shippingTax: 'shipping_tax', + cartTax: 'cart_tax', + totalTax: 'total_tax', + pricesIncludeTax: 'prices_include_tax', + customerId: 'customer_id', + customerNote: 'customer_note', + paymentMethod: 'payment_method', + transactionId: 'transaction_id', + setPaid: 'set_paid', + lineItems: 'line_items', + taxLines: 'tax_lines', + shippingLines: 'shipping_lines', + feeLines: 'fee_lines', + couponLines: 'coupon_lines', + metaData: 'meta_data', + } ), + ] ); +} From 3d606e2eb897aa6a0bc2ff038c37c4d4ab5dd005 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 16 Nov 2023 11:28:16 +0000 Subject: [PATCH 4/6] Add changefile(s) from automation for the following project(s): @woocommerce/api, woocommerce --- .../41452-dev-fix-no-use-before-define-lint-violations | 4 ---- .../41452-dev-fix-no-use-before-define-lint-violations | 4 ---- 2 files changed, 8 deletions(-) delete mode 100644 packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations delete mode 100644 packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations diff --git a/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations b/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations deleted file mode 100644 index 20293a171a1..00000000000 --- a/packages/js/components/changelog/41452-dev-fix-no-use-before-define-lint-violations +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: dev - -Fixed all violations of no-use-before-define eslint rule \ No newline at end of file diff --git a/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations b/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations deleted file mode 100644 index 20293a171a1..00000000000 --- a/packages/js/eslint-plugin/changelog/41452-dev-fix-no-use-before-define-lint-violations +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: dev - -Fixed all violations of no-use-before-define eslint rule \ No newline at end of file From e062db64c94b2e9b2f2d0ba2196c412bcbb97397 Mon Sep 17 00:00:00 2001 From: rjchow Date: Thu, 16 Nov 2023 21:01:09 +0800 Subject: [PATCH 6/6] deleted duplicate changelog --- .../js/api/changelog/dev-lint-violation-no-use-before-define | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 packages/js/api/changelog/dev-lint-violation-no-use-before-define diff --git a/packages/js/api/changelog/dev-lint-violation-no-use-before-define b/packages/js/api/changelog/dev-lint-violation-no-use-before-define deleted file mode 100644 index 44dbeb2a883..00000000000 --- a/packages/js/api/changelog/dev-lint-violation-no-use-before-define +++ /dev/null @@ -1,4 +0,0 @@ -Significance: patch -Type: dev - -Fix no-use-before-define lint rule violation