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

Enhance networks Component #3344

Draft
wants to merge 20 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
39cb05d
feat: Add NetworkItem component to make it less complex
MohamedElmdary Aug 28, 2024
ffa1dd1
feat: Apply solution to all need solutions
MohamedElmdary Aug 28, 2024
d2a40aa
feat: Support has-custom-domain in Networks component
MohamedElmdary Aug 28, 2024
b0e953e
chore: update default value for hasCustomDomain to 'false'
MohamedElmdary Aug 29, 2024
66c76e6
chore: Merge branch 'development' into development_enhance_networks_i…
MohamedElmdary Aug 29, 2024
4b619af
feat: Add createNetworks function
MohamedElmdary Aug 29, 2024
7445413
chore: Refactor useNetworks method
MohamedElmdary Sep 1, 2024
c2762cd
feat: Use 'useNetworks' in freeflow solution
MohamedElmdary Sep 1, 2024
954d979
feat: Use 'useNetworks' in full_vm solution
MohamedElmdary Sep 1, 2024
a9ff88f
feat: Use 'useNetworks' in jenkins solution
MohamedElmdary Sep 1, 2024
8c30abf
feat: Use 'useNetworks' in all solutions
MohamedElmdary Sep 1, 2024
921c8fd
Merge pull request #3352 from threefoldtech/development_enhance_netwo…
MohamedElmdary Sep 1, 2024
30b685a
fix: mark wg input as readonly if domain is needed while use didn't e…
MohamedElmdary Sep 2, 2024
ae76920
fix: mark wg input as readonly if domain is needed while use didn't e…
MohamedElmdary Sep 2, 2024
a61d2e0
Merge branch 'development' into development_enhance_networks_input
MohamedElmdary Sep 4, 2024
96851d8
chore: Remove has-custom-domain from TfSelectionDetails component
MohamedElmdary Sep 4, 2024
0f0f9c9
chore: turn ipv4 into readonly in caprover
MohamedElmdary Sep 4, 2024
89d323e
merge development
0oM4R Oct 30, 2024
a5e7957
chore: jenkins
0oM4R Oct 30, 2024
a2eae58
chore: wirguard
0oM4R Oct 30, 2024
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
38 changes: 38 additions & 0 deletions packages/playground/src/components/NetworkItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<input-tooltip v-if="value !== null" inline :tooltip="tooltipText">
<v-switch
hide-details
color="primary"
inset
:label="label"
:model-value="value"
@update:model-value="callEmitFunction($event ?? false)"
:readonly="readonly"
:style="{ opacity: readonly ? 0.5 : 1 }"
/>
</input-tooltip>
</template>

<script lang="ts">
import { computed, type PropType } from "vue";

