pldn / LDWizard

🧙 LDWizard: A generic framework for simplifying the creation of linked data. Supported by the PLDN community.
European Union Public License 1.2
13 stars 7 forks source link

Error when defining a column refinement #80

Closed vemonet closed 1 year ago

vemonet commented 1 year ago

Hi, I am trying to create column refinements the same way I was doing with LDWizard v1, but I am getting errors from typescript

Here is the config for the LDWizard with columns refinements I use in webpack/runtimeConfig.ts:

const wizardConfig = {
   appName: "LDWizard - Test",
   defaultBaseIri: "https://w3id.org/test/wizard/",
   primaryColor: "#4caf50", // green
   secondaryColor: "#1565c0", // blue

   columnRefinements: [
      {
         label: "Convert lang ISO to Lexvo URIs",
         type:"single",
         description:
            "This transformation will take lang ISO (e.g. fr or fra) and convert it to a Lexvo URI: http://lexvo.org/id/iso639-3/eng",
         transformation: async (searchTerm: string) => {
            // const sources = ["http://vocab.getty.edu/aat/sparql"];
            // return getUriOfSearchTerm(sources, searchTerm);
            if (searchTerm.length == 3) {
               return `http://lexvo.org/id/iso639-3/${searchTerm}`
            }
            if (searchTerm.length == 2) {
               return `http://lexvo.org/id/iso639-1/${searchTerm}`
            }
            return searchTerm
         },
      },
      {
         label: "Convert boolean to URI",
         type: "single-param",
         description:
            "This transformation will generate the given URI only when the value of the row is 1, or true.",
         transformation: async (searchTerm: string, param: any) => {
            if (searchTerm.trim() === '1' || searchTerm.trim().toLowerCase() === 'true') {
               return param
            }
            return null
         },
      },
   ],
};

window.wizardConfig = wizardConfig;

I am getting this error when running yarn dev:

ERROR in /home/vemonet/develop/sandbox/LDWizard-original/webpack/runtimeConfig.ts
./webpack/runtimeConfig.ts 45:1-20
[tsl] ERROR in /home/vemonet/develop/sandbox/LDWizard-original/webpack/runtimeConfig.ts(45,2)
      TS2322: Type '{ appName: string; defaultBaseIri: string; primaryColor: string; secondaryColor: string; columnRefinements: { label: string; type: string; description: string; transformation: (searchTerm: string) => Promise<...>; }[]; }' is not assignable to type 'WizardConfig'.
  Types of property 'columnRefinements' are incompatible.
    Type '{ label: string; type: string; description: string; transformation: (searchTerm: string) => Promise<string>; }[]' is not assignable to type 'ColumnRefinement[]'.
      Type '{ label: string; type: string; description: string; transformation: (searchTerm: string) => Promise<string>; }' is not assignable to type 'ColumnRefinement'.
        Type '{ label: string; type: string; description: string; transformation: (searchTerm: string) => Promise<string>; }' is not assignable to type 'SingleColumnParamRefinement'.
          Types of property 'type' are incompatible.
            Type 'string' is not assignable to type '"single-param"'.

It says that Types of property 'type' are incompatible. Type 'string' is not assignable to type '"single-param"'.

But that does not seems right because the type for columns refinement is properly defined in the code, the same way as it was for v1.

Could those issues be related to a change in how the TypeScript config is handled by webpack when building the LDWizard instances?

Note that most other configuration I tried (such as changing color and description) works fine. And I am getting the error even when using docker-compose

GerwinBosch commented 1 year ago

Hmm.

I don't think this is a bug. This can be fixed by "fixing" the typing. Currently the interface doesn't know what can be assigned as a type. So it assumes that any string can be put there. We can let typescript know that we want to only "that" particular string by either; assigning the WizardConfig type to the configuration object, Directly putting the config in the object, Or adding as const after the refinement types, changing its type from string to "single" and "single-param".

vemonet commented 1 year ago

Yes that was the issue, thanks! This should be commented somewhere, I will add a new "column enrichement" section to the CONFIGURING.md file