Skip to content

Commit 5d9226f

Browse files
authored
Merge pull request #95934 from s77rt/deleteAgent-handle-error
Display DeleteAgent error on failure
2 parents b50155d + 1b6b961 commit 5d9226f

3 files changed

Lines changed: 4 additions & 7 deletions

File tree

src/libs/actions/Agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function deleteAgent(accountID: number, agentLogin?: string, allPolicies?: OnyxC
301301
onyxMethod: Onyx.METHOD.MERGE,
302302
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${accountID}`,
303303
value: {
304-
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
304+
pendingAction: null,
305305
errors: getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
306306
},
307307
},

src/pages/settings/Agents/AgentsPage.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ function AgentsPage() {
7979
}
8080
};
8181

82-
const shouldShowErrors = (pendingAction: PendingAction | null | undefined) =>
83-
pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
84-
8582
const agents: AgentRowData[] = Object.entries(agentPrompts ?? {}).flatMap(([key, agentPrompt]) => {
8683
const accountID = Number(key.slice(ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT.length));
8784
const details = personalDetailsList?.[accountID];
@@ -96,7 +93,7 @@ function AgentsPage() {
9693
}
9794

9895
const mergedErrors = {
99-
...(shouldShowErrors(pendingAction) ? getLatestError(agentPrompt?.errors ?? undefined) : {}),
96+
...getLatestError(agentPrompt?.errors ?? undefined),
10097
...getLatestError(agentPrompt?.nameErrors ?? undefined),
10198
...getLatestError(agentPrompt?.promptErrors ?? undefined),
10299
...getLatestError(agentPrompt?.avatarErrors ?? undefined),

tests/unit/AgentActionTest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,14 @@ describe('deleteAgent', () => {
428428
expect((personalDetailUpdate?.value as Record<string, unknown>)[TEST_ACCOUNT_ID]).toBeNull();
429429
});
430430

431-
it('failure data merges pendingAction DELETE and errors on the prompt key', () => {
431+
it('failure data clears the pendingAction and merges errors on the prompt key', () => {
432432
deleteAgent(TEST_ACCOUNT_ID);
433433

434434
const {failureData} = getWriteOptions();
435435
const promptUpdate = failureData.find((u) => u.key === `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${TEST_ACCOUNT_ID}`);
436436

437437
expect(promptUpdate?.onyxMethod).toBe('merge');
438-
expect(promptUpdate?.value).toMatchObject({pendingAction: 'delete'});
438+
expect(promptUpdate?.value).toMatchObject({pendingAction: null});
439439
expect((promptUpdate?.value as Record<string, unknown>)?.errors).toBeTruthy();
440440
});
441441

0 commit comments

Comments
 (0)