Skip to content

Commit ad1e2ac

Browse files
authored
revert: fix(cloudinary): keep widget open for multi-insert on multi-asset fields [] (#8394)
1 parent ac69162 commit ad1e2ac

3 files changed

Lines changed: 7 additions & 79 deletions

File tree

Lines changed: 6 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,23 @@
11
import { DialogAppSDK } from '@contentful/app-sdk';
2-
import { useAutoResizer, useSDK } from '@contentful/react-apps-toolkit';
2+
import { useSDK } from '@contentful/react-apps-toolkit';
33
import { injectGlobal } from '@emotion/css';
44
import { css } from '@emotion/react';
5-
import { Button } from '@contentful/f36-components';
6-
import { useCallback, useRef, useState } from 'react';
5+
import { useCallback } from 'react';
76
import { APP_ENV, APP_VERSION } from '../constants';
8-
import { AppInstallationParameters, MediaLibraryResultAsset } from '../types';
7+
import { AppInstallationParameters } from '../types';
98
import { loadScript } from '../utils';
109
import { ShowOptions } from './types';
1110

1211
const styles = {
1312
container: css({
1413
height: '100%',
1514
}),
16-
doneBar: css({
17-
position: 'fixed',
18-
bottom: 0,
19-
left: 0,
20-
right: 0,
21-
display: 'flex',
22-
alignItems: 'center',
23-
justifyContent: 'flex-end',
24-
gap: '8px',
25-
padding: '12px 16px',
26-
background: 'white',
27-
borderTop: '1px solid #e5ebed',
28-
zIndex: 10,
29-
}),
30-
doneLabel: css({
31-
fontSize: '14px',
32-
color: '#536171',
33-
}),
3415
};
3516

3617
const AssetPickerDialog = () => {
3718
const sdk = useSDK<DialogAppSDK<AppInstallationParameters>>();
38-
useAutoResizer();
3919
const invocationParams = sdk.parameters.invocation as Record<string, unknown>;
4020
const expression = invocationParams.expression as string;
41-
const [pendingAssets, setPendingAssets] = useState<MediaLibraryResultAsset[]>([]);
42-
const pendingRef = useRef<MediaLibraryResultAsset[]>([]);
43-
44-
const handleDone = useCallback(() => {
45-
sdk.close(pendingRef.current.length > 0 ? { assets: pendingRef.current, mlId: '' } : undefined);
46-
}, [sdk]);
4721

4822
/**
4923
* Initialization is triggered using the div's ref to ensure the container exists in the DOM
@@ -100,19 +74,7 @@ const AssetPickerDialog = () => {
10074
};
10175

10276
const instance = window.cloudinary.createMediaLibrary(options, {
103-
insertHandler: (data) => {
104-
if (maxFiles <= 1) {
105-
// Single-asset field: close immediately (original behavior)
106-
sdk.close(data);
107-
} else {
108-
// Multi-asset field: accumulate up to maxFiles limit and keep widget open
109-
const remaining = maxFiles - pendingRef.current.length;
110-
if (remaining <= 0) return;
111-
const next = [...pendingRef.current, ...data.assets.slice(0, remaining)];
112-
pendingRef.current = next;
113-
setPendingAssets([...next]);
114-
}
115-
},
77+
insertHandler: (data) => sdk.close(data),
11678
});
11779

11880
const showOptions: ShowOptions = {
@@ -124,35 +86,10 @@ const AssetPickerDialog = () => {
12486
instance.show(showOptions);
12587
})();
12688
},
127-
[sdk, invocationParams, expression],
89+
[sdk],
12890
);
12991

130-
const maxFiles = 'maxFiles' in invocationParams ? Number(invocationParams.maxFiles) : sdk.parameters.installation.maxFiles;
131-
const isMulti = maxFiles > 1;
132-
133-
return (
134-
<>
135-
<div ref={init} id="container" css={styles.container} />
136-
{isMulti && (
137-
<div css={styles.doneBar}>
138-
{pendingAssets.length > 0 && (
139-
<span css={styles.doneLabel}>{pendingAssets.length} selected</span>
140-
)}
141-
<Button variant="secondary" size="small" onClick={() => sdk.close(undefined)}>
142-
Cancel
143-
</Button>
144-
<Button
145-
variant="primary"
146-
size="small"
147-
isDisabled={pendingAssets.length === 0}
148-
onClick={handleDone}
149-
>
150-
Add to field {pendingAssets.length > 0 ? `(${pendingAssets.length})` : ''}
151-
</Button>
152-
</div>
153-
)}
154-
</>
155-
);
92+
return <div ref={init} id="container" css={styles.container} />;
15693
};
15794

15895
export default AssetPickerDialog;

apps/flexfields/src/locations/EntryEditor.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from "react";
2-
import { EditorAppSDK, EditorLocaleSettings, ConfigAppSDK } from "@contentful/app-sdk";
2+
import { EditorAppSDK, EditorLocaleSettings } from "@contentful/app-sdk";
33
import { useSDK } from "@contentful/react-apps-toolkit";
44
import { getDefaultWidgetId } from "@contentful/default-field-editors";
55
import { Stack, Form, Heading, Text } from "@contentful/f36-components";
@@ -63,14 +63,6 @@ const EntryEditor = () => {
6363
};
6464
}, [handlePageHide]);
6565

66-
useEffect(() => {
67-
// onConfigurationCompleted fires after the config screen saves new installation parameters.
68-
// EditorAppSDK doesn't expose `app` in its type but the runtime SDK always has it.
69-
(sdk as unknown as ConfigAppSDK).app.onConfigurationCompleted(() => {
70-
window.location.reload();
71-
});
72-
}, [sdk]);
73-
7466
useEffect(() => {
7567
sdk.editor.onLocaleSettingsChanged((localeSetings) =>
7668
setLocaleSetings(localeSetings)

apps/flexfields/test/mocks/mockSdk.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const mockSdk: any = {
44
getParameters: vi.fn().mockReturnValueOnce({}),
55
setReady: vi.fn(),
66
getCurrentState: vi.fn(),
7-
onConfigurationCompleted: vi.fn(),
87
},
98
ids: {
109
app: 'test-app',

0 commit comments

Comments
 (0)