Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove ClassicEditor from window.givewp.form.components and use the new @givewp/form-builder-library npm package #7122

Merged
merged 29 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2504332
refactor: remove ClassicEditor from window.givewp.form.components
glaubersilva Nov 29, 2023
16888f1
chore: install a local version of the @givewp/form-builder-library pa…
glaubersilva Dec 1, 2023
65a5cee
chore: update types for react and react-dom
glaubersilva Dec 1, 2023
161ca3b
refactor: add ts-ignore tags
glaubersilva Dec 4, 2023
32e82d3
refactor: remove unnecessary styles
glaubersilva Dec 4, 2023
f5a04c5
refactor: user ClassicEditor from Form Builder Library
glaubersilva Dec 4, 2023
3779504
chore: add @givewp/form-builder-library npm package
glaubersilva Dec 5, 2023
21aa0bf
refactor: update codebase to use @givewp/form-builder-library npm pac…
glaubersilva Dec 5, 2023
65a5d1b
chore: exclude everything inside the node_modules folder except the @…
glaubersilva Dec 5, 2023
367c5db
refactor: remove local ClassicEditor component
glaubersilva Dec 5, 2023
27bf6a6
refactor: use OptionsPanel component from the form builder library
glaubersilva Dec 5, 2023
8564bf6
refactor: remove local OptionsPanel component
glaubersilva Dec 5, 2023
37043f6
refactor: use the new @givewp/form-builder-library version
glaubersilva Dec 11, 2023
44b2775
refactor: use new @givewp/form-builder-library version
glaubersilva Dec 12, 2023
4e0cc11
chore: update @givewp/form-builder-library to v1.1.2
glaubersilva Dec 12, 2023
eba33d0
Merge branch 'develop' into refactor/unmount-classic-editor
glaubersilva Dec 12, 2023
7ff018f
chore: rollback @types/react and @types/react-dom
glaubersilva Dec 12, 2023
8eeba19
chore: install types for block editor
glaubersilva Dec 12, 2023
121e8cf
chore: move @givewp/form-builder-library to dependencies
glaubersilva Dec 12, 2023
1d30fc7
chore: move @givewp/form-builder-library to dependencies
glaubersilva Dec 12, 2023
460514e
refactor: import as type
glaubersilva Dec 12, 2023
c471a2a
refactor: update memoNode types
Dec 12, 2023
88785ea
feature: add update function
glaubersilva Dec 13, 2023
7db420a
Revert "feature: add update function"
glaubersilva Dec 13, 2023
69b0297
chore: update @givewp/form-builder-library version to 1.2.1
glaubersilva Jan 10, 2024
7304a92
chore: update npm files
glaubersilva Jan 10, 2024
0588c4f
Merge branch 'develop' into refactor/unmount-classic-editor
glaubersilva Jan 10, 2024
c80525e
fix: ts errors
glaubersilva Jan 10, 2024
9a8787b
fix: rollback missing styles
glaubersilva Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
482 changes: 378 additions & 104 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
}
],
"devDependencies": {
"@givewp/form-builder-library": "^1.1.2",
"@types/lodash": "^4.14.199",
"@types/react": "^18.0.27",
"@types/react": "^18.2.42",
"@types/react-datepicker": "^4.15.0",
"@types/react-dom": "^18.0.10",
"@types/react-dom": "^18.2.17",
"@types/wordpress__blocks": "^12.5.0",
"@types/wordpress__components": "^23.0.1",
"@wordpress/dependency-extraction-webpack-plugin": "^3.3.2",
Expand Down
7 changes: 3 additions & 4 deletions src/DonationForms/resources/app/fields/GroupNode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Node, Group, isField, isGroup} from '@givewp/forms/types';
import {Group, Node} from '@givewp/forms/types';
import {useTemplateWrapper} from '../templates';
import type {GroupProps} from '@givewp/forms/propTypes';
import {memo, useEffect} from '@wordpress/element';
import SectionNode from './SectionNode';
import useVisibilityCondition from '@givewp/forms/app/hooks/useVisibilityCondition';
import memoNode from '@givewp/forms/app/utilities/memoNode';

