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

[6633] Remove all logical resources from code #3869

Draft
wants to merge 33 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
81469ca
[6633] Remove logicalResource from ConflictedPathDiffDialog
jvega190 May 10, 2024
4eec135
[6633] Remove logicalResource from PreviewPageExplorerPanel.tsx
jvega190 May 10, 2024
b8e510b
[6633] Remove logicalResource from SiteManagement
jvega190 May 10, 2024
6337966
Merge branch 'develop' of https://github.com/craftercms/studio-ui int…
jvega190 May 10, 2024
57932d9
[6633] Remove logicalResource from NewContentDialog
jvega190 May 20, 2024
576214d
[6633] Remove logicalResource from PreviewDropTargetsPanel
jvega190 May 20, 2024
dd5da3c
[6633] Remove logicalResource from PreviewPageExplorerPanel
jvega190 May 20, 2024
a199d9e
[6633] Remove logicalResource from DeleteContentTypeDialog
jvega190 May 20, 2024
c70e786
[6633] Remove logicalResource from UninstallPluginDialog
jvega190 May 20, 2024
0476aef
[6633] Remove unused imports
jvega190 May 20, 2024
ad3838f
[6633] Remove logicalResource from QuickCreate, delete pages/QuickCre…
jvega190 May 21, 2024
7596eca
[6633] Remove PreviewInPageInstancesPanel.tsx, update Changelog
jvega190 May 21, 2024
abb624f
[6633] Remove logical resource from ViewVersionDialogContainer
jvega190 May 21, 2024
688ff84
[6633] Remove logical resource from CompareVersionsDialog
jvega190 May 21, 2024
afb1c94
Merge branch 'develop' of https://github.com/craftercms/studio-ui int…
jvega190 May 22, 2024
66fe83f
[6633] Remove logical resource from ToolsPanel
jvega190 May 22, 2024
f5b358d
[6633] Add suspense to components
jvega190 May 22, 2024
840d2f0
[6633] Restore PreviewInPageInstancesPanel
jvega190 May 29, 2024
874ff32
[6633] Remove useLogicResource, useSelectorResource and useQuickCreat…
jvega190 May 29, 2024
2509f33
[6633] Rollback CHANGELOG entry
jvega190 Jun 4, 2024
4ea3a60
Merge branch 'develop' of https://github.com/craftercms/studio-ui int…
jvega190 Jun 21, 2024
2fff863
[6633] Memoize filteredContentTypes
jvega190 Jun 21, 2024
40bd902
[6633] Add cancellation
jvega190 Jun 21, 2024
23ba80f
[6633] Memoize filteredContentTypes
jvega190 Jun 21, 2024
d9d8971
[6633] Rollback PreviewInPageInstancesPanel/index.ts
jvega190 Jun 21, 2024
79fdb97
[6633] update filteredContentTypes models validation
jvega190 Jun 21, 2024
73986ee
[6633] Cleanup code, update CHANGELOG
jvega190 Jun 21, 2024
f6d61b8
[6633] Remove unnecessary Suspense usages
jvega190 Jun 21, 2024
46afeb5
[6633] Remove unused imports
jvega190 Jun 21, 2024
675304a
Merge branch 'develop' of https://github.com/craftercms/studio-ui int…
jvega190 Jun 28, 2024
f7f25c9
[6633] Remove remaining resource-related things, update CHANGELOG
jvega190 Jun 28, 2024
cff5cbb
Merge branch 'develop' of https://github.com/craftercms/studio-ui int…
jvega190 Sep 6, 2024
879f191
[6633] Fix conflicts
jvega190 Sep 6, 2024
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
9 changes: 9 additions & 0 deletions ui/app/src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [utils/xml] Upgrade prettier to v3x which changed from sync apis to async
* `serialize` no longer formats code
* `beautify` is now async
* [utils/resource] Removed `createFakeResource`, `createResource` and `createResourceBundle` utils.
* [components]
* HostUI removed, merged with Host (its container component)
* EditModeSwitcherUI removed, merged with EditModeSwitcher (its container component)
Expand All @@ -24,6 +25,9 @@
* `listItemProps` are routed to the list `ListItem` component instead of the `ListItemButton`
* Added `listItemButtonProps` property
* `DraggablePanelListItem` prop `onMenu` send the pointer event as its first and only argument instead of the anchor element attached to the event. Can get element through `event.currentTarget`.
* Removed `pages/QuickCreateMenu` component.
* Removed `SuspenseWithEmptyState` and `WithEmptyState` components.
* Removed `resource` prop from StoreProvider
* [services] Removed services associated with v1 APIs:
* `fetchLegacyGetGoLiveItems`
* `fetchLegacyUserActivities`
Expand All @@ -37,6 +41,11 @@
* `actions/dialogs`: Renamed `updateEditConfig` action to `updateEditDialogConfig`
* [hooks]
* `usePreviewUrlControl`: Removed `history` prop. Retrieval of search and navigate (previously called 'push') is now done internally.
* Removed `useLogicResource` hook.
* Removed `useSelectorResource` hook.
* Removed `useQuickCreateListResource` hook.
* Removed `useSystemVersionResource` hook.
* Removed `useResolveWhenNoNullResource` hook.
* Removed deprecated `aws-file-upload` and `aws-video` upload controls.
* Migrated the Studio UI build to Vite/SWC
* Rollup's XB build to use SWC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ import React, { useEffect, useMemo, useState } from 'react';
import { LegacyContentType } from '../../models/ContentType';
import { fetchLegacyContentTypes } from '../../services/contentTypes';
import { showErrorDialog } from '../../state/reducers/dialogs/error';
import { useLogicResource } from '../../hooks/useLogicResource';
import { useSubject } from '../../hooks/useSubject';
import { debounceTime } from 'rxjs/operators';
import DialogBody from '../DialogBody/DialogBody';
import { Box, Checkbox, FormControlLabel } from '@mui/material';
import SingleItemSelector from '../SingleItemSelector';
import { FormattedMessage } from 'react-intl';
import SearchBar from '../SearchBar/SearchBar';
import { SuspenseWithEmptyState } from '../Suspencified/Suspencified';
import { ContentTypesGrid, ContentTypesLoader } from '../NewContentDialog';
import DialogFooter from '../DialogFooter/DialogFooter';
import { makeStyles } from 'tss-react/mui';
import EmptyState from '../EmptyState';

