-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Initial implementation of plugin which adds support for string[] #6
base: staging
Are you sure you want to change the base?
Conversation
I don't understand the first thing about strapi plugin development yet, so if it works, it works 馃憤 great stuff! |
It works with Strapi itself, but does not work with other plugin which we need to use (import-export plugin) so I will not merge this in the end. Pushed it to repo just for others to see how strapi plugin can look like... |
@@ -0,0 +1,45 @@ | |||
'use strict'; | |||
|
|||
const _ = require("lodash"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const _ = require("lodash"); | |
const { isArray, map, trim, unset } = require("lodash-es"); |
It's recommended to only import what you need instead of the complete library, and using this version of lodash will make it easier.
https://www.npmjs.com/package/lodash-es
@@ -14,6 +14,7 @@ | |||
"@strapi/plugin-i18n": "4.13.1", | |||
"@strapi/plugin-users-permissions": "4.13.1", | |||
"@strapi/strapi": "4.13.1", | |||
"lodash": "^4.17.21", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better use https://www.npmjs.com/package/lodash-es
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should actually NOT be here, but inside the plugin itself
placeholder="Individual strings divided by commas" | ||
label={name} | ||
name={name} | ||
onChange={(e) => handleValueChange(e.target.value)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onChange={(e) => handleValueChange(e.target.value)} | |
onChange={handleValueChange} |
const handleValueChange = (newValue) => { | ||
setArrayOfStrings(newValue); | ||
onChange({ target: { name, value: newValue, type: attribute.type } }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const handleValueChange = (newValue) => { | |
setArrayOfStrings(newValue); | |
onChange({ target: { name, value: newValue, type: attribute.type } }); | |
} | |
const handleValueChange = useCallback((e) => { | |
const newValue = e.target.value; | |
setArrayOfStrings(newValue); | |
onChange({ target: { name, value: newValue, type: attribute.type } }); | |
}, []); |
This form will avoid extra assignations in the renderization cycle loop of React
@@ -0,0 +1,41 @@ | |||
import React, { useState, useEffect } from 'react'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import React, { useState, useEffect } from 'react'; | |
import { useState } from 'react'; |
Remove no needed libs
const Input = ({ | ||
attribute, | ||
error, | ||
name, | ||
onChange, | ||
value | ||
}) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types are missing, but vscode doesn't show any error. I'll take a look
Simple plugin which adds support for
string[]
db type. User's input provided via Administration is divided by,
and individual parts of string are saved as elements of array. Vice versa, individual elements of array are joined together and presented to user.Current implementation is using decorator around
strapi.entityService
that allows to update array column independently outside of Strapi supported types.Provided implementation works at Strapi, but unfortunately does not work for import-export Strapi package when import version 1 is used. Based on this package documentation, this import should be already deprecated, but anyway
csv
and other stuff still use it. Its code does not usestrapi.entityService
(recommended by Strapi) and modifies data directly, therefore I have not figured way how to modify it without forking whole repo and tweaking code directly inside this package. For now decided to useJSON
instead of array data type 馃槩Maybe you find this interesting @davidsingal @tiagojsag :)