This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logic of Upgrade Notice after upgrading Products to Product Colle…
…ction (#10267) * WIP of Upgrade Notice state * Extend the state options with seeing option * Move the logic to the dedicated folder * Subscribe only if not reverted * Refactor the way UpgradeNotice is rendered * Simplify the logic of keeping the Upgrade Notice state in local storage * Improve types organisation * Lift the functions interacting with local storage to the Inspector Controls of Product Colelction * Simplify logic of showing Upgrade Notice * Disable auto migration * Refactoring * Use useLocalStorageState hook * Fix incorrect merge * Final improvements * Allow to display Upgrade Notice after revert and manual upgrade * Fix incorrect merge * Improve the unsubscribe process * Trigger auto-update from Product Collection only * Remove weird console.log * Abstract manual update from Product Query * Fix the taxQuery migration from Product Collection to Products * Product Collection - logic to hide upgrade notice (#10494) * Add timestamp to each upgrade notice status change * Revert back only Product Collections converted from Products block * Make the time threshold configurable * Add logic that hides the Upgrade Notice after some amount of displays * Fix the taxQuery migration from Product Collection to Products * Change the way to count Product Collection entries * Fix the problem of multiple display counter increments with Product Collection * Update Upgrade Notice visibility conditions * Add contiions to unmark Product Collection as converted from Products * Change variable name * Change variable t to time name for better readibility. Improve types * Replace useState with useRef * Remove unecessary props passed to UpgradeNotice
- Loading branch information
Showing
12 changed files
with
316 additions
and
129 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
assets/js/blocks/migration-products-to-product-collection/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { UpgradeNoticeStatus, UpgradeNoticeStatuses } from './types'; | ||
|
||
export const AUTO_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false; | ||
export const MANUAL_REPLACE_PRODUCTS_WITH_PRODUCT_COLLECTION = false; | ||
export const HOURS_TO_DISPLAY_UPGRADE_NOTICE = 72; | ||
export const UPGRADE_NOTICE_DISPLAY_COUNT_THRESHOLD = 4; | ||
export const MIGRATION_STATUS_LS_KEY = | ||
'wc-blocks_upgraded-products-to-product-collection'; | ||
// Initial status used in the localStorage | ||
export const INITIAL_STATUS_LS_VALUE: UpgradeNoticeStatuses = 'notseen'; | ||
|
||
export const getInitialStatusLSValue: () => UpgradeNoticeStatus = () => ( { | ||
status: INITIAL_STATUS_LS_VALUE, | ||
time: Date.now(), | ||
displayCount: 0, | ||
} ); |
3 changes: 3 additions & 0 deletions
3
assets/js/blocks/shared/scripts/index.tsx → ...n-products-to-product-collection/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from './migration-from-products-to-product-collection'; | ||
export * from './migration-from-product-collection-to-products'; | ||
export * from './migration-utils'; | ||
export * from './constants'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
assets/js/blocks/migration-products-to-product-collection/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { type BlockInstance } from '@wordpress/blocks'; | ||
|
||
export type GetBlocksClientIds = ( blocks: BlockInstance[] ) => string[]; | ||
export type IsBlockType = ( block: BlockInstance ) => boolean; | ||
export type TransformBlock = ( | ||
block: BlockInstance, | ||
innerBlock: BlockInstance[] | ||
) => BlockInstance; | ||
export type ProductGridLayoutTypes = 'flex' | 'list'; | ||
export type PostTemplateLayoutTypes = 'grid' | 'default'; | ||
|
||
export type ProductGridLayout = { | ||
type: ProductGridLayoutTypes; | ||
columns: number; | ||
}; | ||
|
||
export type PostTemplateLayout = { | ||
type: PostTemplateLayoutTypes; | ||
columnCount: number; | ||
}; | ||
export type UpgradeNoticeStatuses = 'notseen' | 'seen' | 'reverted'; | ||
export type UpgradeNoticeStatus = { | ||
status: UpgradeNoticeStatuses; | ||
time: number; | ||
displayCount?: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.