Skip to content
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

Chore/legacy support #19

Merged
merged 3 commits into from
Oct 26, 2023
Merged
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
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions config/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default ({ env }) => {
resolve: './src/plugins/strapi-plugin-internal-links',
config: {
environment: 'test',
useSinglePageType: 'api::page.page',
pageBuilder: {
enabled: false
},
Expand Down
1 change: 1 addition & 0 deletions src/plugins/strapi-plugin-internal-links/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = ({ env }) => ({
enabled: true,
config: {
environment: 'test',
useSinglePageType: 'api::page.page', // Optional option to use a single page type like the page builder (without page builder options)
pageBuilder: {
enabled: true, // When enabled, pageBuilder plugin logic is applied.
pageUid: 'undefined | string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ interface IProps extends Omit<IUseInternalLinkInputReturn, 'initialLink' | 'isIn

const InternalLinkForm = ({ link, setLink, errors, setErrors, attribute }: IProps): JSX.Element => {
const { formatMessage } = useIntl();

const { config: pluginConfig, isLoading: isLoadingConfig } = useGetPluginConfig();

const useSinglePageType = !!pluginConfig?.useSinglePageType || pluginConfig?.pageBuilder?.enabled;

// More information including tests: https://regexr.com/7b2ai
const defaultUrlRegex = new RegExp(
/(^https?:\/\/(www.)?[a-zA-Z0-9]{1,}.[^s]{2,}((\/[a-zA-Z0-9\-\_\=\?\%\&\#]{1,}){1,})?)$|^mailto:[\w-\. +]+@([\w-]+\.)+[\w-]{2,4}$|^tel:((\+|00(\s|\s?\-\s?)?)[0-9]{2}(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[0-9](((\s|\s?\-\s?)?[0-9]){1,})$/
Expand Down Expand Up @@ -59,8 +60,8 @@ const InternalLinkForm = ({ link, setLink, errors, setErrors, attribute }: IProp
};

useEffect(() => {
if (pluginConfig?.pageBuilder?.enabled) {
setContentTypeUid(pluginConfig.pageBuilder.pageUid);
if (pluginConfig && useSinglePageType) {
setContentTypeUid(pluginConfig.pageBuilder?.pageUid || pluginConfig.useSinglePageType);
}
}, [pluginConfig]);

Expand Down Expand Up @@ -237,7 +238,7 @@ const InternalLinkForm = ({ link, setLink, errors, setErrors, attribute }: IProp
<FieldError />
</Field>

{!checked && !isLoadingConfig && !pluginConfig?.pageBuilder?.enabled && (
{!checked && !isLoadingConfig && !useSinglePageType && (
<Field required>
<FieldLabel>
{formatMessage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const find = async () => {
const { pageBuilder } = await strapi.service('plugin::internal-links.config').getGlobalConfig();
const pageBuilderPathField = pageBuilder?.pathField;

// TODO: Should we check the useSinglePageType option here?
const filter = Object.values(strapi.contentTypes).filter((contentType: any) => {
if (contentType?.pluginOptions?.['internal-links']?.enabled === false) {
return false;
Expand Down
Loading