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

[Large] Create logic for editing metadata #372

Open
wants to merge 26 commits into
base: feature/metadata-editing/develop
Choose a base branch
from

Conversation

aswallace
Copy link
Contributor

@aswallace aswallace commented Dec 19, 2024

Adds editing logic for existing annotations for FMS and database (csv/duckdb) files. This reopens/continues Sean's work on the edit logic from #260 with minor updates to reflect codebase & MMS changes. The commit history will be a mess because of rebases, but the file changes are accurate.

This is a big PR, but the most important changes are the FileService additions in packages/core/services/FileService/DatabaseFileService/index.ts and packages/core/services/FileService/HttpFileService/index.ts. The logic for sending batches of edit requests via Redux is in packages/core/state/interaction/logics.ts. We also added a put to the HttpFileService. Most other changes are to interfaces, abstract classes or tests.

Testing

  • Unit tests from old PR
  • Successfully edited files in FES staging while pointing to MMS staging (which has the CORS updates)
  • Successfully edited metadata from an uploaded csv, and confirmed that edits are included when you download as CSV

Notes:

Editing FMS files on web WILL NOT WORK unless you add a valid "X-User-Id" to the headers in HttpServiceBase. I didn't commit this because I'm currently using my own user ID locally until we complete #341

The UI occasionally takes a while to display correct data for edited FMS files, even though the edits go through to MMS immediately. I think this is an FMS/FES syncing issue rather than a BFF thing?

@aswallace aswallace changed the title Create logic for editing metadata [Large] Create logic for editing metadata Dec 19, 2024
@aswallace aswallace marked this pull request as ready for review December 19, 2024 00:44
try {
await fileService.editFile(
fileId,
annotations,
Copy link
Contributor

Choose a reason for hiding this comment

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

I see... I think the request to get MMS "editable data" was to for insertion right here where this annotations parameter is. However, that is a very slow GET fetch so I don't think we should necessarily switch to that. Instead, can we just pass here the annotation we want to replace the values for? Lets check up on the way the PATCH method works we might be golden with just switching to that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright found the logic in MMS, this is the logical path:
https://github.com/AllenCellSoftware/metadata-management-service/blob/master/src/main/java/org/alleninstitute/aics/metadatamanagementservice/filemetadata/FileMetadataController.java#L92
https://github.com/AllenCellSoftware/metadata-management-service/blob/master/src/main/java/org/alleninstitute/aics/metadatamanagementservice/filemetadata/FileIngestionService.java#L101C13-L101C40
https://github.com/AllenCellSoftware/metadata-management-service/blob/master/src/main/java/org/alleninstitute/aics/metadatamanagementservice/filemetadata/FileIngestionService.java#L171-L205

So based on the last chunk of code there we actually want that boolean block of replaceOldValues to happen which does not happen with the PATCH and does happen with the PUT. Furthermore, it only replaces annotations that are included in the request with new values. So all to get this working that we need to do is for the annotations parameter in this BFF code assign annotations equal to just the annotation the user modified in the modal with the values they want to replace with from the modal. It seems like that may already be happening so everything might just be all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, currently we are only passing the annotations that we want to edit

packages/core/state/interaction/logics.ts Show resolved Hide resolved
@kmitcham
Copy link

Is it legal to delete an annotation? Or set the value to null?

@aswallace
Copy link
Contributor Author

Is it legal to delete an annotation? Or set the value to null?

Technically yes, passing an empty array as the values effectively deletes annotations when you use the MMS put endpoint. However, the current UI in BFF does not allow you to click submit on the form without entering values (and just spotted that sending an empty string causes MMS to send back an error, so I'm adding a check for that now)

const url = `${mmsBaseUrl}/${HttpFileService.BASE_EDIT_FILES_URL}/${fileId}`;
const annotations = Object.entries(annotationNameToValuesMap).map(([name, values]) => {
const annotationId = annotationNameToAnnotationMap?.[name].id;
if (!annotationId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be better to aggregate all missing annotations and throw a single error

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.

4 participants