export default {
name: "NetworkItem",
props: {
tooltipText: { type: String, required: true },
label: { type: String, required: true },
value: Boolean as PropType<boolean | null | undefined>,
emitFunction: Function as PropType<any>,
},
setup(props) {
const readonly = computed(() => typeof props.emitFunction !== "function");
function callEmitFunction(value?: boolean): void {
if (typeof props.emitFunction === "function") {
props.emitFunction(value);
}
}

return { readonly, callEmitFunction };
},
};
</script>
2 changes: 1 addition & 1 deletion packages/playground/src/components/input_tooltip.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="d-flex" v-if="!disabled">
<div class="d-flex" v-if="!disabled" v-bind="$attrs">
<v-tooltip :text="tooltip || 'None!'" :location="location" :width="width ? width : ''">
<template #activator="{ props }">
{{ getPropsRef(props) }}
Expand Down
230 changes: 90 additions & 140 deletions packages/playground/src/components/networks.vue
Original file line number Diff line number Diff line change
@@ -1,151 +1,91 @@
<template>
<div ref="input">
<input-tooltip tooltip="Enable the network options to be able access your deployment">
<v-expansion-panels variant="inset" class="mb-4">
<v-expansion-panel expand-icon="mdi-menu-down" collapse-icon="mdi-menu-up" :disabled="$props.disabled">
<template v-slot:title>
<span class="text-h6">Network</span>
<v-chip v-if="error" variant="text">
<v-icon color="warning" icon="mdi-alert-circle" />
</v-chip>
<v-chip v-if="ipv4" variant="outlined" class="ml-2"> IPV4 </v-chip>
<v-chip v-if="ipv6" variant="outlined" class="ml-2"> IPV6 </v-chip>
<v-chip v-if="planetary" variant="outlined" class="ml-2"> Planetary </v-chip>
<v-chip v-if="mycelium" variant="outlined" class="ml-2"> Mycelium </v-chip>
<v-chip v-if="wireguard" variant="outlined" class="ml-2"> Wireguard </v-chip>
</template>
<v-expansion-panel-text>
<input-tooltip
v-if="ipv4 !== null"
inline
tooltip="An Internet Protocol version 4 address that is globally unique and accessible over the internet."
>
<v-switch
hide-details
color="primary"
inset
label="Public IPv4"
:readonly="enableIpv4"
:model-value="$props.ipv4"
@update:model-value="$emit('update:ipv4', $event ?? undefined)"
:style="enableIpv4 ? 'opacity: .5' : 'opacity: 1'"
/>
</input-tooltip>
<input-tooltip
v-if="ipv6 !== null"
inline
tooltip="Public IPv6 is the next-generation Internet Protocol that offers an expanded address space to connect a vast number of devices."
>
<v-switch
hide-details
color="primary"
inset
label="Public IPv6"
:modelValue="$props.ipv6"
@update:modelValue="$emit('update:ipv6', $event ?? undefined)"
/>
</input-tooltip>
<input-tooltip
v-if="planetary !== null"
inline
tooltip="The Planetary Network is a distributed network infrastructure that spans across multiple regions and countries, providing global connectivity."
>
<v-switch
hide-details
color="primary"
inset
label="Planetary Network"
:modelValue="$props.planetary"
@update:modelValue="$emit('update:planetary', $event ?? undefined)"
/>
</input-tooltip>
<input-tooltip
v-if="mycelium !== null"
inline
tooltip="Mycelium is an IPv6 overlay network. Each node that joins the overlay network will receive an overlay network IP."
>
<v-switch
hide-details
color="primary"
inset
label="mycelium"
:modelValue="$props.mycelium"
@update:modelValue="$emit('update:mycelium', $event ?? undefined)"
/>
</input-tooltip>
<input-tooltip
v-if="wireguard !== null"
inline
tooltip="Enabling WireGuard Access allows you to establish private, secure, and encrypted connections to your instance."
>
<v-switch
hide-details
color="primary"
inset
label="Add Wireguard Access"
:modelValue="$props.wireguard"
@update:modelValue="$emit('update:wireguard', $event ?? undefined)"
/>
</input-tooltip>
<v-alert v-show="error" class="mb-2" type="warning" variant="tonal">
You must enable at least one of network options.
</v-alert>
</v-expansion-panel-text>
</v-expansion-panel>
</v-expansion-panels>
</input-tooltip>
</div>
<input-tooltip ref="input" tooltip="Enable the network options to be able access your deployment">
<v-expansion-panels variant="inset" class="mb-4">
<v-expansion-panel expand-icon="mdi-menu-down" collapse-icon="mdi-menu-up" :disabled="$props.disabled">
<v-expansion-panel-title>
<v-card-title class="py-0" v-text="'Network'" />
<v-icon v-if="error" color="warning" icon="mdi-alert-circle" class="ml-2" size="small" />
<v-chip v-if="ipv4" variant="outlined" class="ml-2" text="IPV4" />
<v-chip v-if="ipv6" variant="outlined" class="ml-2" text="IPV6" />
<v-chip v-if="planetary" variant="outlined" class="ml-2" text="Planetary" />
<v-chip v-if="mycelium" variant="outlined" class="ml-2" text="Mycelium" />
<v-chip v-if="wireguard" variant="outlined" class="ml-2" text="Wireguard" />
</v-expansion-panel-title>

