am2222 / strapi-plugin-postgis

Add native postgis support to strapi.
https://am2222.github.io/strapi-plugin-postgis/
40 stars 14 forks source link

Error in admin runtime after installing plugin in Strapi 4.5 application #6

Open simb opened 1 year ago

simb commented 1 year ago

I just setup a fresh install of Strapi 4.5. Everything was working but I have not created any collections other than those included in the quickstart.

After installing strapi-plugin-postgis 0.1.7 and starting up the local server again I am having issues. The server compiles the admin UI and the application http interface is working. But when I access the admin I just get a white screen. Checking the Chomr developer console I see this error:

Uncaught TypeError: Cannot set property GenericInput of # which has only a getter

Removing the package from package.json and node_modules and building the admin UI removes the error.

simb commented 1 year ago

This appears to be an issue with 4.4.7 also.

simb commented 1 year ago

I noticed that the last updates to this plugin were 6 months ago. So I looked up the version of Strapi that corresponded. Dropping back to 4.1.12 makes everything work just as the website shows.

simb commented 1 year ago

Ok, It works all the way to 4.4.5. But fails in 4.4.6. So something changes in @strapi/strapi for the 4.4.6 release that causes everything to break down.

am2222 commented 1 year ago

@simb I need to check this issue to see why this error is happening. I will probably be able to check it end of Dec due to the school and work. But any pull a requests into this project is welcomed!

Arrig0 commented 1 year ago

I am facing the same problem now. Any news?

Arrig0 commented 1 year ago

@am2222 Interceptor hack on GenericInput for loading custom admin field doesn't work anymore. Should be used strapi.customFields.register instead.. but this way has a drawback.

In fact registering the Map component as a custom field, make the plugin work perfectly, but unluckily the component remains available in the "add custom fields selector".. and without modifying the schema.json, strapi crashes.

am2222 commented 1 year ago

@Arrig0 sorry, I am busy with work and couldn't take a look at it with the latest version of Strapi.

Do you think using customField solves the issue? As far as I remember the custom fields limited us to the json type for the fields, which technically we are solving it by converting geometries to json

Arrig0 commented 1 year ago

@am2222 I don't know if this is the right way.. what I quickly tried and i'm about to describe was an attempt to find a workaround to allow the plugin to work even with newer versions of strapi.

Maybe you can find useful.

If from the admin ui you try to add the custom field it doesn't work, but if from the model (schema.json) you specify that the postgis column must be managed by the custom field, everything works correctly. This is due to that custom fields cannot add new data types and must use existing built-in (for now).

Project Side // modify content-types adding some postgis columns in schema.json

"attributes": {
  ...
  "polygon": {
    "columnType": {
      "type": "specificType",
      "args": [
        "geometry(POLYGON,4326)" //-> this line according to the Supported Data Types section
      ]
    },
    "type": "json",
    "customField": "plugin::postgis.map" //-> the custom field name
  },
  "geom": {
    "columnType": {
      "type": "specificType",
      "args": [
        "geometry(POINT,4326)" //-> this line according to the Supported Data Types section
      ]
    },
    "type": "json",
    "customField": "plugin::postgis.map" //-> the custom field name
  },
}

Inspecting db:

    Column     |              Type              | 
---------------+--------------------------------+
 ...
 polygon       | geometry(Polygon,4326)         |
 geom          | geometry(Point,4326)           |

Plugin Side // ~/strapi-plugin-postgis/admin/scr/index.js

// comment Interceptor hack that doesn't work anymore (strapi v4)

// import { intercept } from './utils/intercept';
// import * as helperPlugin from '@strapi/helper-plugin'; 
// intercept(helperPlugin, 'GenericInput',....) 
// add the custom field registration inside register(app) function
app.customFields.register({
  name: 'map', // the custom field name
  pluginId,
  type: 'string',
  icon: PluginIcon,
  intlLabel: {
    id: 'postgis.label',
    defaultMessage: 'postgis map',
  },
  intlDescription: {
    id: 'postgis.description',
    defaultMessage: 'postgis map description',
  },
  components: {
    Input: async () => import(
      './components/Map'
    ),
  },
  options: {
  },    
});

// comment addFields(). It works only in strapi v3
//app.addFields({ type: 'postgis', Component: Map });

Querying db:

// SELECT id, ST_AsText(geom), geom FROM tests;
 id |         st_astext         |                        geom                        
----+---------------------------+----------------------------------------------------
  1 | POINT(9.225179 45.497229) | 0101000020E6100000F27D71A94A732240B7CF2A33A5BF4640
Arrig0 commented 1 year ago

@am2222 Sorry for late reply for a PR, but I was busy with work too. Finally using customField solves the issue. If you have time, check it out. Tested on strapi 4.9.2