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

[7095] Rename dialog offers the ability to edit a broken reference but will not allow the user to open the content form #4079

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
31 changes: 21 additions & 10 deletions templates/web/legacy/embedded_legacy_form.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
const newEmbedded = CStudioAuthoring.Utils.getQueryVariable(location.search, 'newEmbedded');
const contentTypeId = CStudioAuthoring.Utils.getQueryVariable(location.search, 'contentTypeId');
const isNewContent = CStudioAuthoring.Utils.getQueryVariable(location.search, 'isNewContent') === 'true';
const formId = CStudioAuthoring.Utils.getQueryVariable(location.search, 'formId');
jvega190 marked this conversation as resolved.
Show resolved Hide resolved
const LEGACY_FORM_DIALOG_CANCEL_REQUEST = 'LEGACY_FORM_DIALOG_CANCEL_REQUEST';

CStudioAuthoring.OverlayRequiredResources.loadContextNavCss();
Expand Down Expand Up @@ -125,6 +126,7 @@
type: 'EMBEDDED_LEGACY_FORM_SUCCESS',
refresh: true,
tab: type,
formId,
action
}, '*');
},
Expand All @@ -134,6 +136,7 @@
type: 'EMBEDDED_LEGACY_FORM_FAILURE',
refresh: false,
tab: type,
formId,
action: 'failure',
message: formatMessage(embeddedLegacyFormMessages.contentFormFailedToLoadErrorMessage)
}, '*');
Expand All @@ -148,6 +151,7 @@
refresh: false,
close: close,
tab: type,
formId,
action: 'cancelled'
}, '*');
},
Expand All @@ -168,24 +172,26 @@
}
});
} else {
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDERED' }, '*');
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDERED', formId }, '*');
}
},
pendingChanges: () => {
window.parent.postMessage({
type: 'EMBEDDED_LEGACY_FORM_PENDING_CHANGES',
action: 'pendingChanges'
action: 'pendingChanges',
formId
}, '*');
},
renderFailed(error) {
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDER_FAILED', payload: { error } }, '*');
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDER_FAILED', payload: { error }, formId }, '*');
},
changeToEditMode() {
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_CHANGE_TO_EDIT_MODE' }, '*');
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_CHANGE_TO_EDIT_MODE', formId }, '*');
},
minimize: () => {
window.parent.postMessage({
type: 'EMBEDDED_LEGACY_MINIMIZE_REQUEST'
type: 'EMBEDDED_LEGACY_MINIMIZE_REQUEST',
formId
}, '*');
},
isParent: true,
Expand All @@ -204,6 +210,7 @@
refresh: false,
tab: type,
action: 'failure',
formId,
message: formatMessage(embeddedLegacyFormMessages.contentFormFailedToLoadErrorMessage)
}, '*');
}
Expand All @@ -227,15 +234,17 @@
tab: type,
redirectUrl: response.item?.browserUri,
action,
isNew: true
isNew: true,
formId
}, '*');
},
failure: (error) => {
error && console.error(error);
window.parent.postMessage({
type: 'EMBEDDED_LEGACY_FORM_FAILURE',
refresh: false, tab: type, action: 'failure',
message: formatMessage(embeddedLegacyFormMessages.contentFormFailedToLoadErrorMessage)
message: formatMessage(embeddedLegacyFormMessages.contentFormFailedToLoadErrorMessage),
formId
}, '*');
},
cancelled: () => {
Expand All @@ -244,16 +253,18 @@
type: 'EMBEDDED_LEGACY_FORM_CLOSE',
refresh: false,
tab: type,
action: 'cancelled'
action: 'cancelled',
formId
}, '*');
},
renderComplete: () => {
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDERED' }, '*');
window.parent.postMessage({ type: 'EMBEDDED_LEGACY_FORM_RENDERED', formId }, '*');
},
pendingChanges: () => {
window.parent.postMessage({
type: 'EMBEDDED_LEGACY_FORM_PENDING_CHANGES',
action: 'pendingChanges'
action: 'pendingChanges',
formId
}, '*');
},
id: type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { useStyles } from './styles';
import { hasEditAction } from '../../utils/content';
import { nnou } from '../../utils/object';
import { useFetchItem } from '../../hooks/useFetchItem';
import { nanoid as uuid } from 'nanoid';
jvega190 marked this conversation as resolved.
Show resolved Hide resolved

