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

feat(frontend): full height component #3676

Merged
merged 32 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d81d3b5
feat(frontend): wip
fatonramadani May 6, 2024
477d169
Merge branch 'main' into full-height-component
fatonramadani May 7, 2024
5058ae2
feat(frontend): Full Height component
fatonramadani May 7, 2024
ff9956d
Merge branch 'main' into full-height-component
fatonramadani May 8, 2024
ca042e0
feat(frontend): wip
fatonramadani May 8, 2024
07bb459
feat(frontend): add fullHeight indicator
fatonramadani May 8, 2024
39ea1e0
Merge branch 'main' into full-height-component
fatonramadani May 8, 2024
f30fcd4
feat(frontend): add indicator for component that won't render
fatonramadani May 8, 2024
ecded80
Merge branch 'full-height-component' of https://github.com/windmill-l…
fatonramadani May 8, 2024
911ecb0
Merge branch 'main' into full-height-component
fatonramadani May 13, 2024
c75b309
feat(frontend): update collision algo
fatonramadani May 13, 2024
1226b2e
Merge main
fatonramadani May 14, 2024
c1a87e4
Merge branch 'main' into full-height-component
fatonramadani May 14, 2024
713de54
fix(frontend): Full height component done
fatonramadani May 14, 2024
2f91838
Merge branch 'full-height-component' of https://github.com/windmill-l…
fatonramadani May 14, 2024
396ed60
fix(frontend): Remove the hidden check from preview
fatonramadani May 15, 2024
24561a9
Merge branch 'main' into full-height-component
rubenfiszel May 15, 2024
ffd6688
feat(frontend): code cleanup
fatonramadani May 15, 2024
957151d
feat(frontend): code cleanup
fatonramadani May 15, 2024
aa96b90
feat(frontend): code cleanup
fatonramadani May 15, 2024
58cd0b8
feat(frontend): code cleanup
fatonramadani May 15, 2024
1fc7df3
Merge branch 'main' into full-height-component
fatonramadani May 15, 2024
018815e
feat(frontend): Fix height issue + fix toggle display
fatonramadani May 15, 2024
7ae5e5d
feat(frontend): Fix insertNewGridITem
fatonramadani May 15, 2024
4887f55
feat(frontend): code cleanup
fatonramadani May 15, 2024
6a6526f
feat(frontend): mobile fullHeigt
fatonramadani May 15, 2024
c2f07a6
feat(frontend): fix wording
fatonramadani May 15, 2024
3fa78c8
feat(frontend): add missing constants
fatonramadani May 15, 2024
38a4493
feat(frontend): fix typo
fatonramadani May 15, 2024
0d572c7
feat(frontend): remove dead code
fatonramadani May 15, 2024
8b3f0af
feat(frontend): improve the structure
fatonramadani May 15, 2024
2c5feed
feat(frontend): done
fatonramadani May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { getContext } from 'svelte'
import { initOutput } from '../../editor/appUtils'
import { initConfig, initOutput } from '../../editor/appUtils'
import SubGridEditor from '../../editor/SubGridEditor.svelte'
import type { AppViewerContext, ComponentCustomCSS, RichConfigurations } from '../../types'
import { initCss } from '../../utils'
Expand All @@ -11,12 +11,15 @@
import { writable } from 'svelte/store'
import { InputValue } from '../helpers'
import GroupWrapper from '../GroupWrapper.svelte'
import { components } from '../../editor/component'
import ResolveConfig from '../helpers/ResolveConfig.svelte'

export let id: string
export let componentContainerHeight: number
export let customCss: ComponentCustomCSS<'containercomponent'> | undefined = undefined
export let render: boolean
export let groupFields: RichConfigurations | undefined = undefined
export let configuration: RichConfigurations

const { app, focusedGrid, selectedComponent, worldStore, connectingInput } =
getContext<AppViewerContext>('AppViewerContext')
Expand All @@ -35,10 +38,24 @@
}

