Skip to content

feat: add organizations filter to audit table #13978

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 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Check multi-org before adding org filter and details
As part of this, make the width adjustable so we only lower it when we
have the new filter added.
  • Loading branch information
code-asher committed Jul 24, 2024
commit aff7321909dc2833e45038d48bbe6fdd5dd9b91e
8 changes: 5 additions & 3 deletions site/src/components/Filter/SelectFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SelectMenuIcon,
} from "components/SelectMenu/SelectMenu";

const BASE_WIDTH = 175;
const BASE_WIDTH = 200;
const POPOVER_WIDTH = 320;

export type SelectFilterOption = {
Expand All @@ -32,6 +32,7 @@ export type SelectFilterProps = {
onSelect: (option: SelectFilterOption | undefined) => void;
// SelectFilterSearch element
selectFilterSearch?: ReactNode;
width?: number;
};

export const SelectFilter: FC<SelectFilterProps> = ({
Expand All @@ -42,6 +43,7 @@ export const SelectFilter: FC<SelectFilterProps> = ({
placeholder,
emptyText,
selectFilterSearch,
width = BASE_WIDTH,
}) => {
const [open, setOpen] = useState(false);

Expand All @@ -50,7 +52,7 @@ export const SelectFilter: FC<SelectFilterProps> = ({
<SelectMenuTrigger>
<SelectMenuButton
startIcon={selectedOption?.startIcon}
css={{ width: BASE_WIDTH }}
css={{ width }}
aria-label={label}
>
{selectedOption?.label ?? placeholder}
Expand All @@ -64,7 +66,7 @@ export const SelectFilter: FC<SelectFilterProps> = ({
// wide as possible.
width: selectFilterSearch ? "100%" : undefined,
maxWidth: POPOVER_WIDTH,
minWidth: BASE_WIDTH,
minWidth: width,
},
}}
>
Expand Down
4 changes: 3 additions & 1 deletion site/src/components/Filter/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export type UserFilterMenu = ReturnType<typeof useUserFilterMenu>;

interface UserMenuProps {
menu: UserFilterMenu;
width?: number;
}

export const UserMenu: FC<UserMenuProps> = ({ menu }) => {
export const UserMenu: FC<UserMenuProps> = ({ menu, width }) => {
return (
<SelectFilter
label="Select user"
Expand All @@ -116,6 +117,7 @@ export const UserMenu: FC<UserMenuProps> = ({ menu }) => {
onChange={menu.setQuery}
/>
}
width={width}
/>
);
};
38 changes: 30 additions & 8 deletions site/src/pages/AuditPage/AuditFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ interface AuditFilterProps {
user: UserFilterMenu;
action: ActionFilterMenu;
resourceType: ResourceTypeFilterMenu;
organization: OrganizationsFilterMenu;
// The organization menu is only provided in a multi-org setup.
organization?: OrganizationsFilterMenu;
};
}

export const AuditFilter: FC<AuditFilterProps> = ({ filter, error, menus }) => {
// Use a smaller width if including the organization filter.
const width = menus.organization && 175;
return (
<Filter
learnMoreLink={docs("/admin/audit-logs#filtering-logs")}
Expand All @@ -59,10 +62,12 @@ export const AuditFilter: FC<AuditFilterProps> = ({ filter, error, menus }) => {
error={error}
options={
<>
<ResourceTypeMenu {...menus.resourceType} />
<ActionMenu {...menus.action} />
<UserMenu menu={menus.user} />
<OrganizationsMenu menu={menus.organization} />
<ResourceTypeMenu width={width} menu={menus.resourceType} />
<ActionMenu width={width} menu={menus.action} />
<UserMenu width={width} menu={menus.user} />
{menus.organization && (
<OrganizationsMenu width={width} menu={menus.organization} />
)}
</>
}
skeleton={
Expand Down Expand Up @@ -97,14 +102,20 @@ export const useActionFilterMenu = ({

export type ActionFilterMenu = ReturnType<typeof useActionFilterMenu>;

const ActionMenu = (menu: ActionFilterMenu) => {
interface ActionMenuProps {
menu: ActionFilterMenu;
width?: number;
}

const ActionMenu: FC<ActionMenuProps> = ({ menu, width }) => {
return (
<SelectFilter
label="Select an action"
placeholder="All actions"
options={menu.searchOptions}
onSelect={menu.selectOption}
selectedOption={menu.selectedOption ?? undefined}
width={width}
/>
);
};
Expand Down Expand Up @@ -151,14 +162,20 @@ export type ResourceTypeFilterMenu = ReturnType<
typeof useResourceTypeFilterMenu
>;

const ResourceTypeMenu = (menu: ResourceTypeFilterMenu) => {
interface ResourceTypeMenuProps {
menu: ResourceTypeFilterMenu;
width?: number;
}

const ResourceTypeMenu: FC<ResourceTypeMenuProps> = ({ menu, width }) => {
return (
<SelectFilter
label="Select a resource type"
placeholder="All resource types"
options={menu.searchOptions}
onSelect={menu.selectOption}
selectedOption={menu.selectedOption ?? undefined}
width={width}
/>
);
};
Expand Down Expand Up @@ -216,9 +233,13 @@ export type OrganizationsFilterMenu = ReturnType<

interface OrganizationsMenuProps {
menu: OrganizationsFilterMenu;
width?: number;
}

export const OrganizationsMenu: FC<OrganizationsMenuProps> = ({ menu }) => {
export const OrganizationsMenu: FC<OrganizationsMenuProps> = ({
menu,
width,
}) => {
return (
<SelectFilter
label="Select an organization"
Expand All @@ -235,6 +256,7 @@ export const OrganizationsMenu: FC<OrganizationsMenuProps> = ({ menu }) => {
onChange={menu.setQuery}
/>
}
width={width}
/>
);
};
4 changes: 3 additions & 1 deletion site/src/pages/AuditPage/AuditLogRow/AuditLogRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export interface AuditLogRowProps {
auditLog: AuditLog;
// Useful for Storybook
defaultIsDiffOpen?: boolean;
showOrgDetails: boolean;
}

export const AuditLogRow: FC<AuditLogRowProps> = ({
auditLog,
defaultIsDiffOpen = false,
showOrgDetails,
}) => {
const [isDiffOpen, setIsDiffOpen] = useState(defaultIsDiffOpen);
const diffs = Object.entries(auditLog.diff);
Expand Down Expand Up @@ -134,7 +136,7 @@ export const AuditLogRow: FC<AuditLogRowProps> = ({
</strong>
</span>
)}
{auditLog.organization && (
{showOrgDetails && auditLog.organization && (
<span css={styles.auditLogInfo}>
<>Org: </>
<Link
Expand Down
7 changes: 6 additions & 1 deletion site/src/pages/AuditPage/AuditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useFilter } from "components/Filter/filter";
import { useUserFilterMenu } from "components/Filter/UserFilter";
import { isNonInitialPage } from "components/PaginationWidget/utils";
import { usePaginatedQuery } from "hooks/usePaginatedQuery";
import { useDashboard } from "modules/dashboard/useDashboard";
import { useFeatureVisibility } from "modules/dashboard/useFeatureVisibility";
import { pageTitle } from "utils/page";
import {
Expand All @@ -17,6 +18,7 @@ import { AuditPageView } from "./AuditPageView";

const AuditPage: FC = () => {
const { audit_log: isAuditLogVisible } = useFeatureVisibility();
const { experiments } = useDashboard();

/**
* There is an implicit link between auditsQuery and filter via the
Expand Down Expand Up @@ -80,14 +82,17 @@ const AuditPage: FC = () => {
isAuditLogVisible={isAuditLogVisible}
auditsQuery={auditsQuery}
error={auditsQuery.error}
showOrgDetails={experiments.includes("multi-organization")}
filterProps={{
filter,
error: auditsQuery.error,
menus: {
user: userMenu,
action: actionMenu,
resourceType: resourceTypeMenu,
organization: organizationsMenu,
organization: experiments.includes("multi-organization")
? organizationsMenu
: undefined,
},
}}
/>
Expand Down
17 changes: 16 additions & 1 deletion site/src/pages/AuditPage/AuditPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const defaultFilterProps = getDefaultFilterProps<FilterProps>({
user: MockMenu,
action: MockMenu,
resourceType: MockMenu,
organization: MockMenu,
},
});

Expand All @@ -43,6 +42,7 @@ const meta: Meta<typeof AuditPageView> = {
auditLogs: [MockAuditLog, MockAuditLog2, MockAuditLog3],
isAuditLogVisible: true,
filterProps: defaultFilterProps,
showOrgDetails: false,
},
};

Expand Down Expand Up @@ -92,3 +92,18 @@ export const NotVisible: Story = {
auditsQuery: mockInitialRenderResult,
},
};

export const MultiOrg: Story = {
parameters: { chromatic: chromaticWithTablet },
args: {
showOrgDetails: true,
auditsQuery: mockSuccessResult,
filterProps: {
...defaultFilterProps,
menus: {
...defaultFilterProps.menus,
organization: MockMenu,
},
},
},
};
8 changes: 7 additions & 1 deletion site/src/pages/AuditPage/AuditPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface AuditPageViewProps {
error?: unknown;
filterProps: ComponentProps<typeof AuditFilter>;
auditsQuery: PaginationResult;
showOrgDetails: boolean;
}

export const AuditPageView: FC<AuditPageViewProps> = ({
Expand All @@ -47,6 +48,7 @@ export const AuditPageView: FC<AuditPageViewProps> = ({
error,
filterProps,
auditsQuery: paginationResult,
showOrgDetails,
}) => {
const isLoading =
(auditLogs === undefined || paginationResult.totalRecords === undefined) &&
Expand Down Expand Up @@ -117,7 +119,11 @@ export const AuditPageView: FC<AuditPageViewProps> = ({
items={auditLogs}
getDate={(log) => new Date(log.time)}
row={(log) => (
<AuditLogRow key={log.id} auditLog={log} />
<AuditLogRow
key={log.id}
auditLog={log}
showOrgDetails={showOrgDetails}
/>
)}
/>
)}
Expand Down
Loading