const useStyles = makeStyles()(() => ({
compact: {
Expand Down Expand Up @@ -61,8 +60,13 @@ export function ChangeContentTypeDialogContainer(props: ChangeContentTypeDialogC
const [openSelector, setOpenSelector] = useState(false);
const [selectedItem, setSelectedItem] = useState(item);
const [contentTypes, setContentTypes] = useState<LegacyContentType[]>();
const [isFetching, setIsFetching] = useState(false);
const [keyword, setKeyword] = useState('');
const [debounceKeyword, setDebounceKeyword] = useState('');
const filteredContentTypes = useMemo(() => {
const lowercaseKeyword = debounceKeyword.toLowerCase();
return contentTypes?.filter((contentType) => contentType.label.toLowerCase().includes(lowercaseKeyword));
}, [contentTypes, debounceKeyword]);

const onSelectedContentType = (contentType: LegacyContentType) => {
onContentTypeSelected?.({
Expand All @@ -72,37 +76,28 @@ export function ChangeContentTypeDialogContainer(props: ChangeContentTypeDialogC

useEffect(() => {
if (selectedItem.path) {
fetchLegacyContentTypes(site, selectedItem.path).subscribe(
(response) => {
setIsFetching(true);
const sub = fetchLegacyContentTypes(site, selectedItem.path).subscribe({
next: (response) => {
setIsFetching(false);
setContentTypes(
response.filter(
(contentType) =>
contentType.type === selectedItem.systemType && contentType.name !== selectedItem.contentTypeId
)
);
},
(response) => {
error: (response) => {
setIsFetching(false);
dispatch(showErrorDialog({ error: response }));
}
);
});
return () => {
sub.unsubscribe();
};
}
}, [dispatch, selectedItem, site]);

const resource = useLogicResource(
useMemo(() => ({ contentTypes, debounceKeyword }), [contentTypes, debounceKeyword]),
{
shouldResolve: ({ contentTypes }) => Boolean(contentTypes),
shouldReject: () => null,
shouldRenew: (source, resource) => resource.complete,
resultSelector: ({ contentTypes, debounceKeyword }) => {
return contentTypes.filter((contentType) =>
contentType.label.toLowerCase().includes(debounceKeyword.toLowerCase())
);
},
errorSelector: () => null
}
);

const onSearch$ = useSubject<string>();

useEffect(() => {
Expand Down Expand Up @@ -138,32 +133,32 @@ export function ChangeContentTypeDialogContainer(props: ChangeContentTypeDialogC
<SearchBar onChange={onSearch} keyword={keyword} autoFocus showActionButton={Boolean(keyword)} />
</Box>
</Box>
<SuspenseWithEmptyState
resource={resource}
suspenseProps={{
fallback: <ContentTypesLoader numOfItems={6} isCompact={isCompact} />
}}
withEmptyStateProps={{
emptyStateProps: {
classes: {
image: classes.emptyStateImg
},
title: (
{isFetching ? (
<ContentTypesLoader numOfItems={6} isCompact={isCompact} />
) : filteredContentTypes ? (
filteredContentTypes.length > 0 ? (
<ContentTypesGrid
contentTypes={filteredContentTypes}
isCompact={isCompact}
onTypeOpen={onSelectedContentType}
selectedContentType={selectedContentType}
/>
) : (
<EmptyState
title={
<FormattedMessage
id="changeContentTypeDialog.emptyStateMessage"
defaultMessage="No Content Types Found"
/>
)
}
}}
>
<ContentTypesGrid
resource={resource}
isCompact={isCompact}
onTypeOpen={onSelectedContentType}
selectedContentType={selectedContentType}
/>
</SuspenseWithEmptyState>
}
classes={{
image: classes.emptyStateImg
}}
/>
)
) : (
<></>
)}
</DialogBody>
<DialogFooter>
<FormControlLabel
Expand Down
13 changes: 2 additions & 11 deletions ui/app/src/components/CompareVersionsDialog/CompareVersions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import { makeStyles } from 'tss-react/mui';
import ContentInstance from '../../models/ContentInstance';
import { LookupTable } from '../../models/LookupTable';
import ContentType from '../../models/ContentType';
import React from 'react';
import { Resource } from '../../models/Resource';
import { useSelection } from '../../hooks/useSelection';

// declare const monaco: any;
Expand Down Expand Up @@ -151,14 +148,8 @@ import { useSelection } from '../../hooks/useSelection';
}
}); */

export interface CompareVersionsResource {
a: ContentInstance;
b: any;
contentTypes: LookupTable<ContentType>;
}

interface CompareVersionsProps {
resource: Resource<CompareVersionsResource>;
versions: ContentInstance[];
}

const getLegacyDialogStyles = makeStyles()(() => ({
Expand All @@ -169,7 +160,7 @@ const getLegacyDialogStyles = makeStyles()(() => ({
}));

export function CompareVersions(props: CompareVersionsProps) {
const { a, b } = props.resource.read();
const [a, b] = props.versions;
const { classes } = getLegacyDialogStyles();
const authoringUrl = useSelection<string>((state) => state.env.authoringBase);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/

import { CompareVersionsDialogContainerProps } from './utils';
import React, { useMemo } from 'react';
import { useLogicResource } from '../../hooks/useLogicResource';
import { CompareVersionsBranch } from '../../models/Version';
import { CompareVersions, CompareVersionsResource } from './CompareVersions';
import { EntityState } from '../../models/EntityState';
import ContentType from '../../models/ContentType';
import React from 'react';
import { CompareVersions } from './CompareVersions';
import DialogBody from '../DialogBody/DialogBody';
import { SuspenseWithEmptyState } from '../Suspencified/Suspencified';
import { makeStyles } from 'tss-react/mui';
import { ApiResponseErrorState } from '../ApiResponseErrorState';
import { LoadingState } from '../LoadingState';
import { EmptyState } from '../EmptyState';
import { FormattedMessage } from 'react-intl';

const useStyles = makeStyles()(() => ({
dialogBody: {
Expand All @@ -42,47 +41,23 @@ const useStyles = makeStyles()(() => ({
}));

export function CompareVersionsDialogContainer(props: CompareVersionsDialogContainerProps) {
const { versionsBranch, contentTypesBranch } = props;
const { versionsBranch } = props;
const { compareVersionsBranch } = versionsBranch;
const { classes, cx } = useStyles();

const compareVersionsData = useMemo(
() => ({
compareVersionsBranch,
contentTypesBranch
}),
[compareVersionsBranch, contentTypesBranch]
);

const compareVersionsResource = useLogicResource<
CompareVersionsResource,
{ compareVersionsBranch: CompareVersionsBranch; contentTypesBranch: EntityState<ContentType> }
>(compareVersionsData, {
shouldResolve: ({ compareVersionsBranch, contentTypesBranch }) =>
compareVersionsBranch.compareVersions &&
contentTypesBranch.byId &&
!compareVersionsBranch.isFetching &&
!contentTypesBranch.isFetching,
shouldReject: ({ compareVersionsBranch, contentTypesBranch }) =>
Boolean(compareVersionsBranch.error || contentTypesBranch.error),
shouldRenew: ({ compareVersionsBranch, contentTypesBranch }, resource) => resource.complete,
resultSelector: ({ compareVersionsBranch, contentTypesBranch }) => ({
a: compareVersionsBranch.compareVersions?.[0],
b: compareVersionsBranch.compareVersions?.[1],
contentTypes: contentTypesBranch.byId
}),
errorSelector: ({ compareVersionsBranch, contentTypesBranch }) =>
compareVersionsBranch.error || contentTypesBranch.error
});

return (
<>
<DialogBody className={cx(classes.dialogBody, classes.noPadding)}>
<SuspenseWithEmptyState resource={compareVersionsResource}>
<CompareVersions resource={compareVersionsResource} />
</SuspenseWithEmptyState>
</DialogBody>
</>
<DialogBody className={cx(classes.dialogBody, classes.noPadding)}>
{compareVersionsBranch &&
(compareVersionsBranch.error ? (
<ApiResponseErrorState error={compareVersionsBranch.error} />
) : compareVersionsBranch.isFetching ? (
<LoadingState />
) : compareVersionsBranch.compareVersions?.length > 0 ? (
<CompareVersions versions={compareVersionsBranch.compareVersions} />
) : (
<EmptyState title={<FormattedMessage defaultMessage="No versions found" />} />
))}
</DialogBody>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import Dialog from '@mui/material/Dialog';
import DialogHeader from '../DialogHeader';
import DialogBody from '../DialogBody/DialogBody';
Expand All @@ -23,7 +23,6 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { diffConflictedFile } from '../../services/repositories';
import ApiResponse from '../../models/ApiResponse';
import { FileDiff } from '../../models/Repository';
import { SuspenseWithEmptyState } from '../Suspencified';
import ConflictedPathDiffDialogUI from './ConflictedPathDiffDialogUI';
import SecondaryButton from '../SecondaryButton';
import ConfirmDropdown from '../ConfirmDropdown';
Expand All @@ -33,7 +32,8 @@ import { makeStyles } from 'tss-react/mui';
import Tab from '@mui/material/Tab';
import Tabs from '@mui/material/Tabs';
import { useActiveSiteId } from '../../hooks/useActiveSiteId';
import { useLogicResource } from '../../hooks/useLogicResource';
import { ApiResponseErrorState } from '../ApiResponseErrorState';
import { LoadingState } from '../LoadingState';

export interface RemoteRepositoriesDiffDialogProps {
open: boolean;
Expand Down Expand Up @@ -101,17 +101,6 @@ export function ConflictedPathDiffDialog(props: RemoteRepositoriesDiffDialogProp
setTab(newValue);
};

const resource = useLogicResource<FileDiff, { fileDiff: FileDiff; error: ApiResponse; fetching: boolean }>(
useMemo(() => ({ fileDiff, error, fetching }), [fileDiff, error, fetching]),
{
shouldResolve: (source) => Boolean(source.fileDiff) && !fetching,
shouldReject: ({ error }) => Boolean(error),
shouldRenew: (source, resource) => fetching && resource.complete,
resultSelector: (source) => source.fileDiff,
errorSelector: () => error
}
);

return (
<Dialog open={open} onClose={onClose} fullWidth maxWidth="md">
<DialogHeader
Expand Down Expand Up @@ -143,9 +132,13 @@ export function ConflictedPathDiffDialog(props: RemoteRepositoriesDiffDialogProp
</Tabs>
</DialogHeader>
<DialogBody className={classes.dialogContent}>
<SuspenseWithEmptyState resource={resource}>
<ConflictedPathDiffDialogUI resource={resource} tab={tab} />
</SuspenseWithEmptyState>
{error ? (
<ApiResponseErrorState error={error} />
) : fetching ? (
<LoadingState />
) : fileDiff ? (
<ConflictedPathDiffDialogUI fileDiff={fileDiff} tab={tab} />
) : null}
</DialogBody>
<DialogFooter>
<SecondaryButton onClick={onClose}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Resource } from '../../models/Resource';
import { FileDiff } from '../../models/Repository';
import React from 'react';
import { makeStyles } from 'tss-react/mui';
Expand Down Expand Up @@ -54,13 +53,12 @@ const useStyles = makeStyles()((theme) => ({
}));

export interface RemoteRepositoriesDiffDialogUIProps {
resource: Resource<FileDiff>;
fileDiff: FileDiff;
tab: number;
}

export function ConflictedPathDiffDialogUI(props: RemoteRepositoriesDiffDialogUIProps) {
const { resource, tab } = props;
const fileDiff = resource.read();
const { fileDiff, tab } = props;
const { classes } = useStyles();

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ const useStyles = makeStyles()((theme) => ({

export function DeleteContentTypeDialogBody(props: DeleteContentTypeDialogBodyProps) {
const { classes } = useStyles();
const { onCloseButtonClick, resource, contentType, onSubmit: onSubmitProp, password = 'delete', submitting } = props;
const data = resource.read();
const { onCloseButtonClick, data, contentType, onSubmit: onSubmitProp, password = 'delete', submitting } = props;
const { formatMessage } = useIntl();
const dataEntries = Object.entries(data) as Array<[keyof FetchContentTypeUsageResponse, SandboxItem[]]>;
const entriesWithItems = dataEntries.filter(([, items]) => items.length > 0);
Expand Down
Loading