let css = initCss($app.css?.containercomponent, customCss)

let resolvedConfig = initConfig(
components['containercomponent'].initialData.configuration,
configuration
)
</script>

<InitializeComponent {id} />

{#each Object.keys(components['containercomponent'].initialData.configuration) as key (key)}
<ResolveConfig
{id}
{key}
bind:resolvedConfig={resolvedConfig[key]}
configuration={configuration[key]}
/>
{/each}

{#each Object.keys(css ?? {}) as key (key)}
<ResolveStyle
{id}
Expand Down
17 changes: 14 additions & 3 deletions frontend/src/lib/components/apps/editor/AppPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { columnConfiguration } from '../gridUtils'
import { HiddenComponent } from '../components'
import { deepEqual } from 'fast-equals'
import { dfs } from './appUtils'
import { dfs, maxHeight } from './appUtils'
import { BG_PREFIX, migrateApp } from '../utils'
import { workspaceStore, enterpriseLicense } from '$lib/stores'
import DarkModeObserver from '$lib/components/DarkModeObserver.svelte'
Expand Down Expand Up @@ -161,6 +161,8 @@
}
}
}

$: maxRow = maxHeight($appStore.grid, window.innerHeight, $breakpoint)
</script>

<DarkModeObserver on:change={onThemeChange} />
Expand Down Expand Up @@ -201,7 +203,7 @@
class={twMerge(
'p-2 overflow-visible',
app.css?.['app']?.['grid']?.class ?? '',
'wm-app-grid subgrid'
'wm-app-grid subgrid'
)}
bind:clientWidth={$parentWidth}
>
Expand All @@ -210,16 +212,24 @@
allIdsInPath={$allIdsInPath}
items={app.grid}
let:dataItem
let:hidden
rowHeight={36}
cols={columnConfiguration}
gap={[4, 2]}
{maxRow}
>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
class={'h-full w-full center-center'}
on:pointerdown={() => ($selectedComponent = [dataItem.id])}
>
<Component render={true} component={dataItem.data} selected={false} locked={true} />
<Component
render={true}
component={dataItem.data}
selected={false}
locked={true}
{hidden}
/>
</div>
</GridViewer>
</div>
Expand All @@ -228,6 +238,7 @@

