Skip to content

Commit b3b92ec

Browse files
authored
Merge pull request #296 from jorrit/bulkgenfixes
Show spinner when bulk generating aliases
2 parents ce025a4 + 0dfc272 commit b3b92ec

File tree

8 files changed

+24
-22
lines changed

8 files changed

+24
-22
lines changed

.changeset/happy-zoos-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"strapi-plugin-webtools": patch
3+
---
4+
5+
show spinner when bulk generating aliases

packages/core/admin/containers/App/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const App = () => {
8585
<Route path="/patterns/new" element={<PatternsCreatePage />} />
8686
<Route path="/patterns/:id" element={<PatternsEditPage />} />
8787
{routerComponents.map(({ path, Component }) => (
88-
<Route path={path} element={<Component />} />
88+
<Route key={path} path={path} element={<Component />} />
8989
))}
9090

9191
<Route path="*" element={<PageNotFound />} />

packages/core/admin/screens/List/components/GeneratePathsModal/index.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const GeneratePathsModal = ({
2525
contentTypes,
2626
children,
2727
}: Props) => {
28-
const [open, setOpen] = React.useState<boolean>();
28+
const [open, setOpen] = React.useState<boolean>(false);
29+
const [submitting, setSubmitting] = React.useState<boolean>(false);
2930
const { formatMessage } = useIntl();
3031
const [selectedContentTypes, setSelectedContentTypes] = React.useState<EnabledContentType['uid'][]>([]);
3132
const [selectedGenerationType, setSelectedGenerationType] = React.useState<GenerationType>();
@@ -62,6 +63,7 @@ const GeneratePathsModal = ({
6263
<Flex direction="column" alignItems="start" gap="1" marginTop="2">
6364
{contentTypes.map((contentType) => (
6465
<Checkbox
66+
key={contentType.uid}
6567
aria-label={`Select ${contentType.name}`}
6668
checked={selectedContentTypes.includes(contentType.uid)}
6769
onCheckedChange={() => {
@@ -134,13 +136,19 @@ const GeneratePathsModal = ({
134136
<Button
135137
// eslint-disable-next-line @typescript-eslint/no-misused-promises
136138
onClick={async () => {
137-
await onSubmit(selectedContentTypes, selectedGenerationType);
138-
setOpen(false);
139+
try {
140+
setSubmitting(true);
141+
await onSubmit(selectedContentTypes, selectedGenerationType);
142+
setOpen(false);
143+
} finally {
144+
setSubmitting(false);
145+
}
139146
}}
147+
loading={submitting}
140148
>
141149
{formatMessage({
142150
id: 'webtools.settings.button.generate_paths',
143-
defaultMessage: 'Generate paths',
151+
defaultMessage: 'Bulk generate',
144152
})}
145153
</Button>
146154
</Modal.Footer>

packages/core/admin/screens/List/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const List = () => {
8585
<Button>
8686
{formatMessage({
8787
id: 'webtools.settings.button.generate_paths',
88-
defaultMessage: 'Generate paths',
88+
defaultMessage: 'Bulk generate',
8989
})}
9090
</Button>
9191
</GeneratePathsModal>

packages/core/admin/screens/Overview/components/ContentTypesList/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ContentTypesList = (props: Props) => {
5353
</Thead>
5454
<Tbody>
5555
{contentTypes.map((contenttype) => (
56-
<Tr>
56+
<Tr key={contenttype.uid}>
5757
<Td width="50%">
5858
<Typography>{contenttype.name}</Typography>
5959
</Td>

packages/core/admin/screens/Overview/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ const List = () => {
156156
width: '240px',
157157
}}
158158
id="fourth"
159+
key={addon.info.name}
159160
>
160161
<CardBody>
161162
<Box padding={2} background="primary100">

packages/core/server/services/bulk-generate.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ const generateUrlAliases = async (params: GenerateParams): Promise<number> => {
3535
}
3636

3737
let relations: string[] = [];
38-
let languages: string[] = [undefined];
3938

40-
languages = [];
4139
const locales = await strapi.documents('plugin::i18n.locale').findMany({});
42-
languages = locales.map((locale) => locale.code);
40+
const languages = locales.map((locale) => locale.code);
4341

4442
// Get all relations for the type
4543
await Promise.all(languages.map(async (lang) => {
Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
import get from 'lodash/get';
22
import { Schema } from '@strapi/strapi';
33

4-
import { pluginId } from './pluginId';
5-
6-
export const isContentTypeEnabled = (ct: Schema.ContentType) => {
7-
let contentType: Schema.ContentType;
8-
9-
if (typeof ct === 'string') {
10-
contentType = strapi.contentTypes[ct];
11-
} else {
12-
contentType = ct;
13-
}
144

5+
export const isContentTypeEnabled = (contentType: Schema.ContentType) => {
156
const { pluginOptions } = contentType;
16-
17-
return get(pluginOptions, [pluginId, 'enabled'], false) as boolean;
7+
return get(pluginOptions, ['webtools', 'enabled'], false) as boolean;
188
};

0 commit comments

Comments
 (0)