Skip to content

Feature/new addons #249

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-apes-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": minor
---

feat: allow addons to register a route without a nav item
5 changes: 5 additions & 0 deletions .changeset/plenty-pillows-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"docs": minor
---

Initial documentation for the redirects addon
5 changes: 5 additions & 0 deletions .changeset/rich-meals-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webtools-addon-redirects": major
---

Initial release of Webtools Redirects addon
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ The full documentation of this plugin can be found on it's dedicated documentati

- [Webtools core plugin](https://docs.pluginpal.io/webtools)
- [Webtools sitemap addon](https://docs.pluginpal.io/webtools/addons/sitemap)

- [Webtools redirects addon](https://docs.pluginpal.io/webtools/addons/redirects)

## 🔌 Addons

Expand Down
4 changes: 2 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = defineConfig({
require('cypress-terminal-report/src/installLogsPrinter')(on);
},
video: true,
defaultCommandTimeout: 10000,
requestTimeout: 10000,
defaultCommandTimeout: 30000,
requestTimeout: 30000,
},
});
71 changes: 71 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//

Cypress.Commands.add('login', (path) => {
cy.visit('/');

cy.intercept({
method: 'GET',
url: '/admin/users/me',
}).as('sessionCheck');

cy.intercept({
method: 'GET',
url: '/admin/init',
}).as('adminInit');

// Wait for the initial request to complete.
cy.wait('@adminInit').its('response.statusCode').should('equal', 200);

// Wait for the form to render.
// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(1000);

cy.get('body').then(($body) => {
// Login
if ($body.text().includes('Log in to your Strapi account')) {
cy.get('input[name="email"]').type('johndoe@example.com');
cy.get('input[name="password"]').type('Abc12345678');
cy.get('button[type="submit"]').click();
cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200);
}
// Register
if ($body.text().includes('Credentials are only used to authenticate in Strapi')) {
cy.get('input[name="firstname"]').type('John');
cy.get('input[name="email"]').type('johndoe@example.com');
cy.get('input[name="password"]').type('Abc12345678');
cy.get('input[name="confirmPassword"]').type('Abc12345678');
cy.get('button[type="submit"]').click();
cy.wait('@sessionCheck').its('response.statusCode').should('equal', 200);
}
});
});

Cypress.Commands.add('navigateToAdminPage', (path) => {
cy.get('a[href="/admin/plugins/webtools"]').click();
});
27 changes: 0 additions & 27 deletions cypress/support/commands.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
"eslint:fix": "turbo run eslint:fix",
"release:publish": "turbo run build && changeset publish",
"release:prepare": "changeset version && YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install",
"playground:install": "cd playground && yarn dlx yalc add --link strapi-plugin-webtools webtools-addon-sitemap && yarn install",
"playground:install": "cd playground && yarn dlx yalc add --link strapi-plugin-webtools webtools-addon-sitemap webtools-addon-redirects && yarn install",
"playground:build": "cd playground && yarn build",
"playground:start": "cd playground && yarn start",
"playground:develop": "rm -rf playground/node_modules/.strapi/ && cd playground && yarn develop --watch-admin --bundler=vite",
"playground:develop:test": "cd playground && rm -rf .tmp/test.db && NODE_ENV=test yarn develop",
"docs:start": "cd packages/docs/ && yarn start",
"docs:build": "cd packages/docs/ && yarn build",
"test:e2e": "cypress open",
Expand Down
13 changes: 13 additions & 0 deletions packages/addons/links/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/node_modules
**/playground
**/public
**/build
**/dist
**/bundle
**/config
**/scripts
**/docs
**/types/generated
**/__tests__
strapi-admin.js
strapi-server.js
18 changes: 18 additions & 0 deletions packages/addons/links/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Don't check auto-generated stuff into git
coverage
node_modules
stats.json
package-lock.json

# Cruft
.DS_Store
npm-debug.log
.idea

# Strapi
.strapi-updater.json

# Production build
build
dist
bundle
6 changes: 6 additions & 0 deletions packages/addons/links/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ignore the .ts and .tsx files
*.ts
*.tsx

# include the .d.ts files
!*.d.ts
7 changes: 7 additions & 0 deletions packages/addons/links/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2024 PluginPal.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
77 changes: 77 additions & 0 deletions packages/addons/links/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<div align="center">
<h1>Webtools Links add-on</h1>

<p style="margin-top: 0;">Custom field for internal links in Strapi CMS.</p>

<a href="https://docs.pluginpal.io/webtools/addons/links">Read the documentation</a>

<p>
<a href="https://www.npmjs.org/package/webtools-addon-links">
<img src="https://img.shields.io/npm/v/webtools-addon-links/latest.svg" alt="NPM Version" />
</a>
<a href="https://www.npmjs.org/package/webtools-addon-links">
<img src="https://img.shields.io/npm/dm/webtools-addon-links" alt="Monthly download on NPM" />
</a>
<a href="https://codecov.io/gh/pluginpal/strapi-webtools">
<img src="https://img.shields.io/github/actions/workflow/status/pluginpal/strapi-webtools/tests.yml?branch=master" alt="CI build status" />
</a>
<a href="https://codecov.io/gh/pluginpal/strapi-webtools">
<img src="https://codecov.io/gh/pluginpal/strapi-webtools/coverage.svg?branch=master" alt="codecov.io" />
</a>
</p>