{#if isLocked}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
on:click={() => (isLocked = false)}
class="absolute inset-0 center-center bg-black/20 z-50 backdrop-blur-[1px] cursor-pointer"
Expand Down
47 changes: 46 additions & 1 deletion frontend/src/lib/components/apps/editor/ComponentHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<script lang="ts">
import { classNames } from '$lib/utils'
import type { AppViewerContext } from '../types'
import { Anchor, Bug, Expand, Move, Network, Pen, Plug2 } from 'lucide-svelte'
import {
Anchor,
ArrowDownFromLine,
Bug,
Expand,
EyeOff,
Move,
Network,
Pen,
Plug2
} from 'lucide-svelte'
import { createEventDispatcher, getContext } from 'svelte'
import Popover from '$lib/components/Popover.svelte'
import { Button, Popup } from '$lib/components/common'
Expand All @@ -21,6 +31,7 @@
export let hasInlineEditor: boolean = false
export let inlineEditorOpened: boolean = false
export let errorHandledByComponent: boolean = false
export let willNotDisplay: boolean = false

const dispatch = createEventDispatcher()

Expand Down Expand Up @@ -115,6 +126,40 @@
<DecisionTreeDebug id={component.id} nodes={component.nodes ?? []} />
{/if}

{#if willNotDisplay}
<Popover>
<svelte:fragment slot="text">
This component won't render, because an other component above it is set to fill the
height.
</svelte:fragment>
<div
title="Fill height"
class={classNames(
'px-1 text-2xs py-0.5 font-bold w-fit border cursor-pointer rounded-sm',
'bg-red-100 text-red-600 border-red-500 hover:bg-red-200 hover:text-red-800'
)}
>
<EyeOff aria-label="Expand position" size={14} />
</div>
</Popover>
{/if}

<button
title="Fill height"
class={classNames(
'px-1 text-2xs py-0.5 font-bold w-fit border cursor-pointer rounded-sm',
'bg-indigo-100 text-indigo-600 border-indigo-500 hover:bg-indigo-200 hover:text-indigo-800'
)}
on:click={() => dispatch('fillHeight')}
on:pointerdown|stopPropagation
>
<ArrowDownFromLine
aria-label="Expand position"
size={14}
class={component.fullHeight ? 'text-orange-500' : ''}
/>
</button>

<button
title="Expand"
class={classNames(
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/lib/components/apps/editor/GridEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
</div>
<div>
{policy.on_behalf_of ? `Author ${policy.on_behalf_of_email}` : ''}
<Tooltip
>The scripts will be run on behalf of the author and a tight policy ensure security about
the possible inputs of the runnables.</Tooltip
>
<Tooltip>
The scripts will be run on behalf of the author and a tight policy ensure security about
the possible inputs of the runnables.
</Tooltip>
</div>
</div>
</div>
Expand Down Expand Up @@ -125,6 +125,7 @@
$app.grid = e.detail
}}
let:dataItem
let:hidden
rowHeight={36}
cols={columnConfiguration}
gap={[4, 2]}
Expand All @@ -139,6 +140,7 @@
>
<GridEditorMenu id={dataItem.id}>
<Component
{hidden}
render={true}
component={dataItem.data}
selected={Boolean($selectedComponent?.includes(dataItem.id))}
Expand All @@ -156,6 +158,13 @@
expandGriditem($app.grid, dataItem.id, $breakpoint)
$app = $app
}}
on:fillHeight={() => {
const gridItem = findGridItem($app, dataItem.id)
if (gridItem) {
gridItem.data.fullHeight = !gridItem.data.fullHeight
}
$app = $app
}}
/>
</GridEditorMenu>
</ComponentWrapper>
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/lib/components/apps/editor/GridViewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
export let cols: [number, number][]
export let gap = [10, 10]
export let throttleUpdate = 100
export let maxRow: number

export let allIdsInPath: string[] | undefined = undefined
export let containerWidth: number | undefined = undefined
Expand Down Expand Up @@ -81,17 +82,23 @@
{@const width =
Math.min(getComputedCols, item[getComputedCols] && item[getComputedCols].w) * xPerPx -
gapX * 2}
{@const height = (item[getComputedCols] && item[getComputedCols].h) * yPerPx - gapY * 2}
{@const height =
(item.data['fullHeight']
? maxRow - item[getComputedCols].y
: item[getComputedCols] && item[getComputedCols].h) *
yPerPx -
gapY * 2}
{@const top = (item[getComputedCols] && item[getComputedCols].y) * yPerPx + gapY}
{@const left = (item[getComputedCols] && item[getComputedCols].x) * xPerPx + gapX}

<div
class="svlt-grid-item"
style="width: {width}px; height:{height}px; {onTop
? 'z-index: 1000;'
: ''} top: {top}px; left: {left}px;"
>
{#if item[getComputedCols]}
<slot dataItem={item} item={item[getComputedCols]} />
<slot dataItem={item} item={item[getComputedCols]} hidden={false} />
{/if}
</div>
{/each}
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/lib/components/apps/editor/SubGridEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { columnConfiguration, isFixed, toggleFixed } from '../gridUtils'
import Grid from '../svelte-grid/Grid.svelte'
import type { AppEditorContext, AppViewerContext, GridItem } from '../types'
import { expandGriditem, findGridItem, selectId } from './appUtils'
import { expandGriditem, findGridItem, maxHeight, selectId } from './appUtils'
import Component from './component/Component.svelte'
import ComponentWrapper from './component/ComponentWrapper.svelte'
import GridViewer from './GridViewer.svelte'
Expand Down Expand Up @@ -66,6 +66,8 @@
}

