Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cm): convert recursive layouts to TS (#18983)
- Loading branch information
1 parent
327b3dc
commit 2951783
Showing
18 changed files
with
393 additions
and
371 deletions.
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
packages/core/admin/admin/src/content-manager/contexts/ContentTypeLayout.jsx
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/core/admin/admin/src/content-manager/contexts/Wysiwyg.jsx
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
packages/core/admin/admin/src/content-manager/contexts/index.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export { useKeyboardDragAndDrop } from './useKeyboardDragAndDrop'; | ||
export { default as usePluginsQueryParams } from './usePluginsQueryParams'; | ||
export { default as useWysiwyg } from './useWysiwyg'; |
7 changes: 0 additions & 7 deletions
7
packages/core/admin/admin/src/content-manager/hooks/useWysiwyg.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/core/admin/admin/src/content-manager/pages/CollectionTypeRecursivePath.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import * as React from 'react'; | ||
|
||
import { Box } from '@strapi/design-system'; | ||
import { CheckPagePermissions, LoadingIndicatorPage, AnErrorOccurred } from '@strapi/helper-plugin'; | ||
import { ErrorBoundary } from 'react-error-boundary'; | ||
import { Route, RouteComponentProps, Switch } from 'react-router-dom'; | ||
|
||
import { useTypedSelector } from '../../core/store/hooks'; | ||
import { useFetchContentTypeLayout } from '../hooks/useFetchContentTypeLayout'; | ||
import { | ||
SettingsViewComponentLayout, | ||
SettingsViewContentTypeLayout, | ||
formatLayoutForSettingsView, | ||
} from '../utils/layouts'; | ||
|
||
// @ts-expect-error – This will be done in CONTENT-1952 | ||
import EditSettingsView from './EditSettingsView'; | ||
import { EditViewLayoutManager } from './EditViewLayoutManager'; | ||
// @ts-expect-error – This will be done in CONTENT-1953 | ||
import { ListSettingsView } from './ListSettingsView'; | ||
// @ts-expect-error – This will be done in CONTENT-1945 | ||
import ListViewLayout from './ListViewLayoutManager'; | ||
|
||
interface CollectionTypeRecursivePathProps extends RouteComponentProps<{ slug: string }> {} | ||
|
||
const CollectionTypeRecursivePath = ({ | ||
match: { | ||
params: { slug }, | ||
url, | ||
}, | ||
}: CollectionTypeRecursivePathProps) => { | ||
const permissions = useTypedSelector((state) => state.admin_app.permissions); | ||
const { isLoading, layout, updateLayout } = useFetchContentTypeLayout(slug); | ||
|
||
const { rawContentTypeLayout, rawComponentsLayouts } = React.useMemo(() => { | ||
let rawContentTypeLayout: SettingsViewContentTypeLayout | null = null; | ||
let rawComponentsLayouts: Record<string, SettingsViewComponentLayout> | null = null; | ||
|
||
if (layout?.contentType) { | ||
rawContentTypeLayout = formatLayoutForSettingsView(layout.contentType); | ||
} | ||
|
||
if (layout?.components) { | ||
rawComponentsLayouts = Object.keys(layout.components).reduce< | ||
Record<string, SettingsViewComponentLayout> | ||
>((acc, current) => { | ||
acc[current] = formatLayoutForSettingsView(layout.components[current]); | ||
|
||
return acc; | ||
}, {}); | ||
} | ||
|
||
return { rawContentTypeLayout, rawComponentsLayouts }; | ||
}, [layout]); | ||
|
||
const uid = layout?.contentType?.uid ?? null; | ||
|
||
// This statement is needed in order to prevent the CollectionTypeFormWrapper effects clean up phase to be run twice. | ||
// What can happen is that when navigating from one entry to another the cleanup phase of the fetch data effect is run twice : once when | ||
// unmounting, once when the url changes. | ||
// Since it can happen that the layout there's a delay when the layout is being fetched and the url changes adding the uid ! == slug | ||
// statement prevent the component from being mounted and unmounted twice. | ||
if (uid !== slug || isLoading || !layout) { | ||
return <LoadingIndicatorPage />; | ||
} | ||
|
||
return ( | ||
<ErrorBoundary | ||
FallbackComponent={() => ( | ||
<Box padding={8}> | ||
<AnErrorOccurred /> | ||
</Box> | ||
)} | ||
> | ||
<Switch> | ||
<Route path={`${url}/configurations/list`}> | ||
<CheckPagePermissions | ||
permissions={permissions.contentManager?.collectionTypesConfigurations} | ||
> | ||
<ListSettingsView | ||
layout={rawContentTypeLayout} | ||
slug={slug} | ||
updateLayout={updateLayout} | ||
/> | ||
</CheckPagePermissions> | ||
</Route> | ||
<Route path={`${url}/configurations/edit`}> | ||
<CheckPagePermissions | ||
permissions={permissions.contentManager?.collectionTypesConfigurations} | ||
> | ||
<EditSettingsView | ||
components={rawComponentsLayouts} | ||
isContentTypeView | ||
mainLayout={rawContentTypeLayout} | ||
slug={slug} | ||
updateLayout={updateLayout} | ||
/> | ||
</CheckPagePermissions> | ||
</Route> | ||
<Route | ||
path={`${url}/create/clone/:origin`} | ||
render={({ | ||
history: { goBack }, | ||
match: { | ||
params: { origin }, | ||
}, | ||
}) => ( | ||
<EditViewLayoutManager slug={slug} layout={layout} goBack={goBack} origin={origin} /> | ||
)} | ||
/> | ||
<Route | ||
path={`${url}/create`} | ||
render={({ history: { goBack } }) => ( | ||
<EditViewLayoutManager slug={slug} layout={layout} goBack={goBack} /> | ||
)} | ||
/> | ||
<Route | ||
path={`${url}/:id`} | ||
render={({ | ||
history: { goBack }, | ||
match: { | ||
params: { id }, | ||
}, | ||
}) => <EditViewLayoutManager slug={slug} layout={layout} goBack={goBack} id={id} />} | ||
/> | ||
<Route | ||
path={`${url}`} | ||
render={({ location: { state }, history: { goBack } }) => ( | ||
<ListViewLayout slug={slug} layout={layout} state={state} goBack={goBack} /> | ||
)} | ||
/> | ||
</Switch> | ||
</ErrorBoundary> | ||
); | ||
}; | ||
|
||
export { CollectionTypeRecursivePath }; |
14 changes: 0 additions & 14 deletions
14
.../admin/src/content-manager/pages/CollectionTypeRecursivePath/components/ErrorFallback.jsx
This file was deleted.
Oops, something went wrong.
134 changes: 0 additions & 134 deletions
134
packages/core/admin/admin/src/content-manager/pages/CollectionTypeRecursivePath/index.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.