</div>

## ✨ Features

[TODO]

## ⏳ Installation

[Read the Getting Started tutorial](https://docs.pluginpal.io/webtools/addons/links) or follow the steps below:

```bash
# using yarn
yarn add webtools-addon-links

# using npm
npm install webtools-addon-links --save
```

After successful installation you have to rebuild the admin UI so it'll include this plugin. To rebuild and restart Strapi run:

```bash
# using yarn
yarn build
yarn develop

# using npm
npm run build
npm run develop
```

Enjoy 🎉

## 📓 Documentation

- [Webtools Links add-on documentation](https://docs.pluginpal.io/webtools/addons/links)

## 🔌 Addons

Webtools can be extended by installing addons that hook into the core Webtools functionality. Read more about how addons work and how to install them in the [addons documentation](https://docs.pluginpal.io/webtools/addons).

## 🔗 Links

- [PluginPal marketplace](https://www.pluginpal.io/plugin/webtools)
- [NPM package](https://www.npmjs.com/package/webtools-addon-links)
- [GitHub repository](https://github.com/pluginpal/strapi-webtools)
- [Strapi marketplace](https://market.strapi.io/plugins/@pluginpal-webtools-core)

## 🌎 Community support

- For general help using Strapi, please refer to [the official Strapi documentation](https://strapi.io/documentation/).
- You can contact me on the Strapi Discord [channel](https://discord.strapi.io/).

## 📝 Resources

- [MIT License](https://github.com/pluginpal/strapi-webtools/blob/master/LICENSE.md)
11 changes: 11 additions & 0 deletions packages/addons/links/admin/components/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { Link } from '@strapi/icons';

const Icon = () => {
return (
// eslint-disable-next-line jsx-a11y/anchor-is-valid
<Link />
);
};

export default Icon;
35 changes: 35 additions & 0 deletions packages/addons/links/admin/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { InputProps, useField } from '@strapi/admin/strapi-admin';
import { Field, TextInput } from '@strapi/design-system';

Check warning on line 2 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

'TextInput' is defined but never used

Check warning on line 2 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (22)

'TextInput' is defined but never used
import * as React from 'react';

import { useIntl } from 'react-intl';

const Input = (props: InputProps) => {
const {
hint, disabled, labelAction, label, name, required,

Check warning on line 9 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

'labelAction' is assigned a value but never used

Check warning on line 9 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

'hint' is assigned a value but never used

Check warning on line 9 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (22)

'labelAction' is assigned a value but never used

Check warning on line 9 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (22)

'hint' is assigned a value but never used
} = props; // these are just some of the props passed by the content-manager
const field = useField(name);

const { formatMessage } = useIntl();

Check warning on line 13 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

'formatMessage' is assigned a value but never used

Check warning on line 13 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (22)

'formatMessage' is assigned a value but never used

const handleChange = (e) => {
field.onChange(name, e.target.value);

Check warning on line 16 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .target on an `any` value

Check warning on line 16 in packages/addons/links/admin/components/Input/index.tsx

View workflow job for this annotation

GitHub Actions / lint (22)

Unsafe member access .target on an `any` value
};

console.log(label);

return (
// eslint-disable-next-line jsx-a11y/label-has-associated-control
<Field.Root
name={name}
aria-disabled={disabled}
onChange={handleChange}
required={required}
>
<Field.Label>{label}</Field.Label>
<Field.Input />
</Field.Root>
);
};

export default Input;
30 changes: 30 additions & 0 deletions packages/addons/links/admin/helpers/displayedFilters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const displayedFilters = [
{
name: 'createdAt',
fieldSchema: {
type: 'date',
},
metadatas: { label: 'createdAt' },
},
{
name: 'updatedAt',
fieldSchema: {
type: 'date',
},
metadatas: { label: 'updatedAt' },
},
{
name: 'mime',
fieldSchema: {
type: 'enumeration',
options: [
{ label: 'image', value: 'image' },
{ label: 'video', value: 'video' },
{ label: 'file', value: 'file' },
],
},
metadatas: { label: 'type' },
},
];

export default displayedFilters;
5 changes: 5 additions & 0 deletions packages/addons/links/admin/helpers/getTrad.ts
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;
10 changes: 10 additions & 0 deletions packages/addons/links/admin/helpers/pluginId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pluginPkg from '../../package.json';

/**
* A helper function to obtain the plugin id.
*
* @return {string} The plugin id.
*/
const pluginId: string = pluginPkg.strapi.name;

export default pluginId;
11 changes: 11 additions & 0 deletions packages/addons/links/admin/helpers/prefixPluginTranslations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const prefixPluginTranslations = (trad, pluginId) => {
if (!pluginId) {
throw new TypeError('pluginId can not be empty');
}
return Object.keys(trad).reduce((acc, current) => {
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};

export { prefixPluginTranslations };
Loading
Loading