const formTemplates = window.givewp.form.templates;
Expand All @@ -16,10 +14,11 @@ const formTemplates = window.givewp.form.templates;
*
* @since 3.0.0
*/
function GroupNode({node}: { node: Group }) {
function GroupNode({node}: {node: Group}) {
const Group = useTemplateWrapper<GroupProps>(formTemplates.groups[node.type], 'div', node.name);

const nodeComponents = node.reduceNodes((nodes, node: Node) => {
// @ts-ignore
nodes[node.name] = (props: Node) => <SectionNode node={{...node, ...props}} />;

return nodes;
Expand Down
4 changes: 4 additions & 0 deletions src/DonationForms/resources/app/fields/SectionNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ function SectionNode({node}: {node: Node}) {

if (isField(node) && fieldTemplateExists(node)) {
if (node.type === 'gateways') {
// @ts-ignore
jonwaldstein marked this conversation as resolved.
Show resolved Hide resolved
return <GatewayFieldNode node={node} />;
}
// @ts-ignore
return <FieldNode node={node} />;
} else if (isElement(node) && elementTemplateExists(node)) {
// @ts-ignore
return <ElementNode node={node} />;
} else if (isGroup(node) && groupTemplateExists(node)) {
// @ts-ignore
return <GroupNode node={node} />;
} else {
console.error(`Node: ${JSON.stringify(node)} does not exist in Form Design: ${JSON.stringify(formTemplates)}`);
Expand Down
11 changes: 8 additions & 3 deletions src/DonationForms/resources/app/form/MultiStepForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type {Form} from '@givewp/forms/types';
import {Section} from '@givewp/forms/types';
import {DonationFormMultiStepStateProvider} from './store';
import {StepObject} from '@givewp/forms/app/form/MultiStepForm/types';
Expand All @@ -9,7 +10,6 @@ import SectionNode from '@givewp/forms/app/fields/SectionNode';
import Steps from '@givewp/forms/app/form/MultiStepForm/components/Steps';
import HeaderStep from '@givewp/forms/app/form/MultiStepForm/components/HeaderStep';
import {DonationSummaryProvider} from '@givewp/forms/app/store/donation-summary';
import type {Form} from '@givewp/forms/types';

const FormSectionTemplate = withTemplateWrapper(window.givewp.form.templates.layouts.section, 'section');

Expand All @@ -33,7 +33,10 @@ const convertSectionsToSteps = (sections: Section[], hasFirstStep: boolean) => {
<FormSectionTemplate key={section.name} section={section} hideLabel>
{section.nodes.map((node) => (
<DonationFormErrorBoundary key={node.name}>
<SectionNode key={node.name} node={node} />
{
// @ts-ignore
<SectionNode key={node.name} node={node} />
}
</DonationFormErrorBoundary>
))}
</FormSectionTemplate>
Expand Down Expand Up @@ -72,7 +75,9 @@ export default function MultiStepForm({form}: {form: Form}) {
}

return (
<DonationFormMultiStepStateProvider initialState={{steps, currentStep: 0, showHeader: form.settings?.showHeader}}>
<DonationFormMultiStepStateProvider
initialState={{steps, currentStep: 0, showHeader: form.settings?.showHeader}}
>
<DonationSummaryProvider>
<Steps steps={steps} />
</DonationSummaryProvider>
Expand Down
5 changes: 4 additions & 1 deletion src/DonationForms/resources/app/form/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export default function Section({section}: {section: SectionType}) {
<FormSectionTemplate section={section}>
{section.nodes.map((node) => (
<DonationFormErrorBoundary key={node.name}>
<SectionNode node={node} />
{
// @ts-ignore
<SectionNode node={node} />
}
</DonationFormErrorBoundary>
))}
</FormSectionTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import periodLookup from '../period-lookup';
import RecurringDonationsPromo from '@givewp/form-builder/promos/recurring-donations';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';
import {useCallback, useState} from '@wordpress/element';
import Options from '@givewp/form-builder/components/OptionsPanel';
import {OptionProps} from '@givewp/form-builder/components/OptionsPanel/types';
import {OptionsPanel} from '@givewp/form-builder-library';
import {OptionProps} from '@givewp/form-builder-library/build/OptionsPanel/types';
glaubersilva marked this conversation as resolved.
Show resolved Hide resolved
import {useEffect} from 'react';
import {DonationAmountAttributes} from '@givewp/form-builder/blocks/fields/amount/types';
import {subscriptionPeriod} from '@givewp/forms/registrars/templates/groups/DonationAmount/subscriptionPeriod';
Expand Down Expand Up @@ -184,6 +184,8 @@ const Inspector = ({attributes, setAttributes}) => {
[recurringBillingPeriodOptions, recurringEnableOneTimeDonations]
);

const {currency = 'USD'} = getFormBuilderWindowData();

return (
<InspectorControls>
<PanelBody title={__('Field Settings', 'give')} initialOpen={true}>
Expand Down Expand Up @@ -248,8 +250,8 @@ const Inspector = ({attributes, setAttributes}) => {

{priceOption === 'multi' && (
<PanelBody title={__('Donation Levels', 'give')} initialOpen={false}>
<Options
currency={true}
<OptionsPanel
currency={currency}
multiple={false}
options={donationLevels}
setOptions={handleLevelsChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@ import {BlockEditProps} from '@wordpress/blocks';
import {PanelBody, PanelRow, SelectControl, TextControl, ToggleControl} from '@wordpress/components';
import {InspectorControls} from '@wordpress/block-editor';
import {useState} from 'react';
import Options from '@givewp/form-builder/components/OptionsPanel';
import {OptionProps} from '@givewp/form-builder/components/OptionsPanel/types';
import {OptionsPanel} from '@givewp/form-builder-library';
import {OptionProps} from '@givewp/form-builder-library/build/OptionsPanel/types';

const titleLabelTransform = (token = '') => token.charAt(0).toUpperCase() + token.slice(1);
const titleValueTransform = (token = '') => token.trim().toLowerCase();

export default function Edit({
attributes: {
showHonorific,
honorifics,
firstNameLabel,
firstNamePlaceholder,
lastNameLabel,
lastNamePlaceholder,
requireLastName,
},
setAttributes,
}: BlockEditProps<any>) {

const [selectedTitle, setSelectedTitle] = useState<string>(Object.values(honorifics)[0] as string ?? '');
attributes: {
showHonorific,
honorifics,
firstNameLabel,
firstNamePlaceholder,
lastNameLabel,
lastNamePlaceholder,
requireLastName,
},
setAttributes,
}: BlockEditProps<any>) {
const [selectedTitle, setSelectedTitle] = useState<string>((Object.values(honorifics)[0] as string) ?? '');
const [honorificOptions, setHonorificOptions] = useState<OptionProps[]>(
Object.values(honorifics).map((token: string) => {
return {
Expand All @@ -38,12 +37,12 @@ export default function Edit({

const filtered = {};
// Filter options
Object.values(options).forEach((option) => {
Object.assign(filtered, {[option.label]: option.label})
Object.values(options).forEach((option) => {
Object.assign(filtered, {[option.label]: option.label});
});

setAttributes({honorifics: filtered})
}
setAttributes({honorifics: filtered});
};

return (
<>
Expand Down Expand Up @@ -99,8 +98,7 @@ export default function Edit({
/>
</div>
{!!showHonorific && (
<Options
currency={false}
<OptionsPanel
multiple={false}
selectable={false}
options={honorificOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ControlForPopover from '@givewp/form-builder/components/settings/ControlF
import StyledPopover from '@givewp/form-builder/blocks/fields/terms-and-conditions/StyledPopover';

import './styles.scss';
import ClassicEditor from '@givewp/form-builder/components/ClassicEditor';
import {ClassicEditor} from '@givewp/form-builder-library';

const DisplayTypeEnum = {
SHOW_MODAL_TERMS: 'showModalTerms',
Expand Down
Loading