Skip to content

Commit

Permalink
Factor out a ViewAsUserMenuItem component
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpgreen2 committed Sep 13, 2023
1 parent 0126cbe commit ff4c407
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
36 changes: 8 additions & 28 deletions web-admin/src/components/authentication/UserButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
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 Menu from "@rilldata/web-common/components/menu/core/Menu.svelte";
import { createPopperActions } from "svelte-popperjs";
import { createAdminServiceGetCurrentUser } from "../../client";
import { ADMIN_URL } from "../../client/http-client";
import ViewAsUserPopover from "../../features/view-as-user/ViewAsUserPopover.svelte";
import ViewAsUserMenuItem from "../../features/view-as-user/ViewAsUserMenuItem.svelte";
import ProjectAccessControls from "../projects/ProjectAccessControls.svelte";
const user = createAdminServiceGetCurrentUser();
Expand All @@ -27,21 +26,16 @@
const isDev = process.env.NODE_ENV === "development";
// Position the first popover
// Position the Menu popover
const [popperRef1, popperContent1] = createPopperActions();
const popperOptions1 = {
placement: "bottom-end",
strategy: "fixed",
modifiers: [{ name: "offset", options: { offset: [0, 4] } }],
};
// Position the nested popover
// Position the View As User popover
const [popperRef2, popperContent2] = createPopperActions();
const popperOptions = {
placement: "left-start",
strategy: "fixed",
modifiers: [{ name: "offset", options: { offset: [0, 4] } }],
};
</script>

<Popover class="relative" let:close={close1}>
Expand All @@ -64,28 +58,14 @@
project={$page.params.project}
>
<svelte:fragment slot="manage-project">
<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={[[popperContent2, popperOptions]]}>
<ViewAsUserPopover
organization={$page.params.organization}
project={$page.params.project}
on:select={() => close1(undefined)}
/>
</PopoverPanel>
</Popover>
<ViewAsUserMenuItem
popperContent={popperContent2}
on:select-user={() => close1(undefined)}
/>
</svelte:fragment>
</ProjectAccessControls>
{/if}

<MenuItem
on:select={() => {
// handleClose();
Expand Down
45 changes: 44 additions & 1 deletion web-admin/src/features/view-as-user/ViewAsUserMenuItem.svelte
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
<!-- TODO: move code from `UserButton.svelte` -->
<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>

0 comments on commit ff4c407

Please sign in to comment.