Skip to content

Commit

Permalink
Merge pull request Expensify#46961 from rezkiy37/fix/45166-report-fie…
Browse files Browse the repository at this point in the history
…ld-list-values-pattern-a

Use Offline Pattern A for report field list values
  • Loading branch information
mountiny committed Aug 13, 2024
2 parents 213c15d + 4cb0191 commit f185c4d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 301 deletions.
97 changes: 7 additions & 90 deletions src/libs/actions/Policy/ReportField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,46 +390,21 @@ function updateReportFieldListValueEnabled(policyID: string, reportFieldID: stri
}
});

// We are using the offline pattern A (optimistic without feedback)
const onyxData: OnyxData = {
optimisticData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[fieldKey]: {...updatedReportField, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
errorFields: null,
},
},
],
successData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[fieldKey]: {pendingAction: null},
},
errorFields: null,
},
},
],
failureData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[fieldKey]: {...reportField, pendingAction: null},
},
errorFields: {
[fieldKey]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.reportFields.genericFailureMessage'),
[fieldKey]: updatedReportField,
},
},
},
],
};

const parameters: EnableWorkspaceReportFieldListValueParams = {
policyID,
reportFields: JSON.stringify([updatedReportField]),
Expand All @@ -450,44 +425,15 @@ function addReportFieldListValue(policyID: string, reportFieldID: string, valueN
updatedReportField.values.push(valueName);
updatedReportField.disabledOptions.push(false);

// We are using the offline pattern A (optimistic without feedback)
const onyxData: OnyxData = {
optimisticData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {
...updatedReportField,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
errorFields: null,
},
},
],
successData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {pendingAction: null},
},
errorFields: null,
},
},
],
failureData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {...reportField, pendingAction: null},
},
errorFields: {
[reportFieldKey]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.reportFields.genericFailureMessage'),
[reportFieldKey]: updatedReportField,
},
},
},
Expand Down Expand Up @@ -524,44 +470,15 @@ function removeReportFieldListValue(policyID: string, reportFieldID: string, val
updatedReportField.disabledOptions.splice(valueIndex, 1);
});

// We are using the offline pattern A (optimistic without feedback)
const onyxData: OnyxData = {
optimisticData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {
...updatedReportField,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
errorFields: null,
},
},
],
successData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {pendingAction: null},
},
errorFields: null,
},
},
],
failureData: [
{
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
fieldList: {
[reportFieldKey]: {...reportField, pendingAction: null},
},
errorFields: {
[reportFieldKey]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.reportFields.genericFailureMessage'),
[reportFieldKey]: updatedReportField,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function ReportFieldsListValuesPage({
keyForList: value,
isSelected: selectedValues[value] && canSelectMultiple,
enabled: !disabledListValues[index] ?? true,
pendingAction: reportFieldID ? policy?.fieldList?.[ReportUtils.getReportFieldKey(reportFieldID)]?.pendingAction : null,
rightElement: (
<ListItemRightCaretWithLabel
shouldShowCaret={false}
Expand All @@ -104,7 +103,7 @@ function ReportFieldsListValuesPage({
}))
.sort((a, b) => localeCompare(a.value, b.value));
return [{data, isDisabled: false}];
}, [disabledListValues, listValues, policy?.fieldList, reportFieldID, selectedValues, canSelectMultiple, translate]);
}, [canSelectMultiple, disabledListValues, listValues, selectedValues, translate]);

const shouldShowEmptyState = Object.values(listValues ?? {}).length <= 0;
const selectedValuesArray = Object.keys(selectedValues).filter((key) => selectedValues[key]);
Expand Down
Loading

0 comments on commit f185c4d

Please sign in to comment.