Skip to content

Commit 353a3c0

Browse files
committed
fix: change the look of the infra provider labels
Fixes: #822 Signed-off-by: Artem Chernyshev <[email protected]>
1 parent 7052e8b commit 353a3c0

File tree

6 files changed

+60
-33
lines changed

6 files changed

+60
-33
lines changed

client/pkg/omni/resources/omni/labels.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,12 @@ const (
9090
// tsgen:LabelMachinePendingAccept
9191
LabelMachinePendingAccept = SystemLabelPrefix + "accept-pending"
9292

93+
// InfraProviderLabelPrefix is the prefix of all labels which are managed by the infra providers.
94+
// tsgen:InfraProviderLabelPrefix
95+
InfraProviderLabelPrefix = SystemLabelPrefix + "infra-provider"
96+
9397
// InfraProviderLabelPrefixFormat is the prefix of all labels which are managed by the infra providers.
94-
InfraProviderLabelPrefixFormat = SystemLabelPrefix + "infra-provider[%s]/"
98+
InfraProviderLabelPrefixFormat = InfraProviderLabelPrefix + "/%s/"
9599
)
96100

97101
const (

frontend/src/api/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export const LabelMachineRequestSet = "omni.sidero.dev/machine-request-set";
131131
export const LabelNoManualAllocation = "omni.sidero.dev/no-manual-allocation";
132132
export const LabelIsManagedByStaticInfraProvider = "omni.sidero.dev/is-managed-by-static-infra-provider";
133133
export const LabelMachinePendingAccept = "omni.sidero.dev/accept-pending";
134+
export const InfraProviderLabelPrefix = "omni.sidero.dev/infra-provider";
134135
export const MachineStatusLabelConnected = "omni.sidero.dev/connected";
135136
export const MachineStatusLabelReadyToUse = "omni.sidero.dev/ready-to-use";
136137
export const MachineStatusLabelDisconnected = "omni.sidero.dev/disconnected";

frontend/src/methods/labels.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Use of this software is governed by the Business Source License
44
// included in the LICENSE file.
55

6+
import { InfraProviderLabelPrefix, SystemLabelPrefix } from "@/api/resources";
7+
68
export const parseLabels = (...labels: string[]): Record<string, string> => {
79
const labelsMap: Record<string, string> = {};
810

@@ -16,12 +18,13 @@ export const parseLabels = (...labels: string[]): Record<string, string> => {
1618
}
1719

1820
export type Label = {
19-
key: string;
20-
id: string,
21-
value: string;
22-
color: string;
23-
removable?: boolean;
24-
description?: string,
21+
key: string
22+
id: string
23+
value: string
24+
color: string
25+
removable?: boolean
26+
description?: string
27+
icon?: string
2528
}
2629

2730
const labelColors = {
@@ -75,3 +78,36 @@ export const selectors = (labels: Label[]) => {
7578
return `${label.key}=${label.value}`;
7679
});
7780
}
81+
82+
const labelDescriptions = {
83+
"invalid-state": "The machine is expected to be unallocated, but still has the configuration of a cluster.\nIt might be required to wipe the machine bypassing Omni."
84+
};
85+
86+
export const getLabelFromID = (key: string, value: string): Label => {
87+
const isUser = key.indexOf(SystemLabelPrefix) !== 0;
88+
89+
let strippedKey = key.replace(new RegExp(`^${SystemLabelPrefix}`), "");
90+
let icon: string | undefined;
91+
let color = getLabelColor(strippedKey);
92+
let description = labelDescriptions[strippedKey];
93+
94+
if (key.indexOf(InfraProviderLabelPrefix) === 0) {
95+
const parts = strippedKey.split("/");
96+
strippedKey = parts[parts.length - 1];
97+
98+
icon = "server-network";
99+
color = "green";
100+
101+
description = `Defined by the infra provider "${parts[1]}""`
102+
}
103+
104+
return {
105+
key: key,
106+
id: strippedKey,
107+
value: value,
108+
color: color,
109+
removable: isUser,
110+
description: description,
111+
icon: icon,
112+
};
113+
}

frontend/src/views/omni/ItemLabels/ItemLabel.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ included in the LICENSE file.
88
<component :is="label.description ? Tooltip : 'div'" :description="label.description" placement="bottom-start">
99
<span class="flex items-center cursor-pointer transition-all" v-bind:class="`resource-label label-${label.color}`"
1010
@click.stop="() => $emit('filterLabel', label)">
11+
<t-icon v-if="label.icon" :icon="label.icon as IconType" class="w-3.5 h-3.5 mr-1 -ml-1"/>
1112
<template v-if="label.value">
1213
{{ label.id }}:<span class="font-semibold">{{ label.value }}</span>
1314
</template>
@@ -22,7 +23,7 @@ included in the LICENSE file.
2223

2324
<script setup lang="ts">
2425
import Tooltip from "@/components/common/Tooltip/Tooltip.vue";
25-
import TIcon from "@/components/common/Icon/TIcon.vue";
26+
import TIcon, { IconType } from "@/components/common/Icon/TIcon.vue";
2627

2728
defineProps<{
2829
label: {
@@ -32,6 +33,7 @@ defineProps<{
3233
color: string,
3334
description?: string,
3435
removable?: boolean,
36+
icon?: string,
3537
},
3638
removeLabel?: (key :string) => Promise<void>
3739
}>();

frontend/src/views/omni/ItemLabels/ItemLabels.vue

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import TButton from "@/components/common/Button/TButton.vue";
2323
import TInput from "@/components/common/TInput/TInput.vue";
2424
import { showError } from "@/notification";
2525
import { SystemLabelPrefix } from "@/api/resources";
26-
import { Label, getLabelColor } from "@/methods/labels";
26+
import { Label, getLabelFromID } from "@/methods/labels";
2727

2828
const props = defineProps<{
2929
resource: Resource
@@ -67,31 +67,19 @@ const getLabelOrder = (l: Label) => {
6767
return labelOrder[l.id] ?? 1000;
6868
}
6969

70-
const labelDescriptions = {
71-
"invalid-state": "The machine is expected to be unallocated, but still has the configuration of a cluster.\nIt might be required to wipe the machine bypassing Omni."
72-
};
73-
7470
const labels = computed((): Array<Label> => {
7571
const labels = resource.value.metadata?.labels || {};
7672

7773
let labelsArray: Array<Label> = [];
7874

7975
for (const key in labels) {
80-
const isUser = key.indexOf(SystemLabelPrefix) !== 0;
81-
const strippedKey = key.replace(new RegExp(`^${SystemLabelPrefix}`), "");
76+
const label = getLabelFromID(key, labels[key]);
8277

83-
if (labelOrder[strippedKey] === -1) {
78+
if (getLabelOrder(label) === -1) {
8479
continue;
8580
}
8681

87-
labelsArray.push({
88-
key: key,
89-
id: strippedKey,
90-
value: labels[key],
91-
color: getLabelColor(strippedKey),
92-
removable: isUser,
93-
description: labelDescriptions[strippedKey],
94-
})
82+
labelsArray.push(label);
9583
}
9684

9785
labelsArray.sort((a, b) => {

frontend/src/views/omni/ItemLabels/LabelsInput.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,13 @@ included in the LICENSE file.
6868

6969
<script setup lang="ts">
7070
import { Runtime } from "@/api/common/omni.pb";
71-
import { SystemLabelPrefix } from "@/api/resources";
7271

7372
import { ref, toRefs, watch } from "vue";
7473
import TInput from "@/components/common/TInput/TInput.vue";
7574
import { Resource, ResourceService } from "@/api/grpc";
7675
import { withAbortController, withRuntime } from "@/api/options";
7776
import ItemLabel from "../ItemLabels/ItemLabel.vue";
78-
import { getLabelColor } from "@/methods/labels";
77+
import { getLabelFromID as createLabel } from "@/methods/labels";
7978

8079
type Label = {
8180
id: string
@@ -223,14 +222,11 @@ watch(filterValue, async (val: string, old: string) => {
223222

224223
matchedLabelsCompletion.value = labelsCompletions.filter(matcher).map(
225224
item => {
226-
const shortKey = item.key.replace(new RegExp(`^${SystemLabelPrefix}`), "");
225+
const label = createLabel(item.key, item.value);
227226

228-
return {
229-
id: item.value === "" ? `has label: ${shortKey}` : shortKey,
230-
value: item.value,
231-
key: item.key,
232-
color: getLabelColor(shortKey)
233-
}
227+
label.id = item.value === "" ? `has label: ${label.id}` : label.id;
228+
229+
return label;
234230
}
235231
);
236232
});

0 commit comments

Comments
 (0)