Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/better-chefs-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: make sure the 'path' parameter from the router endoint doesn't end up on the document service query params
6 changes: 6 additions & 0 deletions .changeset/calm-moments-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"webtools-addon-sitemap": minor
"docs": minor
---

refactor: replace the auto-generate lifecycle methods with a document service middleware
6 changes: 6 additions & 0 deletions .changeset/floppy-swans-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"webtools-addon-sitemap": patch
"strapi-plugin-webtools": patch
---

fix: make the header button(s) smaller to align with the rest of the admin panel
5 changes: 5 additions & 0 deletions .changeset/lazy-news-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webtools-addon-sitemap": patch
---

fix: the 'go to settings' button by making the tab state controlled through URL params
5 changes: 5 additions & 0 deletions .changeset/lazy-sides-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": minor
---

feat: enhance the URL alias overview (locale filters & locale and contenttype in the table)
5 changes: 5 additions & 0 deletions .changeset/quiet-beans-stay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"strapi-plugin-webtools": patch
---

fix: issue with pagination when simulteously using the filter options
5 changes: 5 additions & 0 deletions .changeset/thin-knives-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webtools-addon-sitemap": patch
---

fix: fallback translation for the sitemap index info in the admin panel
5 changes: 5 additions & 0 deletions .changeset/tidy-numbers-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"webtools-addon-sitemap": patch
---

