From ad5228126467424c88c66f3eeafb8c57f8797e32 Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Wed, 27 Sep 2023 11:03:13 +0300 Subject: [PATCH 1/4] Implemented node filters. --- .../playground/src/components/node_filter.vue | 75 ++++++++++++++++ packages/playground/src/utils/filter_nodes.ts | 85 +++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 packages/playground/src/components/node_filter.vue diff --git a/packages/playground/src/components/node_filter.vue b/packages/playground/src/components/node_filter.vue new file mode 100644 index 0000000000..ed69d6c43a --- /dev/null +++ b/packages/playground/src/components/node_filter.vue @@ -0,0 +1,75 @@ + + + diff --git a/packages/playground/src/utils/filter_nodes.ts b/packages/playground/src/utils/filter_nodes.ts index 7ae2799c5c..aa62602852 100644 --- a/packages/playground/src/utils/filter_nodes.ts +++ b/packages/playground/src/utils/filter_nodes.ts @@ -1,7 +1,10 @@ import type { FilterOptions, GridClient, NodeInfo } from "@threefold/grid_client"; +import type { AsyncRule, SyncRule } from "@/components/input_validator.vue"; import type { NodeFilters } from "@/components/select_node.vue"; +import { isNumeric } from "./validators"; + export interface NodeGPUCardType { id: string; vendor: string; @@ -33,3 +36,85 @@ export async function getFilteredNodes(grid: GridClient, options: NodeFilters): const nodes = await grid.capacity.filterNodes(filters); return nodes; } + +// Node filters used in #Explorer, #Dedicated Nodes... + +// Input attrs +export type NodeInputFilterType = { + label: string; + placeholder: string; + value?: string | undefined; + rules?: [syncRules: SyncRule[], asyncRules?: AsyncRule[]]; + error?: string; + type: string; +}; + +// Input fields +export type FilterInputs = { + nodeId: NodeInputFilterType; + farmIds: NodeInputFilterType; + farmName: NodeInputFilterType; + country: NodeInputFilterType; + freeSru: NodeInputFilterType; + freeHru: NodeInputFilterType; + freeMru: NodeInputFilterType; +}; + +// Default input Initialization +export const inputsInitializer: FilterInputs = { + nodeId: { + label: "Node ID", + placeholder: "Filter by node id.", + rules: [[isNumeric("This field accepts numbers only.", { no_symbols: true })]], + type: "text", + }, + farmIds: { + label: "Farm IDs", + placeholder: "e.g. 1, 2, 3", + rules: [ + [ + isNumeric("This field accepts numbers only.", { no_symbols: true }), + (value: string) => { + const ids = value.split(",").map((id: string) => { + if (isNaN(+id)) { + return isNumeric("This field accepts numbers only.", { no_symbols: true }); + } else { + return isNumeric("This field accepts numbers only.", { no_symbols: true }); + } + }); + console.log(ids); + }, + ], + ], + type: "text", + }, + farmName: { + label: "Farm Name", + placeholder: "Filter by farm name.", + type: "text", + }, + country: { + label: "Country Full Name", + placeholder: "Filter by country.", + type: "text", + }, + freeSru: { + label: "Free SRU (GB)", + placeholder: "Filter by Free SSD greater than or equal to.", + rules: [[isNumeric("This field accepts numbers only.", { no_symbols: true })]], + type: "text", + }, + freeHru: { + label: "Free HRU (GB)", + placeholder: "Filter by Free HDD greater than or equal to.", + rules: [[isNumeric("This field accepts numbers only.", { no_symbols: true })]], + type: "text", + }, + freeMru: { + label: "Free MRU (GB)", + placeholder: "Filter by Free Memory greater than or equal to.", + value: undefined, + rules: [[isNumeric("This field accepts numbers only.", { no_symbols: true })]], + type: "text", + }, +}; From 66fdee5079c418a0c0eafa561520e9c2007961d8 Mon Sep 17 00:00:00 2001 From: Mahmoud Emad Date: Wed, 27 Sep 2023 17:10:14 +0300 Subject: [PATCH 2/4] Update the model form to validate the inputs. --- .../src/components/form_validator.vue | 16 ++- .../playground/src/components/node_filter.vue | 101 ++++++++++-------- .../playground/src/hooks/form_validator.ts | 4 +- packages/playground/src/utils/filter_nodes.ts | 11 +- 4 files changed, 79 insertions(+), 53 deletions(-) diff --git a/packages/playground/src/components/form_validator.vue b/packages/playground/src/components/form_validator.vue index 8df4cbaa40..82530fef5e 100644 --- a/packages/playground/src/components/form_validator.vue +++ b/packages/playground/src/components/form_validator.vue @@ -10,13 +10,23 @@ import type { InputValidatorService } from "@/hooks/input_validator"; export default { name: "FormValidator", - props: ["modelValue"], + props: { + modelValue: Boolean, + validOnInit: Boolean, + }, emits: { "update:modelValue": (value: boolean) => value }, - setup(_, { emit, expose }) { + setup(props, { emit, expose }) { const statusMap = ref(new Map()); const serviceMap = new Map(); - const valid = computed(() => [...statusMap.value.values()].every(status => status === ValidatorStatus.Valid)); + const valid = computed(() => + [...statusMap.value.values()].every(status => { + if (props.validOnInit) { + return status === ValidatorStatus.Valid || status === ValidatorStatus.Init; + } + return status === ValidatorStatus.Valid; + }), + ); watch(valid, valid => emit("update:modelValue", valid), { immediate: true }); const form: FormValidatorService = { diff --git a/packages/playground/src/components/node_filter.vue b/packages/playground/src/components/node_filter.vue index ed69d6c43a..8e4448afe8 100644 --- a/packages/playground/src/components/node_filter.vue +++ b/packages/playground/src/components/node_filter.vue @@ -1,52 +1,65 @@