-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from beckn/energy-plugin
Added ptop-energy plugin
- Loading branch information
Showing
33 changed files
with
4,414 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Strapi plugin ptop-energy | ||
|
||
A quick description of ptop-energy. |
24 changes: 24 additions & 0 deletions
24
plugins/ptop-energy/admin/src/components/Initializer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* | ||
* Initializer | ||
* | ||
*/ | ||
|
||
import { useEffect, useRef } from 'react'; | ||
import pluginId from '../../pluginId'; | ||
|
||
type InitializerProps = { | ||
setPlugin: (id: string) => void; | ||
}; | ||
|
||
const Initializer = ({ setPlugin }: InitializerProps) => { | ||
const ref = useRef(setPlugin); | ||
|
||
useEffect(() => { | ||
ref.current(pluginId); | ||
}, []); | ||
|
||
return null; | ||
}; | ||
|
||
export default Initializer; |
12 changes: 12 additions & 0 deletions
12
plugins/ptop-energy/admin/src/components/PluginIcon/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* | ||
* PluginIcon | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Puzzle } from '@strapi/icons'; | ||
|
||
const PluginIcon = () => <Puzzle />; | ||
|
||
export default PluginIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { prefixPluginTranslations } from '@strapi/helper-plugin'; | ||
|
||
import pluginPkg from '../../package.json'; | ||
import pluginId from './pluginId'; | ||
import Initializer from './components/Initializer'; | ||
import PluginIcon from './components/PluginIcon'; | ||
|
||
const name = pluginPkg.strapi.name; | ||
|
||
export default { | ||
register(app: any) { | ||
app.addMenuLink({ | ||
to: `/plugins/${pluginId}`, | ||
icon: PluginIcon, | ||
intlLabel: { | ||
id: `${pluginId}.plugin.name`, | ||
defaultMessage: name, | ||
}, | ||
Component: async () => { | ||
const component = await import(/* webpackChunkName: "[request]" */ './pages/App'); | ||
|
||
return component; | ||
}, | ||
permissions: [ | ||
// Uncomment to set the permissions of the plugin here | ||
// { | ||
// action: '', // the action name should be plugin::plugin-name.actionType | ||
// subject: null, | ||
// }, | ||
], | ||
}); | ||
const plugin = { | ||
id: pluginId, | ||
initializer: Initializer, | ||
isReady: false, | ||
name, | ||
}; | ||
|
||
app.registerPlugin(plugin); | ||
}, | ||
|
||
bootstrap(app: any) {}, | ||
|
||
async registerTrads(app: any) { | ||
const { locales } = app; | ||
|
||
const importedTrads = await Promise.all( | ||
(locales as any[]).map((locale) => { | ||
return import(`./translations/${locale}.json`) | ||
.then(({ default: data }) => { | ||
return { | ||
data: prefixPluginTranslations(data, pluginId), | ||
locale, | ||
}; | ||
}) | ||
.catch(() => { | ||
return { | ||
data: {}, | ||
locale, | ||
}; | ||
}); | ||
}) | ||
); | ||
|
||
return Promise.resolve(importedTrads); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* | ||
* This component is the skeleton around the actual pages, and should only | ||
* contain code that should be seen on all pages. (e.g. navigation bar) | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Switch, Route } from 'react-router-dom'; | ||
import { AnErrorOccurred } from '@strapi/helper-plugin'; | ||
import pluginId from '../../pluginId'; | ||
import HomePage from '../HomePage'; | ||
|
||
const App = () => { | ||
return ( | ||
<div> | ||
<Switch> | ||
<Route path={`/plugins/${pluginId}`} component={HomePage} exact /> | ||
<Route component={AnErrorOccurred} /> | ||
</Switch> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* | ||
* HomePage | ||
* | ||
*/ | ||
|
||
import React from 'react'; | ||
import pluginId from '../../pluginId'; | ||
|
||
const HomePage = () => { | ||
return ( | ||
<div> | ||
<h1>{pluginId}'s HomePage</h1> | ||
<p>Happy coding</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default HomePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pluginPkg from '../../package.json'; | ||
|
||
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, ''); | ||
|
||
export default pluginId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import pluginId from '../pluginId'; | ||
|
||
const getTrad = (id: string) => `${pluginId}.${id}`; | ||
|
||
export default getTrad; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module '@strapi/design-system/*'; | ||
declare module '@strapi/design-system'; | ||
declare module '@strapi/icons'; | ||
declare module '@strapi/icons/*'; | ||
declare module '@strapi/helper-plugin'; |
Oops, something went wrong.