Skip to content

Commit 15b3a49

Browse files
fix: Docs to Rich Text - Resolves bugs on configuration screen [] (#4632)
1 parent 878d94e commit 15b3a49

File tree

4 files changed

+73
-47
lines changed

4 files changed

+73
-47
lines changed

apps/docs-to-rich-text/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/docs-to-rich-text/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docs-to-rich-text",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"private": true,
55
"dependencies": {
66
"@contentful/app-sdk": "^4.29.3",

apps/docs-to-rich-text/src/locations/ConfigScreen.tsx

+68-37
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const ConfigScreen = () => {
5151
const [richTextFields, setRichTextFields] = useState<RtfField[]>([]);
5252
const [richTextFieldsLoaded, setRichTextFieldsLoaded] = useState<boolean>(false);
5353
const [isLicensed, setIsLicensed] = useState(false);
54+
const [isInstalled, setIsInstalled] = useState(false);
5455

5556
const sdk = useSDK<ConfigAppSDK>();
5657

@@ -109,6 +110,30 @@ const ConfigScreen = () => {
109110
setRichTextFieldsLoaded(true);
110111
})();
111112
}, [sdk]);
113+
useEffect(() => {
114+
let intervalId: any;
115+
(async () => {
116+
// Initial check
117+
const installed = await checkInstallationStatus();
118+
if (installed) {
119+
return;
120+
}
121+
// Polling
122+
intervalId = setInterval(async () => {
123+
if (await checkInstallationStatus()) {
124+
clearInterval(intervalId);
125+
}
126+
}, 2000);
127+
})();
128+
return () => {
129+
clearInterval(intervalId);
130+
};
131+
}, [sdk.app]);
132+
async function checkInstallationStatus(): Promise<boolean> {
133+
const installed = await sdk.app.isInstalled();
134+
setIsInstalled(installed);
135+
return installed;
136+
}
112137

113138
async function enableEditorForAllRichTextFields() {
114139
if (!isLicensed && richTextFields.length > 5) {
@@ -258,43 +283,49 @@ const ConfigScreen = () => {
258283
const fieldsCard = (
259284
<Card>
260285
<Heading>Configure Rich Text Fields</Heading>
261-
<p>Select which rich text fields should have Docs to Rich Text enabled</p>
262-
<br />
263-
264-
{!richTextFieldsLoaded && (
265-
<div style={{ display: 'flex', justifyContent: 'center' }}>
266-
<Spinner variant="default" />
267-
</div>
268-
)}
269-
{richTextFieldsLoaded && (
270-
<div>
271-
<div
272-
style={{
273-
display: 'flex',
274-
justifyContent: 'flex-end',
275-
marginBottom: '20px',
276-
}}>
277-
{isLicenseLimitReached ? (
278-
<Tooltip content="Free plan limit reached. Disable another field or upgrade to remove limits" placement="top">
279-
<Button variant="primary" size="small" style={{ marginRight: '20px' }} isDisabled={true}>
280-
Enable All
281-
</Button>
282-
</Tooltip>
283-
) : (
284-
<Button
285-
variant="primary"
286-
size="small"
287-
style={{ marginRight: '20px' }}
288-
onClick={async () => {
289-
await enableEditorForAllRichTextFields();
290-
}}
291-
isDisabled={false}>
292-
Enable All
293-
</Button>
294-
)}
295-
</div>
296-
{fieldsTable}
297-
</div>
286+
{!isInstalled ? (
287+
<p>Install to begin</p>
288+
) : (
289+
<>
290+
<p>Select which rich text fields should have Docs to Rich Text enabled</p>
291+
<br />
292+
293+
{!richTextFieldsLoaded && (
294+
<div style={{ display: 'flex', justifyContent: 'center' }}>
295+
<Spinner variant="default" />
296+
</div>
297+
)}
298+
{richTextFieldsLoaded && (
299+
<div>
300+
<div
301+
style={{
302+
display: 'flex',
303+
justifyContent: 'flex-end',
304+
marginBottom: '20px',
305+
}}>
306+
{isLicenseLimitReached ? (
307+
<Tooltip content="Free plan limit reached. Disable another field or upgrade to remove limits" placement="top">
308+
<Button variant="primary" size="small" style={{ marginRight: '20px' }} isDisabled={true}>
309+
Enable All
310+
</Button>
311+
</Tooltip>
312+
) : (
313+
<Button
314+
variant="primary"
315+
size="small"
316+
style={{ marginRight: '20px' }}
317+
onClick={async () => {
318+
await enableEditorForAllRichTextFields();
319+
}}
320+
isDisabled={false}>
321+
Enable All
322+
</Button>
323+
)}
324+
</div>
325+
{fieldsTable}
326+
</div>
327+
)}
328+
</>
298329
)}
299330
</Card>
300331
);

apps/docs-to-rich-text/src/utils/editorInterfaceUtil.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ export async function getRichTextFields(cma: CMAClient, appDefinitionId: string)
1212
// Get all content types
1313
const contentTypes = await cma.contentType.getMany({});
1414

15-
// Get our widgetId
16-
const def = await cma.appDefinition.get({ appDefinitionId: appDefinitionId });
17-
const appWidgetId = def.sys.id;
18-
1915
const richTextFields: RtfField[] = [];
2016
for (const contentType of contentTypes.items) {
2117
const editorInterface = await cma.editorInterface.get({ contentTypeId: contentType.sys.id });
@@ -27,7 +23,7 @@ export async function getRichTextFields(cma: CMAClient, appDefinitionId: string)
2723
contentTypeName: contentType.name,
2824
fieldId: rtfField.id,
2925
fieldName: rtfField.name,
30-
isEnabled: control!.widgetId === appWidgetId,
26+
isEnabled: control!.widgetId === appDefinitionId,
3127
});
3228
}
3329
}
@@ -48,8 +44,7 @@ export async function getRichTextFields(cma: CMAClient, appDefinitionId: string)
4844

4945
export async function setAppRichTextEditor(sdk: ConfigAppSDK, contentTypeId: string, fieldId: string) {
5046
lock.acquire(contentTypeId, async function () {
51-
const def = await sdk.cma.appDefinition.get({ appDefinitionId: sdk.ids.app });
52-
const appWidgetId = def.sys.id;
47+
const appWidgetId = sdk.ids.app;
5348

5449
const editorInterface = await sdk.cma.editorInterface.get({ contentTypeId: contentTypeId });
5550
const control = editorInterface.controls!.find((w) => w.fieldId === fieldId)!;

0 commit comments

Comments
 (0)