Files
windmill/frontend/src/lib/components/ShareModal.svelte
T
69fc8a98ae feat(frontend): migrate toggle to melt (4/4) (#5329)
* use melt menu in sidebar

* stop keyboard navigation for disabled items

* use melt menu for FavoriteMenu and WorkspaceMenu

* fix popover placement for menuButton

* use melt menu for operator menu

* fix notification

* fix operator menu

* Use melt menu in FlowJobsMenu

* use melt menu for AppMenu

* clean code

* clean code

* add use clickOutside option to Menu

* use pointerdown_outside

* use pointerdown_outside

# Conflicts:
#	frontend/src/lib/components/meltComponents/Menu.svelte

* use pointerdown in menus

* add max-h to app dropdown menu

* keep more open in operator menu

* add a MenuItem component

* clean

* nit

* nit

* clean code

* put conditionalMelt as utility function

* remove unused Portal

* Add debounce effect in operator menu

* fix component jumping due to z-index

* format pages

* migrate dropdown to melt

* migrate toggle to melt

* migrate popup to melt popover

* fix missing toggle item

* feat: remove `pip` fallback option for python and ansible (#5186)

* refactor!: Remove `pip` fallback option for python and ansible

BREAKING CHANGE: pip was deprecated since 1.425.0 (2024-11-15)

* fix errors in main.rs

* fix tests

* remove nsjail for pip

* fix imports

* fix compilation error

* reinforce melt types

* fix racing condition issue in closing operator menu

* nit

* fix id conflix with melt element

* nit

* clean code

* use melt dropdown instead of menubar

* prevent modal from closing on click outside button in menu

* Apply automatic changes

* fix nit

* nit

* close dropdown when opening a new one

* replace MenuV2 with melt Menu (1/4) (#5214)

* use melt menu in sidebar

* stop keyboard navigation for disabled items

* use melt menu for FavoriteMenu and WorkspaceMenu

* fix popover placement for menuButton

* use melt menu for operator menu

* fix notification

* fix operator menu

* Use melt menu in FlowJobsMenu

* use melt menu for AppMenu

* clean code

* clean code

* add use clickOutside option to Menu

* use pointerdown_outside

* use pointerdown_outside

# Conflicts:
#	frontend/src/lib/components/meltComponents/Menu.svelte

* use pointerdown in menus

* add max-h to app dropdown menu

* keep more open in operator menu

* add a MenuItem component

* clean

* nit

* nit

* clean code

* put conditionalMelt as utility function

* remove unused Portal

* Add debounce effect in operator menu

* fix component jumping due to z-index

* feat: remove `pip` fallback option for python and ansible (#5186)

* refactor!: Remove `pip` fallback option for python and ansible

BREAKING CHANGE: pip was deprecated since 1.425.0 (2024-11-15)

* fix errors in main.rs

* fix tests

* remove nsjail for pip

* fix imports

* fix compilation error

* reinforce melt types

* fix racing condition issue in closing operator menu

* nit

* fix id conflix with melt element

* nit

* prevent modal from closing on click outside button in menu

---------

Co-authored-by: pyranota <92104930+pyranota@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
# Conflicts:
#	frontend/src/lib/components/meltComponents/MenuItem.svelte
#	frontend/src/lib/utils.ts

* clean

* fix z index and render

* fix initialize of dropdownmenu after melt migration

* feat: add support for | None and Optional in python (#5361)

* feat: add support for | None and Optional in python

* update python parser package

* add local rooting for MenuItem

* fix z index

* clean

* nit

* nit

* clean code

* nit

* nit

* clean code

* reinforce melt types

* wip

* reiforce instance select types for toggleButton

* nit

* fix double event

* fix selectedTable toggle

* fix sqs toggleButton

* fix potential issue with binding in toggleGroup

* Update frontend/src/routes/(root)/(logged)/runs/[...path]/+page.svelte

Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>

---------

Co-authored-by: pyranota <92104930+pyranota@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
Co-authored-by: HugoCasa <hugo@casademont.ch>
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
2025-02-26 17:32:40 +01:00

198 lines
5.1 KiB
Svelte

<script lang="ts">
import TableCustom from './TableCustom.svelte'
import { GroupService, UserService, GranularAclService } from '$lib/gen'
import { createEventDispatcher } from 'svelte'
import AutoComplete from 'simple-svelte-autocomplete'
import { userStore, workspaceStore } from '$lib/stores'
import { Alert, Button, Drawer } from './common'
import DrawerContent from './common/drawer/DrawerContent.svelte'
import Tooltip from './Tooltip.svelte'
import { sendUserToast } from '$lib/toast'
import { isOwner } from '$lib/utils'
import ToggleButtonGroup from './common/toggleButton-v2/ToggleButtonGroup.svelte'
import ToggleButton from './common/toggleButton-v2/ToggleButton.svelte'
const dispatch = createEventDispatcher()
type Kind =
| 'script'
| 'group_'
| 'resource'
| 'schedule'
| 'variable'
| 'flow'
| 'app'
| 'raw_app'
| 'http_trigger'
| 'websocket_trigger'
| 'kafka_trigger'
| 'nats_trigger'
| 'sqs_trigger'
| 'postgres_trigger'
let kind: Kind
let path: string = ''
let ownerKind: 'user' | 'group' = 'user'
let owner: string = ''
let newOwner: string = ''
let write: boolean = false
let acls: [string, boolean][] = []
let groups: String[] = []
let usernames: string[] = []
let drawer: Drawer
$: newOwner = [ownerKind === 'group' ? 'g' : 'u', owner].join('/')
let own = false
export async function openDrawer(newPath: string, kind_l: Kind) {
path = newPath
kind = kind_l
loadAcls()
loadGroups()
loadUsernames()
loadOwner()
drawer.openDrawer()
}
async function loadOwner() {
own = isOwner(path, $userStore!, $workspaceStore!)
}
async function loadAcls() {
acls = Object.entries(
await GranularAclService.getGranularAcls({ workspace: $workspaceStore!, path, kind })
)
}
async function loadGroups(): Promise<void> {
groups = await GroupService.listGroupNames({ workspace: $workspaceStore! })
}
async function loadUsernames(): Promise<void> {
usernames = await UserService.listUsernames({ workspace: $workspaceStore! })
}
async function deleteAcl(owner: string) {
try {
await GranularAclService.removeGranularAcls({
workspace: $workspaceStore!,
path,
kind,
requestBody: { owner }
})
loadAcls()
dispatch('change', { path, kind })
} catch (err) {
sendUserToast(err.toString(), true)
}
}
async function addAcl(owner: string, write: boolean) {
await GranularAclService.addGranularAcls({
workspace: $workspaceStore!,
path,
kind,
requestBody: { owner, write }
})
loadAcls()
dispatch('change', { path, kind })
}
</script>
<Drawer bind:this={drawer}>
<DrawerContent title="Share {path}" on:close={drawer.closeDrawer}>
<div class="flex flex-col gap-6">
<h1>{path}</h1>
<h2
>Extra Permissions ({acls?.length ?? 0}) &nbsp; <Tooltip
>Items already have default permissions. If belonging to an user or group, that group or
user owns it and can write to it as well as modify its permisions and move it. Folders
have read/write that apply to the whole folder and are additive to the items permissions.</Tooltip
></h2
>
{#if !own}
<Alert type="warning" title="Not owner"
>Since you do not own this item, you cannot modify its permission</Alert
>
{/if}
<div>
{#if own}
<div class="flex flex-row flex-wrap gap-2 items-center">
<div>
<ToggleButtonGroup
bind:selected={ownerKind}
on:selected={() => (owner = '')}
let:item
>
<ToggleButton value="user" size="xs" label="User" {item} />
<ToggleButton value="group" size="xs" label="Group" {item} />
</ToggleButtonGroup>
</div>
{#key ownerKind}
<AutoComplete
required
noInputStyles
items={ownerKind === 'user' ? usernames : groups}
bind:selectedItem={owner}
/>
{/key}
<Button size="sm" on:click={() => addAcl(newOwner, write)}>Add permission</Button>
</div>
{/if}
<TableCustom>
<tr slot="header-row">
<th>owner</th>
<th />
<th />
</tr>
<tbody slot="body">
{#each acls as [owner, write]}
<tr>
<td>{owner}</td>
<td
>{#if own}
<div>
<ToggleButtonGroup
selected={write ? 'writer' : 'viewer'}
on:selected={async (e) => {
const role = e.detail
if (role == 'writer') {
await addAcl(owner, true)
} else {
await addAcl(owner, false)
}
loadAcls()
}}
let:item
>
<ToggleButton value="viewer" size="xs" label="Viewer" {item} />
<ToggleButton value="writer" size="xs" label="Writer" {item} />
</ToggleButtonGroup>
</div>
{:else}{write}{/if}</td
>
<td>
{#if own}
<Button
variant="border"
color="red"
size="xs"
on:click={() => deleteAcl(owner)}
>
Delete
</Button>
{/if}
</td>
</tr>
{/each}
</tbody>
</TableCustom>
</div>
</div>
</DrawerContent>
</Drawer>