woocommerce/plugins/woocommerce-admin/client/layout/controller.js

333 lines
8.3 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
import { Component, Suspense, lazy } from '@wordpress/element';
2019-06-13 19:58:21 +00:00
import { parse, stringify } from 'qs';
import { find, isEqual, last, omit } from 'lodash';
import { applyFilters } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
/**
* WooCommerce dependencies
*/
import {
getNewPath,
getPersistedQuery,
getHistory,
} from '@woocommerce/navigation';
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
import { Spinner } from '@woocommerce/components';
/**
* Internal dependencies
*/
import { getUrlParams } from 'utils';
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
const AnalyticsReport = lazy( () =>
import( /* webpackChunkName: "analytics-report" */ 'analytics/report' )
);
const AnalyticsSettings = lazy( () =>
import( /* webpackChunkName: "analytics-settings" */ 'analytics/settings' )
);
const Dashboard = lazy( () =>
import( /* webpackChunkName: "dashboard" */ 'dashboard' )
);
const DevDocs = lazy( () =>
import( /* webpackChunkName: "devdocs" */ 'devdocs' )
);
const Homescreen = lazy( () =>
import( /* webpackChunkName: "homescreen" */ 'homescreen' )
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
);
const MarketingOverview = lazy( () =>
import( /* webpackChunkName: "marketing-overview" */ 'marketing/overview' )
);
import getReports from 'analytics/report/get-reports';
const TIME_EXCLUDED_SCREENS_FILTER = 'woocommerce_admin_time_excluded_screens';
export const PAGES_FILTER = 'woocommerce_admin_pages_list';
export const getPages = () => {
const pages = [];
const initialBreadcrumbs = [ [ '', wcSettings.woocommerceTranslation ] ];
if ( window.wcAdminFeatures.devdocs ) {
pages.push( {
container: DevDocs,
path: '/devdocs',
breadcrumbs: ( { location } ) => {
const { component } = getUrlParams( location.search );
if ( component ) {
return [
...initialBreadcrumbs,
[ '/devdocs', 'Documentation' ],
component,
];
}
return [ ...initialBreadcrumbs, 'Documentation' ];
},
wpOpenMenu: 'toplevel_page_woocommerce',
} );
}
if (
window.wcAdminFeatures[ 'analytics-dashboard' ] &&
! window.wcAdminFeatures.homescreen
) {
pages.push( {
container: Dashboard,
path: '/',
breadcrumbs: [
...initialBreadcrumbs,
__( 'Dashboard', 'woocommerce-admin' ),
],
wpOpenMenu: 'toplevel_page_woocommerce',
} );
}
if ( window.wcAdminFeatures.homescreen ) {
pages.push( {
container: Homescreen,
path: '/',
breadcrumbs: [
...initialBreadcrumbs,
__( 'Home', 'woocommerce-admin' ),
],
wpOpenMenu: 'toplevel_page_woocommerce',
} );
}
if ( window.wcAdminFeatures.analytics ) {
if ( window.wcAdminFeatures.homescreen ) {
pages.push( {
container: Dashboard,
path: '/analytics/overview',
breadcrumbs: [
...initialBreadcrumbs,
[
'/analytics/overview',
__( 'Analytics', 'woocommerce-admin' ),
],
__( 'Overview', 'woocommerce-admin' ),
],
wpOpenMenu: 'toplevel_page_wc-admin-path--analytics-overview',
} );
}
const ReportWpOpenMenu = `toplevel_page_wc-admin-path--analytics-${
window.wcAdminFeatures.homescreen ? 'overview' : 'revenue'
}`;
pages.push( {
Add settings page with excluded order statuses (https://github.com/woocommerce/woocommerce-admin/pull/1364) * Add settings page routes * Add control options for excluded statuses * Add control options for excluded statuses * Add excluded order statuses to rest api * Add wc settings to wc-api * Add wc settings to wc-api * Split and validate multiselect values in settings controller * Add wcAdminSettings to wcSettings global * Set initial excluded statuses from serverside wcSettings data * Add extensible filter for wcSettings global * Split arrays into comma separated strings in wc-api * Extract setting as separate component * Extra settings to config file * Add checkboxGroup option as input type * Separate status types into default and custom groups * Add setting option styling * Add responsive styling for settings * Fix wpClosedMenu and wpOpenMenu for settings page * Add support for resetting to default values * Only show checkbox group if options are available * Add proptypes to Setting component * Add extensible filter to analytics settings * Add readme for settings config and extensibility * Hook up excluded status settings to reports * Pass object to settings API instead of comma delimited string * Fix inpuType -> inputType typo * Remove hasError from constructor * Bump settings API to v4 * Use interpolateComponents instead of dangerously setting html * Use empty array in initial excldued statuses setting value if none is retrieved * Remove double check for refunded status in default order statuses * Update settings wc-api to use namespace * Add aria=labelledby to checkbox group
2019-01-31 01:04:11 +00:00
container: AnalyticsSettings,
path: '/analytics/settings',
breadcrumbs: [
...initialBreadcrumbs,
[
'/analytics/revenue',
__( 'Analytics', 'woocommerce-admin' ),
],
__( 'Settings', 'woocommerce-admin' ),
],
wpOpenMenu: ReportWpOpenMenu,
} );
Merge Version/1.0 to master (https://github.com/woocommerce/woocommerce-admin/pull/3740) * Try: Moving Customers to main Woo Menu (https://github.com/woocommerce/woocommerce-admin/pull/3632) * Only add onboarding settings on wc-admin pages when task list should be shown. (https://github.com/woocommerce/woocommerce-admin/pull/3722) * Use cron for unsnoozing admin notes (https://github.com/woocommerce/woocommerce-admin/pull/3662) * Use wp-cron for admin note snoozing. * Remove "unsnooze" scheduled action. * Use correct version. * Avoid using deprecated method for unscheduling actions. * Onboarding: Fix toggle tracking events (https://github.com/woocommerce/woocommerce-admin/pull/3645) * Fix errant wcadmin prefix on event name * Track the onboarding toggle on the option in case enable_onboarding isn't used * Move toggle actions to separate function * Move onboarding actions * Move onboarding filters * Move help tab updates to add_toggle_actions * Only run onboarding actions when enabled * Onboarding: Add tracks events when profiler steps are completed (https://github.com/woocommerce/woocommerce-admin/pull/3726) * Add tracks for store profiler step completion * Record event when profiler is completed * Ensure continue setup loads the onboarding profiler (https://github.com/woocommerce/woocommerce-admin/pull/3646) * 'All that include' option removed when input field is empty (https://github.com/woocommerce/woocommerce-admin/pull/3700) * 'All that include' option removed when input field is empty Added a control to check that when the input field 'Search by customer name' is empty, the 'All that include' option is not appearing. * Const name improved The constant name hasValues was changed to optionsHaveValues (more descriptive) * Fix select text alignment (https://github.com/woocommerce/woocommerce-admin/pull/3723) Co-authored-by: Timmy Crawford <timmyc@users.noreply.github.com> Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Joshua T Flowers <joshuatf@gmail.com> Co-authored-by: Fernando <ultimoround@gmail.com> Co-authored-by: edmundcwm <edmundcwm@gmail.com>
2020-02-20 11:59:02 +00:00
pages.push( {
container: AnalyticsReport,
path: '/customers',
breadcrumbs: [
...initialBreadcrumbs,
__( 'Customers', 'woocommerce-admin' ),
],
Merge Version/1.0 to master (https://github.com/woocommerce/woocommerce-admin/pull/3740) * Try: Moving Customers to main Woo Menu (https://github.com/woocommerce/woocommerce-admin/pull/3632) * Only add onboarding settings on wc-admin pages when task list should be shown. (https://github.com/woocommerce/woocommerce-admin/pull/3722) * Use cron for unsnoozing admin notes (https://github.com/woocommerce/woocommerce-admin/pull/3662) * Use wp-cron for admin note snoozing. * Remove "unsnooze" scheduled action. * Use correct version. * Avoid using deprecated method for unscheduling actions. * Onboarding: Fix toggle tracking events (https://github.com/woocommerce/woocommerce-admin/pull/3645) * Fix errant wcadmin prefix on event name * Track the onboarding toggle on the option in case enable_onboarding isn't used * Move toggle actions to separate function * Move onboarding actions * Move onboarding filters * Move help tab updates to add_toggle_actions * Only run onboarding actions when enabled * Onboarding: Add tracks events when profiler steps are completed (https://github.com/woocommerce/woocommerce-admin/pull/3726) * Add tracks for store profiler step completion * Record event when profiler is completed * Ensure continue setup loads the onboarding profiler (https://github.com/woocommerce/woocommerce-admin/pull/3646) * 'All that include' option removed when input field is empty (https://github.com/woocommerce/woocommerce-admin/pull/3700) * 'All that include' option removed when input field is empty Added a control to check that when the input field 'Search by customer name' is empty, the 'All that include' option is not appearing. * Const name improved The constant name hasValues was changed to optionsHaveValues (more descriptive) * Fix select text alignment (https://github.com/woocommerce/woocommerce-admin/pull/3723) Co-authored-by: Timmy Crawford <timmyc@users.noreply.github.com> Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Joshua T Flowers <joshuatf@gmail.com> Co-authored-by: Fernando <ultimoround@gmail.com> Co-authored-by: edmundcwm <edmundcwm@gmail.com>
2020-02-20 11:59:02 +00:00
wpOpenMenu: 'toplevel_page_woocommerce',
} );
pages.push( {
container: AnalyticsReport,
path: '/analytics/:report',
breadcrumbs: ( { match } ) => {
const report = find( getReports(), {
report: match.params.report,
} );
if ( ! report ) {
return [];
}
return [
...initialBreadcrumbs,
[
'/analytics/revenue',
__( 'Analytics', 'woocommerce-admin' ),
],
report.title,
];
},
wpOpenMenu: ReportWpOpenMenu,
} );
}
Marketing Tab MVP (https://github.com/woocommerce/woocommerce-admin/pull/3953) * Add Marketing feature flag * Add marketing page and menu item * Register marketing page with layout controller * Add initial marketing cards * Add max-width to marketing overview page * Add initial marketing WelcomeCard component * Make marketing welcome card permanently dismiss * Add a readme for the marketing page components * Record tracks event when marketing welcome dismissed * Match design width * Add welcome image and initial styles * Use gridicon for close button * Fix whitespace * Add PluginsHelper::get_plugin_data() * Add initial Marketing\InstalledExtensions class * Preload installed marketing extensions data * Tweak extension statuses * Add InstalledExtensionRow component * Add initial extension data to InstalledExtensions card * Refactor PluginsHelper::get_plugin_data method Using the new get_plugin_path_from_slug method * Ensure get_plugins() function is available for PluginsHelper * Simplify using PluginsHelper method * Add MailChimp configured status logic * Add links to InstalledExtensionRow component * Add key prop to extensions list * Setup styles for InstalledExtensions card * Display nothing if no installed extensions * Add InstalledExtensions::get_allowed_plugins() * Setup Marketing Overview API controller * Add /activate-plugin marketing endpoint * Add more extensions URL props * Add Facebook extension configured status logic * Update Facebook extension URL props * Fix extenion data logic * Move component into it’s own directory * Setup /marketing/overview/recommended endpoint * Initial marketing page card header styles * Add basic extension data to RecommendedExtensions * Use color as variable * Tweak card header padding for design * Add basic styling to RecommendedExtensions card * settingsUrl is not available if the plugin is not active * Add /marketing/overview/installed-plugins REST endpoint * Add basic activation functionality to InstalledExtensions component * Don’t throw error on success * Add MVP data store for installed extensions card * Add core dark blue color variable * Add styles for installed extensions card * Move knowledge-base component to its own directory * Pull recommended marketing plugins from remote test site * Hide description when configured As per design * Tweak colors based on design * Finish off styling for RecommendedExtensions * Limit recommended extensions to 6 items * Add error handling to RecommendedExtensions card * Rename ‘copy’ extension prop * Add marketing button component to match design * Create ProductIcon component for marketing * Add InstalledExtension icons * Fix icon image paths * Add ProductIcon to InstallExtensionRow * Final styling to installed extensions card row * Knowledge base card placeholders * Fix missing icons when plugin not activated * Remove logging * Tweak array structure to ensure we have an array in JS and not an object * Refactor KnowledgeBase marketing component - We don’t need loop through every post when rendering, just pick the posts we need - Remove unused classes * Move padding from each slide to the container * Improve slider animations by absolute positioning the slides * Reduce the slider animation timeout and add a note * Add in-app purchase flow url params for recommended extensions * Fix slider animation * Reset slider height on window resize * Short slider animation, fix double margin on smaller screens * Add initial marketing/knowledge-base endpoint * Pull knowledge base posts from API * Rename welcome card dismiss tracks event * Record event on recommended product click * Recond onclick events for installed extensions card * Record event when carousel navigation clicked * img elements must have an alt prop * Remove import that is never used * use camelCase * Decode HTML entities from API call * Remove unused container div * Add card loading state * Add images to knowledge base card * Link knowledge base posts * Use the Pagination component rather than duplicate it’s functionality * Clean up and rename knowledge base slider * Clean knowledge base CSS and update responsive styles for single post slide * Add a README for button component * Add README for product icon component * Add initial readme for Slider component * Add correct image sizes to knowledge base slider, finalize styles * Fix extension link urls * Resolve some code formatting issue * Bind class click methods to this * Wrap nodes in Fragment * Fix wccom-back path * Add placeholder author and gravatar Default avatar url size returned from the API is currently set to 96 so I’ve done a simple replace with 16 * Fix style-lint expected new line * Add docblock for get_knowledge_base_posts() * Setup data store for marketing to handle installedExtensions card * Fix function names “Activating” not “installing” * Move welcome card component to its own dir * IconButton component is going to be deprecated ref: https://github.com/WordPress/gutenberg/pull/19299 * Support multiple activating plugins in the data store * Rename extension to plugin for consistency * Add propTypes to component * Rename data-store/ to data/ * Fix import paths * Extract isActivatingPlugin logic into datastore * Move data store selectors into own file * POST requests are not cached * Export apiFetch action * Don’t wrap API response in object * Implement data store for recommended extensions * Implement data store for marketing knowledge base * Tidy getRecommendedPlugins resolver * Try a cross browser cover/crop image effect to fit proposed design And help fit longer titles in * Add caught errors to handler * Adjust positioning so watermater is displayed * InstalledExtensions phpcs fixes * Marketing phpcs fixes * Alignment fix * MarketingOverview phpcs fixes * Missing full stop * Update breadcrumbs to use new approach * Fix style lint issues * Record `marketing_knowledge_article` track event on knowledge base post click * Import apiFetch and controls from @wordpress/data-controls * Hex color to lowercase * Remove duplicate method after rebase * Use new showPageArrowsLabel rather than hide with CSS * Fix blurry avatars on hidpi displays * Hide avatar if URL is falsy * Replace test author data with live data * Combine conditionals into ternary * Combine conditionals into ternary * Simplify class column logic * Only preload option and component settings in the admin * Fix isActivatingPlugin not updating Component was not re-rendeding. * Use querySelector over getElementsByClassName * Hide Marketing Welcome Card immediately on click * Use create-a-ticket url for supportUrl and make that the default * Add getInstalledPlugins resolver with preloaded data * Revert "Add getInstalledPlugins resolver with preloaded data" This reverts commit b8b127ec6411bef15616576b3bb189dc31777c13. * Load plugin data in a separate request after activation * Update welcome image * Don’t return plugin data in the activation request. * A space is required before closing bracket * Update Jest config to gracefully handle static assets Ref: https://jestjs.io/docs/en/webpack#handling-static-assets * Remove unused onExit property * Remove placeholder README * Use prop directly * yield createNotice * Add note to indicate which Category * Increase transient time to 3 days * Use $gap-small * Add proptype * Add debounce to slider height resize listener * Clean up isLoading logic * Dont show image elements if image data is empty * Open knowledge base posts in a new window * Add “noreferrer” * Turn the tab on in all env Co-authored-by: Daniel Bitzer <danielbitzer@gmail.com>
2020-03-28 13:48:27 +00:00
if ( window.wcAdminFeatures.marketing ) {
pages.push( {
container: MarketingOverview,
path: '/marketing',
breadcrumbs: [
...initialBreadcrumbs,
[
'/marketing',
__( 'Marketing', 'woocommerce-admin' ),
],
__( 'Overview', 'woocommerce-admin' ),
Marketing Tab MVP (https://github.com/woocommerce/woocommerce-admin/pull/3953) * Add Marketing feature flag * Add marketing page and menu item * Register marketing page with layout controller * Add initial marketing cards * Add max-width to marketing overview page * Add initial marketing WelcomeCard component * Make marketing welcome card permanently dismiss * Add a readme for the marketing page components * Record tracks event when marketing welcome dismissed * Match design width * Add welcome image and initial styles * Use gridicon for close button * Fix whitespace * Add PluginsHelper::get_plugin_data() * Add initial Marketing\InstalledExtensions class * Preload installed marketing extensions data * Tweak extension statuses * Add InstalledExtensionRow component * Add initial extension data to InstalledExtensions card * Refactor PluginsHelper::get_plugin_data method Using the new get_plugin_path_from_slug method * Ensure get_plugins() function is available for PluginsHelper * Simplify using PluginsHelper method * Add MailChimp configured status logic * Add links to InstalledExtensionRow component * Add key prop to extensions list * Setup styles for InstalledExtensions card * Display nothing if no installed extensions * Add InstalledExtensions::get_allowed_plugins() * Setup Marketing Overview API controller * Add /activate-plugin marketing endpoint * Add more extensions URL props * Add Facebook extension configured status logic * Update Facebook extension URL props * Fix extenion data logic * Move component into it’s own directory * Setup /marketing/overview/recommended endpoint * Initial marketing page card header styles * Add basic extension data to RecommendedExtensions * Use color as variable * Tweak card header padding for design * Add basic styling to RecommendedExtensions card * settingsUrl is not available if the plugin is not active * Add /marketing/overview/installed-plugins REST endpoint * Add basic activation functionality to InstalledExtensions component * Don’t throw error on success * Add MVP data store for installed extensions card * Add core dark blue color variable * Add styles for installed extensions card * Move knowledge-base component to its own directory * Pull recommended marketing plugins from remote test site * Hide description when configured As per design * Tweak colors based on design * Finish off styling for RecommendedExtensions * Limit recommended extensions to 6 items * Add error handling to RecommendedExtensions card * Rename ‘copy’ extension prop * Add marketing button component to match design * Create ProductIcon component for marketing * Add InstalledExtension icons * Fix icon image paths * Add ProductIcon to InstallExtensionRow * Final styling to installed extensions card row * Knowledge base card placeholders * Fix missing icons when plugin not activated * Remove logging * Tweak array structure to ensure we have an array in JS and not an object * Refactor KnowledgeBase marketing component - We don’t need loop through every post when rendering, just pick the posts we need - Remove unused classes * Move padding from each slide to the container * Improve slider animations by absolute positioning the slides * Reduce the slider animation timeout and add a note * Add in-app purchase flow url params for recommended extensions * Fix slider animation * Reset slider height on window resize * Short slider animation, fix double margin on smaller screens * Add initial marketing/knowledge-base endpoint * Pull knowledge base posts from API * Rename welcome card dismiss tracks event * Record event on recommended product click * Recond onclick events for installed extensions card * Record event when carousel navigation clicked * img elements must have an alt prop * Remove import that is never used * use camelCase * Decode HTML entities from API call * Remove unused container div * Add card loading state * Add images to knowledge base card * Link knowledge base posts * Use the Pagination component rather than duplicate it’s functionality * Clean up and rename knowledge base slider * Clean knowledge base CSS and update responsive styles for single post slide * Add a README for button component * Add README for product icon component * Add initial readme for Slider component * Add correct image sizes to knowledge base slider, finalize styles * Fix extension link urls * Resolve some code formatting issue * Bind class click methods to this * Wrap nodes in Fragment * Fix wccom-back path * Add placeholder author and gravatar Default avatar url size returned from the API is currently set to 96 so I’ve done a simple replace with 16 * Fix style-lint expected new line * Add docblock for get_knowledge_base_posts() * Setup data store for marketing to handle installedExtensions card * Fix function names “Activating” not “installing” * Move welcome card component to its own dir * IconButton component is going to be deprecated ref: https://github.com/WordPress/gutenberg/pull/19299 * Support multiple activating plugins in the data store * Rename extension to plugin for consistency * Add propTypes to component * Rename data-store/ to data/ * Fix import paths * Extract isActivatingPlugin logic into datastore * Move data store selectors into own file * POST requests are not cached * Export apiFetch action * Don’t wrap API response in object * Implement data store for recommended extensions * Implement data store for marketing knowledge base * Tidy getRecommendedPlugins resolver * Try a cross browser cover/crop image effect to fit proposed design And help fit longer titles in * Add caught errors to handler * Adjust positioning so watermater is displayed * InstalledExtensions phpcs fixes * Marketing phpcs fixes * Alignment fix * MarketingOverview phpcs fixes * Missing full stop * Update breadcrumbs to use new approach * Fix style lint issues * Record `marketing_knowledge_article` track event on knowledge base post click * Import apiFetch and controls from @wordpress/data-controls * Hex color to lowercase * Remove duplicate method after rebase * Use new showPageArrowsLabel rather than hide with CSS * Fix blurry avatars on hidpi displays * Hide avatar if URL is falsy * Replace test author data with live data * Combine conditionals into ternary * Combine conditionals into ternary * Simplify class column logic * Only preload option and component settings in the admin * Fix isActivatingPlugin not updating Component was not re-rendeding. * Use querySelector over getElementsByClassName * Hide Marketing Welcome Card immediately on click * Use create-a-ticket url for supportUrl and make that the default * Add getInstalledPlugins resolver with preloaded data * Revert "Add getInstalledPlugins resolver with preloaded data" This reverts commit b8b127ec6411bef15616576b3bb189dc31777c13. * Load plugin data in a separate request after activation * Update welcome image * Don’t return plugin data in the activation request. * A space is required before closing bracket * Update Jest config to gracefully handle static assets Ref: https://jestjs.io/docs/en/webpack#handling-static-assets * Remove unused onExit property * Remove placeholder README * Use prop directly * yield createNotice * Add note to indicate which Category * Increase transient time to 3 days * Use $gap-small * Add proptype * Add debounce to slider height resize listener * Clean up isLoading logic * Dont show image elements if image data is empty * Open knowledge base posts in a new window * Add “noreferrer” * Turn the tab on in all env Co-authored-by: Daniel Bitzer <danielbitzer@gmail.com>
2020-03-28 13:48:27 +00:00
],
wpOpenMenu: 'toplevel_page_woocommerce-marketing',
Marketing Tab MVP (https://github.com/woocommerce/woocommerce-admin/pull/3953) * Add Marketing feature flag * Add marketing page and menu item * Register marketing page with layout controller * Add initial marketing cards * Add max-width to marketing overview page * Add initial marketing WelcomeCard component * Make marketing welcome card permanently dismiss * Add a readme for the marketing page components * Record tracks event when marketing welcome dismissed * Match design width * Add welcome image and initial styles * Use gridicon for close button * Fix whitespace * Add PluginsHelper::get_plugin_data() * Add initial Marketing\InstalledExtensions class * Preload installed marketing extensions data * Tweak extension statuses * Add InstalledExtensionRow component * Add initial extension data to InstalledExtensions card * Refactor PluginsHelper::get_plugin_data method Using the new get_plugin_path_from_slug method * Ensure get_plugins() function is available for PluginsHelper * Simplify using PluginsHelper method * Add MailChimp configured status logic * Add links to InstalledExtensionRow component * Add key prop to extensions list * Setup styles for InstalledExtensions card * Display nothing if no installed extensions * Add InstalledExtensions::get_allowed_plugins() * Setup Marketing Overview API controller * Add /activate-plugin marketing endpoint * Add more extensions URL props * Add Facebook extension configured status logic * Update Facebook extension URL props * Fix extenion data logic * Move component into it’s own directory * Setup /marketing/overview/recommended endpoint * Initial marketing page card header styles * Add basic extension data to RecommendedExtensions * Use color as variable * Tweak card header padding for design * Add basic styling to RecommendedExtensions card * settingsUrl is not available if the plugin is not active * Add /marketing/overview/installed-plugins REST endpoint * Add basic activation functionality to InstalledExtensions component * Don’t throw error on success * Add MVP data store for installed extensions card * Add core dark blue color variable * Add styles for installed extensions card * Move knowledge-base component to its own directory * Pull recommended marketing plugins from remote test site * Hide description when configured As per design * Tweak colors based on design * Finish off styling for RecommendedExtensions * Limit recommended extensions to 6 items * Add error handling to RecommendedExtensions card * Rename ‘copy’ extension prop * Add marketing button component to match design * Create ProductIcon component for marketing * Add InstalledExtension icons * Fix icon image paths * Add ProductIcon to InstallExtensionRow * Final styling to installed extensions card row * Knowledge base card placeholders * Fix missing icons when plugin not activated * Remove logging * Tweak array structure to ensure we have an array in JS and not an object * Refactor KnowledgeBase marketing component - We don’t need loop through every post when rendering, just pick the posts we need - Remove unused classes * Move padding from each slide to the container * Improve slider animations by absolute positioning the slides * Reduce the slider animation timeout and add a note * Add in-app purchase flow url params for recommended extensions * Fix slider animation * Reset slider height on window resize * Short slider animation, fix double margin on smaller screens * Add initial marketing/knowledge-base endpoint * Pull knowledge base posts from API * Rename welcome card dismiss tracks event * Record event on recommended product click * Recond onclick events for installed extensions card * Record event when carousel navigation clicked * img elements must have an alt prop * Remove import that is never used * use camelCase * Decode HTML entities from API call * Remove unused container div * Add card loading state * Add images to knowledge base card * Link knowledge base posts * Use the Pagination component rather than duplicate it’s functionality * Clean up and rename knowledge base slider * Clean knowledge base CSS and update responsive styles for single post slide * Add a README for button component * Add README for product icon component * Add initial readme for Slider component * Add correct image sizes to knowledge base slider, finalize styles * Fix extension link urls * Resolve some code formatting issue * Bind class click methods to this * Wrap nodes in Fragment * Fix wccom-back path * Add placeholder author and gravatar Default avatar url size returned from the API is currently set to 96 so I’ve done a simple replace with 16 * Fix style-lint expected new line * Add docblock for get_knowledge_base_posts() * Setup data store for marketing to handle installedExtensions card * Fix function names “Activating” not “installing” * Move welcome card component to its own dir * IconButton component is going to be deprecated ref: https://github.com/WordPress/gutenberg/pull/19299 * Support multiple activating plugins in the data store * Rename extension to plugin for consistency * Add propTypes to component * Rename data-store/ to data/ * Fix import paths * Extract isActivatingPlugin logic into datastore * Move data store selectors into own file * POST requests are not cached * Export apiFetch action * Don’t wrap API response in object * Implement data store for recommended extensions * Implement data store for marketing knowledge base * Tidy getRecommendedPlugins resolver * Try a cross browser cover/crop image effect to fit proposed design And help fit longer titles in * Add caught errors to handler * Adjust positioning so watermater is displayed * InstalledExtensions phpcs fixes * Marketing phpcs fixes * Alignment fix * MarketingOverview phpcs fixes * Missing full stop * Update breadcrumbs to use new approach * Fix style lint issues * Record `marketing_knowledge_article` track event on knowledge base post click * Import apiFetch and controls from @wordpress/data-controls * Hex color to lowercase * Remove duplicate method after rebase * Use new showPageArrowsLabel rather than hide with CSS * Fix blurry avatars on hidpi displays * Hide avatar if URL is falsy * Replace test author data with live data * Combine conditionals into ternary * Combine conditionals into ternary * Simplify class column logic * Only preload option and component settings in the admin * Fix isActivatingPlugin not updating Component was not re-rendeding. * Use querySelector over getElementsByClassName * Hide Marketing Welcome Card immediately on click * Use create-a-ticket url for supportUrl and make that the default * Add getInstalledPlugins resolver with preloaded data * Revert "Add getInstalledPlugins resolver with preloaded data" This reverts commit b8b127ec6411bef15616576b3bb189dc31777c13. * Load plugin data in a separate request after activation * Update welcome image * Don’t return plugin data in the activation request. * A space is required before closing bracket * Update Jest config to gracefully handle static assets Ref: https://jestjs.io/docs/en/webpack#handling-static-assets * Remove unused onExit property * Remove placeholder README * Use prop directly * yield createNotice * Add note to indicate which Category * Increase transient time to 3 days * Use $gap-small * Add proptype * Add debounce to slider height resize listener * Clean up isLoading logic * Dont show image elements if image data is empty * Open knowledge base posts in a new window * Add “noreferrer” * Turn the tab on in all env Co-authored-by: Daniel Bitzer <danielbitzer@gmail.com>
2020-03-28 13:48:27 +00:00
} );
}
return applyFilters( PAGES_FILTER, pages );
};
export class Controller extends Component {
componentDidMount() {
window.document.documentElement.scrollTop = 0;
}
componentDidUpdate( prevProps ) {
const prevBaseQuery = omit(
prevProps.query,
'chartType',
'filter',
'paged'
);
const baseQuery = omit(
this.props.query,
'chartType',
'filter',
'paged'
);
if ( prevProps.query.paged > 1 && ! isEqual( prevBaseQuery, baseQuery ) ) {
getHistory().replace( getNewPath( { paged: 1 } ) );
}
if ( prevProps.match.url !== this.props.match.url ) {
window.document.documentElement.scrollTop = 0;
}
}
render() {
const { page, match, query } = this.props;
2019-06-13 19:58:21 +00:00
const { url, params } = match;
window.wpNavMenuUrlUpdate( query );
2019-06-13 19:58:21 +00:00
window.wpNavMenuClassChange( page, url );
Use Route based code splitting to optimize bundle size (https://github.com/woocommerce/woocommerce-admin/pull/4094) * Use lazy loading to split up the size of the js downloaded * Use lazy loading to split up the size of the js downloaded * Add Moment Timezone plugin to reduce size of data file. * Lazy load header panels and use Dashicons for faster loading * Load assets from the correct publicPath * Load assets from the correct publicPath * PHP cs fixes * Fix missing quotes on string literal. * Fix PropType warning for lazy loaded component. * Separate the task list and dashboard chunks. * Lazy load dashboard sections. * Restore original icons and reduce size by importing only the icons needed * Lazy load alerts to save more Kb on initial load * Minify built JS in production mode. * Add preload tags for WC Admin assets. (https://github.com/woocommerce/woocommerce-admin/pull/4162) * Fix linting errors. * Add modified UnminifiedWebpackPlugin. * Produce minified and unminified bundles for all builds. * Remove unused variable from webpack config. * Run unminify after sourcemap generation. * Only hook after optimization if we're using a devtool. * Add minification suffix in Loader::get_url(). * Lazy load OBW on new home screen. * Move OBW style up a level to layout. * Hydrate ProfileWizard independently of withSelect and withDispatch * Fix order of composition and fallback function when using hydration. Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Paul Sealock <psealock@gmail.com>
2020-04-29 18:01:27 +00:00
return (
<Suspense fallback={ <Spinner /> }>
<page.container
params={ params }
path={ url }
pathMatch={ page.path }
query={ query }
/>
</Suspense>
);
}
}
/**
* Update an anchor's link in sidebar to include persisted queries. Leave excluded screens
* as is.
*
* @param {HTMLElement} item - Sidebar anchor link.
* @param {Object} nextQuery - A query object to be added to updated hrefs.
* @param {Array} excludedScreens - wc-admin screens to avoid updating.
*/
export function updateLinkHref( item, nextQuery, excludedScreens ) {
2019-06-13 19:58:21 +00:00
const isWCAdmin = /admin.php\?page=wc-admin/.test( item.href );
if ( isWCAdmin ) {
const search = last( item.href.split( '?' ) );
const query = parse( search );
const defaultPath =
window.wcAdminFeatures.homescreen
? 'homescreen'
: 'dashboard';
const path = query.path || defaultPath;
2019-06-13 19:58:21 +00:00
const screen = path.replace( '/analytics', '' ).replace( '/', '' );
const isExcludedScreen = excludedScreens.includes( screen );
const href =
'admin.php?' +
stringify(
Object.assign( query, isExcludedScreen ? {} : nextQuery )
);
2019-06-13 19:58:21 +00:00
// Replace the href so you can see the url on hover.
item.href = href;
item.onclick = ( e ) => {
2019-06-13 19:58:21 +00:00
e.preventDefault();
getHistory().push( href );
};
}
}
2019-06-13 19:58:21 +00:00
// Update's wc-admin links in wp-admin menu
window.wpNavMenuUrlUpdate = function( query ) {
const excludedScreens = applyFilters( TIME_EXCLUDED_SCREENS_FILTER, [
'devdocs',
'stock',
'settings',
'customers',
'homescreen',
] );
2019-06-13 19:58:21 +00:00
const nextQuery = getPersistedQuery( query );
Array.from(
document.querySelectorAll( '#adminmenu a' )
).forEach( ( item ) => updateLinkHref( item, nextQuery, excludedScreens ) );
};
// When the route changes, we need to update wp-admin's menu with the correct section & current link
2019-06-13 19:58:21 +00:00
window.wpNavMenuClassChange = function( page, url ) {
Array.from( document.getElementsByClassName( 'current' ) ).forEach(
function( item ) {
item.classList.remove( 'current' );
}
);
const submenu = Array.from(
document.querySelectorAll( '.wp-has-current-submenu' )
);
submenu.forEach( function( element ) {
element.classList.remove( 'wp-has-current-submenu' );
element.classList.remove( 'wp-menu-open' );
element.classList.remove( 'selected' );
element.classList.add( 'wp-not-current-submenu' );
element.classList.add( 'menu-top' );
} );
2019-06-13 19:58:21 +00:00
const pageUrl =
url === '/'
2019-06-13 19:58:21 +00:00
? 'admin.php?page=wc-admin'
: 'admin.php?page=wc-admin&path=' + encodeURIComponent( url );
const currentItemsSelector =
2019-06-13 19:58:21 +00:00
url === '/'
? `li > a[href$="${ pageUrl }"], li > a[href*="${ pageUrl }?"]`
: `li > a[href*="${ pageUrl }"]`;
const currentItems = document.querySelectorAll( currentItemsSelector );
Array.from( currentItems ).forEach( function( item ) {
item.parentElement.classList.add( 'current' );
} );
if ( page.wpOpenMenu ) {
const currentMenu = document.querySelector( '#' + page.wpOpenMenu );
if ( currentMenu ) {
currentMenu.classList.remove( 'wp-not-current-submenu' );
currentMenu.classList.add( 'wp-has-current-submenu' );
currentMenu.classList.add( 'wp-menu-open' );
currentMenu.classList.add( 'current' );
}
}
const wpWrap = document.querySelector( '#wpwrap' );
wpWrap.classList.remove( 'wp-responsive-open' );
};