-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 #44732 from software-mansion-labs/refactor/central…
…ize-expensimark Centralize ExpensiMark usage with a dedicated Parser module
- Loading branch information
Showing
30 changed files
with
133 additions
and
150 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
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 was deleted.
Oops, something went wrong.
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,51 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import {ExpensiMark} from 'expensify-common'; | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import Log from './Log'; | ||
import * as ReportConnection from './ReportConnection'; | ||
|
||
const accountIDToNameMap: Record<string, string> = {}; | ||
|
||
Onyx.connect({ | ||
key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
callback: (personalDetailsList) => { | ||
Object.values(personalDetailsList ?? {}).forEach((personalDetails) => { | ||
if (!personalDetails) { | ||
return; | ||
} | ||
|
||
accountIDToNameMap[personalDetails.accountID] = personalDetails.login ?? String(personalDetails.accountID); | ||
}); | ||
}, | ||
}); | ||
|
||
type Extras = { | ||
reportIDToName?: Record<string, string>; | ||
accountIDToName?: Record<string, string>; | ||
cacheVideoAttributes?: (vidSource: string, attrs: string) => void; | ||
videoAttributeCache?: Record<string, string>; | ||
}; | ||
|
||
class ExpensiMarkWithContext extends ExpensiMark { | ||
htmlToMarkdown(htmlString: string, extras?: Extras): string { | ||
return super.htmlToMarkdown(htmlString, { | ||
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(), | ||
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap, | ||
cacheVideoAttributes: extras?.cacheVideoAttributes, | ||
}); | ||
} | ||
|
||
htmlToText(htmlString: string, extras?: Extras): string { | ||
return super.htmlToText(htmlString, { | ||
reportIDToName: extras?.reportIDToName ?? ReportConnection.getAllReportsNameMap(), | ||
accountIDToName: extras?.accountIDToName ?? accountIDToNameMap, | ||
cacheVideoAttributes: extras?.cacheVideoAttributes, | ||
}); | ||
} | ||
} | ||
|
||
ExpensiMarkWithContext.setLogger(Log); | ||
const Parser = new ExpensiMarkWithContext(); | ||
|
||
export default Parser; |
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
Oops, something went wrong.