Skip to content

Commit ca38f30

Browse files
authored
Merge pull request #32 from jackbuehner/main
feat: support strapi v5
2 parents 2d73dfe + ad6d11e commit ca38f30

12 files changed

Lines changed: 21925 additions & 76 deletions

File tree

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# dependencies
2+
node_modules
3+
4+
# misc
5+
.DS_Store
6+
7+
# debug
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# build
13+
/admin/dist

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/admin/source
2+
doc
3+
./.*
4+
rollup.config.mjs

admin/src/components/DuplicateButton/index.js

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { LinkButton } from "@strapi/design-system";
2+
import { Duplicate } from "@strapi/icons";
3+
import React from "react";
4+
import { useIntl } from "react-intl";
5+
import { useLocation, useNavigate, useParams } from "react-router-dom";
6+
7+
const DuplicateButton = () => {
8+
const { id: documentId, slug: modelUID, collectionType } = useParams();
9+
const isSingleType = collectionType === "single-types";
10+
11+
const { formatMessage } = useIntl();
12+
13+
const content = {
14+
id: "duplicate-button.components.duplicate.button",
15+
defaultMessage: "Duplicate",
16+
};
17+
18+
const navigate = useNavigate();
19+
const { pathname, search } = useLocation();
20+
const goToCloneRoute = (evt) => {
21+
evt.preventDefault();
22+
navigate(pathname.replace(modelUID, `${modelUID}/clone`) + search);
23+
};
24+
25+
if (isSingleType || !documentId || !modelUID) return null;
26+
if (documentId === "create" || documentId === "clone") return null;
27+
return (
28+
<>
29+
{window && window.location ? (
30+
<LinkButton
31+
href={
32+
// we use `window.location` here because strapi has set a
33+
// base path in the admin panel and `pathname` from `useLocation()`
34+
// does not include the base path
35+
window.location.href.replace(modelUID, `${modelUID}/clone`) + search
36+
}
37+
variant="secondary"
38+
style={{ width: "100%" }}
39+
startIcon={<Duplicate />}
40+
onClick={goToCloneRoute}
41+
>
42+
{formatMessage(content)}
43+
</LinkButton>
44+
) : null}
45+
</>
46+
);
47+
};
48+
49+
export default DuplicateButton;

admin/src/components/Initializer/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
/**
2-
* Initializer
3-
*/
4-
5-
import { useEffect, useRef } from 'react';
6-
import PropTypes from 'prop-types';
7-
import pluginId from '../../pluginId';
1+
import PropTypes from "prop-types";
2+
import { useEffect, useRef } from "react";
3+
import pluginId from "../../pluginId";
84

95
const Initializer = ({ setPlugin }) => {
106
const ref = useRef();

admin/src/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { prefixPluginTranslations } from '@strapi/helper-plugin';
2-
import pluginPkg from '../../package.json';
3-
import pluginId from './pluginId';
4-
import Initializer from './components/Initializer';
5-
import DuplicateButton from './components/DuplicateButton'
1+
import pluginPkg from "../../package.json";
2+
import DuplicateButton from "./components/DuplicateButton";
3+
import Initializer from "./components/Initializer";
4+
import pluginId from "./pluginId";
5+
import prefixPluginTranslations from "./prefixPluginTranslations";
66

77
const name = pluginPkg.strapi.name;
88

@@ -17,14 +17,16 @@ export default {
1717
},
1818

1919
bootstrap(app) {
20-
app.injectContentManagerComponent('editView', 'right-links', {
21-
name: 'DuplicateButton',
22-
Component: DuplicateButton,
23-
});
20+
app
21+
.getPlugin("content-manager")
22+
.injectComponent("editView", "right-links", {
23+
name: pluginId,
24+
Component: DuplicateButton,
25+
});
2426
},
2527
async registerTrads({ locales }) {
2628
const importedTrads = await Promise.all(
27-
locales.map(locale => {
29+
locales.map((locale) => {
2830
return import(`./translations/${locale}.json`)
2931
.then(({ default: data }) => {
3032
return {

admin/src/pluginId.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
const pluginPkg = require('../../package.json');
1+
import pluginPkg from "../../package.json";
22

3-
const pluginId = pluginPkg.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i, '');
3+
const pluginId = pluginPkg.name.replace(
4+
/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i,
5+
""
6+
);
47

5-
module.exports = pluginId;
8+
export default pluginId;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const prefixPluginTranslations = (trad, pluginId) => {
2+
if (!pluginId) {
3+
throw new TypeError("pluginId can't be empty");
4+
}
5+
6+
return Object.keys(trad).reduce((acc, current) => {
7+
acc[`${pluginId}.${current}`] = trad[current];
8+
9+
return acc;
10+
}, {});
11+
};
12+
13+
export default prefixPluginTranslations;

0 commit comments

Comments
 (0)