-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathContainerProviderConnectionSelect.svelte
More file actions
78 lines (69 loc) · 2.32 KB
/
Copy pathContainerProviderConnectionSelect.svelte
File metadata and controls
78 lines (69 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<script lang="ts">
import Select from './Select.svelte';
import type { ProviderContainerConnectionDetailedInfo } from '@podman-desktop/extension-hummingbird-core-api';
interface Props {
value: ProviderContainerConnectionDetailedInfo | undefined;
onChange?: (value: ProviderContainerConnectionDetailedInfo | undefined) => void;
containerProviderConnections: ProviderContainerConnectionDetailedInfo[];
disabled?: boolean;
clearable?: boolean;
}
let { value = $bindable(), clearable = true, containerProviderConnections, onChange, disabled }: Props = $props();
/**
* Handy mechanism to provide the mandatory property `label` and `value` to the Select component
*/
let selected: (ProviderContainerConnectionDetailedInfo & { label: string; value: string }) | undefined = $derived.by(
() => {
if (value) {
return { ...value, label: value.name, value: key(value) };
}
},
);
function key(connection: ProviderContainerConnectionDetailedInfo): string {
return `${connection.providerId}:${connection.name}`;
}
function handleOnChange(nValue: ProviderContainerConnectionDetailedInfo | undefined): void {
value = nValue;
onChange?.(value);
}
function getProviderStatusColor(item: ProviderContainerConnectionDetailedInfo): string {
switch (item.status) {
case 'starting':
case 'stopping':
return 'bg-[var(--pd-status-degraded)]';
case 'started':
return 'bg-[var(--pd-status-running)]';
default:
return 'bg-[var(--pd-status-stopped)]';
}
}
</script>
<Select
label="Select Container Engine"
name="select-container-engine"
disabled={disabled}
value={selected}
onchange={handleOnChange}
clearable={clearable}
placeholder="Select container provider to use"
items={containerProviderConnections.map(containerProviderConnection => ({
...containerProviderConnection,
value: key(containerProviderConnection),
label: containerProviderConnection.name,
}))}>
<div slot="item" let:item>
<div class="flex items-center w-full">
<div class="w-2 h-2 min-w-2 me-2 rounded-full {getProviderStatusColor(item)}"></div>
<div class="flex-1 min-w-0">
<span class="block truncate">
{item.name}
</span>
</div>
{#if item.vmType}
<div class="flex-shrink-0 ms-2">
({item.vmType})
</div>
{/if}
</div>
</div>
</Select>