chore: merge master

This commit is contained in:
James
2021-12-29 16:45:52 -05:00
17 changed files with 140 additions and 27 deletions

View File

@@ -141,6 +141,8 @@ const Blocks: React.FC<Props> = (props) => {
moveRow(sourceIndex, destinationIndex);
}, [moveRow]);
// Get preferences, and once retrieved,
// Reset rows with preferences included
useEffect(() => {
const fetchPreferences = async () => {
const preferences = preferencesKey ? await getPreference<DocumentPreferences>(preferencesKey) : undefined;
@@ -151,6 +153,12 @@ const Blocks: React.FC<Props> = (props) => {
fetchPreferences();
}, [formContext, path, preferencesKey, getPreference]);
// Set row count on mount and when form context is reset
useEffect(() => {
const data = formContext.getDataByPath(path);
dispatchRows({ type: 'SET_ALL', data: data || [] });
}, [formContext, path]);
useEffect(() => {
setValue(rows?.length || 0);

View File

@@ -48,7 +48,6 @@ const Relationship: React.FC<Props> = (props) => {
collections,
} = useConfig();
const formProcessing = useFormProcessing();
const hasMultipleRelations = Array.isArray(relationTo);
@@ -308,7 +307,7 @@ const Relationship: React.FC<Props> = (props) => {
}
} : undefined}
onMenuScrollToBottom={() => {
getResults({ lastFullyLoadedRelation, lastLoadedPage: lastLoadedPage + 1 });
getResults({ lastFullyLoadedRelation, lastLoadedPage: lastLoadedPage + 1, search });
}}
value={valueToRender}
showError={showError}

View File

@@ -27,7 +27,6 @@ const validate = (value) => {
const Upload: React.FC<Props> = (props) => {
const inputRef = useRef(null);
const dropRef = useRef(null);
const [fileList, setFileList] = useState(undefined);
const [selectingFile, setSelectingFile] = useState(false);
const [dragging, setDragging] = useState(false);
const [dragCounter, setDragCounter] = useState(0);
@@ -53,16 +52,16 @@ const Upload: React.FC<Props> = (props) => {
const handleDragIn = useCallback((e) => {
e.preventDefault();
e.stopPropagation();
setDragCounter(dragCounter + 1);
setDragCounter((count) => count + 1);
if (e.dataTransfer.items && e.dataTransfer.items.length > 0) {
setDragging(true);
}
}, [dragCounter]);
}, []);
const handleDragOut = useCallback((e) => {
e.preventDefault();
e.stopPropagation();
setDragCounter(dragCounter - 1);
setDragCounter((count) => count - 1);
if (dragCounter > 1) return;
setDragging(false);
}, [dragCounter]);
@@ -73,7 +72,7 @@ const Upload: React.FC<Props> = (props) => {
setDragging(false);
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
setFileList(e.dataTransfer.files);
setValue(e.dataTransfer.files[0]);
setDragging(false);
e.dataTransfer.clearData();
@@ -81,11 +80,13 @@ const Upload: React.FC<Props> = (props) => {
} else {
setDragging(false);
}
}, []);
}, [setValue]);
// Only called when input is interacted with directly
// Not called when drag + drop is used
// Or when input is cleared
const handleInputChange = useCallback(() => {
setSelectingFile(false);
setFileList(inputRef?.current?.files || null);
setValue(inputRef?.current?.files?.[0] || null);
}, [inputRef, setValue]);
@@ -113,13 +114,7 @@ const Upload: React.FC<Props> = (props) => {
}
return () => null;
}, [handleDragIn, handleDragOut, handleDrop, dropRef]);
useEffect(() => {
if (inputRef.current && fileList !== undefined) {
inputRef.current.files = fileList;
}
}, [fileList]);
}, [handleDragIn, handleDragOut, handleDrop, value]);
useEffect(() => {
setReplacingFile(false);
@@ -143,7 +138,6 @@ const Upload: React.FC<Props> = (props) => {
collection={collection}
handleRemove={() => {
setReplacingFile(true);
setFileList(null);
setValue(null);
}}
/>
@@ -163,7 +157,6 @@ const Upload: React.FC<Props> = (props) => {
buttonStyle="icon-label"
iconStyle="with-border"
onClick={() => {
setFileList(null);
setValue(null);
}}
/>