Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3877,14 +3877,18 @@ function setPolicyMaxExpenseAge(policyID: string, maxExpenseAge: string) {
function updateCustomRules(policyID: string, customRules: string) {
const policy = getPolicy(policyID);
const originalCustomRules = policy?.customRules;
const parsedCustomRules = ReportUtils.getParsedComment(customRules);
if (parsedCustomRules === originalCustomRules) {
return;
}

const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
customRules,
customRules: parsedCustomRules,
},
},
],
Expand Down Expand Up @@ -3916,7 +3920,7 @@ function updateCustomRules(policyID: string, customRules: string) {

const parameters = {
policyID,
description: customRules,
description: parsedCustomRules,
};

API.write(WRITE_COMMANDS.UPDATE_CUSTOM_RULES, parameters, onyxData);
Expand Down
20 changes: 12 additions & 8 deletions src/pages/workspace/rules/CustomRulesSection.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, {useMemo} from 'react';
import {View} from 'react-native';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import Section from '@components/Section';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import {getParsedComment} from '@libs/ReportUtils';
import ROUTES from '@src/ROUTES';

type CustomRulesSectionProps = {
Expand All @@ -16,6 +17,8 @@ function CustomRulesSection({policyID}: CustomRulesSectionProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const policy = usePolicy(policyID);
const parsedRules = useMemo(() => getParsedComment(policy?.customRules ?? ''), [policy]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like here we did take into consideration the fact that when we submit markdown input, that input won't actually be formatted and displayed as markdown in the input field while awaiting for BE to return a response based on the natural language submitted input, which led to this issue:

The issue was fixed by adding an Onyx isLoading variable in the API request such that while loading (awaiting BE response) we're passing the shouldEscapeText: false option to the getParsedComment function such that the markdown input is actually displaying formatted markdown in the input until BE response is received - see PR #57599 for details on the fix.

const rulesDescription = typeof parsedRules === 'string' ? parsedRules : '';

return (
<Section
Expand All @@ -27,16 +30,17 @@ function CustomRulesSection({policyID}: CustomRulesSectionProps) {
>
<View style={[styles.mt3]}>
{/* <OfflineWithFeedback
pendingAction={item.pendingAction}
key={translate(item.descriptionTranslationKey)}
> */}
pendingAction={policy?.pendingFields?.customRules}
errors={policy?.errors?.customRules}
> */}
<MenuItemWithTopDescription
shouldShowRightIcon
title={policy?.customRules ?? ''}
title={rulesDescription}
description={translate('workspace.rules.customRules.subtitle')}
shouldShowRightIcon
interactive
wrapperStyle={styles.sectionMenuItemTopDescription}
onPress={() => Navigation.navigate(ROUTES.RULES_CUSTOM.getRoute(policyID))}
wrapperStyle={[styles.sectionMenuItemTopDescription]}
numberOfLinesTitle={2}
shouldRenderAsHTML
/>
{/* </OfflineWithFeedback> */}
</View>
Expand Down