Ws-2541-UAS metadata update for article#14085
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the “Save Article” flow to keep UAS-saved article metadata automatically in sync with the live article data, and simplifies the Save Article button API by relying on articlePageData rather than a separate title prop.
Changes:
- Simplifies
SaveArticleButton/useUASButtonAPIs by removing thearticleTitleprop and deriving metadata fromarticlePageData. - Introduces metadata comparison + a
useUASMetadataSynchook to detect out-of-date saved metadata and trigger a UAS update + cache invalidation. - Updates
useUASFetchSaveStatusto return both saved status and saved metadata, and adjusts tests accordingly.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/app/pages/ArticlePage/ArticlePage.tsx | Removes articleTitle plumbing when rendering SaveArticleButton. |
| src/app/lib/uasApi/uasUtility.ts | Adds metadata extractor/comparison helpers used by the sync mechanism. |
| src/app/lib/uasApi/saveOrUpdateArticleMetadata.ts | New helper to POST (create/update) saved-article metadata into UAS. |
| src/app/lib/uasApi/saveOrUpdateArticleMetadata.test.ts | Unit tests for the new save/update metadata helper. |
| src/app/hooks/useUASMetadataSync/index.ts | New hook to detect metadata drift and trigger a sync callback. |
| src/app/hooks/useUASMetadataSync/index.test.ts | Tests for the metadata sync hook behaviour. |
| src/app/hooks/useUASFetchSaveStatus/index.ts | Extends the saved-status hook to also surface saved UAS metadata. |
| src/app/hooks/useUASFetchSaveStatus/index.test.tsx | Updates/extends tests for the new return shape and behaviour. |
| src/app/hooks/useUASButton/index.ts | Integrates metadata sync + uses the new save/update helper; updates cache shape. |
| src/app/hooks/useUASButton/index.test.tsx | Updates tests for new cache shape and adds (currently minimal) metadata sync coverage. |
| src/app/components/SaveArticleButton/SaveArticleButtonAuthenticated/index.tsx | Removes articleTitle usage when calling useUASButton. |
| src/app/components/SaveArticleButton/index.tsx | Removes articleTitle from props. |
| src/app/components/SaveArticleButton/index.test.tsx | Adjusts tests to match the updated button props. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| const body = createFavouritesPayload({ | ||
| articleId, | ||
| service, | ||
| articleTitle: articlePageData.promo.headlines.seoHeadline || '', |
There was a problem hiding this comment.
Is this expected we're using seoHeadline here? I think for the Article heading we're using blocks[0].model.blocks[0].model. Probably we should double-check it?
There was a problem hiding this comment.
We were using this
in articlepage to get the articleTitile.This was pointing to seoHeadline.
May be we can double check ,whom should we have to ask ?
There was a problem hiding this comment.
This is confirmed — I checked that existing article-related components use seoHeadline for the title purpose.
| service, | ||
| isSaved, | ||
| savedArticleMetadata: savedMetadata, | ||
| onMetadataOutOfDate: async () => { |
There was a problem hiding this comment.
Have you considered reusing existing mutation, I think onMetadataOutOfDate is redundant, we could do something like this:
const isMetadataStale = useUASMetadataSync(...);
const mutation = useMutation({
// rest...
});
useEffect(() => {
if (isMetadataStale && articlePageData) {
mutation.mutate(UASAction.SAVE);
}
}, [isMetadataStale, articlePageData, mutation]);
Summary
Ticket : https://bbc.atlassian.net/browse/WS-2541
This pull request refactors the Save Article feature to improve how article metadata is handled and synchronized with the User Activity Service (UAS).
If the article is saved:
Compare the live article metadata with the metadata stored in UAS
Update the UAS entry, if metadata is out of date
Update the UAS entry, if metadata needs new field -without any manual action
Code changes
Save Article Button and Hook API Simplification:
articleTitleprop fromSaveArticleButtonPropsand related components and tests, streamlining the API to rely solely onarticlePageDatafor title and metadata.Enhanced Article Metadata Sync and Storage:
useUASButtonto use a newuseUASMetadataSynchook, which ensures that article metadata is up-to-date in UAS and handles cache invalidation for both status and list queries on successful sync.Improved Save Status Fetching with Metadata:
useUASFetchSaveStatusto return both the saved status and associated article metadata, allowing components to access up-to-date metadata about saved articles.Test Enhancements and Adjustments:
useUASButtonanduseUASFetchSaveStatusto cover new behaviors, including metadata sync integration, cache invalidation, and the new return shape of hooks.Testing
Method 1:
Eg :
Method 2:
Update the REACT_QUERY_OFFLINE_CACHE in localstorage bucket.
Change the value of any metadata (title , promoimage url ) of the article from there .
Reload the page - you should see POST api getting triggered.