Skip to content

feat(site): add WorkspacesButton component #10011

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

Merged
merged 26 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f0a2aae
chore: Add OverflowY component
Parkreiner Oct 3, 2023
2420167
chore: Add PopoverContainer component
Parkreiner Oct 3, 2023
88d73af
chore: Add SearchBox
Parkreiner Oct 3, 2023
209eed4
feat: add WorkspacesButton
Parkreiner Oct 3, 2023
9300b11
chore: Install MUI utils package
Parkreiner Oct 3, 2023
2b13f1e
chore: integrate WorkspacesButton
Parkreiner Oct 3, 2023
e86207e
chore: reorganize files
Parkreiner Oct 3, 2023
5b249d5
fix: resolve hover state visual glitch
Parkreiner Oct 3, 2023
b1e1271
chore: Add story for OverflowY
Parkreiner Oct 3, 2023
b367495
fix: remove dynamic name from OverflowY story
Parkreiner Oct 3, 2023
5a34769
chore: update stories again
Parkreiner Oct 3, 2023
b9f6cb8
fix: remove all references to icons (for now)
Parkreiner Oct 3, 2023
1996e2b
refactor: move flex shrink to be OverflowY concern
Parkreiner Oct 4, 2023
5ecbbe6
fix: remove needless render key
Parkreiner Oct 4, 2023
55ab10a
fix: make sure popover closes before navigation
Parkreiner Oct 5, 2023
1a01127
refactor: clean up WorkspacesButton to use more native MUI
Parkreiner Oct 5, 2023
80928c6
Merge branch 'main' into mes/workspace-button-2
Parkreiner Oct 5, 2023
55c6061
fix: update integration into rest of view
Parkreiner Oct 5, 2023
5aea06f
fix: remove JS security concern
Parkreiner Oct 5, 2023
2aee4fe
refactor: parameterize button language
Parkreiner Oct 5, 2023
12ac56f
revert: undo sql/go file change
Parkreiner Oct 5, 2023
99f2656
fix: remove permissions dependency
Parkreiner Oct 5, 2023
430e30c
fix: simplify button prop types
Parkreiner Oct 5, 2023
ff37ab5
fix: lift data dependencies to page component
Parkreiner Oct 5, 2023
1b934ab
refactor: clean up props
Parkreiner Oct 5, 2023
84c6642
fix: update dependencies again for Storybook
Parkreiner Oct 5, 2023
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
Prev Previous commit
Next Next commit
fix: lift data dependencies to page component
  • Loading branch information
Parkreiner committed Oct 5, 2023
commit ff37ab512aed51fe10be459030c47429db8844e5
17 changes: 10 additions & 7 deletions site/src/pages/WorkspacesPage/WorkspacesButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { type PropsWithChildren, type ReactNode, useState } from "react";
import { useOrganizationId } from "hooks";
import { Language } from "./WorkspacesPageView";

import { useQuery } from "@tanstack/react-query";
import { UseQueryResult } from "@tanstack/react-query";
import { type Template } from "api/typesGenerated";
import { templates } from "api/queries/templates";

import { Link as RouterLink } from "react-router-dom";
import Box from "@mui/system/Box";
Expand Down Expand Up @@ -114,9 +112,14 @@ function WorkspaceResultsRow({ template }: { template: Template }) {
);
}

