From efd46a117f1f1dffe7fd5ec291d3a6671eff43cc Mon Sep 17 00:00:00 2001 From: soupette Date: Thu, 10 Dec 2020 18:46:57 +0100 Subject: [PATCH] Created Carret compo in helper plugin Signed-off-by: soupette --- packages/strapi-helper-plugin/lib/src/app.js | 118 ------------------ .../lib/src/components/Carret/index.js | 14 +++ packages/strapi-helper-plugin/lib/src/i18n.js | 63 ---------- .../strapi-helper-plugin/lib/src/index.js | 1 + .../lib/src/public-path.js | 13 -- .../components/CustomTable/Headers/Arrow.js | 1 - .../components/CustomTable/Headers/Header.js | 5 +- .../containers/ListView/FieldPicker/index.js | 4 +- 8 files changed, 19 insertions(+), 200 deletions(-) delete mode 100644 packages/strapi-helper-plugin/lib/src/app.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Carret/index.js delete mode 100644 packages/strapi-helper-plugin/lib/src/i18n.js delete mode 100644 packages/strapi-helper-plugin/lib/src/public-path.js diff --git a/packages/strapi-helper-plugin/lib/src/app.js b/packages/strapi-helper-plugin/lib/src/app.js deleted file mode 100644 index 17520c1c47..0000000000 --- a/packages/strapi-helper-plugin/lib/src/app.js +++ /dev/null @@ -1,118 +0,0 @@ -/** - * app.js - * - * This is the entry file for the application, - * only setup and plugin code. - */ - -/* eslint-disable */ -// Don't move this line! -// import './public-path.js'; // eslint-disable-line import/extensions - -import React from 'react'; -// import Loadable from 'react-loadable'; -// import LoadingIndicatorPage from './components/LoadingIndicatorPage'; -import { translationMessages } from './i18n'; -import App from 'containers/App'; - -// const LoadableApp = Loadable({ -// loader: () => import('containers/App'), -// loading: LoadingIndicatorPage, -// }); - -// const tryRequireRoot = source => { -// try { -// return require('../../../../admin/src/' + source + '.js').default; // eslint-disable-line prefer-template -// } catch (err) { -// return null; -// } -// }; - -const layout = (() => { - try { - return require('../../../../config/layout.js'); - } catch (err) { - return null; - } -})(); - -const injectedComponents = (() => { - try { - return require('injectedComponents').default; - } catch (err) { - return []; - } -})(); - -// Plugin identifier based on the package.json `name` value -const pluginPkg = require('../../../../package.json'); -const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, ''); -const pluginName = pluginPkg.strapi.name; -const pluginDescription = pluginPkg.strapi.description || pluginPkg.description; -const apiUrl = `${strapi.backendURL}/${pluginId}`; -const router = strapi.router; - -// Create redux store with Strapi admin history -// const store = configureStore({}, strapi.router, pluginName); -const store = strapi.store; - -// Define the plugin root component -function Comp(props) { - return ; -} - -// Hot reloadable translation json files -if (module.hot) { - // modules.hot.accept does not accept dynamic dependencies, - // have to be constants at compile-time - module.hot.accept('./i18n', () => { - if (strapi) { - System.import('./i18n').then(result => { - const translationMessagesUpdated = result.translationMessages; - strapi - .refresh(pluginId) - .translationMessages(translationMessagesUpdated); - }); - } - }); -} - -// Require the Initializer component -const initializer = (() => { - try { - return require('../../../../admin/src/initializer.js'); - } catch (err) { - return null; - } -})(); - -// Require the plugin's lifecycle -const lifecycles = (() => { - try { - return require('../../../../admin/src/lifecycles.js'); - } catch (err) { - return null; - } -})(); - -// Register the plugin. -strapi.registerPlugin({ - blockerComponent: null, - blockerComponentProps: {}, - description: pluginDescription, - icon: pluginPkg.strapi.icon, - id: pluginId, - initializer, - injectedComponents, - layout, - lifecycles, - leftMenuLinks: [], - leftMenuSections: [], - mainComponent: Comp, - name: pluginPkg.strapi.name, - preventComponentRendering: false, - translationMessages, -}); - -// Export store -export { store, apiUrl, pluginId, pluginName, pluginDescription, router }; diff --git a/packages/strapi-helper-plugin/lib/src/components/Carret/index.js b/packages/strapi-helper-plugin/lib/src/components/Carret/index.js new file mode 100644 index 0000000000..ec089b3f0c --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Carret/index.js @@ -0,0 +1,14 @@ +import React from 'react'; +import styled from 'styled-components'; +import { Carret as Base } from '@buffetjs/icons'; + +const Carret = styled(({ isUp, ...rest }) => )` + margin-left: 5px; + ${({ isUp }) => + isUp && + ` + transform: rotateZ(180deg); + `} +`; + +export default Carret; diff --git a/packages/strapi-helper-plugin/lib/src/i18n.js b/packages/strapi-helper-plugin/lib/src/i18n.js deleted file mode 100644 index 49abad0fd1..0000000000 --- a/packages/strapi-helper-plugin/lib/src/i18n.js +++ /dev/null @@ -1,63 +0,0 @@ -/** - * i18n.js - * - * This will setup the i18n language files and locale data for your plugin. - * - */ - -/* eslint-disable no-console */ -import { reduce } from 'lodash'; - -// Plugin identifier based on the package.json `name` value -const pluginPkg = require('../../../../package.json'); - -const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, ''); - -/** - * Add plugin identifier as translation message prefix, - * in order to avoid confusion and errors when many - * plugins are installed. - * - * @param messages - */ -const formatMessages = messages => - reduce( - messages, - (result, value, key) => { - result[`${pluginId}.${key}`] = value; - - return result; - }, - {} - ); - -/** - * Try to require translation file. - * - * @param language {String} - */ -const requireTranslations = language => { - try { - return require(`translations/${language}.json`); // eslint-disable-line global-require - } catch (error) { - console.error( - `Unable to load "${language}" translation for the plugin ${pluginId}. Please make sure "${language}.json" file exists in "pluginPath/admin/src/translations" folder.` - ); - } -}; - -/** - * Dynamically generate `translationsMessages object`. - */ - -const translationMessages = reduce( - strapi.languages, - (result, language) => { - result[language] = formatMessages(requireTranslations(language)); - - return result; - }, - {} -); - -export { translationMessages }; diff --git a/packages/strapi-helper-plugin/lib/src/index.js b/packages/strapi-helper-plugin/lib/src/index.js index dfbd64e8bb..6caddf684e 100644 --- a/packages/strapi-helper-plugin/lib/src/index.js +++ b/packages/strapi-helper-plugin/lib/src/index.js @@ -11,6 +11,7 @@ export { default as BaselineAlignement } from './components/BaselineAlignement'; export { default as BlockerComponent } from './components/BlockerComponent'; export { default as Button } from './components/Button'; export { default as ButtonModal } from './components/ButtonModal'; +export { default as Carret } from './components/Carret'; export { default as CircleButton } from './components/CircleButton'; export { default as ContainerFluid } from './components/ContainerFluid'; export { default as ErrorBoundary } from './components/ErrorBoundary'; diff --git a/packages/strapi-helper-plugin/lib/src/public-path.js b/packages/strapi-helper-plugin/lib/src/public-path.js deleted file mode 100644 index 518a786b87..0000000000 --- a/packages/strapi-helper-plugin/lib/src/public-path.js +++ /dev/null @@ -1,13 +0,0 @@ -// const pluginPkg = require('../../../../package.json'); -// const pluginId = pluginPkg.name.replace(/^strapi-plugin-/i, ''); -// const publicPath = `plugins/${pluginId}/`; - -// __webpack_public_path__ = (() => { -// if (window.location.port === '4000') { -// return `${window.location.origin}/`; -// } else if (strapi.mode === 'backend') { -// return `${strapi.backendURL}/${publicPath}`; -// } - -// return `${(strapi.remoteURL).replace(window.location.origin, '')}/${publicPath}`; -// })(); diff --git a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Arrow.js b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Arrow.js index 7adc6708e3..a85862cd3a 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Arrow.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Arrow.js @@ -8,7 +8,6 @@ const Arrow = styled(({ isUp, ...rest }) => )` isUp && ` transform: rotateZ(180deg); - `} `; diff --git a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Header.js b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Header.js index 293656820e..3f8bdf359f 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Header.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/CustomTable/Headers/Header.js @@ -1,8 +1,7 @@ import React, { memo } from 'react'; import PropTypes from 'prop-types'; -import { useGlobalContext } from 'strapi-helper-plugin'; +import { Carret, useGlobalContext } from 'strapi-helper-plugin'; import { useListView } from '../../../hooks'; -import Arrow from './Arrow'; const Header = ({ fieldSchema: { type }, metadatas: { label, sortable, mainField }, name }) => { const { _sort, firstSortableHeader, setQuery } = useListView(); @@ -37,7 +36,7 @@ const Header = ({ fieldSchema: { type }, metadatas: { label, sortable, mainField {label} - {sortBy === sortField && } + {sortBy === sortField && } ); diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/ListView/FieldPicker/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/ListView/FieldPicker/index.js index a68b17eb84..ebd09e7017 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/ListView/FieldPicker/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/ListView/FieldPicker/index.js @@ -1,8 +1,8 @@ import React, { memo } from 'react'; import PropTypes from 'prop-types'; import { Flex, Padded, Picker } from '@buffetjs/core'; -import { Carret } from '@buffetjs/icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { Carret } from 'strapi-helper-plugin'; import Fields from './Fields'; import Header from './Header'; import Wrapper from './Wrapper'; @@ -19,7 +19,7 @@ const FieldPicker = ({ displayedHeaders, items, onChange, onClickReset, slug }) - + )}