Skip to content

Commit 88cb01f

Browse files
committed
feat: improve display of long names in table cells
1 parent ea905c5 commit 88cb01f

File tree

5 files changed

+35
-15
lines changed

5 files changed

+35
-15
lines changed

app/contrib/tests/test_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def test_docker_container():
115115
assert x.id == '123456789abcdef'
116116
assert x.names == ['/container_name']
117117
assert x.image == 'nginx:latest'
118+
assert x.short_image == x.image
118119
assert x.image_id == 'sha256:abcdef123456'
119120
assert x.created == datetime(2023, 1, 1, 12, 0, tzinfo=timezone.utc)
120121
assert x.size_rw == 50000
@@ -135,6 +136,9 @@ def test_docker_container():
135136
})
136137
assert x.clean_names == []
137138

139+
x.image = 'sha256:f31294ac0a9255aa810e2cd9639485260ff9b3c19ef3263a56a091fad37e23b5'
140+
assert x.short_image == 'f31294ac0a92'
141+
138142

139143
def test_docker_container_list():
140144
containers = [
@@ -170,6 +174,7 @@ def test_docker_volume():
170174
})
171175

172176
assert x.name == 'volume1'
177+
assert x.short_name == x.name
173178
assert x.driver == 'local'
174179
assert x.created_at == datetime(2023, 1, 1, 12, 0, tzinfo=timezone.utc)
175180
assert x.mountpoint == '/var/lib/docker/volumes/volume1'
@@ -178,6 +183,9 @@ def test_docker_volume():
178183
assert x.ref_count == 2
179184
assert x.containers == []
180185

186+
x.name = '26fb9bbf928c9a4dae3198438fb02f7b286894069dadf2827f8d3f98bbb2aa64'
187+
assert x.short_name == x.name[:39] + '...'
188+
181189

182190
def test_docker_volume_list():
183191
volumes = [

app/contrib/types.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
from scan.utils import pretty_size
77

88

9+
def truncate(name: str, limit: int) -> str:
10+
if len(name) <= limit:
11+
return name
12+
return name[:limit] + '...'
13+
14+
915
class DockerVersion(BaseModel):
1016
platform_name: str = Field(alias=('Platform', 'Name'), default='')
1117
version: str = Field(alias='Version')
@@ -65,6 +71,12 @@ class DockerContainer(BaseModel):
6571
def short_id(self) -> str:
6672
return self.id[:12]
6773

74+
@property
75+
def short_image(self) -> str:
76+
if self.image.startswith('sha256:'):
77+
return self.image[7:19]
78+
return self.image
79+
6880
@property
6981
def clean_names(self) -> list[str]:
7082
if not self.names:
@@ -95,6 +107,10 @@ class DockerVolume(BaseModel):
95107
usage_data: dict | None = Field(alias='UsageData', default_factory=dict)
96108
containers: list[str] | None = Field(default_factory=list)
97109

110+
@property
111+
def short_name(self) -> str:
112+
return truncate(self.name, 39)
113+
98114
@property
99115
def size(self) -> int:
100116
if 'Size' not in self.usage_data:
@@ -135,11 +151,7 @@ def last_used_delta(self) -> str:
135151

136152
@property
137153
def short_desc(self) -> str:
138-
limit = 180
139-
s = self.description[:limit]
140-
if len(self.description) > limit:
141-
s += '...'
142-
return s
154+
return truncate(self.description, 180)
143155

144156

145157
class DockerBuildCacheList(RootModel):
@@ -223,11 +235,7 @@ class DockerOverlay2Layer(BaseModel):
223235

224236
@property
225237
def short_id(self) -> str:
226-
limit = 22
227-
s = self.id[:limit]
228-
if len(self.id) > limit:
229-
s += '...'
230-
return s
238+
return truncate(self.id, 22)
231239

232240
@property
233241
def created_delta(self) -> str:

app/templates/pages/build_cache.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
{% for item in items %}
2020
<tr>
2121
<td>
22-
<span uk-tooltip="title: {{ item.description }}; pos: top">
22+
{% if item.short_desc == item.description %}
2323
{{ item.short_desc }}
24-
</span>
24+
{% else %}
25+
<span uk-tooltip="title: {{ item.description }}; pos: top">
26+
{{ item.short_desc }}
27+
</span>
28+
{% endif %}
2529
</td>
2630
<td class="width-1">{{ item.size }}</td>
2731
<td class="uk-text-nowrap uk-text-center">{{ item.usage_count }}</td>

app/templates/pages/containers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<td class="uk-text-nowrap">
3131
{{ item.clean_names|join('<br>')|safe }}
3232
</td>
33-
<td class="uk-text-nowrap">{{ item.image }}</td>
33+
<td class="uk-text-nowrap">{{ item.short_image }}</td>
3434
<td class="width-1">{{ item.size_rw }}</td>
3535
<td class="width-1">{{ item.size_root_fs }}</td>
3636
<td class="uk-text-nowrap uk-text-center">{{ item.state }}</td>

app/templates/pages/volumes.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<tbody class="uk-text-secondary">
1717
{% for item in items %}
1818
<tr>
19-
<td class="uk-text-nowrap">{{ item.name }}</td>
19+
<td class="uk-text-nowrap">{{ item.short_name }}</td>
2020
<td class="width-1">{{ item.size }}</td>
2121
<td>
2222
<ul class="uk-text-nowrap uk-padding-small uk-padding-remove-vertical">
@@ -26,7 +26,7 @@
2626
</ul>
2727
</td>
2828
<td class="uk-text-nowrap uk-text-center uk-text-muted">{{ item.driver }}</td>
29-
<td class="uk-text-muted">{{ item.mountpoint }}</td>
29+
<td class="uk-text-muted uk-text-break">{{ item.mountpoint }}</td>
3030
</tr>
3131
{% endfor %}
3232
</tbody>

0 commit comments

Comments
 (0)