describo / crate-builder-component

A VueJS UI component to build an RO-Crate
MIT License
6 stars 3 forks source link

Bugfix on prevent type change #100

Closed csontosreka closed 5 months ago

csontosreka commented 5 months ago

When updating the URL value in a text field, the input was duplicated and saved as another URL-type value.

Steps to recreate the issue:

  1. Select crate and profile
  2. Disable enableUrlMarkup
  3. Save a URL in a text field
  4. Update it and save again
  5. Now the URL is saved twice, once as a string and once as a URL entity
image

I think I was able to solve this issue by checking if enableUrlMarkup is true in RenderEntityPropertyInstance.component.vue.

marcolarosa commented 5 months ago

Ahh right. I see.

I noticed that in RenderEntityPropertyInstance you originally had:

...
function isUrl(string) {
    let result = isURL(string) && configuration.value.enableUrlMarkup;
    return result;
}
...

I removed the check against enableUrlMarkup because it didn't make sense why that check mattered in that function. But the result of removing it is that the url-component was loaded in the template rather than the text-component:

 <url-component
        v-else-if="isUrl(props.value)"
        :property="props.property"
        :value="props.value"
        @create:entity="createEntity"
/>

I think that extra check actually makes more sense in the template as:

 <url-component
         v-else-if="isUrl(props.value) && configuration.enableUrlMarkup"
         :property="props.property"
         :value="props.value"
         @create:entity="createEntity"
  />

so that the isUrl method remains simple. It does one thing - it checks if something is a url or not and that's not complicated by the component configuration.

I'll merge this pr and then update as above. Please check - in my testing it's working as it should. Sorry about that.