Skip to content

Commit

Permalink
Merge pull request #55 from saleem-hadad/fix/transactions-search-not-…
Browse files Browse the repository at this point in the history
…working

fix transactions search
  • Loading branch information
saleem-hadad authored Mar 28, 2024
2 parents 02cc7f3 + 3eb4955 commit 3143775
Show file tree
Hide file tree
Showing 9 changed files with 10,873 additions and 18,519 deletions.
9 changes: 4 additions & 5 deletions app/GraphQL/Directives/SearchDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\GraphQL\Directives;

use App\Models\Transaction;
use Illuminate\Database\Query\Builder;
use Illuminate\Database\Eloquent\Builder;
use Nuwave\Lighthouse\Schema\Directives\BaseDirective;
use Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective;
use Nuwave\Lighthouse\Support\Contracts\ArgDirectiveForArray;
Expand All @@ -16,25 +16,24 @@ public static function definition(): string
"""
Perform search operation.
"""
directive @search() on ARGUMENT_DEFINITION
directive @search(within: String) on ARGUMENT_DEFINITION
GRAPHQL;
}

/**
* Add additional constraints to the builder based on the given argument value.
*
* @param Builder|\Illuminate\Database\Eloquent\Builder $builder
* @param Builder $builder
* @param mixed $value
* @return Builder
*/
public function handleBuilder($builder, $value): Builder
{
if($builder->getModel() instanceof Transaction) {
return $builder->where('amount', 'LIKE', "%$value%")
->orWhere('note', 'LIKE', "%$value%")
->orWhereHas('brand', function($builder) use($value) {
return $builder->where('name', 'LIKE', "%$value%");
});
})->orWhere('note', 'LIKE', "%$value%");
}

return $builder;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dompdf/dompdf": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.6.9",
"laravel/framework": "^9.0|^10.0",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.5",
"mll-lab/graphql-php-scalars": "^6.2",
Expand Down
891 changes: 439 additions & 452 deletions composer.lock

Large diffs are not rendered by default.

28,452 changes: 10,404 additions & 18,048 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"test": "jest --env=jsdom --colors --coverage"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.17.0",
"@babel/preset-env": "^7.16.11",
"@babel/plugin-transform-runtime": "^7.24.3",
"@babel/preset-env": "^7.24.3",
"@babel/preset-react": "^7.16.7",
"@headlessui/react": "^1.6.6",
"@inertiajs/inertia": "^0.10.0",
Expand All @@ -28,10 +28,10 @@
"intersection-observer": "^0.12.0",
"isomorphic-unfetch": "^3.1.0",
"jest": "^27.5.1",
"laravel-mix": "^6.0.6",
"laravel-mix": "^6.0.49",
"lodash": "^4.17.19",
"msw": "^0.39.2",
"postcss": "^8.2.13",
"postcss": "^8.4.38",
"postcss-import": "^14.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -44,7 +44,7 @@
"chart.js": "^3.7.0",
"chartjs-plugin-annotation": "^2.0.1",
"circlepack-chart": "^1.7.1",
"graphql": "^16.3.0",
"graphql": "^16.8.1",
"numbro": "^2.3.6",
"react-chartjs-2": "^4.0.0",
"urql": "^2.2.0"
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=be4dfac583b94c318ba1",
"/css/app.css": "/css/app.css?id=d07925ac6acf48089593"
"/js/app.js": "/js/app.js?id=9a85a2b877db97c3bcffcc9189445339",
"/css/app.css": "/css/app.css?id=a29af113c48845a119a56553951013db"
}
20 changes: 16 additions & 4 deletions resources/js/Pages/Transaction/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ export default function Index({auth}) {
setLoading(false);
})
.catch(console.error);
}, [currentPage, searchQuery]);
}, [currentPage]);

useEffect(() => {
setLoading(true);

getTransactions(currentPage, searchQuery)
.then(({data}) => {
setTransactions([...transactions, ...data.transactions.data])
setHasMorePages(data.transactions.paginatorInfo.hasMorePages)
setLoading(false);
})
.catch(console.error);
}, [searchQuery]);

const onCreate = (createdItem) => {
setShowCreate(false)
Expand Down Expand Up @@ -107,7 +119,7 @@ export default function Index({auth}) {
<div className="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div className="w-full pb-3 mb-4 px-4 sm:px-0">
<h2 className='text-lg text-gray-600'>Transactions</h2>

<div className='flex justify-between items-center mt-2'>
<div>
<div className="relative flex items-center">
Expand All @@ -120,11 +132,11 @@ export default function Index({auth}) {
/>
</div>
</div>

<Button children={"Create Transaction"} type="button" onClick={() => setShowCreate(true)} />
</div>
</div>

<div className="flex flex-col">
{transactions.length > 0 && <div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
Expand Down

0 comments on commit 3143775

Please sign in to comment.