Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
name: 240,
storage: 80,
status: 136,
tags: 160,
// About two and a half chips of 10-character tags (each about 100px) and the cell padding.
tags: 280,
runtime: 112,
errors: 96,
statusChanged: 152,
Expand Down Expand Up @@ -317,10 +318,12 @@
<div class="flex px-2 md:pr-[calc(--spacing(8)-var(--scroll-gutter-width))] md:pl-8">
<!-- The page wraps the table to fit its content, so a percentage width would have nothing
to resolve against. As a flex item the table starts at the columns' total, which also
sets how wide the page scrolls, and grows into any room left over, which Message takes. -->
sets how wide the page scrolls, and grows into any room left over, which Message takes.
The fixed layout applies only to a table with a set width. Without one, long content
such as a tag makes its column wider than the user set it. -->
<table
class="bg-white-dark flex-1 border-separate border-spacing-0 rounded-lg border border-line [&_th:first-child]:rounded-tl-lg [&_th:last-child]:rounded-tr-lg [&_tr:last-child>td:first-child]:rounded-bl-lg [&_tr:last-child>td:last-child]:rounded-br-lg"
style="table-layout: fixed; flex-basis: {tableMinWidth}px; min-width: {tableMinWidth}px"
style="table-layout: fixed; width: {tableMinWidth}px; flex-basis: {tableMinWidth}px; min-width: {tableMinWidth}px"
>
<colgroup>
<col style="width: {CHECKBOX_WIDTH}px" />
Expand Down Expand Up @@ -521,9 +524,7 @@
</td>
<td class="px-3 {rowTd}"
>{@render pipelineLink(pipeline.name)}
<div class="relative w-fit max-w-full">
<Tags pipelineName={pipeline.name} tags={pipeline.tags} {knownTags} {api}></Tags>
</div></td
<Tags pipelineName={pipeline.name} tags={pipeline.tags} {knownTags} {api}></Tags></td
>
<td class="{rowTd} px-3">
{@render pipelineLink(pipeline.name)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,37 @@ import { page, userEvent } from 'vitest/browser'
import { render } from 'vitest-browser-svelte'
import { useLayoutSettings } from '#lib/compositions/layout/useLayoutSettings.svelte.ts'
import type { PipelineThumb } from '#lib/services/pipelineManager.ts'
import { permissionsOf } from '#lib/services/rbac.ts'

const SORT_KEY = 'layout/pipelines/table/sort'

// `vi.mock` factories are hoisted above the imports and run before ordinary
// module-scope consts initialize, so a factory can't read them. `vi.hoisted` is
// hoisted too, so its result is available to both the factory and the fixtures.
const { PLATFORM_VERSION } = vi.hoisted(() => ({ PLATFORM_VERSION: '1.0.0' }))
const { PLATFORM_VERSION, roleState } = vi.hoisted(() => ({
PLATFORM_VERSION: '1.0.0',
// Without a role the tags are static chips. The tests of the tag editor set `write`.
roleState: { current: undefined as 'write' | undefined }
}))

// Table and its PipelineVersion child both read `page.data.feldera`. A `version`
// equal to every thumb's platformVersion keeps the runtime column in its
// "latest" state, so no update Popover is rendered.
vi.mock('$app/state', () => ({
page: { data: { feldera: { version: PLATFORM_VERSION, unstableFeatures: [] } } }
page: {
data: {
get feldera() {
return {
version: PLATFORM_VERSION,
unstableFeatures: [],
...(roleState.current && {
role: roleState.current,
permissions: permissionsOf(roleState.current)
})
}
}
}
}
}))

import Table from './Table.svelte'
Expand Down Expand Up @@ -532,6 +550,14 @@ describe('Table — column resizing', () => {
await expect.poll(() => widthOf('Tags')).toBeCloseTo(64, 0)
})

it('keeps the set width of a column with long content', async () => {
const longTag = 'a-very-long-tag-name-that-is-wider-than-the-tags-column'
mountTable(pipelines.map((p) => ({ ...p, tags: [longTag] })))
await expect.poll(rowOrder).toEqual(['alpha', 'bravo', 'charlie', 'delta'])

expect(widthOf('Tags')).toBeCloseTo(280, 0)
})

it('returns a column to its default width on double-click', async () => {
mountTable()
await expect.poll(rowOrder).toEqual(['alpha', 'bravo', 'charlie', 'delta'])
Expand Down Expand Up @@ -695,6 +721,7 @@ describe('Table — row link', () => {

afterEach(() => {
localStorage.clear()
roleState.current = undefined
})

// Cells of the "alpha" row: 0 is the checkbox, 7 is Errors.
Expand Down Expand Up @@ -729,6 +756,19 @@ describe('Table — row link', () => {
expect(hit).toBe(text)
})

it('links the empty space of the tags cell to the pipeline', async () => {
roleState.current = 'write'
mountTable(pipelines.map((p) => ({ ...p, tags: ['prod'] })))
await expect.poll(rowOrder).toEqual(['alpha', 'bravo', 'charlie', 'delta'])
const box = boxOf(cell(5))
// The tag row spans the content box of the cell, so aim inside the cell's right padding.
const contentRight = box.right - parseFloat(getComputedStyle(cell(5)).paddingRight)

const hit = hitAt(contentRight - 4, box.top + box.height / 2)

expect(hit.closest('a')?.getAttribute('href')).toMatch(/\/pipelines\/alpha\/$/)
})

it('toggles the selection on the empty space of the checkbox cell, with no link', async () => {
mountTable()
await expect.poll(rowOrder).toEqual(['alpha', 'bravo', 'charlie', 'delta'])
Expand All @@ -741,3 +781,59 @@ describe('Table — row link', () => {
await expect.element(page.getByLabelText('Select alpha')).toBeChecked()
})
})

describe('Table — tags', () => {
// The browser is slow while the other test files run. Thus, the screenshot can take longer.
const screenshotOptions = { timeout: 15_000 }
const longTag = 'thisisaveryverylongtagspectacularlylongtagi|ef4444'

// Makes the screenshot stable: a fixed viewport, the theme of `src/app.html`, a fixed
// "now" for the "Status changed" column, and no fade-in of the tag popup.
beforeEach(async () => {
localStorage.clear()
useLayoutSettings().pipelinesTableSort.value = { column: 'name', direction: 'asc' }
useLayoutSettings().pipelinesTableColumnWidths.value = {}
roleState.current = 'write'
vi.useFakeTimers({ toFake: ['Date'] })
vi.setSystemTime(new Date('2024-02-01T00:00:00Z'))
await page.viewport(1280, 720)
document.documentElement.dataset.theme = 'feldera-modern-theme'
const style = document.createElement('style')
style.textContent =
'*, *::before, *::after { animation: none !important; transition: none !important; }'
document.head.append(style)
return () => {
delete document.documentElement.dataset.theme
style.remove()
}
})

afterEach(() => {
localStorage.clear()
roleState.current = undefined
vi.useRealTimers()
})

it('cuts long tags to the column width, and in the tag popup', async () => {
const { container } = mountTable([
{ ...thumb('alpha'), tags: ['production', 'monitoring', 'east-region'] },
{ ...thumb('bravo'), tags: ['tag1|ef4444', longTag] },
{ ...thumb('charlie'), tags: [longTag] },
{ ...thumb('delta'), tags: ['averyrveryvery longtaggggg|3b82f6'] },
{ ...thumb('echo'), tags: [] }
] as PipelineThumb[])
await expect.poll(rowOrder).toEqual(['alpha', 'bravo', 'charlie', 'delta', 'echo'])
// Room under the table, so that the screenshot of the container includes the popup.
container.style.paddingBottom = '240px'

await page
.getByRole('button', { name: 'thisisaveryverylongtagspectacularlylongtagi' })
.nth(1)
.click()
await expect.element(page.getByPlaceholder('Search or add tags')).toBeVisible()

await expect
.element(page.elementLocator(container))
.toMatchScreenshot('tags-cut-to-column-width', screenshotOptions)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
/** The CSS classes of a tag chip, for components that render their own chips. */
export const tagChipClasses =
'flex h-5 items-center gap-1.5 rounded border border-surface-200-800 px-2 text-sm whitespace-nowrap'

/** The width of a chip with its whole name, also while the chip cuts the name. */
export const fullChipWidth = (chip: HTMLElement) => {
const name = chip.querySelector('.truncate') as HTMLElement
return chip.getBoundingClientRect().width - name.clientWidth + name.scrollWidth
}
</script>

<script lang="ts">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<script lang="ts" module>
// One flag for all tag rows. It changes once, when the web font loads.
let areFontsLoaded = $state(false)
document.fonts?.ready.then(() => (areFontsLoaded = true))
</script>

<script lang="ts">
import { partition } from 'common-lib/array'
import { promisePool } from 'common-lib/promise'
Expand All @@ -22,7 +28,7 @@
validateTag
} from '#lib/functions/pipelines/tags.ts'
import { patchPipeline } from '#lib/services/pipelineManager.ts'
import TagChip from './TagChip.svelte'
import TagChip, { fullChipWidth } from './TagChip.svelte'

let {
pipelineName,
Expand Down Expand Up @@ -147,9 +153,37 @@
setTags([...tags.filter((t) => tagDisplayName(t) !== name), tag])
}

// At most two tags fit in the row; the rest collapse into a "+N" chip.
// The row shows at most two tags, and only one when the second does not fit. The other tags
// collapse into a "+N" control. Only the last tag in the row can be cut with an ellipsis.
const inlineTags = $derived(tags.slice(0, 2))
const overflowCount = $derived(Math.max(0, tags.length - 2))
// The least width of a cut chip: the dot, the padding, the border and a few letters.
const MIN_CUT_CHIP_WIDTH = 56
let shownCount = $state(2)
const visibleCount = $derived(Math.min(shownCount, inlineTags.length))
const overflowCount = $derived(tags.length - visibleCount)

let rowElement = $state<HTMLElement>()
let rowContentRect = $state<DOMRectReadOnly>()

// Show the second chip if the first chip fits in full and the second fits when cut.
$effect(() => {
const rowWidth = rowContentRect?.width
// The web font changes the chip widths, so measure the chips again when it loads.
void areFontsLoaded
if (!rowElement || rowWidth === undefined) {
return
}
// The row starts with the chips in the order of `inlineTags`, then the "+N" control.
const row = [...rowElement.children] as HTMLElement[]
const [firstWidth, secondWidth] = row.slice(0, inlineTags.length).map(fullChipWidth)
const gap = parseFloat(getComputedStyle(rowElement).columnGap)
const overflowWidth = tags.length > 2 ? gap + row[2].offsetWidth : 0
shownCount =
secondWidth !== undefined &&
firstWidth + gap + Math.min(secondWidth, MIN_CUT_CHIP_WIDTH) + overflowWidth <= rowWidth
? 2
: 1
})

let page = $state<'list' | 'create' | 'edit' | 'delete'>('list')
let search = $state('')
Expand Down Expand Up @@ -292,7 +326,10 @@
</script>

{#if canEditTags.allowed}
<Popup>
<!-- The tag row spans the whole width of its container, to measure the room for the chips.
Clicks on the empty part of the row go through to the element under it, such as the
link of a table row. -->
<Popup wrapperClass="pointer-events-none">
{#snippet trigger(toggle)}
{@const open = () => {
closeForm()
Expand All @@ -304,12 +341,12 @@
{@render inlineTagRow(open)}
{/snippet}
{#snippet content()}
<!-- Grows with its content from 304px up to 380px; past that, long text (such as the
"Create new tag" button) is truncated. `grid-cols-1` lets the panels shrink
below their content width so the truncation can happen. -->
<!-- The popup grows with its content from 280px to 320px. Longer text, such as a tag
name or the "Create new tag" button, is cut with an ellipsis. `grid-cols-1` lets
the panels shrink below their content width, so that the text can be cut. -->
<div
transition:fade={{ duration: 100 }}
class="bg-white-dark absolute top-full left-0 z-30 mt-1 flex w-max max-w-[380px] min-w-[304px] flex-col overflow-hidden rounded p-1 shadow-md dark:border dark:border-surface-950-50/10"
class="bg-white-dark pointer-events-auto absolute top-full left-0 z-30 mt-1 flex w-max max-w-[320px] min-w-[280px] flex-col overflow-hidden rounded p-1 shadow-md dark:border dark:border-surface-950-50/10"
>
<SlidingPanels
class="grid-cols-1"
Expand Down Expand Up @@ -391,7 +428,7 @@
<span class="text-sm font-medium">Delete tag</span>
</div>
<div class="flex flex-col gap-3 px-3 pb-3">
<p class="">
<p class="wrap-break-word">
The tag “{tagDisplayName(editingTag ?? '')}” will be removed from
{editingTagUsageCount}
{editingTagUsageCount === 1 ? 'pipeline' : 'pipelines'} it's currently assigned to.
Expand Down Expand Up @@ -420,21 +457,35 @@
button all open the popup); without it the row is static display only. -->
{#snippet inlineTagRow(open?: () => void)}
<!-- The row clips its overflow, so it reaches 8px left of the cell's content (and pads
that back) to keep the add button's hover background, which starts there, whole. -->
<div class="-ml-2 flex flex-nowrap items-center gap-1 overflow-hidden pl-2">
{#each inlineTags as tag (tag)}
<TagChip {tag} onclick={open}></TagChip>
that back) to keep the add button's hover background, which starts there, whole.
A chip that does not fit stays in the row as an invisible absolute element, to measure
its full width. The row is positioned, so it shows above the link of a table row. -->
<div
class="pointer-events-none relative -ml-2 flex flex-nowrap items-center gap-1 overflow-hidden pl-2"
bind:this={rowElement}
bind:contentRect={rowContentRect}
>
{#each inlineTags as tag, i (tag)}
<TagChip
{tag}
onclick={open}
class={i < visibleCount - 1
? 'pointer-events-auto shrink-0'
: i === visibleCount - 1
? 'pointer-events-auto min-w-0'
: 'invisible absolute'}
></TagChip>
{/each}
{#if overflowCount > 0}
{@const allTags = tags.map(tagDisplayName).join(', ')}
{@const base = 'px-1 text-sm text-surface-600-400'}
{@const base = 'pointer-events-auto shrink-0 px-1 text-sm text-surface-600-400'}
<!-- Editable: a button that opens the popup, with a hover tooltip. Read-only:
the same "+N" as a static span whose native title shows the full list. -->
{#if open}
<button class="{base} hover:text-surface-950-50" onclick={open} aria-label="Show all tags">
+{overflowCount}
</button>
<Tooltip placement="top" class="max-w-[240px] text-wrap">{allTags}</Tooltip>
<Tooltip placement="top" class="max-w-[240px] text-wrap wrap-break-word">{allTags}</Tooltip>
{:else}
<span class={base} title={allTags}>
+{overflowCount}
Expand All @@ -445,7 +496,7 @@
<!-- A quiet ghost button, so a column of untagged pipelines doesn't read as a column
of boxes; it firms up while its row is hovered. -->
<button
class="hover-bg -ml-2 flex h-6 items-center gap-1 rounded px-2 text-sm whitespace-nowrap text-surface-500 transition-colors group-hover:text-surface-800-200 hover:text-surface-950-50"
class="hover-bg pointer-events-auto -ml-2 flex h-6 items-center gap-1 rounded px-2 text-sm whitespace-nowrap text-surface-500 transition-colors group-hover:text-surface-800-200 hover:text-surface-950-50"
onclick={open}
>
<span class="fd fd-plus text-[14px]"></span>
Expand All @@ -458,7 +509,7 @@
{#snippet tagRow(tag: string, selected: boolean)}
<div class="group/row hover-bg flex h-9 items-center rounded">
<button
class="flex h-full flex-1 items-center gap-2 pl-3 text-left text-sm"
class="flex h-full min-w-0 flex-1 items-center gap-2 pl-3 text-left text-sm"
onclick={() => toggleTag(tag)}
>
<input
Expand Down
Loading
Loading