-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39829 from software-mansion-labs/@szymczak/deprec…
…ate-card.isVirtual-references Deprecate card.isVirtual references
- Loading branch information
Showing
9 changed files
with
62 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import type {NullishDeep, OnyxEntry} from 'react-native-onyx'; | ||
import Log from '@libs/Log'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Card} from '@src/types/onyx'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
|
||
type OldCard = Card & {isVirtual?: boolean}; | ||
|
||
// This migration changes the property name on each card from card list from isVirtual to nameValuePairs.isVirtual | ||
export default function () { | ||
return new Promise<void>((resolve) => { | ||
const connectionID = Onyx.connect({ | ||
key: ONYXKEYS.CARD_LIST, | ||
callback: (cardList: OnyxEntry<Record<string, OldCard>>) => { | ||
Onyx.disconnect(connectionID); | ||
|
||
if (!cardList || isEmptyObject(cardList)) { | ||
Log.info('[Migrate Onyx] Skipped migration RenameCardIsVirtual because there are no cards linked to the account'); | ||
return resolve(); | ||
} | ||
const cardsWithIsVirtualProp = Object.values(cardList).filter((card) => card.isVirtual !== undefined); | ||
if (!cardsWithIsVirtualProp.length) { | ||
Log.info('[Migrate Onyx] Skipped migration RenameCardIsVirtual because there were no cards with the isVirtual property'); | ||
return resolve(); | ||
} | ||
|
||
Log.info('[Migrate Onyx] Running RenameCardIsVirtual migration'); | ||
const dataToSave: Record<string, NullishDeep<OldCard>> = cardsWithIsVirtualProp.reduce((result, card) => { | ||
if (!card) { | ||
return result; | ||
} | ||
return { | ||
...result, | ||
[card.cardID]: { | ||
nameValuePairs: { | ||
isVirtual: card.isVirtual, | ||
}, | ||
isVirtual: undefined, | ||
}, | ||
}; | ||
}, {}); | ||
|
||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
Onyx.merge(ONYXKEYS.CARD_LIST, dataToSave).then(() => { | ||
Log.info(`[Migrate Onyx] Ran migration RenameCardIsVirtual and renamed ${Object.keys(dataToSave)?.length} properties`); | ||
resolve(); | ||
}); | ||
}, | ||
}); | ||
}); | ||
} |
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
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