From cf3d9537daf06046e6f47dec164ba20347860916 Mon Sep 17 00:00:00 2001 From: Ali Amori Kadhim Date: Tue, 22 Nov 2022 09:27:23 +0100 Subject: [PATCH] feat: create strapi-plugin-scheme-select --- package-lock.json | 22 ++++++ packages/strapi-dashboard/package.json | 1 + .../strapi-plugin-scheme-select/README.md | 3 + .../src/components/ComboboxIcon/index.js | 24 ++++++ .../src/components/CustomCombobox/index.js | 77 +++++++++++++++++++ .../admin/src/index.js | 72 +++++++++++++++++ .../admin/src/pluginId.js | 5 ++ .../admin/src/translations/en.json | 4 + .../admin/src/translations/nl.json | 4 + .../admin/src/utils/getTrad.js | 5 ++ .../strapi-plugin-scheme-select/package.json | 30 ++++++++ .../server/index.js | 7 ++ .../server/register.js | 10 +++ .../strapi-admin.js | 3 + .../strapi-server.js | 3 + 15 files changed, 270 insertions(+) create mode 100644 packages/strapi-plugin-scheme-select/README.md create mode 100644 packages/strapi-plugin-scheme-select/admin/src/components/ComboboxIcon/index.js create mode 100644 packages/strapi-plugin-scheme-select/admin/src/components/CustomCombobox/index.js create mode 100644 packages/strapi-plugin-scheme-select/admin/src/index.js create mode 100644 packages/strapi-plugin-scheme-select/admin/src/pluginId.js create mode 100644 packages/strapi-plugin-scheme-select/admin/src/translations/en.json create mode 100644 packages/strapi-plugin-scheme-select/admin/src/translations/nl.json create mode 100644 packages/strapi-plugin-scheme-select/admin/src/utils/getTrad.js create mode 100644 packages/strapi-plugin-scheme-select/package.json create mode 100644 packages/strapi-plugin-scheme-select/server/index.js create mode 100644 packages/strapi-plugin-scheme-select/server/register.js create mode 100644 packages/strapi-plugin-scheme-select/strapi-admin.js create mode 100644 packages/strapi-plugin-scheme-select/strapi-server.js diff --git a/package-lock.json b/package-lock.json index b28911e61..a5660e0f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4250,6 +4250,10 @@ "resolved": "packages/strapi-plugin-gemeente-select", "link": true }, + "node_modules/@frameless/strapi-plugin-scheme-select": { + "resolved": "packages/strapi-plugin-scheme-select", + "link": true + }, "node_modules/@frameless/utrecht-editor": { "resolved": "packages/utrecht-editor", "link": true @@ -34084,6 +34088,7 @@ "@frameless/preview-button": "file:../preview-button", "@frameless/strapi-plugin-ckeditor5": "file:../strapi-plugin-ckeditor5", "@frameless/strapi-plugin-gemeente-select": "0.0.0-semantically-released", + "@frameless/strapi-plugin-scheme-select": "0.0.0-semantically-released", "@strapi/plugin-graphql": "4.5.0", "@strapi/plugin-i18n": "4.5.0", "@strapi/plugin-users-permissions": "4.5.0", @@ -34138,6 +34143,18 @@ "@strapi/strapi": ">=4.0.0" } }, + "packages/strapi-plugin-scheme-select": { + "name": "@frameless/strapi-plugin-scheme-select", + "version": "0.0.0-semantically-released", + "license": "MIT", + "engines": { + "node": ">=16.16.0 <=18.x.x", + "npm": ">=6.0.0" + }, + "peerDependencies": { + "@strapi/strapi": ">=4.0.0" + } + }, "packages/utrecht-editor": { "name": "@frameless/utrecht-editor", "version": "0.0.0-semantically-released", @@ -37189,6 +37206,7 @@ "@frameless/preview-button": "file:../preview-button", "@frameless/strapi-plugin-ckeditor5": "file:../strapi-plugin-ckeditor5", "@frameless/strapi-plugin-gemeente-select": "0.0.0-semantically-released", + "@frameless/strapi-plugin-scheme-select": "0.0.0-semantically-released", "@strapi/plugin-graphql": "4.5.0", "@strapi/plugin-i18n": "4.5.0", "@strapi/plugin-users-permissions": "4.5.0", @@ -37220,6 +37238,10 @@ "version": "file:packages/strapi-plugin-gemeente-select", "requires": {} }, + "@frameless/strapi-plugin-scheme-select": { + "version": "file:packages/strapi-plugin-scheme-select", + "requires": {} + }, "@frameless/utrecht-editor": { "version": "file:packages/utrecht-editor", "requires": { diff --git a/packages/strapi-dashboard/package.json b/packages/strapi-dashboard/package.json index 52ad3b630..15bfc1b83 100644 --- a/packages/strapi-dashboard/package.json +++ b/packages/strapi-dashboard/package.json @@ -17,6 +17,7 @@ "@frameless/preview-button": "file:../preview-button", "@frameless/strapi-plugin-ckeditor5": "file:../strapi-plugin-ckeditor5", "@frameless/strapi-plugin-gemeente-select": "0.0.0-semantically-released", + "@frameless/strapi-plugin-scheme-select": "0.0.0-semantically-released", "@strapi/plugin-graphql": "4.5.0", "@strapi/plugin-i18n": "4.5.0", "@strapi/plugin-users-permissions": "4.5.0", diff --git a/packages/strapi-plugin-scheme-select/README.md b/packages/strapi-plugin-scheme-select/README.md new file mode 100644 index 000000000..36b050b6e --- /dev/null +++ b/packages/strapi-plugin-scheme-select/README.md @@ -0,0 +1,3 @@ +# Strapi plugin scheme-select + +A strapi custom field for selecting a scheme \ No newline at end of file diff --git a/packages/strapi-plugin-scheme-select/admin/src/components/ComboboxIcon/index.js b/packages/strapi-plugin-scheme-select/admin/src/components/ComboboxIcon/index.js new file mode 100644 index 000000000..2c8ab72fb --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/components/ComboboxIcon/index.js @@ -0,0 +1,24 @@ +import React from 'react'; +import styled from 'styled-components'; +import { Icon } from '@strapi/design-system/Icon'; +import { Flex } from '@strapi/design-system/Flex'; +import ManyToMany from '@strapi/icons/ManyToMany'; + +const IconBox = styled(Flex)` + background-color: #f0f0ff; /* primary100 */ + border: 1px solid #d9d8ff; /* primary200 */ + + svg > path { + fill: #4945ff; /* primary600 */ + } +`; + +const ComboboxIcon = () => { + return ( + + + + ); +}; + +export default ComboboxIcon; \ No newline at end of file diff --git a/packages/strapi-plugin-scheme-select/admin/src/components/CustomCombobox/index.js b/packages/strapi-plugin-scheme-select/admin/src/components/CustomCombobox/index.js new file mode 100644 index 000000000..bab3d4857 --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/components/CustomCombobox/index.js @@ -0,0 +1,77 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Combobox, ComboboxOption } from '@strapi/design-system/Combobox'; +import { Stack } from '@strapi/design-system/Stack'; +import { Field, FieldLabel, FieldError, FieldHint } from '@strapi/design-system/Field'; +import { useIntl } from 'react-intl'; + +const CustomCombobox = ({ + value, + onChange, + name, + intlLabel, + labelAction, + required, + attribute, + description, + placeholder, + disabled, + error, +}) => { + const { formatMessage } = useIntl(); + + const schemeData = [{ resourceIdentifier: '{http://standaarden.overheid.nl/owms/terms/}Gemeente', prefLabel: 'Gemeente' }] + return ( + + + + {formatMessage(intlLabel)} + + onChange({ target: { name, value: resourceIdentifier, type: attribute.type } }) + } + > + {schemeData.map(({ prefLabel, resourceIdentifier + }) => ({prefLabel}) + )} + + + + + + ) +} + +CustomCombobox.defaultProps = { + description: null, + disabled: false, + error: null, + labelAction: null, + required: false, + value: '', +}; + +CustomCombobox.propTypes = { + intlLabel: PropTypes.object.isRequired, + onChange: PropTypes.func.isRequired, + attribute: PropTypes.object.isRequired, + name: PropTypes.string.isRequired, + description: PropTypes.object, + disabled: PropTypes.bool, + error: PropTypes.string, + labelAction: PropTypes.object, + required: PropTypes.bool, + value: PropTypes.string, +}; + +export default CustomCombobox; \ No newline at end of file diff --git a/packages/strapi-plugin-scheme-select/admin/src/index.js b/packages/strapi-plugin-scheme-select/admin/src/index.js new file mode 100644 index 000000000..57f6d3acc --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/index.js @@ -0,0 +1,72 @@ +import { prefixPluginTranslations } from '@strapi/helper-plugin'; +import pluginId from './pluginId'; +import ComboboxIcon from './components/ComboboxIcon'; +import getTrad from './utils/getTrad'; + +export default { + register(app) { + app.customFields.register({ + name: 'scheme', + pluginId: 'scheme-select', + type: 'string', + icon: ComboboxIcon, + intlLabel: { + id: getTrad('scheme-select.label'), + defaultMessage: 'Scheme', + }, + intlDescription: { + id: getTrad('scheme-select.description'), + defaultMessage: 'Select any scheme', + }, + components: { + Input: async () => + import('./components/CustomCombobox'), + }, + options: { + advanced: [ + { + sectionTitle: { + id: 'global.settings', + defaultMessage: 'Settings', + }, + items: [ + { + name: 'required', + type: 'checkbox', + intlLabel: { + id: 'form.attribute.item.requiredField', + defaultMessage: 'Required field', + }, + description: { + id: 'form.attribute.item.requiredField.description', + defaultMessage: "You won't be able to create an entry if this field is empty", + }, + }, + ], + }, + ], + }, + }); + }, + async registerTrads({ locales }) { + const importedTrads = await Promise.all( + locales.map((locale) => { + return import(`./translations/${locale}.json`) + .then(({ default: data }) => { + return { + data: prefixPluginTranslations(data, pluginId), + locale, + }; + }) + .catch(() => { + return { + data: {}, + locale, + }; + }); + }) + ); + + return Promise.resolve(importedTrads); + }, +}; diff --git a/packages/strapi-plugin-scheme-select/admin/src/pluginId.js b/packages/strapi-plugin-scheme-select/admin/src/pluginId.js new file mode 100644 index 000000000..86daf9e3e --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/pluginId.js @@ -0,0 +1,5 @@ +const pluginPkg = require('../../package.json') + +const pluginId = pluginPkg.name.replace(/^@frameless\/(@[^-,.][\w,-]+\/|strapi-)plugin-/i, ''); + +module.exports = pluginId; diff --git a/packages/strapi-plugin-scheme-select/admin/src/translations/en.json b/packages/strapi-plugin-scheme-select/admin/src/translations/en.json new file mode 100644 index 000000000..7124169ea --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/translations/en.json @@ -0,0 +1,4 @@ +{ + "scheme-select.label": "Scheme", + "scheme-select.description": "Select a Scheme" +} diff --git a/packages/strapi-plugin-scheme-select/admin/src/translations/nl.json b/packages/strapi-plugin-scheme-select/admin/src/translations/nl.json new file mode 100644 index 000000000..e49ab82f1 --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/translations/nl.json @@ -0,0 +1,4 @@ +{ + "scheme-select.label": "Scheme", + "scheme-select.description": "Selecteer een scheme" +} diff --git a/packages/strapi-plugin-scheme-select/admin/src/utils/getTrad.js b/packages/strapi-plugin-scheme-select/admin/src/utils/getTrad.js new file mode 100644 index 000000000..d0a071b26 --- /dev/null +++ b/packages/strapi-plugin-scheme-select/admin/src/utils/getTrad.js @@ -0,0 +1,5 @@ +import pluginId from '../pluginId'; + +const getTrad = (id) => `${pluginId}.${id}`; + +export default getTrad; diff --git a/packages/strapi-plugin-scheme-select/package.json b/packages/strapi-plugin-scheme-select/package.json new file mode 100644 index 000000000..00ab4a92d --- /dev/null +++ b/packages/strapi-plugin-scheme-select/package.json @@ -0,0 +1,30 @@ +{ + "name": "@frameless/strapi-plugin-scheme-select", + "version": "0.0.0-semantically-released", + "description": "A strapi custom field for selecting scheme", + "private": false, + "strapi": { + "name": "scheme-select", + "description": "Scheme Select custom field", + "kind": "plugin", + "displayName": "Scheme Select" + }, + "repository": { + "type": "git+ssh", + "url": "git@github.com:frameless/strapi.git" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com/" + }, + "author": { + "name": "" + }, + "license": "MIT", + "peerDependencies": { + "@strapi/strapi": ">=4.0.0" + }, + "engines": { + "node": ">=16.16.0 <=18.x.x", + "npm": ">=6.0.0" + } +} \ No newline at end of file diff --git a/packages/strapi-plugin-scheme-select/server/index.js b/packages/strapi-plugin-scheme-select/server/index.js new file mode 100644 index 000000000..fc0880b4e --- /dev/null +++ b/packages/strapi-plugin-scheme-select/server/index.js @@ -0,0 +1,7 @@ +'use strict'; + +const register = require('./register'); + +module.exports = { + register, +}; diff --git a/packages/strapi-plugin-scheme-select/server/register.js b/packages/strapi-plugin-scheme-select/server/register.js new file mode 100644 index 000000000..1b08dc513 --- /dev/null +++ b/packages/strapi-plugin-scheme-select/server/register.js @@ -0,0 +1,10 @@ +'use strict'; +const plugin = require('../admin/src/pluginId') + +module.exports = ({ strapi }) => { + strapi.customFields.register({ + name: 'scheme', + plugin, + type: 'string', + }); +}; diff --git a/packages/strapi-plugin-scheme-select/strapi-admin.js b/packages/strapi-plugin-scheme-select/strapi-admin.js new file mode 100644 index 000000000..2d1a3d93a --- /dev/null +++ b/packages/strapi-plugin-scheme-select/strapi-admin.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./admin/src').default; diff --git a/packages/strapi-plugin-scheme-select/strapi-server.js b/packages/strapi-plugin-scheme-select/strapi-server.js new file mode 100644 index 000000000..8a908be91 --- /dev/null +++ b/packages/strapi-plugin-scheme-select/strapi-server.js @@ -0,0 +1,3 @@ +'use strict'; + +module.exports = require('./server');