Skip to content

Commit

Permalink
NEW LinkFieldController to handle FormSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 25, 2023
1 parent f0a3b25 commit fe7115c
Show file tree
Hide file tree
Showing 10 changed files with 1,368 additions and 21 deletions.
1 change: 0 additions & 1 deletion _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@

// Avoid creating global variables
call_user_func(function () {

});
2 changes: 1 addition & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Name: linkfield

SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\LinkField\Extensions\LeftAndMain
- SilverStripe\LinkField\Extensions\LeftAndMainExtension

SilverStripe\Admin\ModalController:
extensions:
Expand Down
977 changes: 976 additions & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

69 changes: 68 additions & 1 deletion client/dist/styles/bundle.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { Fragment, useState } from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { inject, injectGraphql, loadComponent } from 'lib/Injector';
import fieldHolder from 'components/FieldHolder/FieldHolder';
import { submit } from 'redux-form'

const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, linkDescription, ...props }) => {
const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, linkDescription, submitForm, ...props }) => {
if (loading) {
return <Loading />;
}
Expand Down Expand Up @@ -44,14 +46,17 @@ const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, li
const onModalSubmit = (modalData, action, submitFn) => {
const { SecurityID, action_insert: actionInsert, ...value } = modalData;

console.log(['onModalSubmit was called', onChange]);
// submitForm();

if (typeof onChange === 'function') {
onChange(event, { id, value });
}

setEditing(false);
setNewTypeKey('');

return Promise.resolve();
return submitFn();
};

const modalProps = {
Expand All @@ -67,6 +72,14 @@ const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, li
const handlerName = modalType ? modalType.handlerName : 'FormBuilderModal';
const LinkModal = loadComponent(`LinkModal.${handlerName}`);

// ---
// const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
// sleep(2000).then(() => {
// console.log('just woke from sleep');
// submitForm();
// });
// ---

return <Fragment>
<LinkPicker {...linkProps} />
<LinkModal {...modalProps} />
Expand All @@ -81,10 +94,23 @@ const stringifyData = (Component) => (({ data, value, ...props }) => {
return <Component dataStr={JSON.stringify(dataValue)} {...props} data={dataValue} />;
});

function mapDispatchToProps(dispatch, ownProps) {
// I got this name of the form from console.log() FormBuilder.js:346
const formName = 'Link.EditingLinkInfo.LinkForm_1'; // todo hardcoded
return {
submitForm() {
console.log(['submitForm was called', formName]);
// https://redux-form.com/8.3.0/examples/remotesubmit/
dispatch(submit(formName));
}
};
}

export default compose(
inject(['LinkPicker', 'Loading']),
injectGraphql('readLinkTypes'),
stringifyData,
injectGraphql('readLinkDescription'),
fieldHolder
fieldHolder,
connect(null, mapDispatchToProps)
)(LinkField);
3 changes: 2 additions & 1 deletion client/src/components/LinkModal/LinkModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const buildSchemaUrl = (key, data) => {
const parsedQs = qs.parse(parsedURL.query);
parsedQs.key = key;
if (data) {
parsedQs.data = JSON.stringify(data);
// parsedQs.data = JSON.stringify(data);
parsedQs.id = data.ID;
}
return url.format({ ...parsedURL, search: qs.stringify(parsedQs)});
}
Expand Down
Loading

0 comments on commit fe7115c

Please sign in to comment.