feat: only renders arrays and blocks once they are initialized
This commit is contained in:
@@ -59,7 +59,7 @@ const ArrayFieldType: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
const { preferencesKey, preferences } = useDocumentInfo();
|
const { preferencesKey, preferences } = useDocumentInfo();
|
||||||
const { setPreference } = usePreferences();
|
const { setPreference } = usePreferences();
|
||||||
const [rows, dispatchRows] = useReducer(reducer, []);
|
const [rows, dispatchRows] = useReducer(reducer, undefined);
|
||||||
const formContext = useForm();
|
const formContext = useForm();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { id } = useDocumentInfo();
|
const { id } = useDocumentInfo();
|
||||||
@@ -191,7 +191,7 @@ const ArrayFieldType: React.FC<Props> = (props) => {
|
|||||||
}
|
}
|
||||||
}, [rows, setValue]);
|
}, [rows, setValue]);
|
||||||
|
|
||||||
const hasMaxRows = maxRows && rows.length >= maxRows;
|
const hasMaxRows = maxRows && rows?.length >= maxRows;
|
||||||
|
|
||||||
const classes = [
|
const classes = [
|
||||||
'field-type',
|
'field-type',
|
||||||
@@ -199,6 +199,8 @@ const ArrayFieldType: React.FC<Props> = (props) => {
|
|||||||
className,
|
className,
|
||||||
].filter(Boolean).join(' ');
|
].filter(Boolean).join(' ');
|
||||||
|
|
||||||
|
if (!rows) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DragDropContext onDragEnd={onDragEnd}>
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ const Blocks: React.FC<Props> = (props) => {
|
|||||||
|
|
||||||
const { preferencesKey, preferences } = useDocumentInfo();
|
const { preferencesKey, preferences } = useDocumentInfo();
|
||||||
const { setPreference } = usePreferences();
|
const { setPreference } = usePreferences();
|
||||||
const [rows, dispatchRows] = useReducer(reducer, []);
|
const [rows, dispatchRows] = useReducer(reducer, undefined);
|
||||||
const formContext = useForm();
|
const formContext = useForm();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { id } = useDocumentInfo();
|
const { id } = useDocumentInfo();
|
||||||
@@ -201,7 +201,7 @@ const Blocks: React.FC<Props> = (props) => {
|
|||||||
}
|
}
|
||||||
}, [rows, setValue]);
|
}, [rows, setValue]);
|
||||||
|
|
||||||
const hasMaxRows = maxRows && rows.length >= maxRows;
|
const hasMaxRows = maxRows && rows?.length >= maxRows;
|
||||||
|
|
||||||
const classes = [
|
const classes = [
|
||||||
'field-type',
|
'field-type',
|
||||||
@@ -209,6 +209,8 @@ const Blocks: React.FC<Props> = (props) => {
|
|||||||
className,
|
className,
|
||||||
].filter(Boolean).join(' ');
|
].filter(Boolean).join(' ');
|
||||||
|
|
||||||
|
if (!rows) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DragDropContext onDragEnd={onDragEnd}>
|
<DragDropContext onDragEnd={onDragEnd}>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type MOVE = {
|
|||||||
type Action = SET_ALL | SET_COLLAPSE | SET_ALL_COLLAPSED | ADD | REMOVE | MOVE;
|
type Action = SET_ALL | SET_COLLAPSE | SET_ALL_COLLAPSED | ADD | REMOVE | MOVE;
|
||||||
|
|
||||||
const reducer = (currentState: Row[], action: Action): Row[] => {
|
const reducer = (currentState: Row[], action: Action): Row[] => {
|
||||||
const stateCopy = [...currentState];
|
const stateCopy = [...currentState || []];
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SET_ALL': {
|
case 'SET_ALL': {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const TabsFields: CollectionConfig = {
|
|||||||
tabs: [
|
tabs: [
|
||||||
{
|
{
|
||||||
label: 'Tab One',
|
label: 'Tab One',
|
||||||
|
description: 'Here is a description for tab one',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'array',
|
name: 'array',
|
||||||
@@ -26,6 +27,7 @@ const TabsFields: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Tab Two',
|
label: 'Tab Two',
|
||||||
|
description: 'Description for tab two',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'text',
|
name: 'text',
|
||||||
@@ -36,6 +38,7 @@ const TabsFields: CollectionConfig = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Tab Three',
|
label: 'Tab Three',
|
||||||
|
description: 'Description for tab three',
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'number',
|
name: 'number',
|
||||||
|
|||||||
Reference in New Issue
Block a user