Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions frontend/kubecloud/src/components/NodeFilterPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
<label class="filter-label">Price Range ($/mo)</label>
<v-range-slider
v-model="modelValue.priceRange"
:min="priceMin"
:max="priceMax"
:min="priceMin < Infinity ? priceMin : undefined"
:max="priceMax > -Infinity ? priceMax : undefined"
:step="1"
thumb-label
class="filter-slider"
Expand Down Expand Up @@ -153,4 +153,4 @@ function formatStorage(val: number) {
opacity: 0.85;
margin-top: 0.25rem;
}
</style>
</style>
16 changes: 12 additions & 4 deletions frontend/kubecloud/src/composables/useNodeFilters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { computed, ref, watch } from 'vue';
import type { NormalizedNode } from '../types/normalizedNode';
import { getNodePrice } from '../utils/nodeNormalizer';

export interface NodeFilterState {
cpu: [number, number];
Expand All @@ -16,8 +17,14 @@ export function useNodeFilters(nodes: () => NormalizedNode[], initialPriceRange:
const cpuMax = computed(() => Math.max(...nodes().map(n => n.cpu).filter(Boolean), 0));
const ramMin = computed(() => Math.min(...nodes().map(n => Math.round(n.ram)).filter(Boolean), 0));
const ramMax = computed(() => Math.max(...nodes().map(n => Math.round(n.ram)).filter(Boolean), 0));
const priceMin = computed(() => Math.min(...nodes().map(n => typeof n.price_usd === 'number' ? n.price_usd : Infinity)));
const priceMax = computed(() => Math.max(...nodes().map(n => typeof n.price_usd === 'number' ? n.price_usd : 0)));
const priceMin = computed(() => Math.floor(Math.min(...nodes().map(n => {
const price = getNodePrice(n);
return typeof price === 'number' ? price : Infinity;
}))));
const priceMax = computed(() => Math.ceil(Math.max(...nodes().map(n => {
const price = getNodePrice(n);
return typeof price === 'number' ? price : 0;
}))));

// Location options
const locationOptions = computed(() => {
Expand Down Expand Up @@ -61,10 +68,11 @@ export function useNodeFilters(nodes: () => NormalizedNode[], initialPriceRange:
// Filtering logic
const filteredNodes = computed(() => {
return nodes().filter(node => {
const price = getNodePrice(node);
if (node.cpu < filters.value.cpu[0] || node.cpu > filters.value.cpu[1]) return false;
if (Math.round(node.ram) < filters.value.ram[0] || Math.round(node.ram) > filters.value.ram[1]) return false;
if (filters.value.gpu && node.gpu === false) return false;
if (typeof node.price_usd === 'number' && (node.price_usd < filters.value.priceRange[0] || node.price_usd > filters.value.priceRange[1])) return false;
if (typeof price === 'number' && (price < filters.value.priceRange[0] || price > filters.value.priceRange[1])) return false;
if (filters.value.location &&
!node.locationString.toLowerCase().includes(filters.value.location?.toLowerCase() ?? '')
)
Expand Down Expand Up @@ -99,4 +107,4 @@ export function useNodeFilters(nodes: () => NormalizedNode[], initialPriceRange:
locationOptions,
clearFilters
};
}
}
7 changes: 7 additions & 0 deletions frontend/kubecloud/src/utils/nodeNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { RawNode } from '../types/rawNode';
import type { NormalizedNode } from '../types/normalizedNode';
import type { RentedNode } from '../composables/useNodeManagement';


export function getNodePrice(node: NormalizedNode) {
const base = Number(node.discount_price ?? node.price_usd ?? 0);
const extra = Number(node.extraFee ?? 0) / 1000;
const price = base + extra;
return isNaN(price) ? null : price;
}
export function normalizeNode(node: RawNode): NormalizedNode {
return {
nodeId: node.nodeId,
Expand Down