scalableminds / webknossos

Visualize, share and annotate your large 3D images online
https://webknossos.org
GNU Affero General Public License v3.0
127 stars 24 forks source link

Dataset settings need multiple submits with same form input to succeed #8172

Open MichaelBuessemeyer opened 1 week ago

MichaelBuessemeyer commented 1 week ago

The frontend form validation of the dataset settings seem to be a little faulty.

Context

When I try to edit a dataset via the advanced datasource view and then try to submit the changes, I get an error that some fields have errors, although all values are valid. Only once I try to submit again, the frontend validation succeeds and then sends the data to ther server.

Expected Behavior

The first try of submitting the changes should succeed.

Current Behavior

The first try fails. I gave this a quick investigation. The console shows an error that

validator: syncValidator(
                  (value: string) =>
                    dataLayers.filter((someLayer: APIDataLayer) => someLayer.name === value)
                      .length <= 1,
                  "Layer names must be unique.",
                ),

yields an undefined error in the first try to submit it, as the useWatch value is outdated and undefined. Switching to

validator: syncValidator(
                  (value: string) =>
                    form
                      .getFieldValue(["dataSource", "dataLayers"])
                      .filter((someLayer: APIDataLayer) => someLayer.name === value).length <= 1,
                  "Layer names must be unique.",
                ),

resolves this error, but the validation error still exists. With outOfDate: true being set in the error thrown by the validation. I did not have a quick idea regarding this, thus I created this issue.

Steps to Reproduce the bug

  1. Open the dataset settings for one ds
  2. select the advanced tab
  3. For one color layer increase the bbox by one voxel in each dim.
  4. try to save -> the error should occur
  5. try to save again -> this time it should succeed

Your Environment for bug

Nothing special. Noticed why working on #8075 but seems like this was not introduced in this pr.