export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyEditor(
props: LegacyFormDialogContainerProps,
Expand Down Expand Up @@ -95,6 +96,7 @@ export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyE
fieldsIndexes[id] = index;
});
}
const formId = useMemo(() => uuid(), []);
jvega190 marked this conversation as resolved.
Show resolved Hide resolved

const src = useMemo(
() =>
Expand All @@ -109,6 +111,7 @@ export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyE
contentTypeId,
isNewContent,
iceGroupId,
formId,
...(nnou(availableActions) && !isNewContent ? { canEdit: hasEditAction(availableActions) } : {}),
...(selectedFields && selectedFields.length ? { selectedFields: JSON.stringify(selectedFields) } : {}),
...(newEmbedded ? { newEmbedded: JSON.stringify(newEmbedded) } : {}),
Expand All @@ -128,7 +131,8 @@ export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyE
selectedFields,
newEmbedded,
availableActions,
fieldsIndexes
fieldsIndexes,
formId
]
);

Expand All @@ -147,7 +151,7 @@ export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyE
);

useEffect(() => {
const messagesSubscription = messages.subscribe((e: any) => {
const messagesSubscription = messages.pipe(filter((e) => e.data.formId === formId)).subscribe((e: any) => {
switch (e.data.type) {
case EMBEDDED_LEGACY_FORM_SUCCESS: {
onSave(e.data);
Expand Down Expand Up @@ -259,7 +263,7 @@ export const EmbeddedLegacyContainer = React.forwardRef(function EmbeddedLegacyE
return () => {
messagesSubscription.unsubscribe();
};
}, [inProgress, onSave, messages, dispatch, onClose, formatMessage, onMinimize, setIframeLoaded]);
}, [inProgress, onSave, messages, dispatch, onClose, formatMessage, onMinimize, setIframeLoaded, formId]);

useUnmount(onClosed);

Expand Down
16 changes: 10 additions & 6 deletions ui/app/src/components/LegacyFormDialog/LegacyFormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ export function LegacyFormDialog(props: LegacyFormDialogProps) {
title={title}
disabled={isSubmitting}
onCloseButtonClick={onCloseButtonClick}
rightActions={[
{
icon: { id: '@mui/icons-material/RemoveRounded' },
onClick: onMinimize
}
]}
rightActions={
onMinimize
? [
{
icon: { id: '@mui/icons-material/RemoveRounded' },
onClick: onMinimize
}
]
: []
}
/>
)}
<EmbeddedLegacyContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import { translations } from '../CreateFileDialog/translations';
import { RenameItemView } from '../RenameDialogBody';
import { applyAssetNameRules } from '../../utils/content';
import { DialogBody } from '../DialogBody';
import { getHostToHostBus } from '../../utils/subjects';
import { filter } from 'rxjs/operators';
import { contentEvent } from '../../state/actions/system';

export function RenameAssetDialogContainer(props: RenameAssetContainerProps) {
const {
Expand Down Expand Up @@ -68,6 +71,16 @@ export function RenameAssetDialogContainer(props: RenameAssetContainerProps) {
dispatch(fetchRenameAssetDependants());
}, [dispatch]);

useEffect(() => {
const hostToHost$ = getHostToHostBus();
const subscription = hostToHost$.pipe(filter((e) => e.type === contentEvent.type)).subscribe(() => {
dispatch(fetchRenameAssetDependants());
});
return () => {
subscription.unsubscribe();
};
}, [dispatch]);
jvega190 marked this conversation as resolved.
Show resolved Hide resolved

const onInputChanges = (newValue: string) => {
setName(newValue);
const newHasPendingChanges = newValue !== value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { EnhancedDialog, EnhancedDialogProps } from '../EnhancedDialog';
import { FormattedMessage } from 'react-intl';
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { DetailedItem } from '../../models';
import RenameContentDialogContainer from './RenameContentDialogContainer';
import { fetchDependant } from '../../services/dependencies';
Expand All @@ -25,6 +25,9 @@ import { parseLegacyItemToDetailedItem } from '../../utils/content';
import useWithPendingChangesCloseRequest from '../../hooks/useWithPendingChangesCloseRequest';
import { onSubmittingAndOrPendingChangeProps } from '../../hooks/useEnhancedDialogState';
import { ensureSingleSlash, isBlank } from '../../utils/string';
import { getHostToHostBus } from '../../utils/subjects';
import { filter } from 'rxjs/operators';
import { contentEvent } from '../../state/actions/system';

export interface RenameContentDialogProps extends EnhancedDialogProps {
path: string;
Expand All @@ -41,7 +44,7 @@ export function RenameContentDialog(props: RenameContentDialogProps) {
const siteId = useActiveSiteId();
const pendingChangesCloseRequest = useWithPendingChangesCloseRequest(dialogProps.onClose);

useEffect(() => {
const loadDependants = useCallback((siteId, path, value) => {
if (!isBlank(value) && !isBlank(path)) {
setFetchingDependantItems(true);
fetchDependant(siteId, ensureSingleSlash(`${path}/${value}`)).subscribe({
Expand All @@ -56,7 +59,21 @@ export function RenameContentDialog(props: RenameContentDialogProps) {
}
});
}
}, [path, value, siteId]);
}, []);

useEffect(() => {
loadDependants(siteId, path, value);
}, [path, value, siteId, loadDependants]);

useEffect(() => {
const hostToHost$ = getHostToHostBus();
const subscription = hostToHost$.pipe(filter((e) => e.type === contentEvent.type)).subscribe(() => {
loadDependants(siteId, path, value);
});
return () => {
subscription.unsubscribe();
};
}, [siteId, path, value, loadDependants]);
jvega190 marked this conversation as resolved.
Show resolved Hide resolved

return (
<EnhancedDialog
Expand Down
22 changes: 21 additions & 1 deletion ui/app/src/components/RenameDialogBody/RenameItemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { ApiResponseErrorState } from '../ApiResponseErrorState';
import IconButton from '@mui/material/IconButton';
import EditRoundedIcon from '@mui/icons-material/EditRounded';
import { AjaxError } from 'rxjs/ajax';
import { LegacyFormDialog } from '../LegacyFormDialog';
import useSpreadState from '../../hooks/useSpreadState';

export interface RenameItemViewProps {
name: string;
Expand Down Expand Up @@ -68,9 +70,20 @@ export function RenameItemView(props: RenameItemViewProps) {
const { authoringBase } = useEnv();
const siteId = useActiveSiteId();
const dispatch = useDispatch();
const [legacyFormDialogState, setLegacyFormDialogState] = useSpreadState({
open: false,
path: null
});

const handleEditorDisplay = (item: DetailedItem) => {
openItemEditor(item, authoringBase, siteId, dispatch, fetchRenameAssetDependants());
if (item.systemType === 'component' || item.systemType === 'page') {
jvega190 marked this conversation as resolved.
Show resolved Hide resolved
setLegacyFormDialogState({
open: true,
path: item.path
});
} else {
openItemEditor(item, authoringBase, siteId, dispatch, fetchRenameAssetDependants());
}
};

return fetchingDependantItems ? (
Expand Down Expand Up @@ -158,6 +171,13 @@ export function RenameItemView(props: RenameItemViewProps) {
<FormattedMessage id="renameAsset.noDependentItems" defaultMessage="No dependent items" />
</Typography>
)}
<LegacyFormDialog
open={legacyFormDialogState.open}
authoringBase={authoringBase}
path={legacyFormDialogState.path}
site={siteId}
onClose={() => setLegacyFormDialogState({ open: false, path: null })}
/>
</>
) : (
error && <ApiResponseErrorState error={error.response} />
Expand Down
7 changes: 5 additions & 2 deletions ui/app/src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export function getEditFormSrc({
iceGroupId,
newEmbedded,
canEdit,
fieldsIndexes
fieldsIndexes,
formId
}: {
path: string;
selectedFields?: string;
Expand All @@ -230,6 +231,7 @@ export function getEditFormSrc({
newEmbedded?: string;
canEdit?: boolean;
fieldsIndexes?: string;
formId?: string;
}): string {
const qs = toQueryString({
site,
Expand All @@ -244,7 +246,8 @@ export function getEditFormSrc({
iceId: iceGroupId,
newEmbedded,
canEdit,
fieldsIndexes
fieldsIndexes,
formId
});
return `${authoringBase}/legacy/form${qs}`;
}
Expand Down