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

fix: disable transaction type filter when there are no transactions #818

Merged
merged 8 commits into from
Nov 15, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe("Transactions", () => {
expect(within(screen.getByTestId("TransactionTable")).getAllByTestId("TableRow")).toHaveLength(15),
);

const button = screen.getAllByRole("button", { name: /Type/ })[0];
let button = screen.getAllByRole("button", { name: /Type/ })[0];

expect(button).toBeInTheDocument();

Expand All @@ -235,6 +235,9 @@ describe("Transactions", () => {
await userEvent.click(options.at(-1));

await expect(screen.findByTestId("EmptyBlock")).resolves.toBeVisible();

button = screen.getAllByRole("button", { name: /Type/ })[0];
expect(button).not.toBeDisabled();
});

it("should open detail modal on transaction row click", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const Transactions = memo(function Transactions({
selectedTransactionTypes,
fetchMore,
hasEmptyResults,
hasFilter,
hasMore,
} = useProfileTransactions({ limit: 30, profile, wallets });

Expand Down Expand Up @@ -148,6 +149,14 @@ export const Transactions = memo(function Transactions({
return !hasEmptyResults || hasFilter || hasMore;
}, [activeMode, hasEmptyResults, activeTransactionType, isLoadingTransactions, hasMore]);

const enableFilter = useMemo(() => {
if (isLoadingTransactions || hasFilter) {
Copy link
Contributor Author

@shahin-hq shahin-hq Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to enable filter when transactions are loading or when a filter is applied - I mean by that is initially we have all possible options selected this should be understood as no filters applied, when user picks a filter it means there was at least one transaction to display, so we shouldn't disable the filter.

return true;
}

return !hasEmptyResults || hasMore;
}, [hasEmptyResults, hasMore, isLoadingTransactions, hasFilter]);

if (!isVisible) {
return <></>;
}
Expand Down Expand Up @@ -221,6 +230,7 @@ export const Transactions = memo(function Transactions({
wallets={wallets}
onSelect={filterChangeHandler}
selectedTransactionTypes={selectedTransactionTypes}
isDisabled={!enableFilter}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20877,8 +20877,9 @@ exports[`Transactions > should update wallet filters 1`] = `
data-testid="dropdown__toggle"
>
<button
class="space-x-2 relative items-center inline-flex justify-center font-semibold text-center transition-colors-shadow duration-100 ease-linear outline-none rounded focus:outline-none focus:ring-2 focus:ring-theme-primary-400 disabled:cursor-not-allowed dark:bg-theme-secondary-800 dark:text-theme-secondary-200 bg-theme-primary-100 text-theme-primary-600 hover:bg-theme-primary-800 green:hover:bg-theme-primary-700 hover:text-white dark:hover:bg-theme-primary-500 w-full px-4 py-1.5 text-base sm:w-fit"
class="space-x-2 relative items-center inline-flex justify-center font-semibold text-center transition-colors-shadow duration-100 ease-linear outline-none rounded focus:outline-none focus:ring-2 focus:ring-theme-primary-400 disabled:cursor-not-allowed disabled:bg-theme-secondary-200 disabled:text-theme-secondary-400 dark:disabled:bg-theme-secondary-800 dark:disabled:text-theme-secondary-700 w-full px-4 py-1.5 text-base sm:w-fit"
data-testid="CollapseToggleButton"
disabled=""
type="button"
>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ export const useProfileTransactions = ({ profile, wallets, limit = 30 }: Profile
fetchMore,
fetchTransactions,
hasEmptyResults,
hasFilter: (selectedTransactionTypes?.length ?? 0) < allTransactionTypes.length,
hasMore,
isLoadingMore,
isLoadingTransactions,
Expand Down
Loading