Skip to content

Commit

Permalink
Merge pull request #19 from webbio/chore/legacy-support
Browse files Browse the repository at this point in the history
Chore/legacy support
  • Loading branch information
MaikaiMa authored Oct 26, 2023
2 parents dad4400 + 87b93b7 commit 3fa4a9a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
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

0 comments on commit 3fa4a9a

Please sign in to comment.