<v-expansion-panel-text>
<NetworkItem
tooltip-text="An Internet Protocol version 4 address that is globally unique and accessible over the internet."
label="Public IPv4"
:value="$props.ipv4"
:emit-function="$attrs['onUpdate:ipv4']"
Copy link
Contributor

Choose a reason for hiding this comment

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

on caprover we need the ipv4 to be read only

Copy link
Member Author

Choose a reason for hiding this comment

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

should be fixed

/>

<NetworkItem
tooltip-text="Public IPv6 is the next-generation Internet Protocol that offers an expanded address space to connect a vast number of devices."
label="Public IPv6"
:value="$props.ipv6"
:emit-function="$attrs['onUpdate:ipv6']"
/>

<NetworkItem
tooltip-text="The Planetary Network is a distributed network infrastructure that spans across multiple regions and countries, providing global connectivity."
label="Planetary Network"
:value="$props.planetary"
:emit-function="$attrs['onUpdate:planetary']"
/>

<NetworkItem
tooltip-text="Mycelium is an IPv6 overlay network. Each node that joins the overlay network will receive an overlay network IP."
label="Mycelium"
:value="$props.mycelium"
:emit-function="$attrs['onUpdate:mycelium']"
/>

<NetworkItem
tooltip-text="Enabling WireGuard Access allows you to establish private, secure, and encrypted connections to your instance."
label="Add Wireguard Access"
:value="$props.wireguard"
:emit-function="readonlyWireguard ? undefined : $attrs['onUpdate:wireguard']"
/>

<v-alert
v-if="error"
class="my-2"
type="warning"
variant="tonal"
text="You must enable at least one of network options."
/>
</v-expansion-panel-text>
</v-expansion-panel>
</v-expansion-panels>
</input-tooltip>
</template>

<script lang="ts">
import { noop } from "lodash";
import { computed, getCurrentInstance, onMounted, onUnmounted, ref, watch } from "vue";
import { computed, getCurrentInstance, onMounted, onUnmounted, ref, toRefs, watch } from "vue";

import { useForm, ValidatorStatus } from "@/hooks/form_validator";
import type { InputValidatorService } from "@/hooks/input_validator";

import NetworkItem from "./NetworkItem.vue";