export function WorkspacesButton({ children }: PropsWithChildren) {
const organizationId = useOrganizationId();
const templatesQuery = useQuery(templates(organizationId));
type WorkspacesButtonProps = PropsWithChildren<{
templatesQuery: UseQueryResult<Template[]>;
}>;

export function WorkspacesButton({
children,
templatesQuery,
}: WorkspacesButtonProps) {
const theme = useTheme();

// Dataset should always be small enough that client-side filtering should be
Expand Down Expand Up @@ -172,7 +175,7 @@ export function WorkspacesButton({ children }: PropsWithChildren) {
paddingY: 1,
}}
>
{templatesQuery.isLoading ? (
{status === "loading" ? (
<Loader size={14} />
) : (
<>
Expand Down
13 changes: 11 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import TextField from "@mui/material/TextField";
import { displayError } from "components/GlobalSnackbar/utils";
import { getErrorMessage } from "api/errors";
import { useEffectEvent } from "hooks/hookPolyfills";
import { useQuery } from "@tanstack/react-query";
import { templates } from "api/queries/templates";

function useSafeSearchParams() {
// Have to wrap setSearchParams because React Router doesn't make sure that
Expand All @@ -44,8 +46,13 @@ const WorkspacesPage: FC = () => {
// each hook.
const searchParamsResult = useSafeSearchParams();
const pagination = usePagination({ searchParamsResult });

const organizationId = useOrganizationId();
const templatesQuery = useQuery(templates(organizationId));

const filterProps = useWorkspacesFilter({
searchParamsResult,
organizationId,
onFilterChange: () => pagination.goToPage(1),
});

Expand Down Expand Up @@ -107,6 +114,7 @@ const WorkspacesPage: FC = () => {
checkedWorkspaces={checkedWorkspaces}
onCheckChange={setCheckedWorkspaces}
canCheckWorkspaces={canCheckWorkspaces}
templatesQuery={templatesQuery}
workspaces={data?.workspaces}
dormantWorkspaces={dormantWorkspaces}
error={error}
Expand Down Expand Up @@ -143,11 +151,13 @@ export default WorkspacesPage;
type UseWorkspacesFilterOptions = {
searchParamsResult: ReturnType<typeof useSearchParams>;
onFilterChange: () => void;
organizationId: string;
};

const useWorkspacesFilter = ({
searchParamsResult,
onFilterChange,
organizationId,
}: UseWorkspacesFilterOptions) => {
const filter = useFilter({
fallbackFilter: "owner:me",
Expand All @@ -164,9 +174,8 @@ const useWorkspacesFilter = ({
enabled: canFilterByUser,
});

const orgId = useOrganizationId();
const templateMenu = useTemplateFilterMenu({
orgId,
orgId: organizationId,
value: filter.values.template,
onChange: (option) =>
filter.update({ ...filter.values, template: option?.value }),
Expand Down
9 changes: 7 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Workspace } from "api/typesGenerated";
import { Template, Workspace } from "api/typesGenerated";
import { PaginationWidgetBase } from "components/PaginationWidget/PaginationWidgetBase";
import { ComponentProps, FC } from "react";
import { Margins } from "components/Margins/Margins";
Expand All @@ -19,6 +19,7 @@ import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import DeleteOutlined from "@mui/icons-material/DeleteOutlined";
import { WorkspacesButton } from "./WorkspacesButton";
import { UseQueryResult } from "@tanstack/react-query";

export const Language = {
pageTitle: "Workspaces",
Expand All @@ -44,6 +45,7 @@ export interface WorkspacesPageViewProps {
onCheckChange: (checkedWorkspaces: Workspace[]) => void;
onDeleteAll: () => void;
canCheckWorkspaces: boolean;
templatesQuery: UseQueryResult<Template[]>;
}

export const WorkspacesPageView: FC<
Expand All @@ -62,6 +64,7 @@ export const WorkspacesPageView: FC<
onCheckChange,
onDeleteAll,
canCheckWorkspaces,
templatesQuery,
}) => {
const { saveLocal } = useLocalStorage();

Expand All @@ -76,7 +79,9 @@ export const WorkspacesPageView: FC<
<Margins>
<PageHeader
actions={
<WorkspacesButton>{Language.createWorkspace}</WorkspacesButton>
<WorkspacesButton templatesQuery={templatesQuery}>
{Language.createWorkspace}
</WorkspacesButton>
}
>
<PageHeaderTitle>
Expand Down