fix: issue with the lastmod date for localized documents
2 changes: 0 additions & 2 deletions packages/addons/sitemap/admin/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const Header = () => {
<Button
onClick={handleCancel}
disabled={disabled}
size="L"
variant="secondary"
>
{formatMessage({ id: 'sitemap.Button.Cancel', defaultMessage: 'Cancel' })}
Expand All @@ -49,7 +48,6 @@ const Header = () => {
disabled={disabled}
type="submit"
startIcon={<Check />}
size="L"
>
{formatMessage({ id: 'sitemap.Button.Save', defaultMessage: 'Save' })}
</Button>
Expand Down
11 changes: 7 additions & 4 deletions packages/addons/sitemap/admin/components/Info/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import React from 'react';
import { Map } from 'immutable';
import { useIntl } from 'react-intl';
import { useSelector, useDispatch } from 'react-redux';
import { useSearchParams } from 'react-router-dom';

import { getFetchClient, useNotification } from '@strapi/strapi/admin';
import {
Typography,
Box,
Button,
Link,
Flex,
} from '@strapi/design-system';

import { generateSitemap } from '../../state/actions/Sitemap';
Expand All @@ -18,6 +20,7 @@ import { formatTime } from '../../helpers/timeFormat';
const Info = () => {
const hasHostname = useSelector((state) => state.getIn(['sitemap', 'initialData', 'hostname'], Map()));
const sitemapInfo = useSelector((state) => state.getIn(['sitemap', 'info'], Map()));
let [, setSearchParams] = useSearchParams();
const dispatch = useDispatch();
const { toggleNotification } = useNotification();
const { get } = getFetchClient();
Expand All @@ -38,21 +41,21 @@ const Info = () => {
<Typography variant="delta" style={{ marginBottom: '10px' }}>
{formatMessage({ id: 'sitemap.Info.NoHostname.Title', defaultMessage: 'Set your hostname' })}
</Typography>
<div>
<Flex direction="column" alignItems="flex-start">
<Typography variant="omega">
{formatMessage({ id: 'sitemap.Info.NoHostname.Description', defaultMessage: 'Before you can generate the sitemap you have to specify the hostname of your website.' })}
</Typography>
<Button
onClick={() => {
document.getElementById('tabs-2-tab').click();
setSearchParams({ tab: 'settings' });
setTimeout(() => (document.querySelector('input[name="hostname"]')).focus(), 0);
}}
variant="secondary"
style={{ marginTop: '15px' }}
>
{formatMessage({ id: 'sitemap.Header.Button.GoToSettings', defaultMessage: 'Go to settings' })}
</Button>
</div>
</Flex>
</div>
);
}
Expand Down Expand Up @@ -104,7 +107,7 @@ const Info = () => {
) : (
<div style={{ marginBottom: '15px' }}>
<Typography variant="omega">
{formatMessage({ id: 'sitemap.Info.SitemapIsPresent.AmountOfSitemaps', defaultMessage: 'Amount of URLs:' })}
{formatMessage({ id: 'sitemap.Info.SitemapIsPresent.AmountOfSitemaps', defaultMessage: 'Amount of Sitemaps:' })}
</Typography>
<Typography variant="omega" fontWeight="bold" style={{ marginLeft: '5px' }}>
{sitemapInfo.get('sitemaps')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const CollectionForm = (props) => {
onCheckedChange={(cbValue) => {
onChange(uid, langcode, 'includeLastmod', cbValue);
}}
value={modifiedState.getIn([uid, 'languages', langcode, 'includeLastmod'], true)}
checked={modifiedState.getIn([uid, 'languages', langcode, 'includeLastmod'], true)}
disabled={
!uid || (getSelectedContentType(contentTypes, uid).locales && !langcode)
}
Expand Down
10 changes: 9 additions & 1 deletion packages/addons/sitemap/admin/components/Tabs/index.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import React from 'react';
import { Tabs, Box } from '@strapi/design-system';
import { useIntl } from 'react-intl';
import { useSearchParams } from 'react-router-dom';

import CollectionURLs from '../../tabs/CollectionURLs';
import CustomURLs from '../../tabs/CustomURLs';
import Settings from '../../tabs/Settings';

const SitemapTabs = () => {
const { formatMessage } = useIntl();
let [searchParams, setSearchParams] = useSearchParams();

return (
<Box padding={8}>
<Tabs.Root id="tabs" defaultValue="url-bundles">
<Tabs.Root
id="tabs"
value={searchParams.get('tab') || 'url-bundles'}
onValueChange={(newValue) => {
setSearchParams({ tab: newValue });
}}
>
<Tabs.List>
<Tabs.Trigger value="url-bundles">{formatMessage({ id: 'sitemap.Settings.CollectionTitle', defaultMessage: 'URL bundles' })}</Tabs.Trigger>
<Tabs.Trigger value="custom-urls">{formatMessage({ id: 'sitemap.Settings.CustomTitle', defaultMessage: 'Custom URLs' })}</Tabs.Trigger>
Expand Down
3 changes: 0 additions & 3 deletions packages/addons/sitemap/server/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { getPluginService } from './utils/getPluginService';

export default async () => {
const sitemap = strapi.plugin('webtools-addon-sitemap');

Check warning on line 5 in packages/addons/sitemap/server/bootstrap.js

View workflow job for this annotation

GitHub Actions / lint (18)

'sitemap' is assigned a value but never used

Check warning on line 5 in packages/addons/sitemap/server/bootstrap.js

View workflow job for this annotation

GitHub Actions / lint (20)

'sitemap' is assigned a value but never used
const cron = strapi.config.get('plugin::webtools-addon-sitemap.cron');

try {
Expand Down Expand Up @@ -37,9 +37,6 @@
}
}

// Load lifecycle methods for auto generation of sitemap.
await sitemap.service('lifecycle').loadAllLifecycleMethods();

// Register permission actions.
const actions = [
{
Expand Down
8 changes: 0 additions & 8 deletions packages/addons/sitemap/server/controllers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ export default {
},

updateSettings: async (ctx) => {
const config = await getPluginService('settings').getConfig();
const newContentTypes = Object.keys(ctx.request.body.contentTypes).filter((x) => !Object.keys(config.contentTypes).includes(x));

await strapi
.store({
environment: '',
Expand All @@ -27,11 +24,6 @@ export default {
})
.set({ key: 'settings', value: ctx.request.body });

// Load lifecycle methods for auto generation of sitemap.
await newContentTypes.map(async (contentType) => {
await getPluginService('lifecycle').loadLifecycleMethod(contentType);
});

ctx.send({ ok: true });
},
};
34 changes: 34 additions & 0 deletions packages/addons/sitemap/server/middlewares/auto-generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getPluginService } from '../utils/getPluginService';

// eslint-disable-next-line max-len
const autoGenerateMiddleware = async (context, next) => {
const { uid, action } = context;

// Only add the middleware if auto-generate is enabled.
if (!strapi.config.get('plugin::webtools-addon-sitemap.autoGenerate')) {
return next();
}

const settings = await getPluginService('settings').getConfig();

// Only add the middleware if the content type is added to the sitemap.
if (!settings.contentTypes || !Object.keys(settings.contentTypes).includes(uid)) {
return next();
}

// Only add the middleware for the create, update and delete action.
if (!['create', 'update', 'delete'].includes(action)) {
return next();
}

// Perform the action.
const document = await next();

// Generate the sitemap.
getPluginService('core').createSitemap();

// Return the document
return document;
};

export default autoGenerateMiddleware;
2 changes: 2 additions & 0 deletions packages/addons/sitemap/server/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import _ from 'lodash';
import { isContentTypeEnabled } from './utils/enabledContentTypes';
import autoGenerateMiddleware from './middlewares/auto-generate';

/**
* Adds sitemap_exclude field to all the eligable content types.
Expand Down Expand Up @@ -30,5 +31,6 @@ const extendContentTypesWithExcludeField = async (strapi) => {
};

export default ({ strapi }) => {
strapi.documents.use(autoGenerateMiddleware);
extendContentTypesWithExcludeField(strapi);
};
2 changes: 0 additions & 2 deletions packages/addons/sitemap/server/services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import query from './query';
import core from './core';
import settings from './settings';
import lifecycle from './lifecycle';

export default {
query,
core,
settings,
lifecycle,
};
63 changes: 0 additions & 63 deletions packages/addons/sitemap/server/services/lifecycle.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/addons/sitemap/server/services/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ const getPages = async (config, contentType, ids) => {
} : {},
},
...(isLocalized ? { locale: locale.code } : {}),
fields: isLocalized ? 'locale' : undefined,
fields: isLocalized ? ['locale', 'updatedAt'] : ['updatedAt'],
populate: {
url_alias: {
populate: '*',
},
localizations: {
fields: isLocalized ? 'locale' : undefined,
fields: isLocalized ? ['locale', 'updatedAt'] : ['updatedAt'],
filters: {
$or: [
{
Expand Down
22 changes: 12 additions & 10 deletions packages/core/admin/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ const useQueryParams = () => {
const searchParams = new URLSearchParams(location.search);
const page = searchParams.get('page');
const pageSize = searchParams.get('pageSize');
searchParams.delete('page');
searchParams.delete('pageSize');

if (page || pageSize) {
if (page) {
searchParams.delete('page');
searchParams.append('pagination[page]', page);
}

if (pageSize) {
searchParams.delete('pageSize');
searchParams.append('pagination[pageSize]', pageSize);
}
if (!page && !pageSize) {
searchParams.append('pagination[page]', '1');
searchParams.append('pagination[pageSize]', '10');
}

setParams(searchParams.toString());
if (page && pageSize) {
searchParams.append('pagination[page]', page);
searchParams.append('pagination[pageSize]', pageSize);
}

setParams(searchParams.toString());
}, [location]);


return params;
};

Expand Down
Loading