overwrites arrays instead of merging, initializes upload client fields
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const deepmerge = require('deepmerge');
|
||||
const combineMerge = require('../../utilities/combineMerge');
|
||||
const overwriteMerge = require('../../utilities/overwriteMerge');
|
||||
const { NotFound, Forbidden } = require('../../errors');
|
||||
const executePolicy = require('../executePolicy');
|
||||
const performFieldOperations = require('../../fields/performFieldOperations');
|
||||
@@ -62,7 +62,7 @@ const update = async (args) => {
|
||||
// 3. Merge updates into existing data
|
||||
// /////////////////////////////////////
|
||||
|
||||
options.data = deepmerge(userJSON, options.data, { arrayMerge: combineMerge });
|
||||
options.data = deepmerge(userJSON, options.data, { arrayMerge: overwriteMerge });
|
||||
|
||||
// /////////////////////////////////////
|
||||
// 4. Execute field-level hooks, policies, and validation
|
||||
|
||||
32
src/client/components/forms/field-types/File/index.js
Normal file
32
src/client/components/forms/field-types/File/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import React, { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import FileGraphic from '../../../graphics/File';
|
||||
import Button from '../../../elements/Button';
|
||||
import useForm from '../../Form/useForm';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const baseClass = 'file-field';
|
||||
|
||||
const File = (props) => {
|
||||
const { initialData } = props;
|
||||
|
||||
console.log(initialData);
|
||||
|
||||
return (
|
||||
<div className={baseClass}>
|
||||
<FileGraphic />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
File.defaultProps = {
|
||||
initialData: undefined,
|
||||
};
|
||||
|
||||
File.propTypes = {
|
||||
fieldTypes: PropTypes.shape({}).isRequired,
|
||||
initialData: PropTypes.shape({}),
|
||||
};
|
||||
|
||||
export default File;
|
||||
10
src/client/components/forms/field-types/File/index.scss
Normal file
10
src/client/components/forms/field-types/File/index.scss
Normal file
@@ -0,0 +1,10 @@
|
||||
@import '../../../../scss/styles.scss';
|
||||
|
||||
.file-field {
|
||||
margin-bottom: base(2);
|
||||
background: $color-background-gray;
|
||||
|
||||
.btn {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,7 @@ const Repeater = (props) => {
|
||||
rowIndex={i}
|
||||
fieldSchema={fields}
|
||||
initialData={row.data}
|
||||
initNull={row.initNull}
|
||||
dispatchRows={dispatchRows}
|
||||
customComponentsPath={`${customComponentsPath}${name}.fields.`}
|
||||
positionHandleVerticalAlignment="sticky"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export { default as auth } from './Auth';
|
||||
export { default as file } from './File';
|
||||
|
||||
export { default as email } from './Email';
|
||||
export { default as hidden } from './HiddenInput';
|
||||
|
||||
30
src/client/components/graphics/File/index.js
Normal file
30
src/client/components/graphics/File/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import React from 'react';
|
||||
|
||||
const File = () => {
|
||||
return (
|
||||
<svg
|
||||
width="150"
|
||||
height="120"
|
||||
viewBox="0 0 150 120"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<rect
|
||||
width="150"
|
||||
height="120"
|
||||
transform="translate(0 0.5)"
|
||||
fill="#333333"
|
||||
/>
|
||||
<path
|
||||
d="M82.8876 35.5H55.5555V85.5H94.4444V46.9818H82.8876V35.5Z"
|
||||
fill="white"
|
||||
/>
|
||||
<path
|
||||
d="M82.8876 46.9818H94.4444L82.8876 35.5V46.9818Z"
|
||||
fill="#9A9A9A"
|
||||
/>
|
||||
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export default File;
|
||||
@@ -38,6 +38,14 @@ const formatFields = (config) => {
|
||||
]);
|
||||
}
|
||||
|
||||
if (config.upload) {
|
||||
fields = fields.concat({
|
||||
name: 'filename',
|
||||
label: 'Filename',
|
||||
type: 'text',
|
||||
});
|
||||
}
|
||||
|
||||
return fields;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const deepmerge = require('deepmerge');
|
||||
const combineMerge = require('../../utilities/combineMerge');
|
||||
const overwriteMerge = require('../../utilities/overwriteMerge');
|
||||
const executePolicy = require('../../auth/executePolicy');
|
||||
const { NotFound, Forbidden } = require('../../errors');
|
||||
const performFieldOperations = require('../../fields/performFieldOperations');
|
||||
@@ -64,7 +64,7 @@ const update = async (args) => {
|
||||
// 3. Merge updates into existing data
|
||||
// /////////////////////////////////////
|
||||
|
||||
options.data = deepmerge(docJSON, options.data, { arrayMerge: combineMerge });
|
||||
options.data = deepmerge(docJSON, options.data, { arrayMerge: overwriteMerge });
|
||||
|
||||
// /////////////////////////////////////
|
||||
// 4. Execute field-level hooks, policies, and validation
|
||||
@@ -94,6 +94,12 @@ const update = async (args) => {
|
||||
...options.data,
|
||||
...fileData,
|
||||
};
|
||||
} else if (options.data.file === null) {
|
||||
options.data = {
|
||||
...options.data,
|
||||
filename: null,
|
||||
sizes: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,8 +40,9 @@ module.exports = async function resizeAndSave(config, savedFilename, mimeType) {
|
||||
const outputImage = getOutputImage(savedFilename, desiredSize);
|
||||
const imageNameWithDimensions = `${outputImage.name}-${outputImage.width}x${outputImage.height}.${outputImage.extension}`;
|
||||
const imagePath = `${staticDir}/${imageNameWithDimensions}`;
|
||||
const fileAlreadyExists = await fileExists(imagePath);
|
||||
|
||||
if (fileExists(imagePath)) {
|
||||
if (fileAlreadyExists) {
|
||||
fs.unlinkSync(imagePath);
|
||||
}
|
||||
|
||||
|
||||
3
src/utilities/overwriteMerge.js
Normal file
3
src/utilities/overwriteMerge.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
|
||||
|
||||
module.exports = overwriteMerge;
|
||||
Reference in New Issue
Block a user