css fixes to array / blocks, file handling improvements

This commit is contained in:
James
2020-07-19 12:56:00 -04:00
parent b6c5c5b92c
commit 26b5109bca
7 changed files with 51 additions and 27 deletions

View File

@@ -4,7 +4,7 @@
// HELPER MIXINS
//////////////////////
@mixin realtively-position-panels {
@mixin relatively-position-panels {
.position-panel {
position: relative;
right: 0;
@@ -117,7 +117,7 @@
}
@include mid-break {
@include realtively-position-panels();
@include relatively-position-panels();
.position-panel__move-forward,
.position-panel__move-backward {
@@ -135,12 +135,15 @@
@include absolutely-position-panels();
@include mid-break {
@include realtively-position-panels();
@include relatively-position-panels();
}
}
.field-type.array .field-type.array {
@include realtively-position-panels();
.field-type.blocks .field-type.array,
.field-type.array .field-type.array,
.field-type.array .field-type.blocks,
.field-type.blocks .field-type.blocks {
@include relatively-position-panels();
}
// remove padding above array rows to level

View File

@@ -25,13 +25,16 @@
width: 100%;
}
}
}
.field-type.array,
.field-type.blocks {
.field-type.array {
.field-type.repeater__add-button-wrap {
.field-type.array__add-button-wrap {
margin-left: base(2.65);
}
.field-type.repeater__header {
.field-type.array__header {
display: none;
}
}

View File

@@ -24,3 +24,12 @@
}
}
}
.field-type.array,
.field-type.blocks {
.field-type.blocks {
.field-type.blocks__add-button-wrap {
margin-left: base(2.65);
}
}
}

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import { useModal } from '@faceless-ui/modal';
import config from '../../../../config';
@@ -47,12 +47,17 @@ const Upload = (props) => {
const dataToInitialize = (typeof initialData === 'object' && initialData.id) ? initialData.id : initialData;
const memoizedValidate = useCallback((value) => {
const validationResult = validate(value, { required });
return validationResult;
}, [validate, required]);
const fieldType = useFieldType({
path,
required,
initialData: dataToInitialize,
defaultValue,
validate,
validate: memoizedValidate,
});
const {

View File

@@ -46,18 +46,7 @@ const create = async (args) => {
}, Promise.resolve());
// /////////////////////////////////////
// 3. Execute field-level access, hooks, and validation
// /////////////////////////////////////
data = await performFieldOperations(config, collectionConfig, {
data,
hook: 'beforeCreate',
operationName: 'create',
req,
});
// /////////////////////////////////////
// 4. Upload and resize any files that may be present
// 3. Upload and resize any files that may be present
// /////////////////////////////////////
if (collectionConfig.upload) {
@@ -69,7 +58,7 @@ const create = async (args) => {
throw new MissingFile();
}
await mkdirp(staticDir);
mkdirp.sync(staticDir);
const fsSafeName = await getSafeFilename(staticDir, req.files.file.name);
@@ -95,6 +84,17 @@ const create = async (args) => {
};
}
// /////////////////////////////////////
// 4. Execute field-level access, hooks, and validation
// /////////////////////////////////////
data = await performFieldOperations(config, collectionConfig, {
data,
hook: 'beforeCreate',
operationName: 'create',
req,
});
// /////////////////////////////////////
// 5. Perform database operation
// /////////////////////////////////////

View File

@@ -60,14 +60,18 @@ const deleteQuery = async (args) => {
if (collectionConfig.upload) {
const { staticDir } = collectionConfig.upload;
fs.unlink(`${staticDir}/${resultToDelete.filename}`, () => {
throw new ErrorDeletingFile();
fs.unlink(`${staticDir}/${resultToDelete.filename}`, (err) => {
if (err) {
throw new ErrorDeletingFile();
}
});
if (resultToDelete.sizes) {
Object.values(resultToDelete.sizes).forEach((size) => {
fs.unlink(`${staticDir}/${size.filename}`, () => {
throw new ErrorDeletingFile();
fs.unlink(`${staticDir}/${size.filename}`, (err) => {
if (err) {
throw new ErrorDeletingFile();
}
});
});
}

View File

@@ -89,7 +89,7 @@ const sanitizeCollection = (collections, collection) => {
if (sanitized.upload) {
if (!sanitized.upload.staticDir) sanitized.upload.staticDir = sanitized.slug;
if (!sanitized.upload.staticURL) sanitized.upload.staticURL = sanitized.slug;
if (!sanitized.upload.staticURL) sanitized.upload.staticURL = `/${sanitized.slug}`;
if (!sanitized.admin.useAsTitle) sanitized.admin.useAsTitle = 'filename';
}