export default {
name: "Network",
components: { NetworkItem },
props: {
required: {
type: Boolean,
default: () => false,
},
ipv4: {
type: Boolean,
default: () => null,
},
ipv6: {
type: Boolean,
default: () => null,
},
planetary: {
type: Boolean,
default: () => null,
},
mycelium: {
type: Boolean,
default: () => null,
},
wireguard: {
type: Boolean,
default: () => null,
},
disabled: { type: Boolean },
enableIpv4: {
type: Boolean,
default: () => null,
},
},
emits: {
"update:ipv4": (value?: boolean) => value,
"update:ipv6": (value?: boolean) => value,
"update:planetary": (value?: boolean) => value,
"update:mycelium": (value?: boolean) => value,
"update:wireguard": (value?: boolean) => value,
required: { type: Boolean, default: () => false },
ipv4: { type: Boolean, default: () => null },
ipv6: { type: Boolean, default: () => null },
planetary: { type: Boolean, default: () => null },
mycelium: { type: Boolean, default: () => null },
wireguard: { type: Boolean, default: () => null },
hasCustomDomain: { type: Boolean, default: () => true },
disabled: Boolean,
},
setup(props, { expose }) {
setup(props, { attrs }) {
const input = ref();
const $el = computed(() => input.value?.$el);

if (
props.ipv4 === null &&
Expand All @@ -156,11 +96,8 @@ export default {
) {
throw new Error("You must provide at least one network option");
}
const error = computed(
() => !(props.ipv4 || props.ipv6 || props.planetary || props.wireguard || props.mycelium) && props.required,
);
expose({
error,
const error = computed(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

on k8s I was able to disable all networks and click on deploy without any errors
image

Copy link
Member Author

Choose a reason for hiding this comment

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

this is because it's not required but I checked early versions and it wasn't require too should I turn it into required?

return !(props.ipv4 || props.ipv6 || props.planetary || props.wireguard || props.mycelium) && props.required;
});

/* Adapter to work with old code validation */
Expand All @@ -173,7 +110,7 @@ export default {
reset: noop,
status: ValidatorStatus.Valid,
error: null,
$el: input,
$el,
highlightOnError: true,
};

Expand All @@ -185,9 +122,22 @@ export default {
form?.updateStatus(uid.toString(), fakeService.status);
});

const readonlyWireguard = computed(() => props.hasCustomDomain && !props.ipv4);
MohamedElmdary marked this conversation as resolved.
Show resolved Hide resolved
watch(
readonlyWireguard,
readonly => {
const fn = attrs["onUpdate:wireguard"];
if (readonly && !props.wireguard && typeof fn === "function") {
fn(true);
}
MohamedElmdary marked this conversation as resolved.
Show resolved Hide resolved
},
{ immediate: true },
);

return {
error,
input,
readonlyWireguard,
};
},
};
Expand Down
6 changes: 5 additions & 1 deletion packages/playground/src/weblets/freeflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
:large="{ cpu: 4, memory: 32, disk: 1000 }"
/>

<Networks v-model:ipv4="ipv4" v-model:ipv6="ipv6"></Networks>
<Networks
v-model:ipv4="ipv4"
v-model:ipv6="ipv6"
:has-custom-domain="selectionDetails?.domain?.enabledCustomDomain"
/>

<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
Expand Down
3 changes: 0 additions & 3 deletions packages/playground/src/weblets/full_vm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

<Network
required
ref="network"
v-model:ipv4="ipv4"
v-model:ipv6="ipv6"
v-model:planetary="planetary"
Expand Down Expand Up @@ -155,7 +154,6 @@ const selectionDetails = ref<SelectionDetails>();

const layout = useLayout();
const tabs = ref();
const profileManager = useProfileManager();
const solution = ref() as Ref<SolutionFlavor>;
const images: VmImage[] = [
{
Expand Down Expand Up @@ -196,7 +194,6 @@ const wireguard = ref(false);
const dedicated = ref(false);
const certified = ref(false);
const disks = ref<Disk[]>([]);
const network = ref();
const hasGPU = ref(false);
const rootFilesystemSize = computed(() =>
flist.value?.name === "Ubuntu-24.04" || flist.value?.name === "Other" ? solution.value?.disk : 2,
Expand Down
2 changes: 0 additions & 2 deletions packages/playground/src/weblets/micro_vm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
v-model:planetary="planetary"
v-model:mycelium="mycelium"
v-model:wireguard="wireguard"
ref="network"
/>
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
Expand Down Expand Up @@ -245,7 +244,6 @@ const mycelium = ref(true);
const wireguard = ref(false);
MohamedElmdary marked this conversation as resolved.
Show resolved Hide resolved
const envs = ref<Env[]>([]);
const disks = ref<Disk[]>([]);
const network = ref();
const dedicated = ref(false);
const certified = ref(false);
const selectionDetails = ref<SelectionDetails>();
Expand Down
8 changes: 7 additions & 1 deletion packages/playground/src/weblets/tf_casperlabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@
:large="{ cpu: 8, memory: 32, disk: 1000 }"
/>

<Networks v-model:ipv4="ipv4" v-model:planetary="planetary" v-model:mycelium="mycelium" v-model:ipv6="ipv6" />
<Networks
v-model:ipv4="ipv4"
v-model:planetary="planetary"
v-model:mycelium="mycelium"
v-model:ipv6="ipv6"
:has-custom-domain="selectionDetails?.domain?.enabledCustomDomain"
/>

<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/src/weblets/tf_discourse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
<Networks
v-model:mycelium="mycelium"
v-model:planetary="planetary"
v-model:ipv4="ipv4"
:ipv4="ipv4"
v-model:ipv6="ipv6"
enableIpv4
:has-custom-domain="selectionDetails?.domain?.enabledCustomDomain"
/>

<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
Expand Down
Loading
Loading