q-shift / backstage-plugins

Apache License 2.0
3 stars 7 forks source link

Extension list filtering is broken #38

Closed iocanel closed 8 months ago

iocanel commented 9 months ago

Adding something like:

        extensions:
          title: Alternative Extensions
          type: array
          description: The list of alternative extensions
          ui:field: QuarkusExtensionList
          ui:options:
            filter:
              extensions:
                - io.quarkus:quarkus-resteasy-reactive-jackson
                - io.quarkus:quarkus-smallrye-openapi
                - io.quarkus:quarkus-smallrye-graphql
                - io.quarkus:quarkus-hibernate-orm-rest-data-panache

Should only display the provided extensions, however this seems to be broken at the moment.

Note: Extensions may be provided using wildcards

cmoulliard commented 9 months ago

Should only display the selected templates, however this seems to be broken at the moment.

It should only display the extensions set as default values BUT will it be possible to select more ? @iocanel

iocanel commented 9 months ago

No, it should prevent users from seeing or selecting anything that does not match the filters.

cmoulliard commented 9 months ago

filter: extensions:

Was this filter parameter working before ? Which project ? @iocanel

cmoulliard commented 9 months ago

No, it should prevent users from seeing or selecting anything that does not match the filters.

Why don't we then, int this case, convert the existing ui into an enum as you force the user to use the fixed list of extensions instead of what we got from code.quarkus.io ? @iocanel

iocanel commented 9 months ago

Because this approach allows us to use wildcards, filtering by category and filtering by keyword.

cmoulliard commented 9 months ago

Should only display the selected templates

Can you elaborate a little as the wording seems wrong ? Why do you speak about templates here ? @iocanel

cmoulliard commented 9 months ago

The error which is reported by the browser's console is about =>

Screenshot 2024-02-22 at 14 36 15 Screenshot 2024-02-22 at 14 37 17

This is because the ui:options of the template don't specify the codeQuarkusUrl. This problem is fixed if we specify it like this:

          ui:options:
            codeQuarkusUrl: https://code.quarkus.io
            filter:
              extensions:
                - io.quarkus:quarkus-resteasy-reactive-jackson
                - io.quarkus:quarkus-smallrye-openapi
                - io.quarkus:quarkus-smallrye-graphql
                - io.quarkus:quarkus-hibernate-orm-rest-data-panache

@iocanel

cmoulliard commented 9 months ago

I got such a warning without using the ui:options + filter BUT i don't know if this is blocking or not ...

useAutocomplete.js:249 Material-UI: The value provided to useAutocomplete is invalid.
None of the options match with `{"id":"io.quarkus:quarkus-resteasy-reactive","name":"RESTEasy Reactive"}`.
You can use the `getOptionSelected` prop to customize the equality test. 
    at QuarkusExtensionList (webpack-internal:///../../node_modules/@qshift/plugin-quarkus/dist/index.esm.js:142:33)
    at eval (webpack-internal:///../../node_modules/@backstage/plugin-scaffolder-react/dist/alpha.esm.js:663:47)
    at div
    at FormControl (webpack-internal:///../../node_modules/@material-ui/core/esm/FormControl/FormControl.js:84:24)
    at WithStyles (webpack-internal:///../../node_modules/@material-ui/styles/esm/withStyles/withStyles.js:64:31)
    at ScaffolderField (webpack-internal:///../../node_modules/@backstage/plugin-scaffolder-react/dist/alpha.esm.js:529:5)
    at div
    at WrapIfAdditionalTemplate (webpack-internal:///../../node_modules/@rjsf/material-ui/lib/WrapIfAdditionalTemplate/WrapIfAdditionalTemplate.js:19:13)
    at FieldTemplate (webpack-internal:///../../node_modules/@backstage/plugin-scaffolder-react/dist/alpha.esm.js:562:5)
    at SchemaFieldRender (webpack-internal:///../../node_modules/@rjsf/core/lib/components/fields/SchemaField.js:74:21)
    at SchemaField (webpack-internal:///../../node_modules/@rjsf/core/lib/components/fields/SchemaField.js:178:1)

See discussion: https://stackoverflow.com/questions/62494672/what-is-getoptionselected-and-getoptionlabel-in-material-ui-with-an-example

cmoulliard commented 9 months ago

If I understand well the problem, when the values evaluated within the function filterExtension of matchingCategory, matchingName, matchingKeywords are all equal to TRUE, then the extension should be added to the list = quarkusExtensions, otherwise they should be skipped

Screenshot 2024-02-22 at 15 36 15 Screenshot 2024-02-22 at 15 36 45

Correct ? @iocanel

cmoulliard commented 9 months ago

Problem is fixed but extensions should be filtered Screenshot 2024-02-22 at 15 55 13 Remark: User cannot selected others extensions except what it is displayed within the list

iocanel commented 9 months ago

The codestart url should be made optional and default to https://code.quarkus.io if one not specified.

cmoulliard commented 9 months ago

The codestart url should be made optional and default to https://code.quarkus.io if one not specified.

This is another thing to be fixed later. Let's fix this issue first ;-)

cmoulliard commented 9 months ago

If we sort the options => options: quarkusExtensions.sort((a, b) => a.name.localeCompare(b.name)), then the result looks like this

Screenshot 2024-02-22 at 16 10 46

Do you know why we have twice some extensions ? @iocanel

cmoulliard commented 9 months ago

This is another thing to be fixed later. Let's fix this issue first ;-)

Fixed using such a syntax

  const codeQuarkusUrl = (uiSchema ?? {})['ui:options']?.codeQuarkusUrl ?? 'https://code.quarkus.io';
  const apiUrl = `${codeQuarkusUrl}/api/extensions`

@iocanel

iocanel commented 9 months ago

If we sort the options => options: quarkusExtensions.sort((a, b) => a.name.localeCompare(b.name)), then the result looks like this

Screenshot 2024-02-22 at 16 10 46

Do you know why we have twice some extensions ? @iocanel

No, i can't say I do. I've seen in before but I don't recall how I worked around that.

iocanel commented 9 months ago

Maybe add some logic to enforce uniqueness.

cmoulliard commented 9 months ago

Maybe add some logic to enforce uniqueness.

https://stackoverflow.com/questions/2218999/how-to-remove-all-duplicates-from-an-array-of-objects

cmoulliard commented 9 months ago

I will create a PR @iocanel => Screenshot 2024-02-22 at 17 55 41