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 26, 2023
1 parent f0a3b25 commit 5873ed4
Show file tree
Hide file tree
Showing 11 changed files with 1,349 additions and 29 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
951 changes: 950 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.

23 changes: 14 additions & 9 deletions client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { compose } from 'redux';
import { inject, injectGraphql, loadComponent } from 'lib/Injector';
import fieldHolder from 'components/FieldHolder/FieldHolder';

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 All @@ -15,21 +15,19 @@ const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, li
if (typeof onChange !== 'function') {
return;
}

onChange(event, { id, value: {} });
onChange(event, {});
};

const { typeKey } = data;
const type = types[typeKey];
const modalType = newTypeKey ? types[newTypeKey] : type;

let title = data ? data.Title : '';

if (!title) {
title = data ? data.TitleRelField : '';
}

const linkProps = {
const pickerProps = {
title,
link: type ? { type, title, description: linkDescription } : undefined,
onEdit: () => { setEditing(true); },
Expand All @@ -42,18 +40,22 @@ const LinkField = ({ id, loading, Loading, data, LinkPicker, onChange, types, li
};

const onModalSubmit = (modalData, action, submitFn) => {
const { SecurityID, action_insert: actionInsert, ...value } = modalData;
const { SecurityID, action_submit: actionSubmit, ...data } = modalData;

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

setEditing(false);
setNewTypeKey('');

return Promise.resolve();
// TODO toast here to say success (or somewhere else?)

return submitFn();
};

console.log(['modalProps data is', data])

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

console.log(['pickerProps is', pickerProps]);

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


export default compose(
inject(['LinkPicker', 'Loading']),
injectGraphql('readLinkTypes'),
Expand Down
5 changes: 4 additions & 1 deletion client/src/components/LinkModal/LinkModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ const buildSchemaUrl = (key, data) => {
const parsedQs = qs.parse(parsedURL.query);
parsedQs.key = key;
if (data) {
parsedQs.data = JSON.stringify(data);
for (const prop of ['href', 'path', 'pathname']) {
const id = typeof data.ID !== 'undefined' ? data.ID : '0';
parsedURL[prop] += `/${id}`;
}
}
return url.format({ ...parsedURL, search: qs.stringify(parsedQs)});
}
Expand Down
5 changes: 3 additions & 2 deletions client/src/entwine/JsonField.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ jQuery.entwine('ss', ($) => {
Root.render(<ReactField {...props} noHolder/>);
},

handleChange(event, {id, value}) {
handleChange(event, data) {
console.log(['JsonField data is', data])
const fieldID = $(this).data('field-id');
$('#' + fieldID).val(JSON.stringify(value)).trigger('change');
$('#' + fieldID).val(JSON.stringify(data)).trigger('change');
this.refresh();
},

Expand Down
Loading

0 comments on commit 5873ed4

Please sign in to comment.