-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app-headless-cms): add ref field settings
- Loading branch information
Showing
14 changed files
with
214 additions
and
88 deletions.
There are no files selected for viewing
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
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
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
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
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
23 changes: 23 additions & 0 deletions
23
...ms/src/admin/components/FieldEditor/EditFieldDialog/AppearanceTab/LegacyRichTextInput.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,23 @@ | ||
import React from "react"; | ||
import { Alert } from "@webiny/ui/Alert"; | ||
|
||
export const LegacyRichTextInput = () => { | ||
return ( | ||
<Alert title={"You have legacy editor enabled"} type={"info"}> | ||
Your project has been upgraded from an older Webiny version, with EditorJS as the | ||
default rich text editor. We recommend switching to the new Lexical rich text editor, | ||
where possible. | ||
<br /> | ||
<br /> | ||
Read more about this in our{" "} | ||
<a | ||
href={"https://webiny.link/hcms-legacy-rte-support"} | ||
rel="noreferrer" | ||
target={"_blank"} | ||
> | ||
upgrade guide | ||
</a> | ||
. | ||
</Alert> | ||
); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...ss-cms/src/admin/components/FieldEditor/EditFieldDialog/AppearanceTab/RendererOptions.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,28 @@ | ||
import React from "react"; | ||
import { CmsModelFieldRendererPlugin } from "@webiny/app-headless-cms-common/types"; | ||
import { useModelField } from "~/admin/components/ModelFieldProvider"; | ||
import { Cell, Grid } from "@webiny/ui/Grid"; | ||
|
||
interface RendererOptionsProps { | ||
plugin: CmsModelFieldRendererPlugin | undefined; | ||
} | ||
|
||
export const RendererOptions = ({ plugin }: RendererOptionsProps) => { | ||
const { field } = useModelField(); | ||
if (!plugin || !plugin.renderer.renderSettings) { | ||
return null; | ||
} | ||
|
||
const settings = plugin.renderer.renderSettings({ field }); | ||
|
||
if (!settings) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Grid> | ||
<Cell span={12}>Renderer Settings:</Cell> | ||
{settings} | ||
</Grid> | ||
); | ||
}; |
31 changes: 31 additions & 0 deletions
31
...-cms/src/admin/components/FieldEditor/EditFieldDialog/AppearanceTab/useRendererPlugins.ts
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,31 @@ | ||
import { plugins } from "@webiny/plugins"; | ||
import { CmsModelFieldRendererPlugin } from "@webiny/app-headless-cms-common/types"; | ||
import { useModel } from "~/admin/components/ModelProvider"; | ||
import { useModelField } from "~/admin/components/ModelFieldProvider"; | ||
|
||
/** | ||
* We want the "hidden" renderer to always be the last one in the list. | ||
* @param a | ||
* @param b | ||
*/ | ||
const hiddenLast = (a: CmsModelFieldRendererPlugin, b: CmsModelFieldRendererPlugin) => { | ||
if (a.renderer.rendererName === "hidden") { | ||
return 1; | ||
} | ||
|
||
if (b.renderer.rendererName === "hidden") { | ||
return -1; | ||
} | ||
|
||
return 0; | ||
}; | ||
|
||
export const useRendererPlugins = () => { | ||
const { model } = useModel(); | ||
const { field, fieldPlugin } = useModelField(); | ||
|
||
return plugins | ||
.byType<CmsModelFieldRendererPlugin>("cms-editor-field-renderer") | ||
.filter(item => item.renderer.canUse({ field, fieldPlugin, model })) | ||
.sort(hiddenLast); | ||
}; |
27 changes: 27 additions & 0 deletions
27
...n/components/FieldEditor/EditFieldDialog/AppearanceTab/useSelectFirstAvailableRenderer.ts
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,27 @@ | ||
import { useEffect } from "react"; | ||
import { useRendererPlugins } from "~/admin/components/FieldEditor/EditFieldDialog/AppearanceTab/useRendererPlugins"; | ||
import { useModelField } from "~/admin/components/ModelFieldProvider"; | ||
import { UseBindHook } from "@webiny/form"; | ||
|
||
export const useSelectFirstAvailableRenderer = (bind: UseBindHook) => { | ||
const renderers = useRendererPlugins(); | ||
const { field } = useModelField(); | ||
|
||
useEffect(() => { | ||
// If the currently selected render plugin is no longer available, select the first available one. | ||
const currentlySelectedRenderAvailable = renderers.find( | ||
item => item.renderer.rendererName === field.renderer.name | ||
); | ||
|
||
if (currentlySelectedRenderAvailable) { | ||
return; | ||
} | ||
|
||
if (renderers[0]) { | ||
bind.onChange(renderers[0].renderer.rendererName); | ||
return; | ||
} | ||
|
||
console.info(`No renderers for field ${field.fieldId} found.`, field); | ||
}, [field.id, field.multipleValues, field.predefinedValues?.enabled]); | ||
}; |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ export const FIELDS_FIELDS = ` | |
multipleValues | ||
renderer { | ||
name | ||
settings | ||
} | ||
validation { | ||
name | ||
|
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
26 changes: 26 additions & 0 deletions
26
...dmin/plugins/fieldRenderers/ref/advanced/components/AdvancedMultipleReferenceSettings.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,26 @@ | ||
import { Bind } from "@webiny/form"; | ||
import React from "react"; | ||
import { Select } from "@webiny/ui/Select"; | ||
import { Cell } from "@webiny/ui/Grid"; | ||
|
||
export interface MultiRefFieldSettings { | ||
newItemPosition: "first" | "last"; | ||
} | ||
|
||
export const AdvancedMultipleReferenceSettings = () => { | ||
return ( | ||
<> | ||
<Cell span={12}> | ||
<Bind name={"renderer.settings.newItemPosition"} defaultValue={"last"}> | ||
<Select | ||
label={"New item position"} | ||
description={"Where should the new items be added?"} | ||
> | ||
<option value={"first"}>Top of the list</option> | ||
<option value={"last"}>Bottom of the list</option> | ||
</Select> | ||
</Bind> | ||
</Cell> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.