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 search your farms #2938

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Changes from all commits
Commits
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
22 changes: 3 additions & 19 deletions packages/playground/src/dashboard/components/user_farms.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,18 @@ export default {
const refreshPublicIPs = ref(false);

const reloadFarms = debounce(getUserFarms, 20000);
function filter(items: Farm[]) {
const start = (page.value - 1) * pageSize.value;
const end = start + pageSize.value;

let filteredItems;
if (search.value) {
filteredItems = items.filter(
item => item.name.toLowerCase().includes(search.value!.toLowerCase()) || item.farmId == +search.value!,
);
}

const paginated = filteredItems ? filteredItems.slice(start, end) : items;

return paginated;
}

async function getUserFarms() {
try {
const { data, count } = await gridProxyClient.farms.list({
retCount: true,
twinId,
page: page.value,
size: pageSize.value,
nameContains: search.value,
});

const filteredFarms = filter(data);
farms.value = filteredFarms as unknown as Farm[];
farmsCount.value = count || filteredFarms.length;
farms.value = data as Farm[];
farmsCount.value = count || farms.value.length;
} catch (error) {
console.log(error);
createCustomToast("Failed to get user farms!", ToastType.danger);
Expand Down
Loading