let container: HTMLElement | undefined = undefined

$: maxRow = maxHeight($app.subgrids?.[subGridId] ?? [], containerHeight ?? 0, $breakpoint)
</script>

<div
Expand All @@ -82,7 +84,7 @@
classes ?? '',
noPadding ? 'px-0' : 'px-2'
)}
style="{containerHeight ? `height: ${containerHeight - 2}px;` : ''} {style ?? ''}"
style="{containerHeight ? `height: ${containerHeight}px;` : ''} {style ?? ''}"
>
{#if $mode !== 'preview'}
<div
Expand All @@ -105,6 +107,7 @@
}}
selectedIds={$selectedComponent}
let:dataItem
let:hidden
rowHeight={36}
cols={columnConfiguration}
gap={[4, 2]}
Expand All @@ -123,6 +126,7 @@
>
<GridEditorMenu id={dataItem.id}>
<Component
{hidden}
render={visible}
component={dataItem.data}
selected={Boolean($selectedComponent?.includes(dataItem.id))}
Expand All @@ -146,6 +150,13 @@
)
$app = $app
}}
on:fillHeight={() => {
const gridItem = findGridItem($app, dataItem.id)
if (gridItem) {
gridItem.data.fullHeight = !gridItem.data.fullHeight
}
$app = $app
}}
/>
</GridEditorMenu>
</ComponentWrapper>
Expand All @@ -156,11 +167,13 @@
allIdsInPath={$allIdsInPath}
items={$app.subgrids?.[subGridId] ?? []}
let:dataItem
let:hidden
rowHeight={36}
cols={columnConfiguration}
gap={[4, 2]}
parentWidth={$parentWidth - 17}
{containerWidth}
{maxRow}
>
<!-- svelte-ignore a11y-click-events-have-key-events -->
<div
Expand All @@ -172,6 +185,7 @@
component={dataItem.data}
selected={Boolean($selectedComponent?.includes(dataItem.id))}
locked={isFixed(dataItem)}
{hidden}
/>
</div>
</GridViewer>
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/lib/components/apps/editor/appUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export function appComponentFromType<T extends keyof typeof components>(
numberOfSubgrids: init.numberOfSubgrids,
horizontalAlignment: init.horizontalAlignment,
verticalAlignment: init.verticalAlignment,
fullHeight: init.fullHeight,
id,
...(extra ?? {})
}
Expand All @@ -378,6 +379,7 @@ export function insertNewGridItem(
const id = keepId ?? getNextGridItemId(app)

const data = builddata(id)

if (data.type == 'aggridcomponentee' && !get(enterpriseLicense)) {
sendUserToast('AgGrid Enterprise Edition require Windmill Enterprise Edition', true)
throw Error('AgGrid Enterprise Edition require Windmill Enterprise Edition')
Expand Down Expand Up @@ -419,6 +421,8 @@ export function insertNewGridItem(

let grid = focusedGrid ? app.subgrids[key!] : app.grid

data.fullHeight = false

const newItem = createNewGridItem(grid, id, data, columns)
grid.push(newItem)
return id
Expand Down Expand Up @@ -972,3 +976,28 @@ export function collectOneOfFields(fields: AppInputs, app: App) {
})
)
}

export function maxHeight(
grid: GridItem[],
windowHeight: number,
breakpoint: EditorBreakpoint = 'lg'
) {
const rowHeight = 36
const rowGap = 2

const totalRowHeight = rowHeight + rowGap
let maxRows = Math.floor((windowHeight - rowGap) / totalRowHeight)

if (!grid.length) {
return maxRows
}

const breakpointKey = breakpoint === 'sm' ? 3 : 12
const maxRowPerGrid = grid.reduce((max, item) => {
const y = item[breakpointKey].y
const h = item[breakpointKey].h
return Math.max(max, y + h)
}, 0)

return Math.max(maxRowPerGrid, maxRows)
}