Skip to content

Commit

Permalink
Table module: Fix error with method enqueue_table; Fix warning when s…
Browse files Browse the repository at this point in the history
…orting value is null instead of string; Add test to confirm issue and solution - Resolves #108
  • Loading branch information
eliot-akira committed Apr 7, 2024
1 parent f8c1037 commit 2780aff
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 9 deletions.
4 changes: 2 additions & 2 deletions modules/pager/v1/enqueue.php
Expand Up @@ -10,13 +10,13 @@

function register() {

if (wp_script_is('tangible-paginator')) return;

$url = template_system::$state->url . '/modules/pager/v1/build';
$version = template_system::$state->version;

ajax\register();

if (wp_script_is('tangible-paginator')) return;

wp_register_script(
'tangible-paginator',
"{$url}/paginator.min.js",
Expand Down
9 changes: 9 additions & 0 deletions modules/pager/v1/tangible.config.js
@@ -0,0 +1,9 @@
export default {
build: [
{
src: 'src/index.ts',
dest: 'build/paginator.min.js'
},
],
format: ['**/*.{php,ts,tsx,scss}', '!build'],
}
2 changes: 1 addition & 1 deletion modules/table/body.php
Expand Up @@ -234,7 +234,7 @@

case 'string':
default:
return strcmp($a_value, $b_value) * $order;
return strcmp($a_value ?? '', $b_value ?? '') * $order;
break;
}
});
Expand Down
4 changes: 2 additions & 2 deletions modules/table/index.php
@@ -1,5 +1,6 @@
<?php
use tangible\format;
use tangible\template_system\table;

/**
* Table - Loop type with pagination, sort, and filter via AJAX
Expand Down Expand Up @@ -200,8 +201,7 @@
} else {

// Enqueue Tangible Table module

$html->enqueue_table(); // See ./enqueue.php
table\enqueue(); // See ./enqueue.php
}

// Restore previous
Expand Down
4 changes: 1 addition & 3 deletions tests/e2e/index.js
Expand Up @@ -102,9 +102,7 @@ describe('Admin', () => {

// Make a POST request

const result = await request.post(activateLink)

console.log('Activate result', result)
await request.post(activateLink)
}

const plugin = await requestUtils.rest({
Expand Down
55 changes: 54 additions & 1 deletion tests/modules/table.php
Expand Up @@ -14,7 +14,60 @@ public function test() {

$this->assertEquals( true, isset($html->tags['Table']) );

$result = $html->render('<Table />');
$post_ids = [];

for ($i = 1; $i <= 3; $i++) {
$post_ids []= self::factory()->post->create_object([
'post_type' => 'post',
'post_status' => 'publish', // Important for Loop tag
'post_title' => 'Test ' . $i,
'post_content' => '',
]);
}

$result = $html->render(<<<'HTML'
<Table per_page=3 sort=title sort_order=desc>
<Filter>
<div>
<input type="text" action="search" columns="entry_id,user,entry_date,survey_total_score" placeholder="Search" >
</div>
</Filter>
<Head>
<Col name=entry_id sort_type=string>Entry ID</Col>
<Col name=user sort_type=string>User</Col>
<Col name=entry_date sort_type=string>Entry Date</Col>
<Col name=survey_total_score sort_type=string>Survey Total Score</Col>
</Head>
<RowLoop type=post>
<Col>
<Field id />
</Col>
<Col>
<Loop type="user" id="{Field created_by}">
<Field full_name /><br/>
</Loop>
</Col>
<Col>
<Field date_created />
</Col>
<Col>
<Field survey_score />
</Col>
</RowLoop>
<Paginate>
Page <Field current /> of <Field total />
</Paginate>
<Empty>
<p>Empty</p>
</Empty>
</Table>
HTML);

$this->assertNull( $error );
// $this->assertEquals( true, !empty($result) );
Expand Down

0 comments on commit 2780aff

Please sign in to comment.