Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AJ-1277] select and delete rows #5090

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
Draft

Conversation

mspector
Copy link
Contributor

@mspector mspector commented Sep 18, 2024

Jira Ticket: https://broadworkbench.atlassian.net/browse/AJ-1277

Summary of changes:

What

  • Adds support to select and delete rows in a WDS data table

Why

  • progress towards WDS feature parity

Testing strategy

  • Unit tests
  • Manual tests against dev

@mspector mspector marked this pull request as ready for review September 19, 2024 19:08
@mspector mspector requested a review from a team as a code owner September 19, 2024 19:08
@mspector mspector marked this pull request as draft September 19, 2024 19:14
@mspector mspector marked this pull request as ready for review September 19, 2024 19:57
Copy link

sonarcloud bot commented Sep 20, 2024

parameters: DeleteRecordsRequest
): Promise<any> => {
await fetchWDS(root)(
`records/v1/${collectionId}/${recordType}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`records/v1/${collectionId}/${recordType}`,
`records/v1/${collectionId}/${recordType}/delete`,

Update URL to this since I am getting a 404
Screenshot 2024-09-20 at 4 24 40 PM

setDeletingRecords(false);
setSelectedRecords({});
setRefreshKey(_.add(1));
Ajax().Metrics.captureEvent(Events.workspaceDataDelete, extractWorkspaceDetails(workspace.workspace));
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that we are capturing the deletion event

}
const recordType = recordTypes[0];
setDeleting(true);

Copy link
Contributor

Choose a reason for hiding this comment

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

Add a new function filterAdditionalDeletions to ensure the logic is testable independently.

Suggested change
const filterAdditionalDeletions = async (error: Response, recordsToDelete: Array<{ entityType: string, entityName: string }>) => {
const errorEntities = await error.json();
return _.filter(errorEntities, (errorEntity: { entityType: string, entityName: string }) =>
!_.some(recordsToDelete, (selectedEntity) =>
selectedEntity.entityType === errorEntity.entityType && selectedEntity.entityName === errorEntity.entityName
)
);
};

Comment on lines +35 to +51
switch (error.status) {
case 409:
setAdditionalDeletions(
_.filter(
(errorEntity) =>
!_.some(
(selectedEntity) => selectedEntity.entityType === errorEntity.entityType && selectedEntity.entityName === errorEntity.entityName,
recordsToDelete
),
await error.json()
)
);
setDeleting(false);
break;
default:
await reportError('Error deleting data entries', error);
onDismiss();
Copy link
Contributor

Choose a reason for hiding this comment

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

Sonarcloud suggested removing the switch case: "switch" statements should have at least 3 "case" clauses
Use the new function filterAdditionalDeletions added above in your implementation

Suggested change
switch (error.status) {
case 409:
setAdditionalDeletions(
_.filter(
(errorEntity) =>
!_.some(
(selectedEntity) => selectedEntity.entityType === errorEntity.entityType && selectedEntity.entityName === errorEntity.entityName,
recordsToDelete
),
await error.json()
)
);
setDeleting(false);
break;
default:
await reportError('Error deleting data entries', error);
onDismiss();
if (error.status != 409){
await reportError('Error deleting data entries', error);
return onDismiss();
}
// Handle 409 error by filtering additional deletions that need to be deleted first
setAdditionalDeletions(await filterAdditionalDeletions(error, recordsToDelete));
setDeleting(false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants