diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/actions.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/actions.ts index bbe40db68d434..96e4414be0666 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/actions.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/actions.ts @@ -49,27 +49,24 @@ export function toggleFeature( feature: string, force?: boolean ) { }; } -export function setBlockMd5( feature: string, blockId: string, md5: string ) { +export function setBlockMd5( blockId: string, md5: string ) { return { type: 'SET_BLOCK_MD5', - feature, blockId, md5, }; } -export function invalidateSuggestions( feature: string, blockId: string ) { +export function invalidateSuggestions( blockId: string ) { return { type: 'INVALIDATE_SUGGESTIONS', - feature, blockId, }; } -export function ignoreSuggestion( feature: string, blockId: string, id: string ) { +export function ignoreSuggestion( blockId: string, id: string ) { return { type: 'IGNORE_SUGGESTION', - feature, blockId, id, }; diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/reducer.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/reducer.ts index 922b91e9a9ae7..ccb47dab95e46 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/reducer.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/reducer.ts @@ -107,7 +107,7 @@ export function suggestions( action: { type: string; id: string; - feature: string; + feature?: string; blockId: string; loading: boolean; md5?: string; @@ -119,17 +119,17 @@ export function suggestions( ) { const { id, feature, blockId } = action ?? {}; const current = { ...state }; - const currentBlock = current?.[ feature ]?.[ blockId ] ?? {}; - const currentItem = current?.[ feature ]?.[ blockId ]?.[ id ] || {}; + const currentBlock = current?.[ blockId ] ?? {}; + const currentItem = current?.[ blockId ]?.[ feature ]?.[ id ] || {}; switch ( action.type ) { case 'SET_SUGGESTIONS_LOADING': { return { ...current, - [ feature ]: { - ...( current[ feature ] ?? {} ), - [ blockId ]: { - ...currentBlock, + [ blockId ]: { + ...currentBlock, + [ feature ]: { + ...( currentBlock[ feature ] ?? {} ), [ id ]: { ...currentItem, loading: action.loading, @@ -142,10 +142,10 @@ export function suggestions( case 'SET_SUGGESTIONS': { return { ...current, - [ feature ]: { - ...( current[ feature ] ?? {} ), - [ blockId ]: { - ...currentBlock, + [ blockId ]: { + ...currentBlock, + [ feature ]: { + ...( currentBlock[ feature ] ?? {} ), [ id ]: { ...currentItem, loading: false, @@ -159,12 +159,9 @@ export function suggestions( case 'SET_BLOCK_MD5': { return { ...current, - [ feature ]: { - ...( current[ feature ] ?? {} ), - [ blockId ]: { - ...currentBlock, - md5: action.md5, - }, + [ blockId ]: { + md5: action.md5, + ...currentBlock, }, }; } @@ -172,22 +169,16 @@ export function suggestions( case 'INVALIDATE_SUGGESTIONS': { return { ...current, - [ feature ]: { - ...( current[ feature ] ?? {} ), - [ blockId ]: {}, - }, + [ blockId ]: {}, }; } case 'IGNORE_SUGGESTION': { return { ...current, - [ feature ]: { - ...( current[ feature ] ?? {} ), - [ blockId ]: { - ...currentBlock, - ignored: [ ...( currentBlock.ignored ?? [] ), id ], - }, + [ blockId ]: { + ...currentBlock, + ignored: [ ...( currentBlock.ignored ?? [] ), id ], }, }; } diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/selectors.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/selectors.ts index 3753f1cd89733..b3aa92fb4b2c3 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/selectors.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/store/selectors.ts @@ -37,27 +37,24 @@ export function getDisabledFeatures( state: BreveState ) { // Suggestions -export function getBlockMd5( state: BreveState, feature: string, blockId: string ) { - return state.suggestions?.[ feature ]?.[ blockId ]?.md5 ?? ''; +export function getBlockMd5( state: BreveState, blockId: string ) { + return state.suggestions?.[ blockId ]?.md5 ?? ''; } export function getSuggestionsLoading( state: BreveState, { feature, id, blockId }: { feature: string; id: string; blockId: string } ) { - return state.suggestions?.[ feature ]?.[ blockId ]?.[ id ]?.loading; + return state.suggestions?.[ blockId ]?.[ feature ]?.[ id ]?.loading; } export function getSuggestions( state: BreveState, { feature, id, blockId }: { feature: string; id: string; blockId: string } ) { - return state.suggestions?.[ feature ]?.[ blockId ]?.[ id ]?.suggestions; + return state.suggestions?.[ blockId ]?.[ feature ]?.[ id ]?.suggestions; } -export function getIgnoredSuggestions( - state: BreveState, - { feature, blockId }: { feature: string; blockId: string } -) { - return state.suggestions?.[ feature ]?.[ blockId ]?.ignored; +export function getIgnoredSuggestions( state: BreveState, { blockId }: { blockId: string } ) { + return state.suggestions?.[ blockId ]?.ignored; } diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts index 922b1d4807a80..4f2ec5d580bcb 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts @@ -42,7 +42,7 @@ export type BreveSelect = { isProofreadEnabled: () => boolean; isFeatureEnabled: ( feature: string ) => boolean; getDisabledFeatures: () => Array< string >; - getBlockMd5: ( feature: string, blockId: string ) => string; + getBlockMd5: ( blockId: string ) => string; getSuggestionsLoading: ( { feature, id, @@ -64,13 +64,7 @@ export type BreveSelect = { html: string; suggestion: string; }; - getIgnoredSuggestions: ( { - feature, - blockId, - }: { - feature: string; - blockId: string; - } ) => Array< string >; + getIgnoredSuggestions: ( { blockId }: { blockId: string } ) => Array< string >; }; export type BreveDispatch = { @@ -79,9 +73,9 @@ export type BreveDispatch = { setPopoverAnchor: ( anchor: Anchor ) => void; toggleProofread: ( force?: boolean ) => void; toggleFeature: ( feature: string, force?: boolean ) => void; - invalidateSuggestions: ( feature: string, blockId: string ) => void; - ignoreSuggestion: ( feature: string, blockId: string, id: string ) => void; - setBlockMd5: ( feature: string, blockId: string, md5: string ) => void; + invalidateSuggestions: ( blockId: string ) => void; + ignoreSuggestion: ( blockId: string, id: string ) => void; + setBlockMd5: ( blockId: string, md5: string ) => void; setSuggestions: ( suggestions: { anchor: Anchor[ 'target' ]; id: string;