From b1f185da2afc23d01a22bfef7dc24303ab4487c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Tue, 5 Mar 2024 19:29:00 +0000 Subject: [PATCH] Add example for inexistent collection --- src/ONYXKEYS.ts | 2 ++ src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 675f622393c9..b59c8595098c 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -281,6 +281,7 @@ const ONYXKEYS = { /** Collection Keys */ COLLECTION: { + INEXISTENT: 'inexistentCollection_', DOWNLOAD: 'download_', POLICY: 'policy_', POLICY_MEMBERS: 'policyMembers_', @@ -452,6 +453,7 @@ type OnyxFormDraftValuesMapping = { }; type OnyxCollectionValuesMapping = { + [ONYXKEYS.COLLECTION.INEXISTENT]: {id: string}; [ONYXKEYS.COLLECTION.DOWNLOAD]: OnyxTypes.Download; [ONYXKEYS.COLLECTION.POLICY]: OnyxTypes.Policy; [ONYXKEYS.COLLECTION.POLICY_DRAFTS]: OnyxTypes.Policy; diff --git a/src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx b/src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx index 6b6d103cc69d..2b1f1a8a8d4b 100644 --- a/src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx +++ b/src/pages/OnyxPlayground/WithOnyxVSuseOnyx.tsx @@ -19,6 +19,8 @@ function SubRenderTest({policy}: {policy: UseOnyxData<`policy_${string}`, OnyxEn type ComponentWithOnyxHOCOnyxProps = { account: OnyxEntry; + inexistentCollection: OnyxCollection<{id: string}>; + policies: OnyxCollection; policy: OnyxEntry; @@ -36,6 +38,9 @@ const ComponentWithOnyxHOC = withOnyx policy?.name as unknown as OnyxCollection, }, -})(({policyID, account, policies, policy, sessionEmail, policiesWithSelector}) => { +})(({policyID, account, inexistentCollection, policies, policy, sessionEmail, policiesWithSelector}) => { console.group('OnyxPlayground [App] ComponentWithOnyxHOC'); console.log('OnyxPlayground [App] ComponentWithOnyxHOC policyID', policyID); console.log('OnyxPlayground [App] ComponentWithOnyxHOC account', account); + console.log('OnyxPlayground [App] ComponentWithOnyxHOC inexistentCollection', inexistentCollection); console.log('OnyxPlayground [App] ComponentWithOnyxHOC policies', policies); console.log('OnyxPlayground [App] ComponentWithOnyxHOC policy', policy); console.log('OnyxPlayground [App] ComponentWithOnyxHOC sessionEmail', sessionEmail); @@ -75,6 +81,9 @@ function ComponentWithOnyxHook({policyID}: ComponentWithOnyxHookProps) { const account = useOnyx(ONYXKEYS.ACCOUNT); const [accountValue] = account; + const inexistentCollection = useOnyx(ONYXKEYS.COLLECTION.INEXISTENT); + const [inexistentCollectionValue] = inexistentCollection; + const policies = useOnyx(ONYXKEYS.COLLECTION.POLICY); const [policiesValue] = policies; @@ -108,6 +117,7 @@ function ComponentWithOnyxHook({policyID}: ComponentWithOnyxHookProps) { console.group('OnyxPlayground [App] ComponentWithOnyxHook'); console.log('OnyxPlayground [App] ComponentWithOnyxHook policyID', policyID); console.log('OnyxPlayground [App] ComponentWithOnyxHook account', account); + console.log('OnyxPlayground [App] ComponentWithOnyxHook inexistentCollection', inexistentCollection); console.log('OnyxPlayground [App] ComponentWithOnyxHook policies', policies); console.log('OnyxPlayground [App] ComponentWithOnyxHook policy', policy); console.log('OnyxPlayground [App] ComponentWithOnyxHook policy2', policy2);