Skip to content

Commit

Permalink
Merge branch 'epic/donation-forms-migration' of github.com:impress-or…
Browse files Browse the repository at this point in the history
…g/give into epic/donation-forms-migration
  • Loading branch information
kjohnson committed Jul 26, 2023
2 parents bc4aa7f + 50228b0 commit c6ac93e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/DonationForms/V2/DonationFormsAdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function loadScripts()
'table' => give(DonationFormsListTable::class)->toArray(),
'adminUrl' => $this->adminUrl,
'pluginUrl' => GIVE_PLUGIN_URL,
'showMigrationOnboarding' => ! give_get_option('show_migration_onboarding'),
'migrationOnboardingCompleted' => (bool)give_get_option('migration_onboarding_completed'),
'transferOnboardingCompleted' => (bool)give_get_option('transfer_onboarding_completed'),
'showMigrationOnboarding' => defined('GIVE_NEXT_GEN_VERSION') && ! give_get_option('show_migration_onboarding'),
'migrationOnboardingCompleted' => defined('GIVE_NEXT_GEN_VERSION') && give_get_option('migration_onboarding_completed'),
'transferOnboardingCompleted' => defined('GIVE_NEXT_GEN_VERSION') && give_get_option('transfer_onboarding_completed'),
'unsupportedAddons' => $this->getUnsupportedAddons(),
];

Expand Down
32 changes: 20 additions & 12 deletions src/DonationForms/V2/Endpoints/ListDonationForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function registerRoute()
'type' => 'integer',
'required' => false,
'default' => 1,
'minimum' => 1
'minimum' => 1,
],
'perPage' => [
'type' => 'integer',
'required' => false,
'default' => 30,
'minimum' => 1
'minimum' => 1,
],
'status' => [
'type' => 'string',
Expand All @@ -67,12 +67,12 @@ public function registerRoute()
'trash',
'auto-draft',
'inherit',
'any'
]
'any',
],
],
'search' => [
'type' => 'string',
'required' => false
'required' => false,
],
'sortColumn' => [
'type' => 'string',
Expand All @@ -84,7 +84,7 @@ public function registerRoute()
'required' => false,
'enum' => [
'asc',
'desc'
'desc',
],
],
'locale' => [
Expand All @@ -98,7 +98,7 @@ public function registerRoute()
'default' => 'columns',
'enum' => [
'model',
'columns'
'columns',
],
],
],
Expand Down Expand Up @@ -128,13 +128,21 @@ public function handleRequest(WP_REST_Request $request): WP_REST_Response
$this->listTable->items($forms, $this->request->get_param('locale') ?? '');
$items = $this->listTable->getItems();

foreach($items as &$item ) {
foreach ($items as &$item) {
$v2form = defined('GIVE_NEXT_GEN_VERSION') && ! get_post_meta($item['id'], 'formBuilderFields');
$migrate = $v2form
&& ! get_post_meta($item['id'], 'migratedFormId');

$transfer = $v2form
&& get_post_meta($item['id'], 'migratedFormId')
&& ! get_post_meta($item['id'], 'transferredFormId');

$item['name'] = get_the_title($item['id']);
$item['edit'] = get_edit_post_link($item['id'], 'edit');
$item['permalink'] = get_permalink($item['id']);
$item['migrate'] = (bool)get_post_meta($item['id'], 'migratedFormId');
$item['transfer'] = (bool)get_post_meta($item['id'], 'transferredFormId');;
$item['v2form'] = ! get_post_meta($item['id'], 'formBuilderFields');
$item['migrate'] = $migrate;
$item['transfer'] = $transfer;
$item['v2form'] = $v2form;
}
}

Expand Down Expand Up @@ -172,7 +180,7 @@ public function getForms(): array

$donationForms = $query->getAll();

if (!$donationForms) {
if ( ! $donationForms) {
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export function DonationFormsRowActions({data, item, removeRow, addRow, setUpdat
hiddenText={item?.name}
/>
<RowAction href={item.permalink} displayText={__('View', 'give')} hiddenText={item?.name} />
{!item.migrate && (
{item.migrate && (
<RowAction
onClick={addRow(async (id) => {
const response = await fetchAndUpdateErrors(parameters, '/migrate', id, 'POST');
Expand All @@ -92,7 +92,7 @@ export function DonationFormsRowActions({data, item, removeRow, addRow, setUpdat
hiddenText={item?.name}
/>
)}
{item.migrate && !item.transfer && (
{item.transfer && (
<RowAction
onClick={addRow(async (id) => {
if (!onboardingState.transferOnboardingCompleted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function MigrationSuccessDialog({handleClose, formId}) {

<Button
size="large"
onClick={ () => console.log(formId) }
onClick={ () => window.location.href = `edit.php?post_type=give_forms&page=givewp-form-builder&donationFormID=${formId}`}
>
{__('Test it out', 'give')}
</Button>
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/DonationForms/Endpoints/TestListDonationForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,20 @@ public function getMockColumns(array $donationForms, string $sortDirection = 'de
foreach ( $columns as $column ) {
$expectedItem[$column::getId()] = $column->getCellValue($donationForm);
}
$v2form = defined('GIVE_NEXT_GEN_VERSION') && ! get_post_meta($donationForm->id, 'formBuilderFields');
$migrate = $v2form
&& ! get_post_meta($donationForm->id, 'migratedFormId');

$transfer = $v2form
&& get_post_meta($donationForm->id, 'migratedFormId')
&& ! get_post_meta($donationForm->id, 'transferredFormId');

$expectedItem['name'] = $donationForm->title;
$expectedItem['edit'] = get_edit_post_link($donationForm->id, 'edit');
$expectedItem['permalink'] = get_permalink($donationForm->id);
$expectedItem['migrate'] = $migrate;
$expectedItem['transfer'] = $transfer;
$expectedItem['v2form'] = $v2form;
$expectedItems[] = $expectedItem;
}

Expand Down

0 comments on commit c6ac93e

Please sign in to comment.