-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "View as" button to Rill Cloud dashboards (#3047)
* Refactor `UserButton` * Add conditional 'View as' menu item * Add `svelte-headlessui` and `svelte-popperjs` * Add "View As" popover * Acquire and set JWT * Remove calls to `ListFiles` API * Fix `svelte-check` w/ explicit type * Add comment * Patch `MenuItem` component * Remove File API usage * Handle chip removal * Fix z-index on chip * Clear error when switching users * Switch back to admin's JWT * Handle 404 from `GetCatalog` * Add workaround for metrics view 401s; clean up * Clear mimicked user after navigation * Bugfix * Make the whole chip clickable * Add checkmark to denote active user * Remove comment * Edit 404 copy * Better variable names * Move code to `features/view-as-user` * Factor out a `ViewAsUserMenuItem` component * Use consistent "viewed as" terminology * Use consistent "view as" terminology (cont.) * Clean up actions * Nits * Bug fix * Use query cache * Remove unneccessary query observer * Handle case when admin's JWT gets refreshed
- Loading branch information
1 parent
dff3a4a
commit 26c6bad
Showing
15 changed files
with
462 additions
and
43 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { | ||
Popover, | ||
PopoverButton, | ||
PopoverPanel, | ||
} from "@rgossiaux/svelte-headlessui"; | ||
import { IconSpaceFixer } from "@rilldata/web-common/components/button"; | ||
import { Chip } from "@rilldata/web-common/components/chip"; | ||
import CaretDownIcon from "@rilldata/web-common/components/icons/CaretDownIcon.svelte"; | ||
import { useQueryClient } from "@tanstack/svelte-query"; | ||
import { createPopperActions } from "svelte-popperjs"; | ||
import { errorStore } from "../../components/errors/error-store"; | ||
import { clearViewedAsUserWithinProject } from "./clearViewedAsUser"; | ||
import ViewAsUserPopover from "./ViewAsUserPopover.svelte"; | ||
import { viewAsUserStore } from "./viewAsUserStore"; | ||
// Position the popover | ||
const [popperRef, popperContent] = createPopperActions(); | ||
const popperOptions = { | ||
placement: "bottom-start", | ||
strategy: "fixed", | ||
modifiers: [{ name: "offset", options: { offset: [0, 4] } }], | ||
}; | ||
const queryClient = useQueryClient(); | ||
$: org = $page.params.organization; | ||
$: project = $page.params.project; | ||
</script> | ||
|
||
<Popover let:close let:open> | ||
<PopoverButton use={[popperRef]}> | ||
<Chip | ||
removable | ||
on:remove={async () => { | ||
await clearViewedAsUserWithinProject(queryClient, org, project); | ||
errorStore.reset(); | ||
}} | ||
active={open} | ||
> | ||
<div slot="body"> | ||
<div class="flex gap-x-2"> | ||
<div> | ||
Viewing as <span class="font-bold">{$viewAsUserStore.email}</span> | ||
</div> | ||
<div class="flex items-center"> | ||
<IconSpaceFixer pullRight> | ||
<div class="transition-transform" class:-rotate-180={open}> | ||
<CaretDownIcon size="14px" /> | ||
</div> | ||
</IconSpaceFixer> | ||
</div> | ||
</div> | ||
</div> | ||
<svelte:fragment slot="remove-tooltip"> | ||
<slot name="remove-tooltip-content">Clear view</slot> | ||
</svelte:fragment> | ||
</Chip> | ||
</PopoverButton> | ||
<PopoverPanel use={[[popperContent, popperOptions]]} class="z-[1000]"> | ||
<ViewAsUserPopover | ||
organization={$page.params.organization} | ||
project={$page.params.project} | ||
on:select={() => close(undefined)} | ||
/> | ||
</PopoverPanel> | ||
</Popover> |
44 changes: 44 additions & 0 deletions
44
web-admin/src/features/view-as-user/ViewAsUserMenuItem.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import type { Modifier } from "@popperjs/core"; | ||
import { | ||
Popover, | ||
PopoverButton, | ||
PopoverPanel, | ||
} from "@rgossiaux/svelte-headlessui"; | ||
import CaretDownIcon from "@rilldata/web-common/components/icons/CaretDownIcon.svelte"; | ||
import { MenuItem } from "@rilldata/web-common/components/menu"; | ||
import { createEventDispatcher } from "svelte"; | ||
import type { ContentAction } from "svelte-popperjs"; | ||
import ViewAsUserPopover from "../../features/view-as-user/ViewAsUserPopover.svelte"; | ||
export let popperContent: ContentAction<Partial<Modifier<any, any>>>; | ||
const popperOptions = { | ||
placement: "left-start", | ||
strategy: "fixed", | ||
modifiers: [{ name: "offset", options: { offset: [0, 4] } }], | ||
}; | ||
const dispatch = createEventDispatcher(); | ||
</script> | ||
|
||
<Popover> | ||
<PopoverButton class="w-full text-left"> | ||
<MenuItem animateSelect={false}> | ||
View as | ||
<CaretDownIcon | ||
className="transform -rotate-90" | ||
slot="right" | ||
size="14px" | ||
/> | ||
</MenuItem> | ||
</PopoverButton> | ||
<PopoverPanel use={[[popperContent, popperOptions]]}> | ||
<ViewAsUserPopover | ||
organization={$page.params.organization} | ||
project={$page.params.project} | ||
on:select={() => dispatch("select-user")} | ||
/> | ||
</PopoverPanel> | ||
</Popover> |
Oops, something went wrong.
26c6bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://ui.rilldata.io as production
🚀 Deployed on https://6502a9fdfeef222360cee149--rill-ui-stage.netlify.app