mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-26 18:20:42 +00:00
Compare commits
12 Commits
fix/dashbo
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1f271a505 | ||
|
|
c92bb94caf | ||
|
|
8e3a4f8775 | ||
|
|
a8433ad9e0 | ||
|
|
d07b0f1d82 | ||
|
|
a02330438f | ||
|
|
cb2b3db771 | ||
|
|
40ee169d94 | ||
|
|
865e1c97b3 | ||
|
|
5f24193de6 | ||
|
|
3d63ed6353 | ||
|
|
3af06adabc |
@@ -10,5 +10,6 @@
|
||||
- **Use convensional commit format** for commits and PR title.
|
||||
- **Do not amend the commits once pushed.** Always create a new commit once changes are pushed to remote.
|
||||
- **Review fixes are new commits too.** A force push hides what changed from human reviewers and makes Greptile post its findings again. Bring in `main` with a merge; only a stacked branch (`gh stack`) rebases, since the stack moves as a unit.
|
||||
- **A review fix to an AI-owned file fixes its generator too.** A file with the AI-owned banner (story mocks and plays, `tests/e2e/drivers/`) is rewritten by the skill or agent that made it, so a fix made only in the file comes back on the next run. In the same PR, add the lesson to that skill or agent as a concrete case.
|
||||
- **Answer every Greptile thread.** Reply with the commit that fixes it (`Fixed in 4df6f3198d: <what changed>`) or the reason it stays, then resolve. Never resolve one with neither: Greptile withdraws a finding, and remembers it, only when told why.
|
||||
- **Leave human review threads to the author.** Fix the code they ask for, but never reply to or resolve a human reviewer's thread.
|
||||
|
||||
@@ -110,8 +110,9 @@ await expect(toggle.getAttribute('aria-checked')).toBe(before);
|
||||
|
||||
CI runs each play once, with its story's own args. Anyone can flip a control in the panel, and nothing runs the play against that value, so a play that breaks on it goes unnoticed. Write each play so it cannot.
|
||||
|
||||
Before writing the clicks, list what has to be on screen for the play's target to exist, and return early when the args take it away. These are the cases plays have missed:
|
||||
Before writing the clicks, list what has to be on screen for the play's target to exist. Then walk every control the story exposes, the page's own as well as the shared ones, and return early for each value that takes something on that list away. These are the cases plays have missed:
|
||||
|
||||
- An arg the story sets. The story sets it because the play needs what that value renders, and the panel can flip it. On the `mine` view the dashboards Created-by filter opens with a tag to remove; on the other views it opens empty and there is no × to click. Check the tag is there by parsing the route the view resolves to.
|
||||
- The controls every story has. `State` on loading or error renders no rows and no filter suggestions. `Access`, `Permissions` and `Revoked` remove rows, row actions and gated buttons, and the `editor` and `viewer` presets grant telemetry reads only, so a page gated on its own resource shows them nothing. `Check state` on loading disables every gated control, and on error an `AuthZButton` stays enabled while an `AuthZGuardContent` set to fail closed hides what it wraps. `License` and `Banner` decide the plan, so a cloud-only form is gone on the others. `Hold tooltips open` shows a label a second time, inside its tooltip.
|
||||
- A count at 0. The page can swap its whole list for an empty state, and the header, filters and column picker go with it.
|
||||
- A view, filter or invalid query that leaves no rows, even when the count is above 0.
|
||||
|
||||
12
.github/workflows/goci.yaml
vendored
12
.github/workflows/goci.yaml
vendored
@@ -63,7 +63,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: check-semconv-generated-files
|
||||
@@ -78,7 +78,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: qemu-install
|
||||
@@ -114,7 +114,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: generate-openapi
|
||||
@@ -131,7 +131,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: generate-authz
|
||||
@@ -148,7 +148,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: generate-web-settings
|
||||
@@ -165,7 +165,7 @@ jobs:
|
||||
- name: self-checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: go-install
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
|
||||
with:
|
||||
go-version: "1.25"
|
||||
- name: generate-transaction-groups
|
||||
|
||||
@@ -131,6 +131,10 @@ func runGenerateAuthz(_ context.Context) error {
|
||||
coretypes.NewResourceRef(coretypes.ResourceMetaResourceNotificationChannel).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceUser).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceMetaResourceFactorPassword).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceMetaResourceIngestionKey).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceMetaResourceIngestionLimit).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceMetaResourceAuthDomain).String(): true,
|
||||
coretypes.NewResourceRef(coretypes.ResourceOrganization).String(): true,
|
||||
}
|
||||
|
||||
allowedTypes := map[string]bool{}
|
||||
|
||||
@@ -318,6 +318,11 @@
|
||||
"name": "redux",
|
||||
"message": "[State mgmt] redux is deprecated. Migrate to Zustand, nuqs, or react-query."
|
||||
},
|
||||
{
|
||||
"name": "@signozhq/design-tokens",
|
||||
"importNames": ["Style"],
|
||||
"message": "[bundle] Style is a large object of CSS variable strings and is not tree-shaken. Write the CSS variable directly, for example 'var(--l3-foreground)'."
|
||||
},
|
||||
{
|
||||
"name": "react-redux",
|
||||
"message": "[State mgmt] react-redux is deprecated. Migrate to Zustand, nuqs, or react-query."
|
||||
@@ -340,6 +345,11 @@
|
||||
"importNames": ["patchDashboardV2", "usePatchDashboardV2"],
|
||||
"message": "[dashboard-v2] Don't call patchDashboardV2/usePatchDashboardV2 directly — use useOptimisticPatch().patchAsync so spec edits update the react-query cache optimistically and reconcile on settle."
|
||||
},
|
||||
{
|
||||
"name": "antd/lib",
|
||||
"allowTypeImports": true,
|
||||
"message": "[bundle] antd/lib is the CommonJS root and bundles every antd component. Import from 'antd' instead."
|
||||
},
|
||||
{
|
||||
"name": "motion/react-client",
|
||||
"message": "[motion] motion/react-client is for React Server Components only. Use 'motion/react' instead — it provides the same exports and works correctly in client-side SPAs."
|
||||
|
||||
@@ -197,7 +197,9 @@ const preview: Preview = {
|
||||
['Overview', 'Authz'],
|
||||
'Service Accounts',
|
||||
'Ingestion',
|
||||
['Overview', 'Authz'],
|
||||
'Single Sign-on',
|
||||
['Overview', 'Authz'],
|
||||
'Keyboard Shortcuts',
|
||||
],
|
||||
'Auth',
|
||||
|
||||
@@ -175,8 +175,8 @@ function PrivateRoute({ children }: PrivateRouteProps): JSX.Element {
|
||||
pathname === ROUTES.SETTINGS ||
|
||||
pathname === ROUTES.BILLING ||
|
||||
pathname === ROUTES.MEMBERS_SETTINGS ||
|
||||
(isAdmin &&
|
||||
(pathname === ROUTES.ORG_SETTINGS || pathname === ROUTES.MY_SETTINGS));
|
||||
pathname === ROUTES.ORG_SETTINGS ||
|
||||
(isAdmin && pathname === ROUTES.MY_SETTINGS);
|
||||
|
||||
if (
|
||||
pathname !== ROUTES.WORKSPACE_LOCKED &&
|
||||
|
||||
@@ -808,7 +808,7 @@ describe('PrivateRoute', () => {
|
||||
assertStaysOnRoute(ROUTES.BILLING);
|
||||
});
|
||||
|
||||
it('should redirect VIEWER to workspace locked when trying to access org-settings', async () => {
|
||||
it('should allow VIEWER to access org-settings when workspace is blocked', () => {
|
||||
renderPrivateRoute({
|
||||
initialRoute: ROUTES.ORG_SETTINGS,
|
||||
appContext: {
|
||||
@@ -821,7 +821,7 @@ describe('PrivateRoute', () => {
|
||||
isCloudUser: true,
|
||||
});
|
||||
|
||||
await assertRedirectsTo(ROUTES.WORKSPACE_LOCKED);
|
||||
assertStaysOnRoute(ROUTES.ORG_SETTINGS);
|
||||
});
|
||||
|
||||
it('should allow VIEWER to access members settings when workspace is blocked', () => {
|
||||
@@ -1707,6 +1707,7 @@ describe('PrivateRoute', () => {
|
||||
// Everything under /settings resolves to the non-exact SETTINGS route
|
||||
SETTINGS: { path: ROUTES.SETTINGS, deniedRoles: DENIED_ROLES },
|
||||
MY_SETTINGS: { path: ROUTES.MY_SETTINGS, deniedRoles: DENIED_ROLES },
|
||||
ORG_SETTINGS: { path: ROUTES.ORG_SETTINGS, deniedRoles: DENIED_ROLES },
|
||||
ROLES_SETTINGS: { path: ROUTES.ROLES_SETTINGS, deniedRoles: DENIED_ROLES },
|
||||
ROLE_CREATE: { path: ROUTES.ROLE_CREATE, deniedRoles: DENIED_ROLES },
|
||||
ROLE_DETAILS: {
|
||||
|
||||
@@ -14,14 +14,14 @@ export type CreatedByProps =
|
||||
creatorOptions: CreatorOption[];
|
||||
createdBy: string[];
|
||||
onCreatedByChange: (emails: string[]) => void;
|
||||
// Clear all Created-by selections and run immediately.
|
||||
onClearCreatedBy: () => void;
|
||||
// Run a Created-by change made with the dropdown closed.
|
||||
onCreatedByCommit: (emails: string[]) => void;
|
||||
}
|
||||
| {
|
||||
creatorOptions?: undefined;
|
||||
createdBy?: undefined;
|
||||
onCreatedByChange?: undefined;
|
||||
onClearCreatedBy?: undefined;
|
||||
onCreatedByCommit?: undefined;
|
||||
};
|
||||
|
||||
type Props = CreatedByProps & {
|
||||
@@ -61,8 +61,8 @@ function FilterChips(props: Props): JSX.Element {
|
||||
placeholder="Created by"
|
||||
testId={`${testIdPrefix}-filter-created-by`}
|
||||
disabled={disabled}
|
||||
onClear={props.onClearCreatedBy}
|
||||
onChange={props.onCreatedByChange}
|
||||
onCommit={props.onCreatedByCommit}
|
||||
onDropdownVisibleChange={runOnClose}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -81,7 +81,7 @@ function FilterZone({
|
||||
applyDraft,
|
||||
handleCreatedByChange,
|
||||
handleUpdatedChange,
|
||||
handleClearCreatedBy,
|
||||
handleCreatedByCommit,
|
||||
handleClear,
|
||||
} = useFilterZoneDraft({
|
||||
query,
|
||||
@@ -96,7 +96,7 @@ function FilterZone({
|
||||
creatorOptions,
|
||||
createdBy: reflected.createdBy,
|
||||
onCreatedByChange: handleCreatedByChange,
|
||||
onClearCreatedBy: handleClearCreatedBy,
|
||||
onCreatedByCommit: handleCreatedByCommit,
|
||||
}
|
||||
: {};
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { ConfigProvider, Select } from 'antd';
|
||||
import { Checkbox } from '@signozhq/ui/checkbox';
|
||||
import cx from 'classnames';
|
||||
@@ -20,7 +21,9 @@ interface Props {
|
||||
placeholder: string;
|
||||
testId: string;
|
||||
onChange: (values: string[]) => void;
|
||||
onClear?: () => void;
|
||||
// A change made with the dropdown closed (a tag's ×, the clear icon) has no
|
||||
// close to run on, so it is committed here instead of staged via onChange.
|
||||
onCommit: (values: string[]) => void;
|
||||
onDropdownVisibleChange?: (open: boolean) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
@@ -31,10 +34,31 @@ function MultiSelectFilter({
|
||||
placeholder,
|
||||
testId,
|
||||
onChange,
|
||||
onClear,
|
||||
onCommit,
|
||||
onDropdownVisibleChange,
|
||||
disabled = false,
|
||||
}: Props): JSX.Element {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const handleChange = useCallback(
|
||||
(next: string[]): void => {
|
||||
if (!isOpen) {
|
||||
onCommit(next);
|
||||
return;
|
||||
}
|
||||
onChange(next);
|
||||
},
|
||||
[isOpen, onChange, onCommit],
|
||||
);
|
||||
|
||||
const handleDropdownVisibleChange = useCallback(
|
||||
(nextOpen: boolean): void => {
|
||||
setIsOpen(nextOpen);
|
||||
onDropdownVisibleChange?.(nextOpen);
|
||||
},
|
||||
[onDropdownVisibleChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<ConfigProvider theme={CHECKBOX_SELECT_THEME}>
|
||||
<Select
|
||||
@@ -51,7 +75,6 @@ function MultiSelectFilter({
|
||||
menuItemSelectedIcon={null}
|
||||
data-testid={testId}
|
||||
disabled={disabled}
|
||||
onClear={onClear}
|
||||
optionRender={(option): JSX.Element => (
|
||||
<div
|
||||
className={styles.checkOption}
|
||||
@@ -66,8 +89,8 @@ function MultiSelectFilter({
|
||||
<span className={styles.checkOptionLabel}>{option.label}</span>
|
||||
</div>
|
||||
)}
|
||||
onChange={(next): void => onChange(next as string[])}
|
||||
onDropdownVisibleChange={onDropdownVisibleChange}
|
||||
onChange={(next): void => handleChange(next as string[])}
|
||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||
/>
|
||||
</ConfigProvider>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render, screen } from 'tests/test-utils';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { render, screen, within } from 'tests/test-utils';
|
||||
|
||||
import type { DslGrammar } from '../../dsl/types';
|
||||
import FilterZone from '../FilterZone';
|
||||
@@ -47,4 +48,33 @@ describe('FilterZone', () => {
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('things-filter-updated')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('runs the query when a creator is removed with the dropdown closed', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onQueryChange = jest.fn();
|
||||
render(
|
||||
<FilterZone
|
||||
query="created_by = 'ada@example.com'"
|
||||
grammar={grammar}
|
||||
testIdPrefix="things"
|
||||
creatorOptions={[{ email: 'ada@example.com', label: 'Ada' }]}
|
||||
source={source}
|
||||
onQueryChange={onQueryChange}
|
||||
/>,
|
||||
);
|
||||
|
||||
// antd renders the tag's × aria-hidden.
|
||||
await user.click(
|
||||
within(screen.getByTitle('Ada')).getByRole('img', {
|
||||
name: 'close',
|
||||
hidden: true,
|
||||
}),
|
||||
);
|
||||
|
||||
expect(
|
||||
within(screen.getByTestId('things-filter-created-by')).getByRole('combobox'),
|
||||
).toHaveAttribute('aria-expanded', 'false');
|
||||
|
||||
expect(onQueryChange).toHaveBeenCalledWith('');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,12 +106,20 @@ describe('useFilterZoneDraft', () => {
|
||||
"created_by = 'a@x.io' AND name = 'x'",
|
||||
);
|
||||
|
||||
act(() => result.current.handleClearCreatedBy());
|
||||
act(() => result.current.handleCreatedByCommit([]));
|
||||
|
||||
expect(result.current.draft).toBe("name = 'x'");
|
||||
expect(onQueryChange).toHaveBeenCalledWith("name = 'x'");
|
||||
});
|
||||
|
||||
it('runs the remaining creators when one is removed', () => {
|
||||
const { result, onQueryChange } = setup("created_by IN ['a@x.io', 'b@x.io']");
|
||||
|
||||
act(() => result.current.handleCreatedByCommit(['b@x.io']));
|
||||
|
||||
expect(onQueryChange).toHaveBeenCalledWith("created_by = 'b@x.io'");
|
||||
});
|
||||
|
||||
it('empties the draft and runs the empty query on clear', () => {
|
||||
const { result, onQueryChange, onCleared, onClearAll } = setup();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ interface FilterZoneDraft {
|
||||
applyDraft: (next: string) => void;
|
||||
handleCreatedByChange: (emails: string[]) => void;
|
||||
handleUpdatedChange: (window: UpdatedWindow) => void;
|
||||
handleClearCreatedBy: () => void;
|
||||
handleCreatedByCommit: (emails: string[]) => void;
|
||||
handleClear: () => void;
|
||||
}
|
||||
|
||||
@@ -97,10 +97,14 @@ export function useFilterZoneDraft({
|
||||
[draft, applyDraft, onFilterApplied],
|
||||
);
|
||||
|
||||
// Clear-all on the Created-by select removes its clause and runs immediately.
|
||||
const handleClearCreatedBy = useCallback((): void => {
|
||||
applyDraft(spliceClause(draft, 'created_by', null));
|
||||
}, [draft, applyDraft]);
|
||||
// Runs a Created-by change made with its dropdown closed.
|
||||
const handleCreatedByCommit = useCallback(
|
||||
(emails: string[]): void => {
|
||||
onFilterApplied?.('createdBy', { valueCount: emails.length });
|
||||
applyDraft(spliceClause(draft, 'created_by', createdByClause(emails)));
|
||||
},
|
||||
[draft, applyDraft, onFilterApplied],
|
||||
);
|
||||
|
||||
// Clear resets the draft and runs immediately (empty query).
|
||||
const handleClear = useCallback((): void => {
|
||||
@@ -122,7 +126,7 @@ export function useFilterZoneDraft({
|
||||
applyDraft,
|
||||
handleCreatedByChange,
|
||||
handleUpdatedChange,
|
||||
handleClearCreatedBy,
|
||||
handleCreatedByCommit,
|
||||
handleClear,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ interface Props {
|
||||
confirmLabel: string;
|
||||
/** Name the input holds each time the dialog opens. */
|
||||
initialName?: string;
|
||||
placeholder: string;
|
||||
testIdPrefix: string;
|
||||
}
|
||||
|
||||
@@ -35,6 +36,7 @@ function ViewNameDialog({
|
||||
description,
|
||||
confirmLabel,
|
||||
initialName = '',
|
||||
placeholder,
|
||||
testIdPrefix,
|
||||
}: Props): JSX.Element {
|
||||
const [name, setName] = useState(initialName);
|
||||
@@ -116,7 +118,7 @@ function ViewNameDialog({
|
||||
id={inputId}
|
||||
value={name}
|
||||
maxLength={VIEW_NAME_MAX_LENGTH}
|
||||
placeholder="e.g. Prod alerts"
|
||||
placeholder={placeholder}
|
||||
autoComplete="off"
|
||||
testId={`${testIdPrefix}-name`}
|
||||
onChange={(e: ChangeEvent<HTMLInputElement>): void =>
|
||||
|
||||
@@ -39,6 +39,7 @@ interface Props {
|
||||
saveTestIdPrefix?: string;
|
||||
renameTestIdPrefix?: string;
|
||||
customSectionLabel?: string;
|
||||
viewNamePlaceholder?: string;
|
||||
deleteDescription?: string;
|
||||
/** Wraps the rail body, e.g. in an authz guard. */
|
||||
guard?: (content: ReactElement) => ReactElement;
|
||||
@@ -67,6 +68,7 @@ function ViewsRail({
|
||||
saveTestIdPrefix = 'save-view',
|
||||
renameTestIdPrefix = 'rename-view',
|
||||
customSectionLabel = 'My views',
|
||||
viewNamePlaceholder = 'e.g. Production',
|
||||
deleteDescription = 'This removes the saved view.',
|
||||
guard,
|
||||
onViewSaved,
|
||||
@@ -287,6 +289,7 @@ function ViewsRail({
|
||||
title="Save as view"
|
||||
description="Save the current filters as a view you can return to."
|
||||
confirmLabel="Save view"
|
||||
placeholder={viewNamePlaceholder}
|
||||
testIdPrefix={saveTestIdPrefix}
|
||||
/>
|
||||
<ViewNameDialog
|
||||
@@ -297,6 +300,7 @@ function ViewsRail({
|
||||
description="The view keeps its filters under the new name."
|
||||
confirmLabel="Rename"
|
||||
initialName={renameTarget?.label}
|
||||
placeholder={viewNamePlaceholder}
|
||||
testIdPrefix={renameTestIdPrefix}
|
||||
/>
|
||||
{contextHolder}
|
||||
|
||||
@@ -163,6 +163,22 @@ describe('ViewsRail', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('shows the list placeholder in the save and rename dialogs', async () => {
|
||||
const user = userEvent.setup();
|
||||
renderRail({ viewNamePlaceholder: 'e.g. Prod things' });
|
||||
|
||||
await user.click(screen.getByTestId(`${PREFIX}-view-save-trigger`));
|
||||
await expect(
|
||||
screen.findByTestId('save-view-name-field'),
|
||||
).resolves.toHaveAttribute('placeholder', 'e.g. Prod things');
|
||||
await user.click(screen.getByTestId('save-view-cancel'));
|
||||
|
||||
await user.click(screen.getByTestId(`${PREFIX}-view-rename-view-1`));
|
||||
await expect(
|
||||
screen.findByTestId('rename-view-name-field'),
|
||||
).resolves.toHaveAttribute('placeholder', 'e.g. Prod things');
|
||||
});
|
||||
|
||||
it('opens the save dialog empty again after a cancel', async () => {
|
||||
const user = userEvent.setup();
|
||||
const props = renderRail({ isModified: true });
|
||||
|
||||
@@ -105,6 +105,8 @@ const stopEventsExtension = EditorView.domEventHandlers({
|
||||
},
|
||||
});
|
||||
|
||||
const EDITOR_BASIC_SETUP = { lineNumbers: false };
|
||||
|
||||
interface QuerySearchProps {
|
||||
placeholder?: string;
|
||||
onChange: (value: string) => void;
|
||||
@@ -713,14 +715,17 @@ function QuerySearch({
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleChange = (value: string): void => {
|
||||
const onChangeRef = useRef(onChange);
|
||||
onChangeRef.current = onChange;
|
||||
|
||||
const handleChange = useCallback((value: string): void => {
|
||||
if (isProgrammaticChangeRef.current) {
|
||||
isProgrammaticChangeRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
onChange(value);
|
||||
};
|
||||
onChangeRef.current(value);
|
||||
}, []);
|
||||
|
||||
const handleBlur = (): void => {
|
||||
const currentExpression = getCurrentExpression();
|
||||
@@ -1474,6 +1479,65 @@ function QuerySearch({
|
||||
};
|
||||
}
|
||||
|
||||
const completionSourceRef = useRef(combinedSuggestions);
|
||||
completionSourceRef.current = combinedSuggestions;
|
||||
const handleRunRef = useRef(handleRun);
|
||||
handleRunRef.current = handleRun;
|
||||
|
||||
// Built once: new extensions reconfigure CodeMirror, which closes the open suggestions.
|
||||
const editorExtensions = useMemo(
|
||||
() => [
|
||||
autocompletion({
|
||||
override: [
|
||||
(context: CompletionContext): CompletionResult | null =>
|
||||
completionSourceRef.current(context),
|
||||
],
|
||||
defaultKeymap: true,
|
||||
closeOnBlur: true,
|
||||
activateOnTyping: true,
|
||||
maxRenderedOptions: 50,
|
||||
addToOptions: [{ render: renderRecentDeleteButton, position: 100 }],
|
||||
}),
|
||||
javascript({ jsx: false, typescript: false }),
|
||||
EditorView.lineWrapping,
|
||||
stopEventsExtension,
|
||||
Prec.highest(
|
||||
keymap.of([
|
||||
...completionKeymap,
|
||||
{
|
||||
key: 'Escape',
|
||||
run: closeCompletion,
|
||||
},
|
||||
{
|
||||
key: 'Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Enter to add new line
|
||||
// and instead run a custom action
|
||||
run: (): boolean => true,
|
||||
},
|
||||
{
|
||||
key: 'Mod-Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Mod-Enter to add new line
|
||||
// and instead run a custom action
|
||||
// Mod-Enter is usually Ctrl-Enter or Cmd-Enter based on OS
|
||||
run: (): boolean => {
|
||||
handleRunRef.current();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'Shift-Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Shift-Enter to add new line
|
||||
run: (): boolean => true,
|
||||
},
|
||||
]),
|
||||
),
|
||||
],
|
||||
[],
|
||||
);
|
||||
|
||||
// Effect to handle focus state and trigger suggestions
|
||||
useEffect(() => {
|
||||
const clearTimeout = toggleSuggestions(10);
|
||||
@@ -1650,56 +1714,9 @@ function QuerySearch({
|
||||
hasErrors: validation.errors.length > 0,
|
||||
hasInitialExpression: isScopedFilter && !showScopeChip,
|
||||
})}
|
||||
extensions={[
|
||||
autocompletion({
|
||||
override: [combinedSuggestions],
|
||||
defaultKeymap: true,
|
||||
closeOnBlur: true,
|
||||
activateOnTyping: true,
|
||||
maxRenderedOptions: 50,
|
||||
addToOptions: [{ render: renderRecentDeleteButton, position: 100 }],
|
||||
}),
|
||||
javascript({ jsx: false, typescript: false }),
|
||||
EditorView.lineWrapping,
|
||||
stopEventsExtension,
|
||||
Prec.highest(
|
||||
keymap.of([
|
||||
...completionKeymap,
|
||||
{
|
||||
key: 'Escape',
|
||||
run: closeCompletion,
|
||||
},
|
||||
{
|
||||
key: 'Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Enter to add new line
|
||||
// and instead run a custom action
|
||||
run: (): boolean => true,
|
||||
},
|
||||
{
|
||||
key: 'Mod-Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Mod-Enter to add new line
|
||||
// and instead run a custom action
|
||||
// Mod-Enter is usually Ctrl-Enter or Cmd-Enter based on OS
|
||||
run: (): boolean => {
|
||||
handleRun();
|
||||
return true;
|
||||
},
|
||||
},
|
||||
{
|
||||
key: 'Shift-Enter',
|
||||
preventDefault: true,
|
||||
// Prevent default behavior of Shift-Enter to add new line
|
||||
run: (): boolean => true,
|
||||
},
|
||||
]),
|
||||
),
|
||||
]}
|
||||
extensions={editorExtensions}
|
||||
placeholder={placeholder}
|
||||
basicSetup={{
|
||||
lineNumbers: false,
|
||||
}}
|
||||
basicSetup={EDITOR_BASIC_SETUP}
|
||||
onFocus={(): void => {
|
||||
setIsFocused(true);
|
||||
}}
|
||||
|
||||
@@ -192,6 +192,8 @@ describe('QuerySearch (Integration with Real CodeMirror)', () => {
|
||||
release();
|
||||
// Outlasts the 10 ms timer QuerySearch uses to reopen suggestions.
|
||||
await act(() => new Promise((resolve) => setTimeout(resolve, 50)));
|
||||
// Outlasts the 100 ms CodeMirror waits before it queries suggestions again.
|
||||
await new Promise((resolve) => setTimeout(resolve, 150));
|
||||
|
||||
expect(screen.getByText('payment-service')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import { useState } from 'react';
|
||||
import { Tooltip } from '@signozhq/ui/tooltip';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import { ChevronDown, ChevronRight, Undo2 } from '@signozhq/icons';
|
||||
|
||||
@@ -22,31 +20,6 @@ export function CheckboxFilterV2Header({
|
||||
onToggleOpen,
|
||||
onClear,
|
||||
}: CheckboxFilterHeaderProps): JSX.Element {
|
||||
const [isTitleTruncated, setIsTitleTruncated] = useState(false);
|
||||
|
||||
const measureTitle = (el: HTMLElement | null): void => {
|
||||
if (el) {
|
||||
setIsTitleTruncated(el.scrollWidth > el.clientWidth);
|
||||
}
|
||||
};
|
||||
|
||||
const titleText = (
|
||||
<Typography
|
||||
ref={measureTitle}
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="span"
|
||||
display="inline-block"
|
||||
minWidth={0}
|
||||
textOverflow="ellipsis"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
);
|
||||
|
||||
return (
|
||||
<section
|
||||
role="button"
|
||||
@@ -67,7 +40,19 @@ export function CheckboxFilterV2Header({
|
||||
) : (
|
||||
<ChevronRight size={13} cursor="pointer" />
|
||||
)}
|
||||
<Tooltip title={isTitleTruncated ? title : undefined}>{titleText}</Tooltip>
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="secondary"
|
||||
as="span"
|
||||
display="inline-block"
|
||||
minWidth={0}
|
||||
textOverflow="ellipsis"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{title}
|
||||
</Typography>
|
||||
</section>
|
||||
{isOpen && canReset && (
|
||||
<section className={styles.rightAction}>
|
||||
|
||||
@@ -120,43 +120,4 @@ describe('CheckboxFilterV2Header', () => {
|
||||
expect(onToggleOpen).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('title tooltip', () => {
|
||||
// jsdom has no layout, so truncation is simulated at the prototype level
|
||||
// before mount (the component measures in a layout effect).
|
||||
function mockTitleWidths(scrollWidth: number, clientWidth: number): void {
|
||||
jest
|
||||
.spyOn(HTMLElement.prototype, 'scrollWidth', 'get')
|
||||
.mockReturnValue(scrollWidth);
|
||||
jest
|
||||
.spyOn(HTMLElement.prototype, 'clientWidth', 'get')
|
||||
.mockReturnValue(clientWidth);
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('shows the full name on hover when the title is truncated', async () => {
|
||||
mockTitleWidths(200, 100);
|
||||
const user = userEvent.setup();
|
||||
render(<CheckboxFilterV2Header {...defaultProps} />);
|
||||
|
||||
await user.hover(screen.getByText(defaultProps.title));
|
||||
|
||||
await expect(screen.findByRole('tooltip')).resolves.toHaveTextContent(
|
||||
defaultProps.title,
|
||||
);
|
||||
});
|
||||
|
||||
it('shows no tooltip when the title fits', async () => {
|
||||
mockTitleWidths(100, 100);
|
||||
const user = userEvent.setup();
|
||||
render(<CheckboxFilterV2Header {...defaultProps} />);
|
||||
|
||||
await user.hover(screen.getByText(defaultProps.title));
|
||||
|
||||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,6 +114,19 @@ export const loadingFiltersHandlers = [
|
||||
),
|
||||
];
|
||||
|
||||
export const longTitleConfig = [
|
||||
{
|
||||
attributeKey: {
|
||||
dataType: DataTypes.Int64,
|
||||
key: 'http.request.content_length_uncompressed',
|
||||
type: 'tag',
|
||||
},
|
||||
defaultOpen: false,
|
||||
title: 'Http Request Content Length Uncompressed',
|
||||
type: FiltersType.CHECKBOX,
|
||||
},
|
||||
];
|
||||
|
||||
export const LONG_FILTER_VALUES = [
|
||||
'checkout-service.production-eu-central-1.svc.cluster.local',
|
||||
'payments-authorisation-worker.production-us-east-2.svc.cluster.local',
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { GlobalMockArgs } from '@/storybook/globals';
|
||||
import QuickFilters from '../QuickFilters';
|
||||
import {
|
||||
dirtySettings,
|
||||
hoverTruncatedTitle,
|
||||
openQueryPicker,
|
||||
openSettings,
|
||||
} from './__story_mockdata__/quickFilters.play';
|
||||
@@ -18,6 +19,7 @@ import {
|
||||
handlers,
|
||||
LONG_FILTER_VALUES,
|
||||
loadingFiltersHandlers,
|
||||
longTitleConfig,
|
||||
MANY_FILTER_VALUES,
|
||||
queryBuilder,
|
||||
selectedServiceQueryBuilder,
|
||||
@@ -159,6 +161,15 @@ export const Tooltips: GlobalArgsStory = {
|
||||
},
|
||||
};
|
||||
|
||||
/** A section title too long for the rail: hovering it shows the full title once. */
|
||||
export const TruncatedTitle: GlobalArgsStory = {
|
||||
args: { config: longTitleConfig },
|
||||
parameters: {
|
||||
msw: { handlers: [noSavedFiltersHandler, ...handlers] },
|
||||
},
|
||||
play: hoverTruncatedTitle,
|
||||
};
|
||||
|
||||
const [firstQuery] = queryBuilder.currentQuery.builder.queryData;
|
||||
|
||||
/** Interaction: the query picker lists every query the filters can follow. */
|
||||
|
||||
@@ -8,9 +8,12 @@ import { QuickFilterManagePermissions } from 'lib/authz/hooks/useAuthZ/permissio
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { grantsAll } from '@/storybook/access/access';
|
||||
import { hoverTruncatableText } from '@/storybook/play/truncatedText';
|
||||
import type { GlobalMockArgs } from '@/storybook/globals';
|
||||
|
||||
import type QuickFilters from '../../QuickFilters';
|
||||
import { longTitleConfig } from '../QuickFilters.stories.mocks';
|
||||
import { FiltersType } from '../../types';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
@@ -61,6 +64,26 @@ export const dirtySettings = async (context: PlayContext): Promise<void> => {
|
||||
await screen.findByRole('button', { name: 'Save changes' });
|
||||
};
|
||||
|
||||
export const hoverTruncatedTitle = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const [filter] = args.config ?? [];
|
||||
// Duration and slider sections render no title of their own.
|
||||
if (filter?.type !== FiltersType.CHECKBOX || !filter.title) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [label] = await within(canvasElement).findAllByText(
|
||||
filter.title,
|
||||
{},
|
||||
UNTIL_LOADED,
|
||||
);
|
||||
await hoverTruncatableText(label, filter.title, {
|
||||
cut: filter.title === longTitleConfig[0].title || undefined,
|
||||
});
|
||||
};
|
||||
|
||||
export const openQueryPicker = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
.ingestion-keys-search-auth-trigger {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.ant-table-row {
|
||||
.ant-table-cell {
|
||||
padding: 0;
|
||||
|
||||
@@ -26,13 +26,13 @@ import type { NotificationInstance } from 'antd/es/notification/interface';
|
||||
import type { CollapseProps } from 'antd/lib';
|
||||
import {
|
||||
useCreateIngestionKey,
|
||||
useCreateIngestionKeyLimit,
|
||||
useCreateIngestionLimit,
|
||||
useDeleteIngestionKey,
|
||||
useDeleteIngestionKeyLimit,
|
||||
useDeleteIngestionLimit,
|
||||
useGetIngestionKeys,
|
||||
useSearchIngestionKeys,
|
||||
useUpdateIngestionKey,
|
||||
useUpdateIngestionKeyLimit,
|
||||
useUpdateIngestionLimit,
|
||||
} from 'api/generated/services/gateway';
|
||||
import {
|
||||
GatewaytypesIngestionKeyDTO,
|
||||
@@ -71,6 +71,21 @@ import {
|
||||
TriangleAlert,
|
||||
X,
|
||||
} from '@signozhq/icons';
|
||||
import AuthZButton from 'lib/authz/components/AuthZButton/AuthZButton';
|
||||
import { AuthZGuardContent } from 'lib/authz/components/AuthZGuard/AuthZGuardContent';
|
||||
import AuthZTooltip from 'lib/authz/components/AuthZTooltip/AuthZTooltip';
|
||||
import {
|
||||
buildIngestionKeyAttachPermission,
|
||||
buildIngestionKeyDeletePermission,
|
||||
buildIngestionKeyDetachPermission,
|
||||
buildIngestionKeyUpdatePermission,
|
||||
buildIngestionLimitDeletePermission,
|
||||
buildIngestionLimitUpdatePermission,
|
||||
IngestionKeyCreatePermission,
|
||||
IngestionKeyListPermission,
|
||||
IngestionLimitCreatePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/ingestion.permissions';
|
||||
import { useAuthZ } from 'lib/authz/hooks/useAuthZ/useAuthZ';
|
||||
import { useAppContext } from 'providers/App/App';
|
||||
import { useTimezone } from 'providers/Timezone';
|
||||
import {
|
||||
@@ -210,6 +225,13 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
|
||||
const [totalIngestionKeys, setTotalIngestionKeys] = useState(0);
|
||||
|
||||
const { permissions: authzPermissions } = useAuthZ([
|
||||
IngestionKeyListPermission,
|
||||
]);
|
||||
|
||||
const canListIngestionKeys =
|
||||
authzPermissions?.[IngestionKeyListPermission].isGranted ?? false;
|
||||
|
||||
const [
|
||||
hasCreateLimitForIngestionKeyError,
|
||||
setHasCreateLimitForIngestionKeyError,
|
||||
@@ -314,7 +336,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
},
|
||||
{
|
||||
query: {
|
||||
enabled: !isSearching,
|
||||
enabled: !isSearching && canListIngestionKeys,
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -334,7 +356,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
},
|
||||
{
|
||||
query: {
|
||||
enabled: isSearching,
|
||||
enabled: isSearching && canListIngestionKeys,
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -345,7 +367,14 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
: ingestionKeysData;
|
||||
const isLoading = isSearching ? isLoadingSearch : isLoadingGet;
|
||||
const isRefetching = isSearching ? isRefetchingSearch : isRefetchingGet;
|
||||
const refetchAPIKeys = isSearching ? refetchSearchAPIKeys : refetchGetAPIKeys;
|
||||
const refetchKeysQuery = isSearching
|
||||
? refetchSearchAPIKeys
|
||||
: refetchGetAPIKeys;
|
||||
const refetchAPIKeys = async (): Promise<void> => {
|
||||
if (canListIngestionKeys) {
|
||||
await refetchKeysQuery();
|
||||
}
|
||||
};
|
||||
const error = isSearching ? searchError : getError;
|
||||
const isError = isSearching ? isSearchError : isGetError;
|
||||
|
||||
@@ -393,15 +422,15 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
useDeleteIngestionKey<AxiosError<RenderErrorResponseDTO>>();
|
||||
|
||||
const { mutate: createLimitForIngestionKey, isLoading: isLoadingLimitForKey } =
|
||||
useCreateIngestionKeyLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
useCreateIngestionLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
|
||||
const {
|
||||
mutate: updateLimitForIngestionKey,
|
||||
isLoading: isLoadingUpdatedLimitForKey,
|
||||
} = useUpdateIngestionKeyLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
} = useUpdateIngestionLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
|
||||
const { mutate: deleteLimitForKey, isLoading: isDeletingLimit } =
|
||||
useDeleteIngestionKeyLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
useDeleteIngestionLimit<AxiosError<RenderErrorResponseDTO>>();
|
||||
|
||||
const onDeleteHandler = (): void => {
|
||||
clearSearch();
|
||||
@@ -638,8 +667,8 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
|
||||
createLimitForIngestionKey(
|
||||
{
|
||||
pathParams: { keyId: payload.keyID },
|
||||
data: {
|
||||
keyId: payload.keyID,
|
||||
signal: payload.signal,
|
||||
config: payload.config,
|
||||
},
|
||||
@@ -1027,12 +1056,14 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
icon
|
||||
color="secondary"
|
||||
aria-label="Edit ingestion key"
|
||||
testId={`ingestion-key-edit-btn-${APIKey.id}`}
|
||||
onClick={onEditKey}
|
||||
>
|
||||
<PenLine size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
aria-label="Delete ingestion key"
|
||||
testId={`ingestion-key-delete-open-btn-${APIKey.id}`}
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon
|
||||
@@ -1160,8 +1191,19 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
});
|
||||
};
|
||||
|
||||
const isAddingNewLimit = !hasLimits(signalName);
|
||||
|
||||
const ingestionLimitPermissions = APIKey?.id
|
||||
? isAddingNewLimit
|
||||
? [
|
||||
IngestionLimitCreatePermission,
|
||||
buildIngestionKeyAttachPermission(APIKey.id),
|
||||
]
|
||||
: [buildIngestionLimitUpdatePermission(limit.id)]
|
||||
: [];
|
||||
|
||||
const onSaveSignalLimit = (): void => {
|
||||
if (!hasLimits(signalName)) {
|
||||
if (isAddingNewLimit) {
|
||||
handleAddLimit(APIKey, signalName);
|
||||
} else {
|
||||
handleUpdateLimit(APIKey, limitsDict[signalName]);
|
||||
@@ -1200,6 +1242,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
icon
|
||||
color="danger"
|
||||
aria-label={`Delete ${signalName} limit`}
|
||||
testId={`ingestion-limit-delete-open-btn-${signalName}`}
|
||||
disabled={
|
||||
!!(activeAPIKey?.id === APIKey?.id && activeSignal)
|
||||
}
|
||||
@@ -1217,6 +1260,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
prefix={<Plus size={12} />}
|
||||
disabled={!!(activeAPIKey?.id === APIKey?.id && activeSignal)}
|
||||
onClick={onAddSignalLimit}
|
||||
testId={`ingestion-limit-add-btn-${signalName}`}
|
||||
>
|
||||
Limits
|
||||
</Button>
|
||||
@@ -1448,7 +1492,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
isEditAddLimitOpen && (
|
||||
<div className="signal-limit-save-discard">
|
||||
<div className="signal-limit-save-discard-actions">
|
||||
<Button
|
||||
<AuthZButton
|
||||
color="primary"
|
||||
variant="solid"
|
||||
size="sm"
|
||||
@@ -1456,9 +1500,11 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
isLoadingLimitForKey || isLoadingUpdatedLimitForKey
|
||||
}
|
||||
onClick={onSaveSignalLimit}
|
||||
testId="ingestion-limit-save-btn"
|
||||
checks={ingestionLimitPermissions}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</AuthZButton>
|
||||
<Button
|
||||
disabledTooltip="Wait for the limit to save"
|
||||
variant="outlined"
|
||||
@@ -1781,42 +1827,50 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
)}
|
||||
|
||||
<div className="ingestion-keys-search-add-new">
|
||||
<Input
|
||||
placeholder="Search for ingestion key..."
|
||||
prefix={<Search size={12} color={Color.BG_VANILLA_400} />}
|
||||
value={searchValue}
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
<AuthZTooltip
|
||||
triggerClassName="ingestion-keys-search-auth-trigger"
|
||||
checks={[IngestionKeyListPermission]}
|
||||
>
|
||||
<Input
|
||||
placeholder="Search for ingestion key..."
|
||||
prefix={<Search size={12} color={Color.BG_VANILLA_400} />}
|
||||
value={searchValue}
|
||||
onChange={handleSearch}
|
||||
/>
|
||||
</AuthZTooltip>
|
||||
|
||||
<div className="ingestion-keys-add-new">
|
||||
<Button
|
||||
<AuthZButton
|
||||
size="md"
|
||||
color="primary"
|
||||
variant="solid"
|
||||
prefix={<Plus size={14} />}
|
||||
onClick={showAddModal}
|
||||
testId="ingestion-key-add-btn"
|
||||
checks={[IngestionKeyCreatePermission]}
|
||||
>
|
||||
New Ingestion key
|
||||
</Button>
|
||||
</AuthZButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
loading={isLoading || isRefetching}
|
||||
showHeader={false}
|
||||
onChange={handleTableChange}
|
||||
pagination={{
|
||||
pageSize: isSearching ? SEARCH_PAGE_SIZE : paginationParams?.per_page,
|
||||
hideOnSinglePage: true,
|
||||
showTotal: (total: number, range: number[]): string =>
|
||||
`${range[0]}-${range[1]} of ${total} Ingestion keys`,
|
||||
total: totalIngestionKeys,
|
||||
}}
|
||||
className="ingestion-keys-table"
|
||||
/>
|
||||
<AuthZGuardContent checks={[IngestionKeyListPermission]}>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={dataSource}
|
||||
loading={isLoading || isRefetching}
|
||||
showHeader={false}
|
||||
onChange={handleTableChange}
|
||||
pagination={{
|
||||
pageSize: isSearching ? SEARCH_PAGE_SIZE : paginationParams?.per_page,
|
||||
hideOnSinglePage: true,
|
||||
showTotal: (total: number, range: number[]): string =>
|
||||
`${range[0]}-${range[1]} of ${total} Ingestion keys`,
|
||||
total: totalIngestionKeys,
|
||||
}}
|
||||
className="ingestion-keys-table"
|
||||
/>
|
||||
</AuthZGuardContent>
|
||||
</div>
|
||||
|
||||
{/* Delete Key Modal */}
|
||||
@@ -1839,7 +1893,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button
|
||||
<AuthZButton
|
||||
size="md"
|
||||
key="submit"
|
||||
variant="solid"
|
||||
@@ -1847,9 +1901,15 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
prefix={<Trash2 size={16} />}
|
||||
loading={isDeleteingAPIKey}
|
||||
onClick={onDeleteHandler}
|
||||
testId="ingestion-key-delete-btn"
|
||||
checks={
|
||||
isDeleteModalOpen && activeAPIKey?.id
|
||||
? [buildIngestionKeyDeletePermission(activeAPIKey.id)]
|
||||
: []
|
||||
}
|
||||
>
|
||||
Delete Ingestion Key
|
||||
</Button>,
|
||||
</AuthZButton>,
|
||||
]}
|
||||
>
|
||||
<Typography
|
||||
@@ -1886,7 +1946,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button
|
||||
<AuthZButton
|
||||
size="md"
|
||||
key="submit"
|
||||
variant="solid"
|
||||
@@ -1894,9 +1954,18 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
prefix={<Trash2 size={16} />}
|
||||
loading={isDeletingLimit}
|
||||
onClick={onDeleteLimitHandler}
|
||||
testId="ingestion-limit-delete-btn"
|
||||
checks={
|
||||
isDeleteLimitModalOpen && activeSignal?.id && activeAPIKey?.id
|
||||
? [
|
||||
buildIngestionLimitDeletePermission(activeSignal.id),
|
||||
buildIngestionKeyDetachPermission(activeAPIKey.id),
|
||||
]
|
||||
: []
|
||||
}
|
||||
>
|
||||
Delete Limit
|
||||
</Button>,
|
||||
</AuthZButton>,
|
||||
]}
|
||||
>
|
||||
<Typography
|
||||
@@ -1936,7 +2005,7 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button
|
||||
<AuthZButton
|
||||
size="md"
|
||||
color="primary"
|
||||
key="submit"
|
||||
@@ -1944,9 +2013,15 @@ function MultiIngestionSettings(): JSX.Element {
|
||||
prefix={<Check size={14} />}
|
||||
loading={isLoadingUpdateAPIKey}
|
||||
onClick={onUpdateApiKey}
|
||||
testId="ingestion-key-update-btn"
|
||||
checks={
|
||||
isEditModalOpen && activeAPIKey?.id
|
||||
? [buildIngestionKeyUpdatePermission(activeAPIKey.id)]
|
||||
: []
|
||||
}
|
||||
>
|
||||
Update Ingestion Key
|
||||
</Button>,
|
||||
</AuthZButton>,
|
||||
]}
|
||||
>
|
||||
<Form
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
import dayjs from 'dayjs';
|
||||
import type {
|
||||
AuthtypesTransactionDTO,
|
||||
GatewaytypesIngestionKeyDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import {
|
||||
buildIngestionKeyAttachPermission,
|
||||
buildIngestionKeyDeletePermission,
|
||||
buildIngestionKeyDetachPermission,
|
||||
buildIngestionKeyUpdatePermission,
|
||||
buildIngestionLimitDeletePermission,
|
||||
buildIngestionLimitUpdatePermission,
|
||||
IngestionKeyCreatePermission,
|
||||
IngestionKeyListPermission,
|
||||
IngestionLimitCreatePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/ingestion.permissions';
|
||||
import { gettableTransactionToPermission } from 'lib/authz/hooks/useAuthZ/utils';
|
||||
import {
|
||||
AUTHZ_CHECK_URL,
|
||||
setupAuthzAdmin,
|
||||
setupAuthzDeny,
|
||||
} from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
import MultiIngestionSettings from '../MultiIngestionSettings';
|
||||
|
||||
jest.setTimeout(15_000);
|
||||
|
||||
const ROUTE = '/ingestion-settings';
|
||||
const DATE = '2024-01-01T00:00:00Z';
|
||||
const EXPIRES_AT = '2030-01-01T00:00:00Z';
|
||||
|
||||
const DENIED_TEXT = /is not authorized to perform/i;
|
||||
|
||||
const makeKey = (
|
||||
id: string,
|
||||
name: string,
|
||||
limits: GatewaytypesIngestionKeyDTO['limits'] = [],
|
||||
): GatewaytypesIngestionKeyDTO => ({
|
||||
id,
|
||||
name,
|
||||
value: 'secret',
|
||||
workspace_id: 'w1',
|
||||
expires_at: EXPIRES_AT,
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
tags: [],
|
||||
limits,
|
||||
});
|
||||
|
||||
const KEY_ONE = makeKey('k1', 'Key One', [
|
||||
{ id: 'l1', signal: 'logs', config: { day: { size: 1073741824 } } },
|
||||
]);
|
||||
const KEY_TWO = makeKey('k2', 'Key Two');
|
||||
const KEY_THREE = makeKey('k3', 'Key Three');
|
||||
|
||||
function mockKeys(keys: GatewaytypesIngestionKeyDTO[]): jest.Mock {
|
||||
const onList = jest.fn();
|
||||
server.use(
|
||||
rest.get('*/api/v1/global/config*', (_req, res, ctx) =>
|
||||
res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
status: 'success',
|
||||
data: {
|
||||
external_url: '',
|
||||
ingestion_url: 'http://ingest.example.com',
|
||||
ai_assistant_url: null,
|
||||
mcp_url: null,
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
rest.get('*/api/v2/gateway/ingestion_keys*', (_req, res, ctx) => {
|
||||
onList();
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
status: 'success',
|
||||
data: {
|
||||
keys,
|
||||
_pagination: {
|
||||
page: 1,
|
||||
per_page: 10,
|
||||
pages: 1,
|
||||
total: keys.length,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
return onList;
|
||||
}
|
||||
|
||||
function recordAuthzChecks(): Set<string> {
|
||||
const seen = new Set<string>();
|
||||
server.use(
|
||||
rest.post(AUTHZ_CHECK_URL, async (req) => {
|
||||
const payload = (await req.json()) as AuthtypesTransactionDTO[];
|
||||
payload.forEach((txn) => seen.add(gettableTransactionToPermission(txn)));
|
||||
return undefined;
|
||||
}),
|
||||
);
|
||||
return seen;
|
||||
}
|
||||
|
||||
async function expandKey(
|
||||
user: ReturnType<typeof userEvent.setup>,
|
||||
name: string,
|
||||
): Promise<void> {
|
||||
await user.click(
|
||||
await screen.findByRole('button', { name: new RegExp(`right ${name}`, 'i') }),
|
||||
);
|
||||
await screen.findByText('LIMITS');
|
||||
}
|
||||
|
||||
async function settledButton(testId: string): Promise<HTMLElement> {
|
||||
const button = await screen.findByTestId(testId);
|
||||
await waitFor(() => {
|
||||
expect(button).not.toHaveAttribute('aria-busy');
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
function renderPage(): ReturnType<typeof userEvent.setup> {
|
||||
render(<MultiIngestionSettings />, undefined, { initialRoute: ROUTE });
|
||||
return userEvent.setup({ pointerEventsCheck: 0 });
|
||||
}
|
||||
|
||||
describe('MultiIngestionSettings authz', () => {
|
||||
afterEach(async () => {
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 100);
|
||||
});
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
describe('ingestion-key:list', () => {
|
||||
it('hides the list, disables search and fires no list request when denied', async () => {
|
||||
const onList = mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzDeny(IngestionKeyListPermission));
|
||||
|
||||
renderPage();
|
||||
|
||||
await screen.findByText(DENIED_TEXT);
|
||||
expect(
|
||||
screen.getByPlaceholderText('Search for ingestion key...'),
|
||||
).toBeDisabled();
|
||||
expect(screen.queryByText('Key One')).not.toBeInTheDocument();
|
||||
expect(onList).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('shows the list and requests it when granted', async () => {
|
||||
const onList = mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzAdmin());
|
||||
|
||||
renderPage();
|
||||
|
||||
await screen.findByText('Key One');
|
||||
expect(onList).toHaveBeenCalled();
|
||||
expect(screen.queryByText(DENIED_TEXT)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ingestion-key:create', () => {
|
||||
it('disables "New Ingestion key" when denied', async () => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzDeny(IngestionKeyCreatePermission));
|
||||
|
||||
renderPage();
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-key-add-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('enables "New Ingestion key" and opens the modal when granted', async () => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzAdmin());
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-key-add-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
await user.click(screen.getByTestId('ingestion-key-add-btn'));
|
||||
|
||||
await screen.findByTestId('create-new-key');
|
||||
});
|
||||
});
|
||||
|
||||
describe('creating a key without list access', () => {
|
||||
it('sends no list request after the key is created', async () => {
|
||||
const onList = mockKeys([KEY_ONE]);
|
||||
const onCreate = jest.fn();
|
||||
server.use(
|
||||
setupAuthzDeny(IngestionKeyListPermission),
|
||||
rest.post('*/api/v2/gateway/ingestion_keys', (_req, res, ctx) => {
|
||||
onCreate();
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({ status: 'success', data: { id: 'k9', value: 'v' } }),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-key-add-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
await user.click(screen.getByTestId('ingestion-key-add-btn'));
|
||||
await user.type(await screen.findByLabelText('Name'), 'new-key');
|
||||
await user.click(screen.getByLabelText('Expiration'));
|
||||
await user.click(
|
||||
await screen.findByTitle(dayjs().add(1, 'day').format('YYYY-MM-DD')),
|
||||
);
|
||||
await user.click(screen.getByTestId('create-new-key'));
|
||||
|
||||
await waitFor(() => expect(onCreate).toHaveBeenCalledTimes(1));
|
||||
await screen.findByText(DENIED_TEXT);
|
||||
expect(onList).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('ingestion-key:update', () => {
|
||||
it('disables "Update Ingestion Key" for the denied key', async () => {
|
||||
mockKeys([KEY_ONE, KEY_TWO]);
|
||||
server.use(setupAuthzDeny(buildIngestionKeyUpdatePermission('k1')));
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await user.click(await screen.findByTestId('ingestion-key-edit-btn-k1'));
|
||||
await expect(
|
||||
settledButton('ingestion-key-update-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('keeps "Update Ingestion Key" enabled for another key', async () => {
|
||||
mockKeys([KEY_ONE, KEY_TWO]);
|
||||
server.use(setupAuthzDeny(buildIngestionKeyUpdatePermission('k1')));
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await user.click(await screen.findByTestId('ingestion-key-edit-btn-k2'));
|
||||
await expect(
|
||||
settledButton('ingestion-key-update-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('ingestion-key:delete', () => {
|
||||
it('disables "Delete Ingestion Key" when denied for that key', async () => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzDeny(buildIngestionKeyDeletePermission('k1')));
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await user.click(
|
||||
await screen.findByTestId('ingestion-key-delete-open-btn-k1'),
|
||||
);
|
||||
await expect(
|
||||
settledButton('ingestion-key-delete-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('saving a new limit', () => {
|
||||
it('disables "Save" when attach is denied on the key', async () => {
|
||||
mockKeys([KEY_TWO]);
|
||||
server.use(setupAuthzDeny(buildIngestionKeyAttachPermission('k2')));
|
||||
|
||||
const user = renderPage();
|
||||
await expandKey(user, 'Key Two');
|
||||
await user.click(screen.getByTestId('ingestion-limit-add-btn-logs'));
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-limit-save-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('disables "Save" when ingestion-limit:create is denied', async () => {
|
||||
mockKeys([KEY_TWO]);
|
||||
server.use(setupAuthzDeny(IngestionLimitCreatePermission));
|
||||
|
||||
const user = renderPage();
|
||||
await expandKey(user, 'Key Two');
|
||||
await user.click(screen.getByTestId('ingestion-limit-add-btn-logs'));
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-limit-save-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('saving an existing limit', () => {
|
||||
it('disables "Save" when update is denied on that limit', async () => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzDeny(buildIngestionLimitUpdatePermission('l1')));
|
||||
|
||||
const user = renderPage();
|
||||
await expandKey(user, 'Key One');
|
||||
await user.click(screen.getByTestId('edit-limit-btn-logs'));
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-limit-save-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('keeps "Save" enabled when only create and attach are denied', async () => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(
|
||||
setupAuthzDeny(
|
||||
IngestionLimitCreatePermission,
|
||||
buildIngestionKeyAttachPermission('k1'),
|
||||
),
|
||||
);
|
||||
|
||||
const user = renderPage();
|
||||
await expandKey(user, 'Key One');
|
||||
await user.click(screen.getByTestId('edit-limit-btn-logs'));
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-limit-save-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('deleting a limit', () => {
|
||||
it.each([
|
||||
['ingestion-limit:delete', buildIngestionLimitDeletePermission('l1')],
|
||||
['ingestion-key:detach', buildIngestionKeyDetachPermission('k1')],
|
||||
])('disables "Delete Limit" when %s is denied', async (_name, denied) => {
|
||||
mockKeys([KEY_ONE]);
|
||||
server.use(setupAuthzDeny(denied));
|
||||
|
||||
const user = renderPage();
|
||||
await expandKey(user, 'Key One');
|
||||
await user.click(screen.getByTestId('ingestion-limit-delete-open-btn-logs'));
|
||||
|
||||
await expect(
|
||||
settledButton('ingestion-limit-delete-btn'),
|
||||
).resolves.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('id checks', () => {
|
||||
it('only checks list and create on load, and per-id checks once a modal opens', async () => {
|
||||
mockKeys([KEY_ONE, KEY_TWO, KEY_THREE]);
|
||||
server.use(setupAuthzAdmin());
|
||||
const seen = recordAuthzChecks();
|
||||
|
||||
const user = renderPage();
|
||||
|
||||
await screen.findByText('Key Three');
|
||||
await expect(
|
||||
settledButton('ingestion-key-add-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
expect([...seen].sort()).toStrictEqual(
|
||||
[IngestionKeyListPermission, IngestionKeyCreatePermission].sort(),
|
||||
);
|
||||
|
||||
await user.click(screen.getByTestId('ingestion-key-edit-btn-k1'));
|
||||
await expect(
|
||||
settledButton('ingestion-key-update-btn'),
|
||||
).resolves.not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
expect(seen.has(buildIngestionKeyUpdatePermission('k1'))).toBe(true);
|
||||
expect(seen.has(buildIngestionKeyUpdatePermission('k2'))).toBe(false);
|
||||
expect(seen.has(buildIngestionKeyUpdatePermission('k3'))).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GatewaytypesGettableIngestionKeysDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import { setupAuthzAdmin } from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
@@ -39,6 +40,7 @@ const GLOBAL_CONFIG_RESPONSE = {
|
||||
describe('MultiIngestionSettings Page', () => {
|
||||
beforeEach(() => {
|
||||
mockNavigate.mockClear();
|
||||
server.use(setupAuthzAdmin());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -350,7 +352,7 @@ describe('MultiIngestionSettings Page', () => {
|
||||
initialRoute: INGESTION_SETTINGS_ROUTE,
|
||||
});
|
||||
|
||||
await screen.findByText('Key Regular');
|
||||
await screen.findByText('Key Regular', undefined, { timeout: 5000 });
|
||||
expect(getHandler).toHaveBeenCalled();
|
||||
expect(searchHandler).not.toHaveBeenCalled();
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@ import { Dispatch, SetStateAction, useEffect, useMemo, useState } from 'react';
|
||||
import { useAppNavigate } from 'lib/router/useAppNavigate';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Select, Skeleton } from 'antd';
|
||||
import { SelectProps } from 'antd/lib';
|
||||
import { Select, SelectProps, Skeleton } from 'antd';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { useListAccounts } from 'api/generated/services/cloudintegration';
|
||||
import cx from 'classnames';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Modal } from 'antd/lib';
|
||||
import { Modal } from 'antd';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { useDisconnectAccount } from 'api/generated/services/cloudintegration';
|
||||
import { CloudintegrationtypesGCPConnectionMethodDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { RuletypesAlertStateDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import MultiSelectFilter, {
|
||||
type MultiSelectFilterOption,
|
||||
@@ -25,25 +25,27 @@ function RuleStatesFilter({
|
||||
onChange,
|
||||
}: RuleStatesFilterProps): JSX.Element {
|
||||
const [draft, setDraft] = useState(states);
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setDraft(states);
|
||||
}, [states]);
|
||||
|
||||
const handleChange = (next: string[]): void => {
|
||||
setDraft(next);
|
||||
if (!open) {
|
||||
const handleCommit = useCallback(
|
||||
(next: string[]): void => {
|
||||
setDraft(next);
|
||||
onChange(next);
|
||||
}
|
||||
};
|
||||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
const handleDropdownVisibleChange = (nextOpen: boolean): void => {
|
||||
setOpen(nextOpen);
|
||||
if (!nextOpen && !isSameStates(draft, states)) {
|
||||
onChange(draft);
|
||||
}
|
||||
};
|
||||
const handleDropdownVisibleChange = useCallback(
|
||||
(isOpen: boolean): void => {
|
||||
if (!isOpen && !isSameStates(draft, states)) {
|
||||
onChange(draft);
|
||||
}
|
||||
},
|
||||
[draft, states, onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<MultiSelectFilter
|
||||
@@ -51,7 +53,8 @@ function RuleStatesFilter({
|
||||
options={STATE_OPTIONS}
|
||||
placeholder="Status"
|
||||
testId="alert-rules-filter-states"
|
||||
onChange={handleChange}
|
||||
onChange={setDraft}
|
||||
onCommit={handleCommit}
|
||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -212,6 +212,7 @@ function ListAlertRules(): JSX.Element {
|
||||
testIdPrefix="alert-rules"
|
||||
saveTestIdPrefix="save-alert-rule-view"
|
||||
renameTestIdPrefix="rename-alert-rule-view"
|
||||
viewNamePlaceholder="e.g. Prod alerts"
|
||||
deleteDescription="Views are shared across your organization, so this removes it for everyone. Alert rules are not affected."
|
||||
/>
|
||||
<div className={styles.main}>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Color, Style } from '@signozhq/design-tokens';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
@@ -81,7 +81,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="google-domain">
|
||||
Domain
|
||||
<Tooltip title="The email domain for users who should use SSO (e.g., `example.com` for users with `@example.com` emails)">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -104,7 +104,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="google-client-id">
|
||||
Client ID
|
||||
<Tooltip title="ClientID is the application's ID. For example, 292085223830.apps.googleusercontent.com.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -122,7 +122,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="google-client-secret">
|
||||
Client Secret
|
||||
<Tooltip title="It is the application's secret.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -161,7 +161,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title='Whether to skip email verification. Defaults to "false"'>
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
@@ -243,7 +243,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title="Enable fetching Google Workspace groups for the user. Requires service account configuration.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
@@ -256,7 +256,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
>
|
||||
Service Account JSON
|
||||
<Tooltip title="The JSON content of the Google Service Account credentials file. Required for group fetching.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -298,7 +298,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title="If enabled, recursively fetch groups that contain other groups (transitive membership).">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
@@ -309,7 +309,7 @@ function ConfigureGoogleAuthAuthnProvider({
|
||||
>
|
||||
Allowed Groups
|
||||
<Tooltip title="Optional list of allowed groups. If configured, only users belonging to one of these groups will be allowed to login.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Style } from '@signozhq/design-tokens';
|
||||
import { CircleHelp, TriangleAlert } from '@signozhq/icons';
|
||||
import { Callout } from '@signozhq/ui/callout';
|
||||
import { Checkbox } from '@signozhq/ui/checkbox';
|
||||
@@ -55,7 +54,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="oidc-domain">
|
||||
Domain
|
||||
<Tooltip title="The email domain for users who should use SSO (e.g., `example.com` for users with `@example.com` emails)">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -77,7 +76,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="oidc-issuer">
|
||||
Issuer URL
|
||||
<Tooltip title='The URL identifier for the OIDC provider. For example: "https://accounts.google.com" or "https://login.salesforce.com".'>
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -95,7 +94,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="oidc-issuer-alias">
|
||||
Issuer Alias
|
||||
<Tooltip title="Optional: Override the issuer URL from .well-known/openid-configuration for providers like Azure or Oracle IDCS.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -110,7 +109,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="oidc-client-id">
|
||||
Client ID
|
||||
<Tooltip title="The application's client ID from your OIDC provider.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -128,7 +127,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="oidc-client-secret">
|
||||
Client Secret
|
||||
<Tooltip title="The application's client secret from your OIDC provider.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -166,7 +165,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title='Whether to skip email verification. Defaults to "false"'>
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
@@ -187,7 +186,7 @@ function ConfigureOIDCAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title="Use the userinfo endpoint to get additional claims. Useful when providers return thin ID tokens.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
<div className="authn-provider__callout-wrapper">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Style } from '@signozhq/design-tokens';
|
||||
import { CircleHelp, TriangleAlert } from '@signozhq/icons';
|
||||
import { Callout } from '@signozhq/ui/callout';
|
||||
import { Checkbox } from '@signozhq/ui/checkbox';
|
||||
@@ -54,7 +53,7 @@ function ConfigureSAMLAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="saml-domain">
|
||||
Domain
|
||||
<Tooltip title="The email domain for users who should use SSO (e.g., `example.com` for users with `@example.com` emails)">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -76,7 +75,7 @@ function ConfigureSAMLAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="saml-acs-url">
|
||||
SAML ACS URL
|
||||
<Tooltip title="The SSO endpoint of the SAML identity provider. It can typically be found in the SingleSignOnService element in the SAML metadata of the identity provider.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -98,7 +97,7 @@ function ConfigureSAMLAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="saml-entity-id">
|
||||
SAML Entity ID
|
||||
<Tooltip title="The entityID of the SAML identity provider. It can typically be found in the EntityID attribute of the EntityDescriptor element in the SAML metadata.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -120,7 +119,7 @@ function ConfigureSAMLAuthnProvider({
|
||||
<label className="authn-provider__label" htmlFor="saml-certificate">
|
||||
SAML X.509 Certificate
|
||||
<Tooltip title="The certificate of the SAML identity provider. It can typically be found in the X509Certificate element in the SAML metadata.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -163,7 +162,7 @@ function ConfigureSAMLAuthnProvider({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title="Whether to skip signing the SAML requests. For providers like JumpCloud, this should be enabled.">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Color, Style } from '@signozhq/design-tokens';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
@@ -98,7 +98,7 @@ function AttributeMappingSection({
|
||||
>
|
||||
Email Attribute
|
||||
<Tooltip title="The SAML attribute key that contains the user's email. Default: 'email'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -117,7 +117,7 @@ function AttributeMappingSection({
|
||||
>
|
||||
Name Attribute
|
||||
<Tooltip title="The SAML attribute key that contains the user's display name. Default: 'name'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -136,7 +136,7 @@ function AttributeMappingSection({
|
||||
>
|
||||
Groups Attribute
|
||||
<Tooltip title="The SAML attribute key that contains the user's group memberships. Used for role mapping. Default: 'groups'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -155,7 +155,7 @@ function AttributeMappingSection({
|
||||
>
|
||||
Role Attribute
|
||||
<Tooltip title="The SAML attribute key that contains the user's role directly from the IDP. Default: 'role'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Color, Style } from '@signozhq/design-tokens';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
@@ -93,7 +93,7 @@ function ClaimMappingSection({
|
||||
<label className="claim-mapping-section__label" htmlFor="email-claim">
|
||||
Email Claim
|
||||
<Tooltip title="The claim key that contains the user's email address. Default: 'email'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -109,7 +109,7 @@ function ClaimMappingSection({
|
||||
<label className="claim-mapping-section__label" htmlFor="name-claim">
|
||||
Name Claim
|
||||
<Tooltip title="The claim key that contains the user's display name. Default: 'name'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -125,7 +125,7 @@ function ClaimMappingSection({
|
||||
<label className="claim-mapping-section__label" htmlFor="groups-claim">
|
||||
Groups Claim
|
||||
<Tooltip title="The claim key that contains the user's group memberships. Used for role mapping. Default: 'groups'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -141,7 +141,7 @@ function ClaimMappingSection({
|
||||
<label className="claim-mapping-section__label" htmlFor="role-claim">
|
||||
Role Claim
|
||||
<Tooltip title="The claim key that contains the user's role directly from the IDP. Default: 'role'">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Color, Style } from '@signozhq/design-tokens';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import {
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
@@ -108,7 +108,7 @@ function RoleMappingSection({
|
||||
<label className="role-mapping-section__label" htmlFor="default-role">
|
||||
Default Role
|
||||
<Tooltip title='The default role assigned to new SSO users if no other role mapping applies. Default: "signoz-viewer"'>
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</label>
|
||||
<Form.Item
|
||||
@@ -148,7 +148,7 @@ function RoleMappingSection({
|
||||
</Checkbox>
|
||||
</Form.Item>
|
||||
<Tooltip title="If enabled, the role claim/attribute from the IDP will be used directly instead of group mappings. The role value must match a SigNoz role name (e.g. signoz-viewer, signoz-editor, signoz-admin, or a custom role).">
|
||||
<CircleHelp size={14} color={Style.L3_FOREGROUND} cursor="help" />
|
||||
<CircleHelp size={14} color="var(--l3-foreground)" cursor="help" />
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import {
|
||||
AuthDomainListPermission,
|
||||
buildAuthDomainDeletePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/auth-domain.permissions';
|
||||
import {
|
||||
setupAuthzAdmin,
|
||||
setupAuthzAllow,
|
||||
setupAuthzDeny,
|
||||
} from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
import AuthDomain from '../index';
|
||||
import {
|
||||
AUTH_DOMAINS_DELETE_ENDPOINT,
|
||||
AUTH_DOMAINS_LIST_ENDPOINT,
|
||||
mockDeleteSuccessResponse,
|
||||
mockDomainsListResponse,
|
||||
mockGoogleAuthDomain,
|
||||
} from './mocks';
|
||||
|
||||
jest.mock('@signozhq/ui/toast', () => ({
|
||||
...jest.requireActual('@signozhq/ui/toast'),
|
||||
toast: {
|
||||
success: jest.fn(),
|
||||
danger: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
const FIRST_ID = mockGoogleAuthDomain.id ?? '';
|
||||
const FIRST_ROW = `auth-domain-row-${mockGoogleAuthDomain.name}`;
|
||||
|
||||
function useListHandler(): { calls: () => number } {
|
||||
let calls = 0;
|
||||
server.use(
|
||||
rest.get(AUTH_DOMAINS_LIST_ENDPOINT, (_, res, ctx) => {
|
||||
calls += 1;
|
||||
return res(ctx.status(200), ctx.json(mockDomainsListResponse));
|
||||
}),
|
||||
);
|
||||
return { calls: (): number => calls };
|
||||
}
|
||||
|
||||
async function openDeleteModal(rowIndex = 0): Promise<void> {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
await screen.findByTestId(FIRST_ROW);
|
||||
await user.click(screen.getAllByTestId('auth-domain-delete')[rowIndex]);
|
||||
await screen.findByTestId('auth-domain-delete-confirm');
|
||||
}
|
||||
|
||||
async function confirmAfterCheck(): Promise<HTMLElement> {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('auth-domain-delete-confirm')).not.toHaveAttribute(
|
||||
'aria-busy',
|
||||
),
|
||||
);
|
||||
return screen.getByTestId('auth-domain-delete-confirm');
|
||||
}
|
||||
|
||||
describe('AuthDomain — authz', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
describe('list', () => {
|
||||
it('renders the domains when list is granted', async () => {
|
||||
server.use(setupAuthzAdmin());
|
||||
useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
|
||||
await expect(screen.findByTestId(FIRST_ROW)).resolves.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText(/is not authorized to perform/i),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the permission-denied UI and sends no list request when list is denied', async () => {
|
||||
server.use(setupAuthzDeny(AuthDomainListPermission));
|
||||
const list = useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
|
||||
await expect(
|
||||
screen.findByText(/is not authorized to perform/i),
|
||||
).resolves.toBeInTheDocument();
|
||||
expect(screen.queryByTestId(FIRST_ROW)).not.toBeInTheDocument();
|
||||
expect(list.calls()).toBe(0);
|
||||
});
|
||||
|
||||
it('keeps Add Domain and Configure enabled without create or update grants', async () => {
|
||||
server.use(setupAuthzAllow(AuthDomainListPermission));
|
||||
useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
|
||||
await screen.findByTestId(FIRST_ROW);
|
||||
|
||||
expect(screen.getByTestId('auth-domain-add')).not.toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
);
|
||||
expect(
|
||||
screen.getAllByTestId('auth-domain-configure')[0],
|
||||
).not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
});
|
||||
|
||||
describe('delete', () => {
|
||||
it('deletes the domain and refetches the list when delete is granted', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
let deletedId: string | readonly string[] | undefined;
|
||||
server.use(
|
||||
setupAuthzAdmin(),
|
||||
rest.delete(AUTH_DOMAINS_DELETE_ENDPOINT, (req, res, ctx) => {
|
||||
deletedId = req.params.id;
|
||||
return res(ctx.status(200), ctx.json(mockDeleteSuccessResponse));
|
||||
}),
|
||||
);
|
||||
const list = useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
await openDeleteModal();
|
||||
|
||||
const confirm = await confirmAfterCheck();
|
||||
expect(confirm).not.toHaveAttribute('aria-disabled', 'true');
|
||||
await user.click(confirm);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(toast.success).toHaveBeenCalledWith('Domain deleted successfully'),
|
||||
);
|
||||
expect(deletedId).toBe(mockGoogleAuthDomain.id);
|
||||
await waitFor(() => expect(list.calls()).toBeGreaterThan(1));
|
||||
});
|
||||
|
||||
it('disables confirm with the denied permission when delete is denied on that domain', async () => {
|
||||
server.use(setupAuthzDeny(buildAuthDomainDeletePermission(FIRST_ID)));
|
||||
useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
await openDeleteModal();
|
||||
|
||||
const confirm = await confirmAfterCheck();
|
||||
expect(confirm).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(confirm).toHaveAttribute(
|
||||
'data-denied-permissions',
|
||||
expect.stringContaining(FIRST_ID),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps confirm enabled on a domain whose delete is granted', async () => {
|
||||
server.use(setupAuthzDeny(buildAuthDomainDeletePermission(FIRST_ID)));
|
||||
useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
await openDeleteModal(1);
|
||||
|
||||
const confirm = await confirmAfterCheck();
|
||||
expect(confirm).not.toHaveAttribute('data-denied-permissions');
|
||||
expect(confirm).not.toHaveAttribute('aria-disabled', 'true');
|
||||
});
|
||||
|
||||
it('shows the error modal and keeps the domain when the delete is rejected', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
server.use(
|
||||
setupAuthzAdmin(),
|
||||
rest.delete(AUTH_DOMAINS_DELETE_ENDPOINT, (_, res, ctx) =>
|
||||
res(
|
||||
ctx.status(403),
|
||||
ctx.json({
|
||||
error: {
|
||||
code: 'authz_forbidden',
|
||||
message: 'not allowed to delete this domain',
|
||||
url: '',
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
useListHandler();
|
||||
|
||||
render(<AuthDomain />);
|
||||
await openDeleteModal();
|
||||
|
||||
const confirm = await confirmAfterCheck();
|
||||
expect(confirm).not.toHaveAttribute('aria-disabled', 'true');
|
||||
await user.click(confirm);
|
||||
|
||||
expect(
|
||||
(await screen.findAllByText(/not allowed to delete this domain/i)).length,
|
||||
).toBeGreaterThan(0);
|
||||
expect(toast.success).not.toHaveBeenCalled();
|
||||
expect(screen.getByTestId(FIRST_ROW)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { setupAuthzAdmin } from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
@@ -20,6 +21,7 @@ jest.mock('@signozhq/ui/toast', () => ({
|
||||
describe('AuthDomain', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
server.use(setupAuthzAdmin());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
import CreateEdit from '../CreateEdit/CreateEdit';
|
||||
import {
|
||||
AUTH_DOMAINS_CREATE_ENDPOINT,
|
||||
AUTH_DOMAINS_UPDATE_ENDPOINT,
|
||||
mockGoogleAuthDomain,
|
||||
} from './mocks';
|
||||
|
||||
// The real @signozhq/ui/button keeps form.validateFields() from resolving inside
|
||||
// act(); see CreateEdit.payload.test.tsx for the same workaround.
|
||||
jest.mock('@signozhq/ui/button', () => ({
|
||||
...jest.requireActual('@signozhq/ui/button'),
|
||||
Button: ({
|
||||
children,
|
||||
onClick,
|
||||
loading,
|
||||
disabled,
|
||||
testId,
|
||||
}: {
|
||||
children?: React.ReactNode;
|
||||
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
loading?: boolean;
|
||||
disabled?: boolean;
|
||||
testId?: string;
|
||||
}) => (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
disabled={disabled || loading}
|
||||
data-testid={testId}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
const FORBIDDEN_RESPONSE = {
|
||||
error: {
|
||||
code: 'authz_forbidden',
|
||||
message: 'not allowed to save this domain',
|
||||
url: '',
|
||||
},
|
||||
};
|
||||
|
||||
describe('CreateEdit — authz', () => {
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
it('shows the error modal and keeps the filled form when create is rejected', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
const onClose = jest.fn();
|
||||
server.use(
|
||||
rest.post(AUTH_DOMAINS_CREATE_ENDPOINT, (_, res, ctx) =>
|
||||
res(ctx.status(403), ctx.json(FORBIDDEN_RESPONSE)),
|
||||
),
|
||||
);
|
||||
|
||||
render(<CreateEdit isCreate onClose={onClose} />);
|
||||
|
||||
await user.click(
|
||||
await screen.findByTestId('authn-provider-configure-google'),
|
||||
);
|
||||
await user.type(await screen.findByLabelText(/^domain/i), 'acme.io');
|
||||
await user.type(screen.getByLabelText(/client id/i), 'client-id');
|
||||
await user.type(screen.getByLabelText(/client secret/i), 'secret');
|
||||
await user.click(screen.getByTestId('auth-domain-save'));
|
||||
|
||||
expect(
|
||||
(
|
||||
await screen.findAllByText(/not allowed to save this domain/i, undefined, {
|
||||
timeout: 5000,
|
||||
})
|
||||
).length,
|
||||
).toBeGreaterThan(0);
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
expect(screen.getByLabelText(/^domain/i)).toHaveValue('acme.io');
|
||||
expect(screen.getByLabelText(/client id/i)).toHaveValue('client-id');
|
||||
});
|
||||
|
||||
it('shows the error modal and keeps the form when update is rejected', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
const onClose = jest.fn();
|
||||
let updateCalls = 0;
|
||||
server.use(
|
||||
rest.put(AUTH_DOMAINS_UPDATE_ENDPOINT, (_, res, ctx) => {
|
||||
updateCalls += 1;
|
||||
return res(ctx.status(403), ctx.json(FORBIDDEN_RESPONSE));
|
||||
}),
|
||||
);
|
||||
|
||||
render(
|
||||
<CreateEdit
|
||||
isCreate={false}
|
||||
record={mockGoogleAuthDomain}
|
||||
onClose={onClose}
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.click(await screen.findByTestId('auth-domain-save'));
|
||||
|
||||
await waitFor(() => expect(updateCalls).toBe(1));
|
||||
expect(
|
||||
(
|
||||
await screen.findAllByText(/not allowed to save this domain/i, undefined, {
|
||||
timeout: 5000,
|
||||
})
|
||||
).length,
|
||||
).toBeGreaterThan(0);
|
||||
expect(onClose).not.toHaveBeenCalled();
|
||||
expect(screen.getByLabelText(/client id/i)).toHaveValue('test-client-id');
|
||||
});
|
||||
});
|
||||
@@ -156,6 +156,44 @@ describe('SSOEnforcementToggle', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('reverts the switch and shows the error modal when the update is forbidden', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
|
||||
server.use(
|
||||
rest.put(AUTH_DOMAINS_UPDATE_ENDPOINT, (_, res, ctx) =>
|
||||
res(
|
||||
ctx.status(403),
|
||||
ctx.json({
|
||||
error: {
|
||||
code: 'authz_forbidden',
|
||||
message: 'not allowed to update this domain',
|
||||
url: '',
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
render(
|
||||
<SSOEnforcementToggle
|
||||
isDefaultChecked={true}
|
||||
record={mockGoogleAuthDomain}
|
||||
/>,
|
||||
);
|
||||
|
||||
const switchElement = screen.getByRole('switch');
|
||||
await user.click(switchElement);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByText(/not allowed to update this domain/i),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('switch')).toHaveAttribute('aria-checked', 'true'),
|
||||
);
|
||||
});
|
||||
|
||||
it('does not call API when record has no id', async () => {
|
||||
const user = userEvent.setup();
|
||||
let apiCalled = false;
|
||||
|
||||
@@ -24,6 +24,13 @@ import SSOEnforcementToggle from './SSOEnforcementToggle';
|
||||
|
||||
import './AuthDomain.styles.scss';
|
||||
import '../../IngestionSettings/IngestionSettings.styles.scss';
|
||||
import { useAuthZ } from '@/lib/authz/hooks/useAuthZ/useAuthZ';
|
||||
import {
|
||||
AuthDomainListPermission,
|
||||
buildAuthDomainDeletePermission,
|
||||
} from '@/lib/authz/hooks/useAuthZ/permissions/auth-domain.permissions';
|
||||
import { AuthZGuardContent } from '@/lib/authz/components/AuthZGuard/AuthZGuardContent';
|
||||
import AuthZButton from '@/lib/authz/components/AuthZButton/AuthZButton';
|
||||
|
||||
export const SSOType = new Map<string, string>([
|
||||
['google', 'Google Auth'],
|
||||
@@ -41,13 +48,18 @@ function AuthDomain(): JSX.Element {
|
||||
|
||||
const { showErrorModal } = useErrorModal();
|
||||
|
||||
const { permissions: authzPermissions } = useAuthZ([AuthDomainListPermission]);
|
||||
|
||||
const canListAuthDomains =
|
||||
authzPermissions?.[AuthDomainListPermission]?.isGranted ?? false;
|
||||
|
||||
const {
|
||||
data: authDomainListResponse,
|
||||
isLoading: isLoadingAuthDomainListResponse,
|
||||
isFetching: isFetchingAuthDomainListResponse,
|
||||
error: errorFetchingAuthDomainListResponse,
|
||||
refetch: refetchAuthDomainListResponse,
|
||||
} = useListAuthDomains();
|
||||
} = useListAuthDomains({ query: { enabled: canListAuthDomains } });
|
||||
|
||||
const { mutate: deleteAuthDomain, isLoading } =
|
||||
useDeleteAuthDomain<AxiosError<RenderErrorResponseDTO>>();
|
||||
@@ -198,25 +210,29 @@ function AuthDomain(): JSX.Element {
|
||||
</Button>
|
||||
</section>
|
||||
{formattedError && <ErrorContent error={formattedError} />}
|
||||
{!errorFetchingAuthDomainListResponse && (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={authDomainListResponse?.data}
|
||||
onRow={(
|
||||
record: AuthtypesGettableAuthDomainDTO,
|
||||
): HTMLAttributes<HTMLElement> =>
|
||||
// data-* attributes are valid row props but absent from the antd typing
|
||||
({
|
||||
'data-testid': `auth-domain-row-${record.name}`,
|
||||
}) as unknown as HTMLAttributes<HTMLElement>
|
||||
}
|
||||
loading={
|
||||
isLoadingAuthDomainListResponse || isFetchingAuthDomainListResponse
|
||||
}
|
||||
className="auth-domain-list"
|
||||
rowKey="id"
|
||||
/>
|
||||
)}
|
||||
<AuthZGuardContent checks={[AuthDomainListPermission]}>
|
||||
{!errorFetchingAuthDomainListResponse ? (
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={authDomainListResponse?.data}
|
||||
onRow={(
|
||||
record: AuthtypesGettableAuthDomainDTO,
|
||||
): HTMLAttributes<HTMLElement> =>
|
||||
// data-* attributes are valid row props but absent from the antd typing
|
||||
({
|
||||
'data-testid': `auth-domain-row-${record.name}`,
|
||||
}) as unknown as HTMLAttributes<HTMLElement>
|
||||
}
|
||||
loading={
|
||||
isLoadingAuthDomainListResponse || isFetchingAuthDomainListResponse
|
||||
}
|
||||
className="auth-domain-list"
|
||||
rowKey="id"
|
||||
/>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</AuthZGuardContent>
|
||||
{(addDomain || record) && (
|
||||
<CreateEdit
|
||||
isCreate={!record}
|
||||
@@ -224,7 +240,9 @@ function AuthDomain(): JSX.Element {
|
||||
onClose={(): void => {
|
||||
setAddDomain(false);
|
||||
setRecord(undefined);
|
||||
refetchAuthDomainListResponse();
|
||||
if (canListAuthDomains) {
|
||||
void refetchAuthDomainListResponse();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -248,7 +266,7 @@ function AuthDomain(): JSX.Element {
|
||||
>
|
||||
Cancel
|
||||
</Button>,
|
||||
<Button
|
||||
<AuthZButton
|
||||
size="md"
|
||||
variant="solid"
|
||||
color="danger"
|
||||
@@ -257,9 +275,14 @@ function AuthDomain(): JSX.Element {
|
||||
onClick={handleDeleteDomain}
|
||||
loading={isLoading}
|
||||
testId="auth-domain-delete-confirm"
|
||||
checks={
|
||||
isDeleteModalOpen && activeDomain?.id
|
||||
? [buildAuthDomainDeletePermission(activeDomain.id)]
|
||||
: []
|
||||
}
|
||||
>
|
||||
Delete Domain
|
||||
</Button>,
|
||||
</AuthZButton>,
|
||||
]}
|
||||
>
|
||||
<p className="delete-text">
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
.org-input-disabled-tooltip-class {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.field-error {
|
||||
color: var(--destructive);
|
||||
margin-top: var(--spacing-2);
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
import {
|
||||
buildOrganizationReadPermission,
|
||||
buildOrganizationUpdatePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/organization.permissions';
|
||||
import {
|
||||
setupAuthzAdmin,
|
||||
setupAuthzDeny,
|
||||
} from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, waitFor } from 'tests/test-utils';
|
||||
|
||||
import DisplayName from '../index';
|
||||
|
||||
const ORG_ID = 'does-not-matter-id';
|
||||
const ORG_ME_ENDPOINT = '*/api/v2/orgs/me';
|
||||
|
||||
function renderWithoutSavedName(): void {
|
||||
render(<DisplayName index={0} id={ORG_ID} />, undefined, {
|
||||
appContextOverrides: {
|
||||
org: [{ createdAt: 0, id: ORG_ID, displayName: '' }],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function useOrgFetchHandler(): { calls: () => number } {
|
||||
let calls = 0;
|
||||
server.use(
|
||||
rest.get(ORG_ME_ENDPOINT, (_, res, ctx) => {
|
||||
calls += 1;
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
status: 'success',
|
||||
data: { id: ORG_ID, displayName: 'Fetched Org' },
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
return { calls: (): number => calls };
|
||||
}
|
||||
|
||||
describe('DisplayName — authz', () => {
|
||||
afterEach(() => {
|
||||
server.resetHandlers();
|
||||
});
|
||||
|
||||
it('disables the input and submit with the denied permission when update is denied', async () => {
|
||||
server.use(setupAuthzDeny(buildOrganizationUpdatePermission(ORG_ID)));
|
||||
|
||||
render(<DisplayName index={0} id={ORG_ID} />);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('org-display-name-submit')).not.toHaveAttribute(
|
||||
'aria-busy',
|
||||
),
|
||||
);
|
||||
const submit = screen.getByTestId('org-display-name-submit');
|
||||
expect(submit).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(submit).toHaveAttribute(
|
||||
'data-denied-permissions',
|
||||
expect.stringContaining('update'),
|
||||
);
|
||||
expect(screen.getByTestId('org-display-name-input-field')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('shows the denial instead of the form and skips the fetch when read is denied', async () => {
|
||||
server.use(setupAuthzDeny(buildOrganizationReadPermission(ORG_ID)));
|
||||
const fetch = useOrgFetchHandler();
|
||||
|
||||
renderWithoutSavedName();
|
||||
|
||||
await expect(
|
||||
screen.findByText(/is not authorized/i),
|
||||
).resolves.toBeInTheDocument();
|
||||
expect(screen.getByText(/read:organization/i)).toBeInTheDocument();
|
||||
expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByTestId('org-display-name-submit'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(fetch.calls()).toBe(0);
|
||||
});
|
||||
|
||||
it('fetches the organization when read is granted', async () => {
|
||||
const fetch = useOrgFetchHandler();
|
||||
server.use(setupAuthzAdmin());
|
||||
|
||||
renderWithoutSavedName();
|
||||
|
||||
await waitFor(() => expect(fetch.calls()).toBe(1));
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { setupAuthzAdmin } from 'lib/authz/utils/authz-test-utils';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import {
|
||||
fireEvent,
|
||||
@@ -25,6 +26,7 @@ const defaultProps = { index: 0, id: 'does-not-matter-id' };
|
||||
describe('DisplayName', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
server.use(setupAuthzAdmin());
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -34,10 +36,15 @@ describe('DisplayName', () => {
|
||||
it('renders form pre-filled with org displayName from context', async () => {
|
||||
render(<DisplayName {...defaultProps} />);
|
||||
|
||||
const input = await screen.findByRole('textbox');
|
||||
const input = await screen.findByTestId('org-display-name-input-field');
|
||||
expect(input).toHaveValue('Pentagon');
|
||||
|
||||
expect(screen.getByRole('button', { name: /submit/i })).toBeDisabled();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('org-display-name-submit')).toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('enables submit and calls PUT when display name is changed', async () => {
|
||||
@@ -47,12 +54,15 @@ describe('DisplayName', () => {
|
||||
|
||||
render(<DisplayName {...defaultProps} />);
|
||||
|
||||
const input = await screen.findByRole('textbox');
|
||||
const input = await screen.findByTestId('org-display-name-input-field');
|
||||
await waitFor(() => expect(input).toBeEnabled());
|
||||
await user.clear(input);
|
||||
await user.type(input, 'New Org Name');
|
||||
|
||||
const submitBtn = screen.getByRole('button', { name: /submit/i });
|
||||
expect(submitBtn).toBeEnabled();
|
||||
const submitBtn = screen.getByTestId('org-display-name-submit');
|
||||
await waitFor(() =>
|
||||
expect(submitBtn).not.toHaveAttribute('aria-disabled', 'true'),
|
||||
);
|
||||
|
||||
await user.click(submitBtn);
|
||||
|
||||
@@ -66,7 +76,8 @@ describe('DisplayName', () => {
|
||||
|
||||
render(<DisplayName {...defaultProps} />);
|
||||
|
||||
const input = await screen.findByRole('textbox');
|
||||
const input = await screen.findByTestId('org-display-name-input-field');
|
||||
await waitFor(() => expect(input).toBeEnabled());
|
||||
await user.clear(input);
|
||||
|
||||
fireEvent.submit(screen.getByTestId('org-display-name-form'));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { useEffect } from 'react';
|
||||
import { Controller, useForm } from 'react-hook-form';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Input } from '@signozhq/ui/input';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Button, Input } from 'antd';
|
||||
import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs';
|
||||
import {
|
||||
useGetMyOrganization,
|
||||
@@ -10,25 +10,42 @@ import {
|
||||
} from 'api/generated/services/orgs';
|
||||
import type { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { AxiosError } from 'axios';
|
||||
import AuthZButton from 'lib/authz/components/AuthZButton/AuthZButton';
|
||||
import AuthZTooltip from 'lib/authz/components/AuthZTooltip/AuthZTooltip';
|
||||
import {
|
||||
buildOrganizationReadPermission,
|
||||
buildOrganizationUpdatePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/organization.permissions';
|
||||
import { useAuthZ } from 'lib/authz/hooks/useAuthZ/useAuthZ';
|
||||
import { useAppContext } from 'providers/App/App';
|
||||
import { IUser } from 'providers/App/types';
|
||||
import { useErrorModal } from 'providers/ErrorModalProvider';
|
||||
import APIError from 'types/api/error';
|
||||
import { USER_ROLES } from 'types/roles';
|
||||
import { requireErrorMessage } from 'utils/form/requireErrorMessage';
|
||||
|
||||
import { getSubmitBlockedReason } from './utils';
|
||||
|
||||
import './DisplayName.styles.scss';
|
||||
import { AuthZGuardContent } from '@/lib/authz/components/AuthZGuard/AuthZGuardContent';
|
||||
|
||||
function DisplayName({ index, id: orgId }: DisplayNameProps): JSX.Element {
|
||||
const { t } = useTranslation(['organizationsettings', 'common']);
|
||||
const { showErrorModal } = useErrorModal();
|
||||
const { org, updateOrg, user } = useAppContext();
|
||||
const { org, updateOrg } = useAppContext();
|
||||
const currentOrg = (org || [])[index];
|
||||
const isAdmin = user.role === USER_ROLES.ADMIN;
|
||||
const readPermission = buildOrganizationReadPermission(orgId);
|
||||
const updatePermission = buildOrganizationUpdatePermission(orgId);
|
||||
const { permissions: authzPermissions } = useAuthZ([
|
||||
readPermission,
|
||||
updatePermission,
|
||||
]);
|
||||
|
||||
const canReadOrg = authzPermissions?.[readPermission]?.isGranted ?? false;
|
||||
const canUpdateOrg = authzPermissions?.[updatePermission]?.isGranted ?? false;
|
||||
|
||||
const { data: orgData } = useGetMyOrganization({
|
||||
query: {
|
||||
enabled: isAdmin && !currentOrg?.displayName,
|
||||
enabled: canReadOrg && !currentOrg?.displayName,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -76,7 +93,11 @@ function DisplayName({ index, id: orgId }: DisplayNameProps): JSX.Element {
|
||||
return <div />;
|
||||
}
|
||||
|
||||
const isDisabled = isLoading || orgName === displayName || !orgName;
|
||||
const submitBlockedReason = getSubmitBlockedReason({
|
||||
canUpdate: canUpdateOrg,
|
||||
name: orgName,
|
||||
savedName: displayName,
|
||||
});
|
||||
|
||||
return (
|
||||
<form
|
||||
@@ -87,38 +108,50 @@ function DisplayName({ index, id: orgId }: DisplayNameProps): JSX.Element {
|
||||
>
|
||||
<div className="form-field">
|
||||
<label htmlFor="displayName">Display name</label>
|
||||
<Controller
|
||||
name="displayName"
|
||||
control={control}
|
||||
rules={{ required: requireErrorMessage('Display name') }}
|
||||
render={({ field, fieldState }): JSX.Element => (
|
||||
<>
|
||||
<Input
|
||||
{...field}
|
||||
id="displayName"
|
||||
data-testid="org-display-name-input"
|
||||
size="large"
|
||||
placeholder={t('signoz')}
|
||||
status={fieldState.error ? 'error' : ''}
|
||||
/>
|
||||
{fieldState.error && (
|
||||
<div className="field-error">{fieldState.error.message}</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
loading={isLoading}
|
||||
disabled={isDisabled}
|
||||
type="primary"
|
||||
htmlType="submit"
|
||||
data-testid="org-display-name-submit"
|
||||
>
|
||||
Submit
|
||||
</Button>
|
||||
<AuthZGuardContent checks={[readPermission]}>
|
||||
<Controller
|
||||
name="displayName"
|
||||
control={control}
|
||||
rules={{ required: requireErrorMessage('Display name') }}
|
||||
render={({ field, fieldState }): JSX.Element => (
|
||||
<>
|
||||
<AuthZTooltip
|
||||
triggerClassName="org-input-disabled-tooltip-class"
|
||||
checks={[updatePermission]}
|
||||
>
|
||||
<Input
|
||||
{...field}
|
||||
id="displayName"
|
||||
testId="org-display-name-input"
|
||||
size="lg"
|
||||
placeholder={t('signoz')}
|
||||
status={fieldState.error ? 'danger' : undefined}
|
||||
/>
|
||||
</AuthZTooltip>
|
||||
{fieldState.error && (
|
||||
<div className="field-error">{fieldState.error.message}</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
</AuthZGuardContent>
|
||||
</div>
|
||||
{canReadOrg && (
|
||||
<div>
|
||||
<AuthZButton
|
||||
size="md"
|
||||
variant="solid"
|
||||
color="primary"
|
||||
type="submit"
|
||||
loading={isLoading}
|
||||
disabledTooltip={submitBlockedReason}
|
||||
testId="org-display-name-submit"
|
||||
checks={[updatePermission]}
|
||||
>
|
||||
Submit
|
||||
</AuthZButton>
|
||||
</div>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
interface SubmitBlockedReasonArgs {
|
||||
canUpdate: boolean;
|
||||
name: string;
|
||||
savedName: string;
|
||||
}
|
||||
|
||||
// A permission denial is left to AuthZButton, which names the missing scope.
|
||||
export function getSubmitBlockedReason({
|
||||
canUpdate,
|
||||
name,
|
||||
savedName,
|
||||
}: SubmitBlockedReasonArgs): string | undefined {
|
||||
if (!canUpdate) {
|
||||
return undefined;
|
||||
}
|
||||
if (name === savedName) {
|
||||
return 'No change detected';
|
||||
}
|
||||
if (!name) {
|
||||
return "Can't be empty";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -108,6 +108,8 @@
|
||||
.left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
gap: 8px;
|
||||
|
||||
.value {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useMemo } from 'react';
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Tooltip } from 'antd';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import cx from 'classnames';
|
||||
import { isEmpty, isObject } from 'lodash-es';
|
||||
@@ -46,28 +45,73 @@ function Suggestions(props: ISuggestionsProps): React.ReactElement {
|
||||
return (
|
||||
<div className="option">
|
||||
{!isEmpty(optionType) && isObject(value) ? (
|
||||
<Tooltip title={value.key} placement="topLeft">
|
||||
<div className="container">
|
||||
<section className="left-section">
|
||||
{value.isIndexed ? (
|
||||
<Zap size={12} fill={Color.BG_AMBER_500} />
|
||||
) : (
|
||||
<div className="dot" />
|
||||
)}
|
||||
<div className="value">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="container">
|
||||
<section className="left-section">
|
||||
{value.isIndexed ? (
|
||||
<Zap size={12} fill={Color.BG_AMBER_500} />
|
||||
) : (
|
||||
<div className="dot" />
|
||||
)}
|
||||
<div className="value">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{label}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right-section">
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{value.dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
<section className={cx('type-tag', value.type)}>
|
||||
<div className="dot" />
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="small"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="span"
|
||||
textOverflow="visible"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{value.type}
|
||||
</Typography>
|
||||
</section>
|
||||
<section className="right-section">
|
||||
</section>
|
||||
</div>
|
||||
) : (
|
||||
<div className="container-without-tag">
|
||||
<section className="left">
|
||||
<div className="dot" />
|
||||
<div className={cx('value', option)}>
|
||||
<Typography
|
||||
{...labelTextStyle}
|
||||
size="base"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{`${label}`}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right">
|
||||
{dataType && (
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
@@ -77,62 +121,13 @@ function Suggestions(props: ISuggestionsProps): React.ReactElement {
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{value.dataType}
|
||||
{dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
<section className={cx('type-tag', value.type)}>
|
||||
<div className="dot" />
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="small"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="span"
|
||||
textOverflow="visible"
|
||||
textTransform="capitalize"
|
||||
>
|
||||
{value.type}
|
||||
</Typography>
|
||||
</section>
|
||||
</section>
|
||||
</div>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Tooltip title={label} placement="topLeft">
|
||||
<div className="container-without-tag">
|
||||
<section className="left">
|
||||
<div className="dot" />
|
||||
<div className={cx('value', option)}>
|
||||
<Typography
|
||||
{...labelTextStyle}
|
||||
size="base"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="ellipsis"
|
||||
>
|
||||
{`${label}`}
|
||||
</Typography>
|
||||
</div>
|
||||
</section>
|
||||
<section className="right">
|
||||
{dataType && (
|
||||
<div className="data-type">
|
||||
<Typography
|
||||
variant="paragraph"
|
||||
size="base"
|
||||
weight="regular"
|
||||
color="inherit"
|
||||
as="p"
|
||||
textOverflow="visible"
|
||||
>
|
||||
{dataType}
|
||||
</Typography>
|
||||
</div>
|
||||
)}
|
||||
{tagValue.includes(label) && <Check size={14} />}
|
||||
</section>
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
{tagValue.includes(label) && <Check size={14} />}
|
||||
</section>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
getResourcePanel,
|
||||
getResourceVerbs,
|
||||
RESOURCE_ORDER,
|
||||
} from '../permissions.config';
|
||||
|
||||
describe('ingestion permissions in the roles editor', () => {
|
||||
it('lists both entities', () => {
|
||||
expect(RESOURCE_ORDER).toContain('ingestion-key');
|
||||
expect(RESOURCE_ORDER).toContain('ingestion-limit');
|
||||
expect(getResourcePanel('ingestion-key').label).toBe('Ingestion Keys');
|
||||
expect(getResourcePanel('ingestion-limit').label).toBe('Ingestion Limits');
|
||||
});
|
||||
|
||||
it('offers every metaresource verb for ingestion-key', () => {
|
||||
expect([...getResourceVerbs('ingestion-key')].sort()).toStrictEqual([
|
||||
'attach',
|
||||
'create',
|
||||
'delete',
|
||||
'detach',
|
||||
'list',
|
||||
'read',
|
||||
'update',
|
||||
]);
|
||||
});
|
||||
|
||||
it('offers no attach or detach for ingestion-limit', () => {
|
||||
expect([...getResourceVerbs('ingestion-limit')].sort()).toStrictEqual([
|
||||
'create',
|
||||
'delete',
|
||||
'list',
|
||||
'read',
|
||||
'update',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -329,15 +329,19 @@ describe('transformTransactionGroupsToResourcePermissions', () => {
|
||||
it('returns all resources from RESOURCE_ORDER even with empty transaction groups', () => {
|
||||
const result = transformTransactionGroupsToResourcePermissions([]);
|
||||
|
||||
expect(result).toHaveLength(15);
|
||||
expect(result).toHaveLength(19);
|
||||
expect(result.map((r) => r.resourceKind)).toStrictEqual([
|
||||
'factor-api-key',
|
||||
'auth-domain',
|
||||
'dashboard',
|
||||
'ingestion-key',
|
||||
'ingestion-limit',
|
||||
'license',
|
||||
'logs',
|
||||
'meter-metrics',
|
||||
'metrics',
|
||||
'notification-channel',
|
||||
'organization',
|
||||
'factor-password',
|
||||
'quick-filter',
|
||||
'role',
|
||||
@@ -426,15 +430,19 @@ describe('createEmptyRolePermissions', () => {
|
||||
it('creates permissions for all resources in RESOURCE_ORDER', () => {
|
||||
const result = createEmptyRolePermissions();
|
||||
|
||||
expect(result).toHaveLength(15);
|
||||
expect(result).toHaveLength(19);
|
||||
expect(result.map((r) => r.resourceKind)).toStrictEqual([
|
||||
'factor-api-key',
|
||||
'auth-domain',
|
||||
'dashboard',
|
||||
'ingestion-key',
|
||||
'ingestion-limit',
|
||||
'license',
|
||||
'logs',
|
||||
'meter-metrics',
|
||||
'metrics',
|
||||
'notification-channel',
|
||||
'organization',
|
||||
'factor-password',
|
||||
'quick-filter',
|
||||
'role',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
Bot,
|
||||
Building,
|
||||
Cable,
|
||||
ChartLine,
|
||||
DraftingCompass,
|
||||
@@ -8,6 +9,7 @@ import {
|
||||
Grid3X3,
|
||||
Key,
|
||||
ListFilter,
|
||||
LogIn,
|
||||
Logs,
|
||||
Receipt,
|
||||
Shield,
|
||||
@@ -165,6 +167,37 @@ export const RESOURCE_PANELS: Record<AuthZResource, ResourcePanelConfig> = {
|
||||
'Type password ID, separate multiple with comma or space',
|
||||
docsAnchor: 'factor-password',
|
||||
},
|
||||
'ingestion-key': {
|
||||
label: 'Ingestion Keys',
|
||||
description: 'Keys used to send telemetry to the workspace.',
|
||||
icon: Key,
|
||||
selectorPlaceholder:
|
||||
'Type ingestion key ID, separate multiple with comma or space',
|
||||
docsAnchor: 'ingestion-key',
|
||||
},
|
||||
'ingestion-limit': {
|
||||
label: 'Ingestion Limits',
|
||||
description: 'Daily and per-second limits set on ingestion keys.',
|
||||
icon: Gauge,
|
||||
selectorPlaceholder:
|
||||
'Type ingestion limit ID, separate multiple with comma or space',
|
||||
docsAnchor: 'ingestion-limit',
|
||||
},
|
||||
'auth-domain': {
|
||||
label: 'Auth Domains',
|
||||
description: 'SSO domains and the roles they grant at sign-in.',
|
||||
icon: LogIn,
|
||||
selectorPlaceholder:
|
||||
'Type auth domain ID, separate multiple with comma or space',
|
||||
docsAnchor: 'auth-domain',
|
||||
},
|
||||
organization: {
|
||||
label: 'Organization',
|
||||
description: 'The workspace organization and its display name.',
|
||||
icon: Building,
|
||||
selectorPlaceholder: 'Type * to cover the workspace organization',
|
||||
docsAnchor: 'organization',
|
||||
},
|
||||
};
|
||||
|
||||
export const RESOURCE_ORDER = (
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useCallback } from 'react';
|
||||
import MultiSelectFilter from 'components/ListFilter/FilterZone/MultiSelectFilter';
|
||||
|
||||
import { SERVICE_ACCOUNTS_STATUS_OPTIONS } from './list.config';
|
||||
@@ -10,15 +11,34 @@ interface Props {
|
||||
setDraft: (newDraft: string) => void;
|
||||
}
|
||||
|
||||
// Picks splice into the draft and run when the dropdown closes; Clear runs at
|
||||
// once. A status term the box holds with another operator shows as nothing
|
||||
// picked.
|
||||
// Picks splice into the draft and run when the dropdown closes; a tag's × or
|
||||
// Clear runs at once. A status term the box holds with another operator shows
|
||||
// as nothing picked.
|
||||
function ServiceAccountStatusFilter({
|
||||
draft,
|
||||
disabled,
|
||||
onApplyDraft,
|
||||
setDraft,
|
||||
}: Props): JSX.Element {
|
||||
const handleChange = useCallback(
|
||||
(statuses: string[]): void => setDraft(withStatuses(draft, statuses)),
|
||||
[draft, setDraft],
|
||||
);
|
||||
|
||||
const handleCommit = useCallback(
|
||||
(statuses: string[]): void => onApplyDraft(withStatuses(draft, statuses)),
|
||||
[draft, onApplyDraft],
|
||||
);
|
||||
|
||||
const handleDropdownVisibleChange = useCallback(
|
||||
(isOpen: boolean): void => {
|
||||
if (!isOpen) {
|
||||
onApplyDraft(draft);
|
||||
}
|
||||
},
|
||||
[draft, onApplyDraft],
|
||||
);
|
||||
|
||||
return (
|
||||
<MultiSelectFilter
|
||||
value={statusesOfQuery(draft)}
|
||||
@@ -26,13 +46,9 @@ function ServiceAccountStatusFilter({
|
||||
placeholder="Status"
|
||||
testId="sa-filter-status"
|
||||
disabled={disabled}
|
||||
onChange={(statuses): void => setDraft(withStatuses(draft, statuses))}
|
||||
onClear={(): void => onApplyDraft(withStatuses(draft, []))}
|
||||
onDropdownVisibleChange={(open): void => {
|
||||
if (!open) {
|
||||
onApplyDraft(draft);
|
||||
}
|
||||
}}
|
||||
onChange={handleChange}
|
||||
onCommit={handleCommit}
|
||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import { GlobalShortcuts } from 'constants/shortcuts/globalShortcuts';
|
||||
import { USER_PREFERENCES } from 'constants/userPreferences';
|
||||
import { useAIAssistantStore } from 'container/AIAssistant/store/useAIAssistantStore';
|
||||
import { useKeyboardHotkeys } from 'hooks/hotkeys/useKeyboardHotkeys';
|
||||
import useComponentPermission from 'hooks/useComponentPermission';
|
||||
import { useGetTenantLicense } from 'hooks/useGetTenantLicense';
|
||||
import { useIsAIAssistantEnabled } from 'hooks/useIsAIAssistantEnabled';
|
||||
import { useNotifications } from 'hooks/useNotifications';
|
||||
@@ -615,14 +614,7 @@ function SideNav({ isPinned }: { isPinned: boolean }): JSX.Element {
|
||||
changelog,
|
||||
]);
|
||||
|
||||
const [isCurrentOrgSettings] = useComponentPermission(
|
||||
['current_org_settings'],
|
||||
user.role,
|
||||
);
|
||||
|
||||
const settingsRoute = isCurrentOrgSettings
|
||||
? ROUTES.ORG_SETTINGS
|
||||
: ROUTES.SETTINGS;
|
||||
const settingsRoute = ROUTES.ORG_SETTINGS;
|
||||
|
||||
const handleMenuItemClick = (event: MouseEvent, item: SidebarItem): void => {
|
||||
if (item.key === ROUTES.SETTINGS) {
|
||||
|
||||
@@ -48,7 +48,6 @@ import {
|
||||
SettingsNavSection,
|
||||
SidebarItem,
|
||||
} from './sideNav.types';
|
||||
import { Style } from '@signozhq/design-tokens';
|
||||
import Noz from 'components/Noz/Noz';
|
||||
import { NOZ_TOOLTIP_TITLE } from 'components/Noz/Noz.constants';
|
||||
|
||||
@@ -523,7 +522,7 @@ export const getUserSettingsDropdownMenuItems = ({
|
||||
type: 'item',
|
||||
value: 'workspace',
|
||||
label: USER_SETTINGS_MENU_LABELS.workspace,
|
||||
prefix: <Building2 size={14} color={Style.L1_FOREGROUND} />,
|
||||
prefix: <Building2 size={14} color="var(--l1-foreground)" />,
|
||||
testId: 'workspace-settings-nav-item',
|
||||
disabled: isWorkspaceBlocked,
|
||||
disabledTooltip: WORKSPACE_LOCKED_TOOLTIP,
|
||||
@@ -533,7 +532,7 @@ export const getUserSettingsDropdownMenuItems = ({
|
||||
type: 'item',
|
||||
value: 'account',
|
||||
label: USER_SETTINGS_MENU_LABELS.account,
|
||||
prefix: <User size={14} color={Style.L1_FOREGROUND} />,
|
||||
prefix: <User size={14} color="var(--l1-foreground)" />,
|
||||
testId: 'account-settings-nav-item',
|
||||
onClick: (event): void => onSelect('account', event),
|
||||
},
|
||||
@@ -544,7 +543,7 @@ export const getUserSettingsDropdownMenuItems = ({
|
||||
type: 'item',
|
||||
value: 'license',
|
||||
label: USER_SETTINGS_MENU_LABELS.license,
|
||||
prefix: <Shield size={14} color={Style.L1_FOREGROUND} />,
|
||||
prefix: <Shield size={14} color="var(--l1-foreground)" />,
|
||||
testId: 'manage-license-nav-item',
|
||||
onClick: (event): void => onSelect('license', event),
|
||||
});
|
||||
@@ -554,7 +553,7 @@ export const getUserSettingsDropdownMenuItems = ({
|
||||
type: 'item',
|
||||
value: 'keyboard-shortcuts',
|
||||
label: USER_SETTINGS_MENU_LABELS['keyboard-shortcuts'],
|
||||
prefix: <Keyboard size={14} color={Style.L1_FOREGROUND} />,
|
||||
prefix: <Keyboard size={14} color="var(--l1-foreground)" />,
|
||||
testId: 'keyboard-shortcuts-nav-item',
|
||||
onClick: (event): void => onSelect('keyboard-shortcuts', event),
|
||||
});
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { CloudAccount } from 'container/Integrations/CloudIntegration/AmazonWebServices/types';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
import { CloudAccount } from 'container/Integrations/types';
|
||||
|
||||
@@ -7,8 +7,7 @@ import {
|
||||
useState,
|
||||
} from 'react';
|
||||
import { toast } from '@signozhq/ui/toast';
|
||||
import { Form } from 'antd';
|
||||
import { FormInstance } from 'antd/lib';
|
||||
import { Form, FormInstance } from 'antd';
|
||||
import { useUpdateAccount } from 'api/generated/services/cloudintegration';
|
||||
import { INTEGRATION_TYPES } from 'container/Integrations/constants';
|
||||
import { CloudAccount } from 'container/Integrations/types';
|
||||
|
||||
@@ -5,7 +5,6 @@ import useComponentPermission from './useComponentPermission';
|
||||
|
||||
describe('useComponentPermission', () => {
|
||||
const componentList: ComponentTypes[] = [
|
||||
'current_org_settings',
|
||||
'create_new_dashboards',
|
||||
'import_dashboard',
|
||||
'export_dashboard',
|
||||
@@ -27,7 +26,6 @@ describe('useComponentPermission', () => {
|
||||
useComponentPermission(componentList, 'ADMIN'),
|
||||
);
|
||||
const expectedResult = [
|
||||
true, // current_org_settings
|
||||
true, // create_new_dashboards
|
||||
true, // import_dashboard
|
||||
true, // export_dashboard
|
||||
@@ -51,7 +49,6 @@ describe('useComponentPermission', () => {
|
||||
useComponentPermission(componentList, 'EDITOR'),
|
||||
);
|
||||
const expectedResult = [
|
||||
false, // current_org_settings
|
||||
true, // create_new_dashboards
|
||||
true, // import_dashboard
|
||||
true, // export_dashboard
|
||||
@@ -75,7 +72,6 @@ describe('useComponentPermission', () => {
|
||||
useComponentPermission(componentList, 'VIEWER'),
|
||||
);
|
||||
const expectedResult = [
|
||||
false, // current_org_settings
|
||||
false, // create_new_dashboards
|
||||
false, // import_dashboard
|
||||
true, // export_dashboard
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { CircleSlash2 } from '@signozhq/icons';
|
||||
|
||||
import styles from './PermissionDeniedFullPage.module.scss';
|
||||
import { Style } from '@signozhq/design-tokens';
|
||||
import { useAppContext } from 'providers/App/App';
|
||||
import { BrandedPermission } from 'lib/authz/hooks/useAuthZ/types';
|
||||
import { formatPermission } from 'lib/authz/hooks/useAuthZ/utils';
|
||||
@@ -31,7 +30,7 @@ function PermissionDeniedFullPage({
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
<span className={styles.icon}>
|
||||
<CircleSlash2 color={Style.CALLOUT_ERROR_TITLE} size={14} />
|
||||
<CircleSlash2 color="var(--callout-error-title)" size={14} />
|
||||
</span>
|
||||
<p className={styles.title}>Uh-oh! You are not authorized</p>
|
||||
<p className={styles.subtitle}>
|
||||
|
||||
@@ -3,6 +3,19 @@ export default {
|
||||
status: 'success',
|
||||
data: {
|
||||
resources: [
|
||||
{
|
||||
kind: 'auth-domain',
|
||||
type: 'metaresource',
|
||||
allowedVerbs: [
|
||||
'attach',
|
||||
'create',
|
||||
'delete',
|
||||
'detach',
|
||||
'list',
|
||||
'read',
|
||||
'update',
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'dashboard',
|
||||
type: 'metaresource',
|
||||
@@ -18,6 +31,24 @@ export default {
|
||||
type: 'metaresource',
|
||||
allowedVerbs: ['create', 'list', 'read'],
|
||||
},
|
||||
{
|
||||
kind: 'ingestion-key',
|
||||
type: 'metaresource',
|
||||
allowedVerbs: [
|
||||
'attach',
|
||||
'create',
|
||||
'delete',
|
||||
'detach',
|
||||
'list',
|
||||
'read',
|
||||
'update',
|
||||
],
|
||||
},
|
||||
{
|
||||
kind: 'ingestion-limit',
|
||||
type: 'metaresource',
|
||||
allowedVerbs: ['create', 'delete', 'list', 'read', 'update'],
|
||||
},
|
||||
{
|
||||
kind: 'license',
|
||||
type: 'metaresource',
|
||||
@@ -51,6 +82,11 @@ export default {
|
||||
type: 'metaresource',
|
||||
allowedVerbs: ['create', 'delete', 'list', 'read', 'update'],
|
||||
},
|
||||
{
|
||||
kind: 'organization',
|
||||
type: 'organization',
|
||||
allowedVerbs: ['read', 'update'],
|
||||
},
|
||||
{
|
||||
kind: 'role',
|
||||
type: 'role',
|
||||
@@ -121,12 +157,13 @@ export default {
|
||||
list: ['metaresource', 'role', 'serviceaccount', 'user'],
|
||||
read: [
|
||||
'metaresource',
|
||||
'organization',
|
||||
'role',
|
||||
'serviceaccount',
|
||||
'telemetryresource',
|
||||
'user',
|
||||
],
|
||||
update: ['metaresource', 'role', 'serviceaccount', 'user'],
|
||||
update: ['metaresource', 'organization', 'role', 'serviceaccount', 'user'],
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { BrandedPermission } from '../types';
|
||||
import { buildPermission } from '../utils';
|
||||
|
||||
export const AuthDomainListPermission = buildPermission(
|
||||
'list',
|
||||
'auth-domain:*',
|
||||
);
|
||||
|
||||
export const buildAuthDomainDeletePermission = (
|
||||
id: string,
|
||||
): BrandedPermission => buildPermission('delete', `auth-domain:${id}`);
|
||||
@@ -0,0 +1,35 @@
|
||||
import { formatPermission } from '../utils';
|
||||
import {
|
||||
AuthDomainListPermission,
|
||||
buildAuthDomainDeletePermission,
|
||||
} from './auth-domain.permissions';
|
||||
import {
|
||||
buildOrganizationReadPermission,
|
||||
buildOrganizationUpdatePermission,
|
||||
} from './organization.permissions';
|
||||
|
||||
describe('auth domain permissions', () => {
|
||||
it('checks list on the collection wildcard', () => {
|
||||
expect(formatPermission(AuthDomainListPermission)).toBe('list:auth-domain:*');
|
||||
});
|
||||
|
||||
it('checks delete on the given domain id', () => {
|
||||
expect(formatPermission(buildAuthDomainDeletePermission('domain-1'))).toBe(
|
||||
'delete:auth-domain:domain-1',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('organization permissions', () => {
|
||||
it('checks read on the given org id', () => {
|
||||
expect(formatPermission(buildOrganizationReadPermission('org-1'))).toBe(
|
||||
'read:organization:org-1',
|
||||
);
|
||||
});
|
||||
|
||||
it('checks update on the given org id', () => {
|
||||
expect(formatPermission(buildOrganizationUpdatePermission('org-1'))).toBe(
|
||||
'update:organization:org-1',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { BrandedPermission } from '../types';
|
||||
import { buildPermission } from '../utils';
|
||||
|
||||
export const IngestionKeyListPermission = buildPermission(
|
||||
'list',
|
||||
'ingestion-key:*',
|
||||
);
|
||||
|
||||
export const IngestionKeyCreatePermission = buildPermission(
|
||||
'create',
|
||||
'ingestion-key:*',
|
||||
);
|
||||
|
||||
export const buildIngestionKeyUpdatePermission = (
|
||||
keyId: string,
|
||||
): BrandedPermission => buildPermission('update', `ingestion-key:${keyId}`);
|
||||
|
||||
export const buildIngestionKeyDeletePermission = (
|
||||
keyId: string,
|
||||
): BrandedPermission => buildPermission('delete', `ingestion-key:${keyId}`);
|
||||
|
||||
export const buildIngestionKeyAttachPermission = (
|
||||
keyId: string,
|
||||
): BrandedPermission => buildPermission('attach', `ingestion-key:${keyId}`);
|
||||
|
||||
export const buildIngestionKeyDetachPermission = (
|
||||
keyId: string,
|
||||
): BrandedPermission => buildPermission('detach', `ingestion-key:${keyId}`);
|
||||
|
||||
export const IngestionLimitCreatePermission = buildPermission(
|
||||
'create',
|
||||
'ingestion-limit:*',
|
||||
);
|
||||
export const buildIngestionLimitUpdatePermission = (
|
||||
id: string,
|
||||
): BrandedPermission => buildPermission('update', `ingestion-limit:${id}`);
|
||||
|
||||
export const buildIngestionLimitDeletePermission = (
|
||||
id: string,
|
||||
): BrandedPermission => buildPermission('delete', `ingestion-limit:${id}`);
|
||||
@@ -0,0 +1,10 @@
|
||||
import { BrandedPermission } from '../types';
|
||||
import { buildPermission } from '../utils';
|
||||
|
||||
export const buildOrganizationReadPermission = (
|
||||
id: string,
|
||||
): BrandedPermission => buildPermission('read', `organization:${id}`);
|
||||
|
||||
export const buildOrganizationUpdatePermission = (
|
||||
id: string,
|
||||
): BrandedPermission => buildPermission('update', `organization:${id}`);
|
||||
@@ -12,6 +12,7 @@ import { getFiltersFromKeyValue } from '../CeleryOverviewUtils';
|
||||
import OverviewRightPanelGraph from './OverviewRightPanelGraph';
|
||||
import ValueInfo from './ValueInfo';
|
||||
|
||||
import 'components/CeleryTask/CeleryTaskDetail/CeleryTaskDetail.style.scss';
|
||||
import './CeleryOverviewDetails.styles.scss';
|
||||
|
||||
export default function CeleryOverviewDetails({
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
//
|
||||
// Icons are the always-present set (shown in the picker), so we let Vite inline the
|
||||
// small ones as data URIs — they ship in the bundle and render with no network
|
||||
// call. Logos are a large, JSON-only catalogue, so `?url` keeps them as emitted
|
||||
// files fetched (and cached) on demand rather than bloating the bundle.
|
||||
// call. Logos are a large, JSON-only catalogue, so `?no-inline` keeps them as
|
||||
// emitted files fetched (and cached) on demand rather than bloating the bundle
|
||||
// (`?url` alone still inlines files under `build.assetsInlineLimit`).
|
||||
const iconModules = import.meta.glob('../../../assets/Icons/**/*.{svg,png}', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
@@ -14,7 +15,7 @@ const iconModules = import.meta.glob('../../../assets/Icons/**/*.{svg,png}', {
|
||||
|
||||
const logoModules = import.meta.glob('../../../assets/Logos/**/*.{svg,png}', {
|
||||
eager: true,
|
||||
query: '?url',
|
||||
query: '?no-inline',
|
||||
import: 'default',
|
||||
});
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
import {
|
||||
currentDashboardDocument,
|
||||
cyclicVariablesDashboardResponse,
|
||||
DASHBOARD_IMAGES,
|
||||
DURATION_CHOICES,
|
||||
patchDashboardDocument,
|
||||
PANEL_IDS,
|
||||
@@ -43,6 +44,7 @@ import {
|
||||
STORY_DASHBOARD_ID,
|
||||
VARIABLE_KINDS,
|
||||
type DashboardArgs,
|
||||
type DashboardImage,
|
||||
type DurationChoice,
|
||||
type PanelId,
|
||||
type VariableKind,
|
||||
@@ -168,6 +170,13 @@ export const dashboardMocks = defineStoryMocks({
|
||||
options: DURATION_CHOICES,
|
||||
value: 'unset',
|
||||
}),
|
||||
image: choiceControl<DashboardImage>('Image', {
|
||||
group: LAYOUT,
|
||||
description:
|
||||
"The dashboard's `image`, shown beside its name in the header and in the settings icon picker: a bundled icon or a logo, which dashboard JSON can reference but the picker does not offer.",
|
||||
options: DASHBOARD_IMAGES,
|
||||
value: '/assets/Icons/circus-tent',
|
||||
}),
|
||||
variableValues: countControl('Variable options', {
|
||||
group: DATA,
|
||||
description: 'Values the query-backed `service` variable resolves to.',
|
||||
@@ -244,6 +253,7 @@ export const dashboardMocks = defineStoryMocks({
|
||||
variables: values.variables,
|
||||
locked: values.locked,
|
||||
duration: values.duration,
|
||||
image: values.image,
|
||||
};
|
||||
|
||||
return [
|
||||
@@ -384,6 +394,7 @@ export const dashboardMocks = defineStoryMocks({
|
||||
variables: values.variables,
|
||||
locked: values.locked,
|
||||
duration: values.duration,
|
||||
image: values.image,
|
||||
});
|
||||
// The sync mode persists per dashboard, so one story's pick would open the
|
||||
// next one on it.
|
||||
|
||||
@@ -120,6 +120,11 @@ export const DefaultTimeRange: Story = {
|
||||
args: { duration: '6h' },
|
||||
};
|
||||
|
||||
/** A dashboard whose image is a bundled logo, beside its name in the header. */
|
||||
export const Logo: Story = {
|
||||
args: { image: '/assets/Logos/kubernetes' },
|
||||
};
|
||||
|
||||
/** The panels mid-fetch, with the header, variable bar and grid already laid out. */
|
||||
export const Loading: Story = {
|
||||
args: { dataState: 'loading' },
|
||||
|
||||
@@ -360,6 +360,16 @@ export const DURATION_CHOICES = ['unset', '6h', '90m', '1s', '0m'] as const;
|
||||
|
||||
export type DurationChoice = (typeof DURATION_CHOICES)[number];
|
||||
|
||||
/** The default icon, then logos either side of the 4 KB asset inline limit, one a PNG. */
|
||||
export const DASHBOARD_IMAGES = [
|
||||
'/assets/Icons/circus-tent',
|
||||
'/assets/Logos/kubernetes',
|
||||
'/assets/Logos/nginx',
|
||||
'/assets/Logos/rails',
|
||||
] as const;
|
||||
|
||||
export type DashboardImage = (typeof DASHBOARD_IMAGES)[number];
|
||||
|
||||
export interface PanelQueryShape {
|
||||
requestType: string;
|
||||
metricName?: string;
|
||||
@@ -393,6 +403,7 @@ export interface DashboardArgs {
|
||||
variables: readonly VariableKind[];
|
||||
locked: boolean;
|
||||
duration?: DurationChoice;
|
||||
image?: DashboardImage;
|
||||
}
|
||||
|
||||
export const dashboardResponse = ({
|
||||
@@ -401,6 +412,7 @@ export const dashboardResponse = ({
|
||||
variables,
|
||||
locked,
|
||||
duration,
|
||||
image = '/assets/Icons/circus-tent',
|
||||
}: DashboardArgs): GetDashboardV2200 => {
|
||||
const kept = PANEL_IDS.slice(0, panels);
|
||||
|
||||
@@ -420,7 +432,7 @@ export const dashboardResponse = ({
|
||||
id: STORY_DASHBOARD_ID,
|
||||
orgId: 'storybook-org',
|
||||
name: 'Checkout service overview',
|
||||
image: '/assets/Icons/circus-tent',
|
||||
image,
|
||||
schemaVersion: 'v6',
|
||||
source: DashboardtypesSourceDTO.user,
|
||||
locked,
|
||||
|
||||
@@ -52,6 +52,15 @@ export const Overview: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* A dashboard whose image is a logo: the picker keeps it as the selected first
|
||||
* option, ahead of the icons it offers.
|
||||
*/
|
||||
export const OverviewLogo: Story = {
|
||||
...Overview,
|
||||
args: { image: '/assets/Logos/rails' },
|
||||
};
|
||||
|
||||
/** Two fields edited, so the footer counts them and offers to save or discard. */
|
||||
export const OverviewUnsavedChanges: Story = {
|
||||
play: async ({ canvasElement }) => {
|
||||
|
||||
@@ -317,6 +317,7 @@ function DashboardsList(): JSX.Element {
|
||||
onDelete={handleRemoveView}
|
||||
onRename={renameView}
|
||||
testIdPrefix="dashboards"
|
||||
viewNamePlaceholder="e.g. Prod dashboards"
|
||||
deleteDescription="This removes the saved view. Your dashboards are not affected."
|
||||
guard={guardViewsRail}
|
||||
onViewSaved={logViewSaved}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DashboardtypesListSortDTO,
|
||||
type GetDashboardV2200,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import { parseReflectedClauses } from 'components/ListFilter/dsl/filterQuery';
|
||||
import ROUTES from 'constants/routes';
|
||||
import {
|
||||
buildDashboardDeletePermission,
|
||||
@@ -53,6 +54,7 @@ import {
|
||||
dashboardsListResponse,
|
||||
PIN_WRITES,
|
||||
recentDashboardIds,
|
||||
ROW_IMAGES,
|
||||
ROW_MARKERS,
|
||||
savedView,
|
||||
seedPinnedDashboards,
|
||||
@@ -61,6 +63,7 @@ import {
|
||||
TOOLTIP_TAGS,
|
||||
WRITE_STATES,
|
||||
type PinWrite,
|
||||
type RowImages,
|
||||
type RowMarker,
|
||||
type TemplateRequest,
|
||||
type WriteState,
|
||||
@@ -256,6 +259,13 @@ export const dashboardsListMocks = defineStoryMocks({
|
||||
options: ROW_MARKERS,
|
||||
value: [...ROW_MARKERS],
|
||||
}),
|
||||
images: choiceControl<RowImages>('Row images', {
|
||||
group: LIST,
|
||||
description:
|
||||
'What each row shows beside its name: a bundled icon, or a bundled logo, which dashboard JSON can reference but the icon picker does not offer.',
|
||||
options: ROW_IMAGES,
|
||||
value: 'icons',
|
||||
}),
|
||||
columns: multiChoiceControl<DetailColumn>('Detail columns', {
|
||||
group: LIST,
|
||||
description: 'The optional fields on each row’s second line.',
|
||||
@@ -353,6 +363,7 @@ export const dashboardsListMocks = defineStoryMocks({
|
||||
limit: Number(req.url.searchParams.get('limit') ?? 20),
|
||||
markers: values.markers,
|
||||
query: req.url.searchParams.get('query') ?? '',
|
||||
images: values.images,
|
||||
}),
|
||||
),
|
||||
),
|
||||
@@ -592,6 +603,7 @@ export const listedDashboards = (
|
||||
new URL(listRoute(args.view), 'http://localhost').searchParams.get(
|
||||
'query',
|
||||
) ?? '',
|
||||
images: args.images,
|
||||
}).data.dashboards;
|
||||
|
||||
return view?.clientFilter
|
||||
@@ -602,6 +614,13 @@ export const listedDashboards = (
|
||||
: rows;
|
||||
};
|
||||
|
||||
/** The view's own filter picks creators, so the Created-by chip opens with a tag. */
|
||||
export const showsCreatedByTag = (args: DashboardsListArgs): boolean =>
|
||||
parseReflectedClauses(
|
||||
new URL(listRoute(args.view), 'http://localhost').searchParams.get('query') ??
|
||||
'',
|
||||
).createdBy.length > 0;
|
||||
|
||||
export const showsWorkspaceEmpty = (args: DashboardsListArgs): boolean =>
|
||||
args.view === DEFAULT_DASHBOARD_VIEW &&
|
||||
args.dataState === 'loaded' &&
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
openTemplateTab,
|
||||
pinDashboard,
|
||||
renameDashboard,
|
||||
removeCreatedByTag,
|
||||
renameView,
|
||||
saveView,
|
||||
submitTemplateRequest,
|
||||
@@ -85,6 +86,11 @@ export const Viewer: Story = {
|
||||
args: { access: 'viewer' },
|
||||
};
|
||||
|
||||
/** Rows whose images are bundled logos rather than icons. */
|
||||
export const Logos: Story = {
|
||||
args: { images: 'logos' },
|
||||
};
|
||||
|
||||
/** The rows the user pinned, which the page filters out of the fetched page. */
|
||||
export const Pinned: Story = {
|
||||
args: { view: 'pinned' },
|
||||
@@ -100,6 +106,12 @@ export const CreatedByFilterOpen: Story = {
|
||||
play: openCreatedByFilter,
|
||||
};
|
||||
|
||||
/** My dashboards with its creator tag removed by its ×: the list runs unfiltered. */
|
||||
export const CreatedByTagRemoved: Story = {
|
||||
args: { view: 'mine' },
|
||||
play: removeCreatedByTag,
|
||||
};
|
||||
|
||||
/** The template tab of the New dashboard dialog. */
|
||||
export const NewDashboardTemplateTab: Story = {
|
||||
play: openTemplateTab,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, screen, userEvent, within } from 'storybook/test';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { isCloudShell } from '@/storybook/globals/appShellMocks';
|
||||
import { findMonacoEditor } from '@/storybook/play/monacoEditor';
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
pickRowAction,
|
||||
requestTemplate,
|
||||
retryMigration,
|
||||
showsCreatedByTag,
|
||||
showsWorkspaceEmpty,
|
||||
TOAST_TIMEOUT,
|
||||
uploadDashboardJson,
|
||||
@@ -81,6 +82,38 @@ export const openCreatedByFilter = async ({
|
||||
await screen.findAllByRole('checkbox', { checked: true });
|
||||
};
|
||||
|
||||
// antd renders a tag's × aria-hidden.
|
||||
const tagRemove = { name: 'close', hidden: true } as const;
|
||||
|
||||
export const removeCreatedByTag = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (
|
||||
!canList(args) ||
|
||||
args.dataState !== 'loaded' ||
|
||||
showsWorkspaceEmpty(args) ||
|
||||
!showsCreatedByTag(args)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const filter = await within(canvasElement).findByTestId(
|
||||
'dashboards-filter-created-by',
|
||||
{},
|
||||
{ timeout: TOAST_TIMEOUT },
|
||||
);
|
||||
|
||||
await userEvent.click(
|
||||
await within(filter).findByRole('img', tagRemove, {
|
||||
timeout: TOAST_TIMEOUT,
|
||||
}),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(within(filter).queryByRole('img', tagRemove)).not.toBeInTheDocument(),
|
||||
);
|
||||
};
|
||||
|
||||
export const openTemplateTab = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
|
||||
@@ -28,6 +28,7 @@ const tag = (key: string, value: string): TagtypesGettableTagDTO => ({
|
||||
interface DashboardSeed {
|
||||
name: string;
|
||||
icon: string;
|
||||
logo: string;
|
||||
tags: TagtypesGettableTagDTO[];
|
||||
locked?: boolean;
|
||||
}
|
||||
@@ -36,67 +37,84 @@ const SEEDS: DashboardSeed[] = [
|
||||
{
|
||||
name: 'Kubernetes cluster health',
|
||||
icon: 'circus-tent',
|
||||
logo: 'kubernetes',
|
||||
tags: [tag('env', 'prod'), tag('team', 'platform')],
|
||||
locked: true,
|
||||
},
|
||||
{
|
||||
name: 'API latency and errors',
|
||||
icon: 'siren',
|
||||
logo: 'api-gateway',
|
||||
tags: [tag('env', 'prod'), tag('team', 'api')],
|
||||
},
|
||||
{
|
||||
name: 'Checkout funnel',
|
||||
icon: 'bagel',
|
||||
logo: 'rails',
|
||||
tags: [tag('team', 'growth')],
|
||||
},
|
||||
{
|
||||
name: 'Postgres connections',
|
||||
icon: 'cheese',
|
||||
logo: 'postgresql',
|
||||
tags: [tag('env', 'prod'), tag('component', 'database')],
|
||||
},
|
||||
{
|
||||
name: 'Kafka consumer lag',
|
||||
icon: 'drum',
|
||||
logo: 'kafka',
|
||||
tags: [tag('team', 'platform'), tag('component', 'kafka')],
|
||||
},
|
||||
{
|
||||
name: 'Nginx ingress overview',
|
||||
icon: 'crane',
|
||||
logo: 'nginx',
|
||||
tags: [tag('env', 'staging')],
|
||||
},
|
||||
{
|
||||
name: 'Billing jobs',
|
||||
icon: 'dartboard',
|
||||
logo: 'celery',
|
||||
tags: [tag('team', 'billing')],
|
||||
locked: true,
|
||||
},
|
||||
{
|
||||
name: 'Frontend web vitals',
|
||||
icon: 'basketball',
|
||||
logo: 'reactjs',
|
||||
tags: [tag('team', 'frontend')],
|
||||
},
|
||||
{
|
||||
name: 'Redis cache hit ratio',
|
||||
icon: 'cookie',
|
||||
logo: 'redis',
|
||||
tags: [tag('component', 'redis')],
|
||||
},
|
||||
{
|
||||
name: 'Collector pipeline throughput',
|
||||
icon: 'motorcycle',
|
||||
logo: 'opentelemetry',
|
||||
tags: [tag('env', 'prod'), tag('component', 'otel')],
|
||||
},
|
||||
{
|
||||
name: 'On-call triage board',
|
||||
icon: 'police-car',
|
||||
logo: 'prometheus',
|
||||
tags: [tag('team', 'sre')],
|
||||
},
|
||||
{
|
||||
name: 'Cost per service',
|
||||
icon: 'orange',
|
||||
logo: 'cloudwatch',
|
||||
tags: [tag('team', 'finops')],
|
||||
},
|
||||
];
|
||||
|
||||
/** Whether rows show a bundled icon or a bundled logo. */
|
||||
export const ROW_IMAGES = ['icons', 'logos'] as const;
|
||||
|
||||
export type RowImages = (typeof ROW_IMAGES)[number];
|
||||
|
||||
/** Row markers a story can put on the list, each landing on a slice of the rows. */
|
||||
export const ROW_MARKERS = ['pinned', 'locked', 'legacy'] as const;
|
||||
|
||||
@@ -141,6 +159,7 @@ interface ListArgs {
|
||||
limit: number;
|
||||
markers: readonly RowMarker[];
|
||||
query: string;
|
||||
images?: RowImages;
|
||||
}
|
||||
|
||||
const seedAt = (index: number): DashboardSeed => SEEDS[index % SEEDS.length];
|
||||
@@ -155,6 +174,7 @@ const nameAt = (index: number): string => {
|
||||
const dashboardAt = (
|
||||
index: number,
|
||||
markers: readonly RowMarker[],
|
||||
images: RowImages,
|
||||
): DashboardtypesListedDashboardForUserV2DTO => {
|
||||
const seed = seedAt(index);
|
||||
const name = nameAt(index);
|
||||
@@ -165,7 +185,10 @@ const dashboardAt = (
|
||||
orgId: 'storybook-org',
|
||||
name,
|
||||
spec: { display: { name } },
|
||||
image: `/assets/Icons/${seed.icon}`,
|
||||
image:
|
||||
images === 'logos'
|
||||
? `/assets/Logos/${seed.logo}`
|
||||
: `/assets/Icons/${seed.icon}`,
|
||||
schemaVersion: 'v2',
|
||||
source: DashboardtypesSourceDTO.user,
|
||||
pinned: pinned.has(dashboardIdAt(index)),
|
||||
@@ -236,9 +259,10 @@ export const dashboardsListResponse = ({
|
||||
limit,
|
||||
markers,
|
||||
query,
|
||||
images = 'icons',
|
||||
}: ListArgs): ListDashboardsForUserV2200 => {
|
||||
const all = Array.from({ length: count }, (_, index) =>
|
||||
dashboardAt(index, markers),
|
||||
dashboardAt(index, markers, images),
|
||||
);
|
||||
const matched = query ? all.filter((d) => matchesQuery(d, query)) : all;
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { screen, userEvent, within } from 'storybook/test';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
import { homeMocks } from './HomePage.stories.mocks';
|
||||
import { openCommandPalette } from './__story_mockdata__/home.play';
|
||||
import {
|
||||
openCommandPalette,
|
||||
openNavHelpMenu,
|
||||
openNavSettingsMenu,
|
||||
} from './__story_mockdata__/home.play';
|
||||
|
||||
import HomePage from '../HomePage';
|
||||
|
||||
@@ -70,16 +73,7 @@ export const Loading: Story = {
|
||||
* this menu is the same on every page; Home is where it is shot.
|
||||
*/
|
||||
export const NavHelpMenu: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(
|
||||
'help-support-nav-item',
|
||||
{},
|
||||
{ timeout: 10000 },
|
||||
),
|
||||
);
|
||||
await screen.findByRole('menu');
|
||||
},
|
||||
play: openNavHelpMenu,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -87,16 +81,16 @@ export const NavHelpMenu: Story = {
|
||||
* reaches without leaving the page.
|
||||
*/
|
||||
export const NavSettingsMenu: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(
|
||||
'settings-nav-item',
|
||||
{},
|
||||
{ timeout: 10000 },
|
||||
),
|
||||
);
|
||||
await screen.findByRole('menu');
|
||||
},
|
||||
play: openNavSettingsMenu,
|
||||
};
|
||||
|
||||
/**
|
||||
* The sidebar's Settings menu on a self-hosted enterprise license, which adds
|
||||
* Manage License between the account and shortcut entries.
|
||||
*/
|
||||
export const NavSettingsMenuSelfHosted: Story = {
|
||||
args: { license: 'enterprise' },
|
||||
play: openNavSettingsMenu,
|
||||
};
|
||||
|
||||
/** The command palette, opened with the same shortcut the shell listens for. */
|
||||
|
||||
@@ -3,14 +3,37 @@
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { screen, userEvent } from 'storybook/test';
|
||||
import { screen, userEvent, within } from 'storybook/test';
|
||||
|
||||
import { type HomeArgs, paletteListsHome } from '../HomePage.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: HomeArgs;
|
||||
}
|
||||
|
||||
const openNavMenu = async (
|
||||
canvasElement: HTMLElement,
|
||||
testId: string,
|
||||
): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(testId, {}, { timeout: 10000 }),
|
||||
);
|
||||
await screen.findByRole('menu');
|
||||
};
|
||||
|
||||
export const openNavHelpMenu = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await openNavMenu(canvasElement, 'help-support-nav-item');
|
||||
};
|
||||
|
||||
export const openNavSettingsMenu = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await openNavMenu(canvasElement, 'settings-nav-item');
|
||||
};
|
||||
|
||||
export const openCommandPalette = async ({
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
|
||||
@@ -23,7 +23,10 @@ import {
|
||||
updateTaggedAccount,
|
||||
} from './CloudIntegration.stories.mocks';
|
||||
import {
|
||||
openAccountSelect,
|
||||
openAccountSettings,
|
||||
openConnectDialog,
|
||||
openDisconnectConfirm,
|
||||
openGcpRegionDropdown,
|
||||
} from './__story_mockdata__/cloudIntegration.play';
|
||||
|
||||
@@ -86,6 +89,17 @@ export const GoogleCloudPlatform: Story = {
|
||||
args: { provider: 'gcp' },
|
||||
};
|
||||
|
||||
/** The page while the account list is loading, the account picker a skeleton. */
|
||||
export const Loading: Story = {
|
||||
args: { dataState: 'loading' },
|
||||
};
|
||||
|
||||
/** The account picker open over two connected accounts. */
|
||||
export const AccountSelectOpen: Story = {
|
||||
args: { accounts: 2 },
|
||||
play: openAccountSelect,
|
||||
};
|
||||
|
||||
/** Every log attribute and metric a service collects, as the agent names them. */
|
||||
export const DataCollected: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
@@ -129,16 +143,27 @@ export const AzureConnectAccount: Story = {
|
||||
|
||||
/** The regions an already-connected account collects from. */
|
||||
export const EditAccount: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(
|
||||
/edit account/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByRole('dialog', undefined, untilLoaded);
|
||||
},
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/** The resource groups an already-connected Azure subscription collects from. */
|
||||
export const AzureEditAccount: Story = {
|
||||
args: { provider: 'azure' },
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/** The projects an already-connected GCP account collects from. */
|
||||
export const GcpEditAccount: Story = {
|
||||
args: { provider: 'gcp' },
|
||||
play: openAccountSettings,
|
||||
};
|
||||
|
||||
/**
|
||||
* Disconnecting an account, which asks first and names what is removed from the
|
||||
* cloud account and what is left to delete by hand.
|
||||
*/
|
||||
export const DisconnectConfirm: Story = {
|
||||
play: openDisconnectConfirm,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
type CloudIntegrationArgs,
|
||||
offersIntegrateNow,
|
||||
openConnectFlow,
|
||||
openEditAccount,
|
||||
untilLoaded,
|
||||
} from '../CloudIntegration.stories.mocks';
|
||||
|
||||
@@ -17,6 +18,16 @@ interface PlayContext {
|
||||
args: CloudIntegrationArgs;
|
||||
}
|
||||
|
||||
/** The hero shows the account picker and Edit Account only once accounts have answered. */
|
||||
const offersAccountActions = (args: CloudIntegrationArgs): boolean =>
|
||||
args.dataState === 'loaded' && args.accounts > 0;
|
||||
|
||||
const blurActiveElement = (): void => {
|
||||
if (document.activeElement instanceof HTMLElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
};
|
||||
|
||||
export const openConnectDialog = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
@@ -48,3 +59,49 @@ export const openGcpRegionDropdown = async ({
|
||||
);
|
||||
await screen.findByRole('listbox');
|
||||
};
|
||||
|
||||
export const openAccountSelect = async ({
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await userEvent.click(
|
||||
await screen.findByRole('combobox', { name: 'Cloud account' }, untilLoaded),
|
||||
);
|
||||
await screen.findByRole('listbox');
|
||||
};
|
||||
|
||||
export const openAccountSettings = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await openEditAccount(canvasElement);
|
||||
blurActiveElement();
|
||||
};
|
||||
|
||||
export const openDisconnectConfirm = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!offersAccountActions(args)) {
|
||||
return;
|
||||
}
|
||||
await openEditAccount(canvasElement);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
'cloud-disconnect-account-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByTestId(
|
||||
'cloud-remove-account-confirm',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
blurActiveElement();
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import { type PipelinesArgs, pipelinesMocks } from './Pipelines.stories.mocks';
|
||||
import {
|
||||
expandProcessors,
|
||||
hoverPipelineFilterSuggestions,
|
||||
openAddPipeline,
|
||||
openAddProcessor,
|
||||
openChangeHistory,
|
||||
@@ -75,6 +76,11 @@ export const AddPipelineFilterValues: Story = {
|
||||
play: suggestPipelineFilterValues,
|
||||
};
|
||||
|
||||
/** The filter's suggestions hovered: a key that fits has no tooltip, a route cut short shows in full once. */
|
||||
export const AddPipelineFilterHover: Story = {
|
||||
play: hoverPipelineFilterSuggestions,
|
||||
};
|
||||
|
||||
/** The same form over an existing pipeline, filter included. */
|
||||
export const EditPipeline: Story = {
|
||||
play: openEditPipeline,
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { screen, userEvent, within } from 'storybook/test';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { hoverTruncatableText } from '@/storybook/play/truncatedText';
|
||||
|
||||
import { LONG_HTTP_ROUTE } from '../../../stories/__story_mockdata__/logs';
|
||||
|
||||
import type { PipelinesArgs } from '../Pipelines.stories.mocks';
|
||||
|
||||
@@ -144,6 +148,42 @@ export const suggestPipelineFilterValues = async ({
|
||||
await screen.findAllByText('checkout', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
/** The pipeline list behind the form can show the same text, so look only in the open list. */
|
||||
const findSuggestion = (text: string): Promise<HTMLElement> =>
|
||||
waitFor(async () => {
|
||||
const match = Array.from(
|
||||
document.querySelectorAll<HTMLElement>(
|
||||
'.ant-select-dropdown:not(.ant-select-dropdown-hidden) .option p',
|
||||
),
|
||||
).find((element) => element.textContent === text);
|
||||
|
||||
await expect(match).toBeTruthy();
|
||||
|
||||
return match as HTMLElement;
|
||||
}, untilLoaded);
|
||||
|
||||
export const hoverPipelineFilterSuggestions = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!listsPipelines(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await openNewPipelineForm(canvasElement);
|
||||
const input = await focusPipelineFilter();
|
||||
await hoverTruncatableText(await findSuggestion('http.route'), 'http.route', {
|
||||
cut: false,
|
||||
});
|
||||
|
||||
await userEvent.type(input, 'http.route = ');
|
||||
await hoverTruncatableText(
|
||||
await findSuggestion(LONG_HTTP_ROUTE),
|
||||
LONG_HTTP_ROUTE,
|
||||
{ cut: true },
|
||||
);
|
||||
};
|
||||
|
||||
export const openEditPipeline = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
|
||||
@@ -445,6 +445,10 @@ export const logFieldKeysResponse = (
|
||||
};
|
||||
};
|
||||
|
||||
/** A route longer than the query builder's suggestion list is wide. */
|
||||
export const LONG_HTTP_ROUTE =
|
||||
'/api/v1/checkout/orders/{order_id}/payments/{payment_id}/authorisations/{authorisation_id}/retries/{retry_id}/events/{event_id}/acknowledgements/{acknowledgement_id}';
|
||||
|
||||
/** Keyed by the fields the quick filters and the query builder ask about. */
|
||||
const STRING_VALUES: Record<string, string[]> = {
|
||||
severity_text: [...LOG_SEVERITIES],
|
||||
@@ -459,7 +463,12 @@ const STRING_VALUES: Record<string, string[]> = {
|
||||
'host.name': ['ip-10-0-1-14', 'ip-10-0-2-31'],
|
||||
'os.description': ['Linux 6.8.0 x86_64', 'Darwin 23.5.0 arm64'],
|
||||
'process.owner': ['root', 'app'],
|
||||
'http.route': ['/api/v1/checkout', '/api/v1/cart', '/api/v1/auth/token'],
|
||||
'http.route': [
|
||||
'/api/v1/checkout',
|
||||
'/api/v1/cart',
|
||||
'/api/v1/auth/token',
|
||||
LONG_HTTP_ROUTE,
|
||||
],
|
||||
'body.level': LOG_SEVERITIES.map((severity) => severity.toLowerCase()),
|
||||
'body.service': SERVICES,
|
||||
'body.http.method': ['POST', 'GET', 'DELETE'],
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
import Loadable from 'components/Loadable';
|
||||
import RouteTab from 'components/RouteTab';
|
||||
import { TabRoutes } from 'components/RouteTab/types';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { useAppLocation } from 'lib/router/useAppLocation';
|
||||
import { ListMinus, Rows3 } from '@signozhq/icons';
|
||||
import CeleryOverview from 'pages/Celery/CeleryOverview/CeleryOverview';
|
||||
|
||||
import CeleryTask from '../Celery/CeleryTask/CeleryTask';
|
||||
import MessagingQueues from './MessagingQueues';
|
||||
import MQDetailPage from './MQDetailPage/MQDetailPage';
|
||||
|
||||
import './MessagingQueuesMainPage.styles.scss';
|
||||
|
||||
const MessagingQueues = Loadable(() => import('./MessagingQueues'));
|
||||
|
||||
const MQDetailPage = Loadable(() => import('./MQDetailPage/MQDetailPage'));
|
||||
|
||||
const CeleryTask = Loadable(() => import('../Celery/CeleryTask/CeleryTask'));
|
||||
|
||||
const CeleryOverview = Loadable(
|
||||
() => import('pages/Celery/CeleryOverview/CeleryOverview'),
|
||||
);
|
||||
|
||||
export const Kafka: TabRoutes = {
|
||||
Component: MessagingQueues,
|
||||
name: (
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
import Loadable from 'components/Loadable';
|
||||
import { TabRoutes } from 'components/RouteTab/types';
|
||||
import ROUTES from 'constants/routes';
|
||||
import BreakDownPage from 'container/MeterExplorer/Breakdown/BreakDown';
|
||||
import ExplorerPage from 'container/MeterExplorer/Explorer';
|
||||
import { Compass, TowerControl } from '@signozhq/icons';
|
||||
|
||||
const ExplorerPage = Loadable(() => import('container/MeterExplorer/Explorer'));
|
||||
|
||||
const BreakDownPage = Loadable(
|
||||
() => import('container/MeterExplorer/Breakdown/BreakDown'),
|
||||
);
|
||||
|
||||
export const Explorer: TabRoutes = {
|
||||
Component: (): JSX.Element => <ExplorerPage />,
|
||||
Component: ExplorerPage,
|
||||
name: (
|
||||
<div className="tab-item">
|
||||
<Compass size={16} /> Explorer
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import Loadable from 'components/Loadable';
|
||||
import { TabRoutes } from 'components/RouteTab/types';
|
||||
import ROUTES from 'constants/routes';
|
||||
import ExplorerPage from 'container/MetricsExplorer/Explorer';
|
||||
import SummaryPage from 'container/MetricsExplorer/Summary';
|
||||
import VolumeControlTab from 'container/MetricsExplorer/VolumeControl/components/VolumeControlTab/VolumeControlTab';
|
||||
import { BarChart, Compass, Gauge } from '@signozhq/icons';
|
||||
|
||||
const SummaryPage = Loadable(() => import('container/MetricsExplorer/Summary'));
|
||||
|
||||
const ExplorerPage = Loadable(
|
||||
() => import('container/MetricsExplorer/Explorer'),
|
||||
);
|
||||
|
||||
const VolumeControlTab = Loadable(
|
||||
() =>
|
||||
import('container/MetricsExplorer/VolumeControl/components/VolumeControlTab/VolumeControlTab'),
|
||||
);
|
||||
|
||||
export const Summary: TabRoutes = {
|
||||
Component: SummaryPage,
|
||||
name: (
|
||||
@@ -17,7 +26,7 @@ export const Summary: TabRoutes = {
|
||||
};
|
||||
|
||||
export const Explorer: TabRoutes = {
|
||||
Component: (): JSX.Element => <ExplorerPage />,
|
||||
Component: ExplorerPage,
|
||||
name: (
|
||||
<div className="tab-item">
|
||||
<Compass size={16} /> Explorer
|
||||
|
||||
@@ -7,7 +7,7 @@ import { FeatureKeys } from 'constants/features';
|
||||
import ROUTES from 'constants/routes';
|
||||
import dayjs from 'dayjs';
|
||||
import { rest } from 'msw';
|
||||
import { screen, userEvent, within } from 'storybook/test';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
import { defaultFeatureFlags } from 'tests/fixtures/appContextMock';
|
||||
|
||||
import {
|
||||
@@ -124,17 +124,17 @@ export const ingestionMocks = defineStoryMocks({
|
||||
),
|
||||
|
||||
rest.post(
|
||||
'http://localhost/api/v2/gateway/ingestion_keys/:keyId/limits',
|
||||
'http://localhost/api/v2/gateway/ingestion_limits',
|
||||
response.json(() => ({ status: 'success', data: { id: 'limit-new' } })),
|
||||
),
|
||||
|
||||
rest.patch(
|
||||
'http://localhost/api/v2/gateway/ingestion_keys/limits/:limitId',
|
||||
'http://localhost/api/v2/gateway/ingestion_limits/:limitId',
|
||||
response.json(() => ({ status: 'success', data: null })),
|
||||
),
|
||||
|
||||
rest.delete(
|
||||
'http://localhost/api/v2/gateway/ingestion_keys/limits/:limitId',
|
||||
'http://localhost/api/v2/gateway/ingestion_limits/:limitId',
|
||||
response.json(() => ({ status: 'success', data: null })),
|
||||
),
|
||||
|
||||
@@ -159,13 +159,13 @@ export const untilLoaded = { timeout: 15_000 };
|
||||
export async function openCreateKey(
|
||||
canvasElement: HTMLElement,
|
||||
): Promise<ReturnType<typeof within>> {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(
|
||||
'New Ingestion key',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
const add = await within(canvasElement).findByTestId(
|
||||
'ingestion-key-add-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await waitFor(() => expect(add).not.toHaveAttribute('aria-busy'), untilLoaded);
|
||||
await userEvent.click(add);
|
||||
return within(
|
||||
await screen.findByRole(
|
||||
'dialog',
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import dayjs from 'dayjs';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import { ingestionMocks } from './Ingestion.stories.mocks';
|
||||
import {
|
||||
addTag,
|
||||
ingestionMocks,
|
||||
openCreateKey,
|
||||
submitCreateKey,
|
||||
untilLoaded,
|
||||
} from './Ingestion.stories.mocks';
|
||||
addDuplicateTag,
|
||||
addLongTag,
|
||||
addTags,
|
||||
openCreateForm,
|
||||
openExpiration,
|
||||
showKeyLimits,
|
||||
submitHeldKey,
|
||||
submitInvalidKey,
|
||||
submitRejectedKey,
|
||||
typeNewTag,
|
||||
} from './__story_mockdata__/ingestion.play';
|
||||
|
||||
import SettingsPage from '../../Settings';
|
||||
|
||||
@@ -21,13 +24,14 @@ const pageStory = storyMocks(ingestionMocks, { layout: 'app' });
|
||||
|
||||
/**
|
||||
* Ingestion keys, their expiry and their per signal limits, against the gateway
|
||||
* that owns them.
|
||||
* that owns them. Every action on it is gated on an `ingestion-key` or
|
||||
* `ingestion-limit` permission, one story per permission under `Ingestion/Authz`.
|
||||
*
|
||||
* Route: `/settings/ingestion-settings`.
|
||||
*/
|
||||
const meta = {
|
||||
title: 'Pages/Settings/Ingestion',
|
||||
tags: ['play'],
|
||||
title: 'Pages/Settings/Ingestion/Overview',
|
||||
tags: ['authz', 'play'],
|
||||
component: SettingsPage,
|
||||
...pageStory,
|
||||
parameters: { ...pageStory.parameters },
|
||||
@@ -68,43 +72,22 @@ export const WithoutGateway: Story = {
|
||||
|
||||
/** A key opened up: the caps per signal, and the usage against each. */
|
||||
export const KeyLimits: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(
|
||||
/production-us-east/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByRole('button', { name: 'Edit logs limit' }, untilLoaded);
|
||||
},
|
||||
play: showKeyLimits,
|
||||
};
|
||||
|
||||
/** The form a new key is named and dated in. */
|
||||
export const CreateKey: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await openCreateKey(canvasElement);
|
||||
},
|
||||
play: openCreateForm,
|
||||
};
|
||||
|
||||
/** A tag typed on the new key and not confirmed yet. */
|
||||
export const CreateKeyAddingTag: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.click(dialog.getByRole('button', { name: /New Tag/ }));
|
||||
await userEvent.keyboard('team-payments');
|
||||
},
|
||||
play: typeNewTag,
|
||||
};
|
||||
|
||||
/** The new key with its tags confirmed, each one removable. */
|
||||
export const CreateKeyTagsAdded: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
for (const tag of ['team-payments', 'env:production']) {
|
||||
await addTag(dialog, tag);
|
||||
await dialog.findByText(tag);
|
||||
}
|
||||
},
|
||||
play: addTags,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -112,60 +95,30 @@ export const CreateKeyTagsAdded: Story = {
|
||||
* and adds nothing, with no message saying why.
|
||||
*/
|
||||
export const CreateKeyDuplicateTag: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await addTag(dialog, 'team-payments');
|
||||
await addTag(dialog, 'team-payments');
|
||||
await dialog.findByDisplayValue('team-payments');
|
||||
},
|
||||
play: addDuplicateTag,
|
||||
};
|
||||
|
||||
/** A tag longer than its pill, cut short with an ellipsis. */
|
||||
export const CreateKeyLongTag: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
const tag =
|
||||
'team-payments-platform-observability-production-us-east-1-canary-collectors';
|
||||
await addTag(dialog, tag);
|
||||
await dialog.findByText(tag);
|
||||
},
|
||||
play: addLongTag,
|
||||
};
|
||||
|
||||
/** A name with a space and no expiration, submitted: each field names its rule. */
|
||||
export const CreateKeyInvalid: Story = {
|
||||
// The page logs the rejected validation through `console.error`.
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.type(dialog.getByLabelText('Name'), 'otel collectors');
|
||||
await userEvent.click(
|
||||
dialog.getByRole('button', { name: 'Create new Ingestion key' }),
|
||||
);
|
||||
await dialog.findByText(/should only contain letters/);
|
||||
},
|
||||
play: submitInvalidKey,
|
||||
};
|
||||
|
||||
/** The expiration calendar, where today and every day before it are disabled. */
|
||||
export const CreateKeyExpirationOpen: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.click(dialog.getByLabelText('Expiration'));
|
||||
await screen.findByTitle(dayjs().format('YYYY-MM-DD'));
|
||||
},
|
||||
play: openExpiration,
|
||||
};
|
||||
|
||||
/** The new key sent, with the create still in flight. */
|
||||
export const CreateKeySubmitting: Story = {
|
||||
args: { create: 'hangs' },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await submitCreateKey(dialog);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
dialog.getByRole('button', { name: 'Create new Ingestion key' }),
|
||||
).toHaveAttribute('aria-busy', 'true'),
|
||||
);
|
||||
},
|
||||
play: submitHeldKey,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -176,13 +129,5 @@ export const CreateKeyFailed: Story = {
|
||||
args: { create: 'fails' },
|
||||
// The deliberate 409 is the state under test.
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await submitCreateKey(dialog);
|
||||
await screen.findByText(
|
||||
'An ingestion key with this name already exists.',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
},
|
||||
play: submitRejectedKey,
|
||||
};
|
||||
|
||||
216
frontend/src/pages/Settings/Ingestion/stories/__story_mockdata__/ingestion.authz.play.ts
generated
Normal file
216
frontend/src/pages/Settings/Ingestion/stories/__story_mockdata__/ingestion.authz.play.ts
generated
Normal file
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { accessFor } from '@/storybook/access/access';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import { type ingestionMocks, untilLoaded } from '../Ingestion.stories.mocks';
|
||||
import { LIMIT_SIGNALS } from './ingestion';
|
||||
|
||||
type IngestionArgs = PageStoryArgs<typeof ingestionMocks>;
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: IngestionArgs;
|
||||
}
|
||||
|
||||
const FIRST_KEY = /production-us-east/i;
|
||||
const SEARCH_PLACEHOLDER = 'Search for ingestion key...';
|
||||
|
||||
const LIST_KEY = 'list:ingestion-key';
|
||||
const CREATE_KEY = 'create:ingestion-key';
|
||||
const UPDATE_KEY = 'update:ingestion-key';
|
||||
const DELETE_KEY = 'delete:ingestion-key';
|
||||
const ATTACH_KEY = 'attach:ingestion-key';
|
||||
const DETACH_KEY = 'detach:ingestion-key';
|
||||
const CREATE_LIMIT = 'create:ingestion-limit';
|
||||
const UPDATE_LIMIT = 'update:ingestion-limit';
|
||||
const DELETE_LIMIT = 'delete:ingestion-limit';
|
||||
|
||||
const allows = (args: IngestionArgs, ...permissions: string[]): boolean => {
|
||||
const held = accessFor(
|
||||
args.access,
|
||||
args.permissions,
|
||||
args.revoked,
|
||||
).permissions;
|
||||
return permissions.every((permission) => held.has(permission));
|
||||
};
|
||||
|
||||
const isDisabled = (element: HTMLElement): boolean =>
|
||||
element.hasAttribute('disabled') ||
|
||||
element.getAttribute('aria-disabled') === 'true';
|
||||
|
||||
const expectGated = (
|
||||
element: HTMLElement,
|
||||
args: IngestionArgs,
|
||||
...permissions: string[]
|
||||
): Promise<void> =>
|
||||
waitFor(
|
||||
() => expect(isDisabled(element)).toBe(!allows(args, ...permissions)),
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
const hasRows = (args: IngestionArgs): boolean =>
|
||||
args.dataState === 'loaded' &&
|
||||
args.authzState === 'loaded' &&
|
||||
args.keys > 0 &&
|
||||
allows(args, LIST_KEY);
|
||||
|
||||
const openFirstKey = async (canvasElement: HTMLElement): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(FIRST_KEY, undefined, untilLoaded),
|
||||
);
|
||||
};
|
||||
|
||||
const openKeyModal = async (
|
||||
canvasElement: HTMLElement,
|
||||
label: 'Edit ingestion key' | 'Delete ingestion key',
|
||||
): Promise<void> => {
|
||||
const [button] = await within(canvasElement).findAllByLabelText(
|
||||
label,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await userEvent.click(button);
|
||||
};
|
||||
|
||||
export const expectListDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (args.authzState !== 'loaded') {
|
||||
return;
|
||||
}
|
||||
const search = await within(canvasElement).findByPlaceholderText(
|
||||
SEARCH_PLACEHOLDER,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(search, args, LIST_KEY);
|
||||
if (!allows(args, LIST_KEY)) {
|
||||
await within(canvasElement).findByText(
|
||||
/is not authorized/,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export const expectCreateDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (args.authzState !== 'loaded') {
|
||||
return;
|
||||
}
|
||||
const button = await within(canvasElement).findByTestId(
|
||||
'ingestion-key-add-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(button, args, CREATE_KEY);
|
||||
};
|
||||
|
||||
export const expectUpdateDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!hasRows(args)) {
|
||||
return;
|
||||
}
|
||||
await openKeyModal(canvasElement, 'Edit ingestion key');
|
||||
const button = await screen.findByTestId(
|
||||
'ingestion-key-update-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(button, args, UPDATE_KEY);
|
||||
};
|
||||
|
||||
export const expectDeleteDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!hasRows(args)) {
|
||||
return;
|
||||
}
|
||||
await openKeyModal(canvasElement, 'Delete ingestion key');
|
||||
const button = await screen.findByTestId(
|
||||
'ingestion-key-delete-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(button, args, DELETE_KEY);
|
||||
};
|
||||
|
||||
export const expectNewLimitDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const signal = LIMIT_SIGNALS.find((name) => !args.limits.includes(name));
|
||||
if (!hasRows(args) || !signal) {
|
||||
return;
|
||||
}
|
||||
await openFirstKey(canvasElement);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
`ingestion-limit-add-btn-${signal}`,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
const save = await screen.findByTestId(
|
||||
'ingestion-limit-save-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(save, args, CREATE_LIMIT, ATTACH_KEY);
|
||||
};
|
||||
|
||||
export const expectLimitUpdateDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const [signal] = args.limits;
|
||||
if (!hasRows(args) || !signal) {
|
||||
return;
|
||||
}
|
||||
await openFirstKey(canvasElement);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(`edit-limit-btn-${signal}`, undefined, untilLoaded),
|
||||
);
|
||||
const save = await screen.findByTestId(
|
||||
'ingestion-limit-save-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(save, args, UPDATE_LIMIT);
|
||||
};
|
||||
|
||||
export const expectLimitDeleteDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const [signal] = args.limits;
|
||||
if (!hasRows(args) || !signal) {
|
||||
return;
|
||||
}
|
||||
await openFirstKey(canvasElement);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
`ingestion-limit-delete-open-btn-${signal}`,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
const confirm = await screen.findByTestId(
|
||||
'ingestion-limit-delete-btn',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectGated(confirm, args, DELETE_LIMIT, DETACH_KEY);
|
||||
};
|
||||
117
frontend/src/pages/Settings/Ingestion/stories/__story_mockdata__/ingestion.play.ts
generated
Normal file
117
frontend/src/pages/Settings/Ingestion/stories/__story_mockdata__/ingestion.play.ts
generated
Normal file
@@ -0,0 +1,117 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import {
|
||||
addTag,
|
||||
openCreateKey,
|
||||
submitCreateKey,
|
||||
untilLoaded,
|
||||
} from '../Ingestion.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
}
|
||||
|
||||
export const showKeyLimits = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByText(
|
||||
/production-us-east/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await screen.findByRole('button', { name: 'Edit logs limit' }, untilLoaded);
|
||||
};
|
||||
|
||||
export const openCreateForm = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
await openCreateKey(canvasElement);
|
||||
};
|
||||
|
||||
export const typeNewTag = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.click(dialog.getByRole('button', { name: /New Tag/ }));
|
||||
await userEvent.keyboard('team-payments');
|
||||
};
|
||||
|
||||
export const addTags = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
for (const tag of ['team-payments', 'env:production']) {
|
||||
await addTag(dialog, tag);
|
||||
await dialog.findByText(tag);
|
||||
}
|
||||
};
|
||||
|
||||
export const addDuplicateTag = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await addTag(dialog, 'team-payments');
|
||||
await addTag(dialog, 'team-payments');
|
||||
await dialog.findByDisplayValue('team-payments');
|
||||
};
|
||||
|
||||
export const addLongTag = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
const tag =
|
||||
'team-payments-platform-observability-production-us-east-1-canary-collectors';
|
||||
await addTag(dialog, tag);
|
||||
await dialog.findByText(tag);
|
||||
};
|
||||
|
||||
export const submitInvalidKey = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.type(dialog.getByLabelText('Name'), 'otel collectors');
|
||||
await userEvent.click(
|
||||
dialog.getByRole('button', { name: 'Create new Ingestion key' }),
|
||||
);
|
||||
await dialog.findByText(/should only contain letters/);
|
||||
};
|
||||
|
||||
export const openExpiration = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await userEvent.click(dialog.getByLabelText('Expiration'));
|
||||
await screen.findByTitle(dayjs().format('YYYY-MM-DD'));
|
||||
};
|
||||
|
||||
export const submitHeldKey = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await submitCreateKey(dialog);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
dialog.getByRole('button', { name: 'Create new Ingestion key' }),
|
||||
).toHaveAttribute('aria-busy', 'true'),
|
||||
);
|
||||
};
|
||||
|
||||
export const submitRejectedKey = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const dialog = await openCreateKey(canvasElement);
|
||||
await submitCreateKey(dialog);
|
||||
await screen.findByText(
|
||||
'An ingestion key with this name already exists.',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import { ingestionMocks } from '../Ingestion.stories.mocks';
|
||||
import {
|
||||
expectCreateDenied,
|
||||
expectDeleteDenied,
|
||||
expectLimitDeleteDenied,
|
||||
expectLimitUpdateDenied,
|
||||
expectListDenied,
|
||||
expectNewLimitDenied,
|
||||
expectUpdateDenied,
|
||||
} from '../__story_mockdata__/ingestion.authz.play';
|
||||
|
||||
import SettingsPage from '../../../Settings';
|
||||
|
||||
type IngestionArgs = PageStoryArgs<typeof ingestionMocks>;
|
||||
|
||||
const pageStory = storyMocks(ingestionMocks, { layout: 'app' });
|
||||
|
||||
/**
|
||||
* The ingestion keys tab with one permission missing at a time. Every story here
|
||||
* is an admin who is denied exactly what its name says, so what goes with a
|
||||
* permission is what the story shows.
|
||||
*
|
||||
* Route: `/settings/ingestion-settings`.
|
||||
*/
|
||||
const meta = {
|
||||
title: 'Pages/Settings/Ingestion/Authz',
|
||||
tags: ['authz', 'play'],
|
||||
component: SettingsPage,
|
||||
...pageStory,
|
||||
parameters: { ...pageStory.parameters },
|
||||
} satisfies Meta<IngestionArgs>;
|
||||
|
||||
export default meta;
|
||||
|
||||
type Story = StoryObj<IngestionArgs>;
|
||||
|
||||
const LIST_KEY = 'list:ingestion-key';
|
||||
const CREATE_KEY = 'create:ingestion-key';
|
||||
const UPDATE_KEY = 'update:ingestion-key';
|
||||
const DELETE_KEY = 'delete:ingestion-key';
|
||||
const ATTACH_KEY = 'attach:ingestion-key';
|
||||
const DETACH_KEY = 'detach:ingestion-key';
|
||||
const CREATE_LIMIT = 'create:ingestion-limit';
|
||||
const UPDATE_LIMIT = 'update:ingestion-limit';
|
||||
const DELETE_LIMIT = 'delete:ingestion-limit';
|
||||
|
||||
/**
|
||||
* Without it the keys are replaced by the permission callout, the search box is
|
||||
* locked and neither the list nor the search request is made.
|
||||
*/
|
||||
export const NoList: Story = {
|
||||
args: { revoked: [LIST_KEY] },
|
||||
play: expectListDenied,
|
||||
};
|
||||
|
||||
/** The keys stay in view, with the button that adds one locked. */
|
||||
export const NoCreate: Story = {
|
||||
args: { revoked: [CREATE_KEY] },
|
||||
play: expectCreateDenied,
|
||||
};
|
||||
|
||||
/** The edit form opens, with its Update button locked. */
|
||||
export const NoUpdate: Story = {
|
||||
args: { revoked: [UPDATE_KEY] },
|
||||
play: expectUpdateDenied,
|
||||
};
|
||||
|
||||
/** The delete dialog opens, with the button that confirms it locked. */
|
||||
export const NoDelete: Story = {
|
||||
args: { revoked: [DELETE_KEY] },
|
||||
play: expectDeleteDenied,
|
||||
};
|
||||
|
||||
/**
|
||||
* A new limit is a create on the limit and an attach on its key, so losing the
|
||||
* limit half locks Save on a signal with no cap yet.
|
||||
*/
|
||||
export const NoLimitCreate: Story = {
|
||||
args: { revoked: [CREATE_LIMIT] },
|
||||
play: expectNewLimitDenied,
|
||||
};
|
||||
|
||||
/** The other half of the same pair, which locks the same Save. */
|
||||
export const NoAttach: Story = {
|
||||
args: { revoked: [ATTACH_KEY] },
|
||||
play: expectNewLimitDenied,
|
||||
};
|
||||
|
||||
/** Changing a cap that is already set takes `update` on the limit alone. */
|
||||
export const NoLimitUpdate: Story = {
|
||||
args: { revoked: [UPDATE_LIMIT] },
|
||||
play: expectLimitUpdateDenied,
|
||||
};
|
||||
|
||||
/**
|
||||
* Removing a limit is a delete on the limit and a detach from its key, so losing
|
||||
* the limit half locks the button that confirms it.
|
||||
*/
|
||||
export const NoLimitDelete: Story = {
|
||||
args: { revoked: [DELETE_LIMIT] },
|
||||
play: expectLimitDeleteDenied,
|
||||
};
|
||||
|
||||
/** The other half of the same pair, which locks the same button. */
|
||||
export const NoDetach: Story = {
|
||||
args: { revoked: [DETACH_KEY] },
|
||||
play: expectLimitDeleteDenied,
|
||||
};
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
keyUpdatedToast,
|
||||
openSearchSuggestions,
|
||||
openStatusChip,
|
||||
removeStatusTag,
|
||||
saveFailed,
|
||||
} from './__story_mockdata__/serviceAccounts.play';
|
||||
import {
|
||||
@@ -116,6 +117,14 @@ export const StatusChipOpen: Story = {
|
||||
play: openStatusChip,
|
||||
};
|
||||
|
||||
/** Deleted only, with its status tag removed by its ×: the list runs unfiltered. */
|
||||
export const StatusTagRemoved: Story = {
|
||||
parameters: at(
|
||||
`search=${encodeURIComponent(where('status', '=', 'deleted'))}`,
|
||||
),
|
||||
play: removeStatusTag,
|
||||
};
|
||||
|
||||
/** Empty: a search that matches no account keeps the list shell and empty state. */
|
||||
export const SearchNoResults: Story = {
|
||||
parameters: at('search=no-such-service-account'),
|
||||
|
||||
@@ -46,6 +46,20 @@ export const openStatusChip = async (): Promise<void> => {
|
||||
await screen.findByTitle('Deleted', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
// antd renders a tag's × aria-hidden.
|
||||
const tagRemove = { name: 'close', hidden: true } as const;
|
||||
|
||||
export const removeStatusTag = async (): Promise<void> => {
|
||||
await editableSearch();
|
||||
const filter = screen.getByTestId('sa-filter-status');
|
||||
await userEvent.click(
|
||||
await within(filter).findByRole('img', tagRemove, untilLoaded),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(within(filter).queryByRole('img', tagRemove)).not.toBeInTheDocument(),
|
||||
);
|
||||
};
|
||||
|
||||
export const openSearchSuggestions = async (): Promise<void> => {
|
||||
await userEvent.click(await editableSearch());
|
||||
await screen.findByText('status', undefined, untilLoaded);
|
||||
|
||||
@@ -9,7 +9,6 @@ import { buildNavUrl, getQueryString } from 'container/SideNav/helper';
|
||||
import { settingsNavSections } from 'container/SideNav/menuItems';
|
||||
import NavItem from 'container/SideNav/NavItem/NavItem';
|
||||
import { SidebarItem } from 'container/SideNav/sideNav.types';
|
||||
import useComponentPermission from 'hooks/useComponentPermission';
|
||||
import { useGetTenantLicense } from 'hooks/useGetTenantLicense';
|
||||
import { useAppLocation } from 'lib/router/useAppLocation';
|
||||
import { navigate } from 'lib/router/navigation';
|
||||
@@ -40,10 +39,6 @@ function SettingsPage(): JSX.Element {
|
||||
|
||||
const isWorkspaceBlocked = trialInfo?.workSpaceBlock || false;
|
||||
|
||||
const [isCurrentOrgSettings] = useComponentPermission(
|
||||
['current_org_settings'],
|
||||
user.role,
|
||||
);
|
||||
const { t } = useTranslation(['routes']);
|
||||
|
||||
const isGatewayEnabled =
|
||||
@@ -61,11 +56,10 @@ function SettingsPage(): JSX.Element {
|
||||
isEnabled:
|
||||
item.key === ROUTES.BILLING ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.ORG_SETTINGS ||
|
||||
!!(
|
||||
isAdmin &&
|
||||
(item.key === ROUTES.ORG_SETTINGS ||
|
||||
item.key === ROUTES.MY_SETTINGS ||
|
||||
item.key === ROUTES.SHORTCUTS)
|
||||
(item.key === ROUTES.MY_SETTINGS || item.key === ROUTES.SHORTCUTS)
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -83,7 +77,9 @@ function SettingsPage(): JSX.Element {
|
||||
item.key === ROUTES.ROLE_DETAILS ||
|
||||
item.key === ROUTES.ROLE_EDIT ||
|
||||
item.key === ROUTES.SERVICE_ACCOUNTS_SETTINGS ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.ORG_SETTINGS ||
|
||||
item.key === ROUTES.INGESTION_SETTINGS
|
||||
? true
|
||||
: item.isEnabled,
|
||||
}));
|
||||
@@ -93,9 +89,6 @@ function SettingsPage(): JSX.Element {
|
||||
...item,
|
||||
isEnabled:
|
||||
item.key === ROUTES.INTEGRATIONS ||
|
||||
item.key === ROUTES.INGESTION_SETTINGS ||
|
||||
item.key === ROUTES.ORG_SETTINGS ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.SHORTCUTS ||
|
||||
item.key === ROUTES.MCP_SERVER
|
||||
? true
|
||||
@@ -107,7 +100,6 @@ function SettingsPage(): JSX.Element {
|
||||
updatedItems = updatedItems.map((item) => ({
|
||||
...item,
|
||||
isEnabled:
|
||||
item.key === ROUTES.INGESTION_SETTINGS ||
|
||||
item.key === ROUTES.INTEGRATIONS ||
|
||||
item.key === ROUTES.SHORTCUTS ||
|
||||
item.key === ROUTES.MCP_SERVER
|
||||
@@ -135,7 +127,9 @@ function SettingsPage(): JSX.Element {
|
||||
item.key === ROUTES.ROLE_DETAILS ||
|
||||
item.key === ROUTES.ROLE_EDIT ||
|
||||
item.key === ROUTES.SERVICE_ACCOUNTS_SETTINGS ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.ORG_SETTINGS ||
|
||||
item.key === ROUTES.INGESTION_SETTINGS
|
||||
? true
|
||||
: item.isEnabled,
|
||||
}));
|
||||
@@ -144,11 +138,7 @@ function SettingsPage(): JSX.Element {
|
||||
updatedItems = updatedItems.map((item) => ({
|
||||
...item,
|
||||
isEnabled:
|
||||
item.key === ROUTES.INTEGRATIONS ||
|
||||
item.key === ROUTES.ORG_SETTINGS ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.INGESTION_SETTINGS ||
|
||||
item.key === ROUTES.MCP_SERVER
|
||||
item.key === ROUTES.INTEGRATIONS || item.key === ROUTES.MCP_SERVER
|
||||
? true
|
||||
: item.isEnabled,
|
||||
}));
|
||||
@@ -158,9 +148,7 @@ function SettingsPage(): JSX.Element {
|
||||
updatedItems = updatedItems.map((item) => ({
|
||||
...item,
|
||||
isEnabled:
|
||||
item.key === ROUTES.INTEGRATIONS ||
|
||||
item.key === ROUTES.INGESTION_SETTINGS ||
|
||||
item.key === ROUTES.MCP_SERVER
|
||||
item.key === ROUTES.INTEGRATIONS || item.key === ROUTES.MCP_SERVER
|
||||
? true
|
||||
: item.isEnabled,
|
||||
}));
|
||||
@@ -184,7 +172,8 @@ function SettingsPage(): JSX.Element {
|
||||
item.key === ROUTES.ROLE_DETAILS ||
|
||||
item.key === ROUTES.ROLE_EDIT ||
|
||||
item.key === ROUTES.SERVICE_ACCOUNTS_SETTINGS ||
|
||||
item.key === ROUTES.MEMBERS_SETTINGS
|
||||
item.key === ROUTES.MEMBERS_SETTINGS ||
|
||||
item.key === ROUTES.ORG_SETTINGS
|
||||
? true
|
||||
: item.isEnabled,
|
||||
}));
|
||||
@@ -192,10 +181,7 @@ function SettingsPage(): JSX.Element {
|
||||
if (isAdmin) {
|
||||
updatedItems = updatedItems.map((item) => ({
|
||||
...item,
|
||||
isEnabled:
|
||||
item.key === ROUTES.ORG_SETTINGS || item.key === ROUTES.MEMBERS_SETTINGS
|
||||
? true
|
||||
: item.isEnabled,
|
||||
isEnabled: item.key === ROUTES.MEMBERS_SETTINGS ? true : item.isEnabled,
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -226,7 +212,6 @@ function SettingsPage(): JSX.Element {
|
||||
() =>
|
||||
getRoutes(
|
||||
user.role,
|
||||
isCurrentOrgSettings,
|
||||
isGatewayEnabled,
|
||||
isWorkspaceBlocked,
|
||||
isCloudUser,
|
||||
@@ -235,7 +220,6 @@ function SettingsPage(): JSX.Element {
|
||||
),
|
||||
[
|
||||
user.role,
|
||||
isCurrentOrgSettings,
|
||||
isGatewayEnabled,
|
||||
isWorkspaceBlocked,
|
||||
isCloudUser,
|
||||
|
||||
@@ -4,10 +4,17 @@
|
||||
*/
|
||||
|
||||
import ROUTES from 'constants/routes';
|
||||
import {
|
||||
AuthDomainListPermission,
|
||||
buildAuthDomainDeletePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/auth-domain.permissions';
|
||||
import {
|
||||
buildOrganizationReadPermission,
|
||||
buildOrganizationUpdatePermission,
|
||||
} from 'lib/authz/hooks/useAuthZ/permissions/organization.permissions';
|
||||
import { rest } from 'msw';
|
||||
import { componentPermission } from 'utils/permission';
|
||||
|
||||
import { accessFor } from '@/storybook/access/access';
|
||||
import { grantsAll } from '@/storybook/access/access';
|
||||
import {
|
||||
choiceControl,
|
||||
countControl,
|
||||
@@ -128,15 +135,22 @@ export const singleSignOnMocks = defineStoryMocks({
|
||||
|
||||
export type SingleSignOnArgs = PageStoryArgs<typeof singleSignOnMocks>;
|
||||
|
||||
/** The Settings page lists the organization tab for the admin role only. */
|
||||
export const showsOrgSettings = (args: SingleSignOnArgs): boolean =>
|
||||
componentPermission.current_org_settings.includes(
|
||||
accessFor(args.access, args.permissions, args.revoked).legacyRole,
|
||||
);
|
||||
export const canReadDisplayName = (args: SingleSignOnArgs): boolean =>
|
||||
grantsAll(args, buildOrganizationReadPermission('*'));
|
||||
|
||||
export const canEditDisplayName = (args: SingleSignOnArgs): boolean =>
|
||||
canReadDisplayName(args) &&
|
||||
grantsAll(args, buildOrganizationUpdatePermission('*'));
|
||||
|
||||
export const canListDomains = (args: SingleSignOnArgs): boolean =>
|
||||
grantsAll(args, AuthDomainListPermission);
|
||||
|
||||
export const canDeleteDomain = (args: SingleSignOnArgs): boolean =>
|
||||
grantsAll(args, buildAuthDomainDeletePermission('*'));
|
||||
|
||||
/** Rows come from the domains handler, which State can hold back or fail. */
|
||||
export const listsDomains = (args: SingleSignOnArgs): boolean =>
|
||||
showsOrgSettings(args) &&
|
||||
canListDomains(args) &&
|
||||
args.dataState === 'loaded' &&
|
||||
authDomainsResponse(args.domains, args.provider, args.enforced).data.length >
|
||||
0;
|
||||
|
||||
@@ -5,14 +5,19 @@ import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import { singleSignOnMocks } from './SingleSignOn.stories.mocks';
|
||||
import {
|
||||
createDomain,
|
||||
deleteDomain,
|
||||
expandAttributeMapping,
|
||||
expandRoleMappings,
|
||||
expandWorkspaceGroups,
|
||||
expectViewerAccess,
|
||||
openAddDomain,
|
||||
openConfigureDomain,
|
||||
openDeleteDomain,
|
||||
openProviderSelector,
|
||||
saveConfiguredDomain,
|
||||
submitEmptyProvider,
|
||||
toggleEnforcement,
|
||||
updateDisplayName,
|
||||
} from './__story_mockdata__/singleSignOn.play';
|
||||
|
||||
@@ -24,13 +29,14 @@ const pageStory = storyMocks(singleSignOnMocks, { layout: 'app' });
|
||||
|
||||
/**
|
||||
* SAML and OIDC domains for the org, whether SSO is enforced, and the role a new
|
||||
* user lands on.
|
||||
* user lands on. Gated on authz permissions: the domain list, delete and the
|
||||
* display name; saving a domain is checked by the backend.
|
||||
*
|
||||
* Route: `/settings/org-settings`.
|
||||
*/
|
||||
const meta = {
|
||||
title: 'Pages/Settings/Single Sign-on',
|
||||
tags: ['play'],
|
||||
title: 'Pages/Settings/Single Sign-on/Overview',
|
||||
tags: ['authz', 'play'],
|
||||
component: SettingsPage,
|
||||
...pageStory,
|
||||
parameters: { ...pageStory.parameters },
|
||||
@@ -100,6 +106,15 @@ export const ClaimMappingExpanded: Story = {
|
||||
play: expandAttributeMapping,
|
||||
};
|
||||
|
||||
/**
|
||||
* Interaction: the Google form with its Workspace groups open, group fetching on
|
||||
* and the allowed groups listed.
|
||||
*/
|
||||
export const WorkspaceGroupsExpanded: Story = {
|
||||
args: { provider: 'google' },
|
||||
play: expandWorkspaceGroups,
|
||||
};
|
||||
|
||||
/** Validation: submitting a new provider without required fields leaves form errors visible. */
|
||||
export const CreateDomainValidation: Story = {
|
||||
play: submitEmptyProvider,
|
||||
@@ -125,3 +140,45 @@ export const DisplayNameUpdatedToast: Story = {
|
||||
export const DomainDeletedToast: Story = {
|
||||
play: deleteDomain,
|
||||
};
|
||||
|
||||
/**
|
||||
* A viewer: the tab is listed for every role, but the domain list is denied and
|
||||
* the display name is locked.
|
||||
*/
|
||||
export const Viewer: Story = {
|
||||
args: { access: 'viewer' },
|
||||
play: expectViewerAccess,
|
||||
};
|
||||
|
||||
/**
|
||||
* Adding a domain whose save the backend rejects: the error modal opens and the
|
||||
* filled form stays. Set Domain save to `success` for the created toast.
|
||||
*/
|
||||
export const DomainCreateFailed: Story = {
|
||||
args: { domainSave: 'error' },
|
||||
// The deliberate 500 is the state under test.
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: createDomain,
|
||||
};
|
||||
|
||||
/**
|
||||
* Saving a configured domain the backend rejects: the error modal opens over the
|
||||
* form. Set Domain save to `success` for the updated toast.
|
||||
*/
|
||||
export const DomainUpdateFailed: Story = {
|
||||
args: { domainSave: 'error' },
|
||||
// The deliberate 500 is the state under test.
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: saveConfiguredDomain,
|
||||
};
|
||||
|
||||
/**
|
||||
* The enforce SSO switch flipped on a domain the backend rejects: the error modal
|
||||
* opens and the switch returns to where it was.
|
||||
*/
|
||||
export const EnforceSsoFailed: Story = {
|
||||
args: { domainSave: 'error' },
|
||||
// The deliberate 500 is the state under test.
|
||||
parameters: { allowConsoleErrors: true },
|
||||
play: toggleEnforcement,
|
||||
};
|
||||
|
||||
@@ -5,9 +5,13 @@
|
||||
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { expectDenied } from './singleSignOnAuthz';
|
||||
import {
|
||||
canDeleteDomain,
|
||||
canEditDisplayName,
|
||||
canReadDisplayName,
|
||||
canListDomains,
|
||||
listsDomains,
|
||||
showsOrgSettings,
|
||||
type SingleSignOnArgs,
|
||||
} from '../SingleSignOn.stories.mocks';
|
||||
|
||||
@@ -53,11 +57,7 @@ export const openConfigureDomain = async ({
|
||||
|
||||
export const openAddDomain = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!showsOrgSettings(args)) {
|
||||
return;
|
||||
}
|
||||
await userEvent.click(
|
||||
await within(canvasElement).findByTestId(
|
||||
'auth-domain-add',
|
||||
@@ -70,9 +70,6 @@ export const openAddDomain = async ({
|
||||
export const openProviderSelector = async (
|
||||
context: PlayContext,
|
||||
): Promise<void> => {
|
||||
if (!showsOrgSettings(context.args)) {
|
||||
return;
|
||||
}
|
||||
await openAddDomain(context);
|
||||
await screen.findByText(
|
||||
/configure authentication method/i,
|
||||
@@ -113,12 +110,28 @@ export const expandAttributeMapping = async (
|
||||
);
|
||||
};
|
||||
|
||||
export const expandWorkspaceGroups = async (
|
||||
context: PlayContext,
|
||||
): Promise<void> => {
|
||||
if (!listsDomains(context.args)) {
|
||||
return;
|
||||
}
|
||||
await openConfigureDomain(context);
|
||||
if (context.args.provider !== 'google') {
|
||||
return;
|
||||
}
|
||||
|
||||
await userEvent.click(
|
||||
screen.getByTestId('google-auth-workspace-groups-header'),
|
||||
);
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('google-auth-allowed-groups')).toBeVisible(),
|
||||
);
|
||||
};
|
||||
|
||||
export const submitEmptyProvider = async (
|
||||
context: PlayContext,
|
||||
): Promise<void> => {
|
||||
if (!showsOrgSettings(context.args)) {
|
||||
return;
|
||||
}
|
||||
await openAddDomain(context);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
@@ -152,14 +165,15 @@ export const updateDisplayName = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!showsOrgSettings(args)) {
|
||||
if (!canEditDisplayName(args)) {
|
||||
return;
|
||||
}
|
||||
const input = await within(canvasElement).findByLabelText(
|
||||
/display name/i,
|
||||
const input = await within(canvasElement).findByTestId(
|
||||
'org-display-name-input-field',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await waitFor(() => expect(input).toBeEnabled(), untilLoaded);
|
||||
|
||||
await userEvent.clear(input);
|
||||
await userEvent.type(input, 'Night Watch');
|
||||
@@ -179,16 +193,120 @@ export const deleteDomain = async ({
|
||||
return;
|
||||
}
|
||||
await clickFirst(canvasElement, 'auth-domain-delete');
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
'auth-domain-delete-confirm',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
const confirm = await screen.findByTestId(
|
||||
'auth-domain-delete-confirm',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectDenied(confirm, !canDeleteDomain(args));
|
||||
if (!canDeleteDomain(args)) {
|
||||
return;
|
||||
}
|
||||
await userEvent.click(confirm);
|
||||
if (args.domainDelete === 'success') {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByText(/domain deleted successfully/i)).toBeVisible(),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const waitForSaveOutcome = async (
|
||||
outcome: SingleSignOnArgs['domainSave'],
|
||||
successToast: RegExp,
|
||||
): Promise<void> => {
|
||||
if (outcome === 'error') {
|
||||
await screen.findAllByText(/the request failed/i, undefined, untilLoaded);
|
||||
}
|
||||
if (outcome === 'success') {
|
||||
await waitFor(() => expect(screen.getByText(successToast)).toBeVisible(), {
|
||||
timeout: 15_000,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const createDomain = async (context: PlayContext): Promise<void> => {
|
||||
await openAddDomain(context);
|
||||
await userEvent.click(
|
||||
await screen.findByTestId(
|
||||
'authn-provider-configure-google',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
);
|
||||
await userEvent.type(
|
||||
await screen.findByLabelText(/^domain/i, undefined, untilLoaded),
|
||||
'acme.io',
|
||||
);
|
||||
await userEvent.type(screen.getByLabelText(/client id/i), 'client-id');
|
||||
await userEvent.type(screen.getByLabelText(/client secret/i), 'secret');
|
||||
await userEvent.click(screen.getByTestId('auth-domain-save'));
|
||||
await waitForSaveOutcome(
|
||||
context.args.domainSave,
|
||||
/domain created successfully/i,
|
||||
);
|
||||
};
|
||||
|
||||
export const saveConfiguredDomain = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!listsDomains(args)) {
|
||||
return;
|
||||
}
|
||||
await clickFirst(canvasElement, 'auth-domain-configure');
|
||||
await userEvent.click(
|
||||
await screen.findByTestId('auth-domain-save', undefined, untilLoaded),
|
||||
);
|
||||
await waitForSaveOutcome(args.domainSave, /domain updated successfully/i);
|
||||
};
|
||||
|
||||
export const toggleEnforcement = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!listsDomains(args)) {
|
||||
return;
|
||||
}
|
||||
await clickFirst(canvasElement, 'auth-domain-enforce-sso');
|
||||
if (args.domainSave === 'error') {
|
||||
await screen.findAllByText(/the request failed/i, undefined, untilLoaded);
|
||||
}
|
||||
};
|
||||
|
||||
export const expectViewerAccess = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (args.authzState !== 'loaded') {
|
||||
return;
|
||||
}
|
||||
if (!canListDomains(args)) {
|
||||
await within(canvasElement).findAllByText(
|
||||
/is not authorized/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
}
|
||||
if (!canReadDisplayName(args)) {
|
||||
await waitFor(
|
||||
() =>
|
||||
expect(
|
||||
within(canvasElement).queryByTestId('org-display-name-input-field'),
|
||||
).toBeNull(),
|
||||
untilLoaded,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const input = await within(canvasElement).findByTestId(
|
||||
'org-display-name-input-field',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await waitFor(
|
||||
() =>
|
||||
canEditDisplayName(args)
|
||||
? expect(input).toBeEnabled()
|
||||
: expect(input).toBeDisabled(),
|
||||
untilLoaded,
|
||||
);
|
||||
};
|
||||
|
||||
103
frontend/src/pages/Settings/SingleSignOn/stories/__story_mockdata__/singleSignOnAuthz.play.ts
generated
Normal file
103
frontend/src/pages/Settings/SingleSignOn/stories/__story_mockdata__/singleSignOnAuthz.play.ts
generated
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, screen, userEvent, within } from 'storybook/test';
|
||||
|
||||
import { expectDenied } from './singleSignOnAuthz';
|
||||
import {
|
||||
canDeleteDomain,
|
||||
canEditDisplayName,
|
||||
canListDomains,
|
||||
canReadDisplayName,
|
||||
listsDomains,
|
||||
type SingleSignOnArgs,
|
||||
} from '../SingleSignOn.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: SingleSignOnArgs;
|
||||
}
|
||||
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
|
||||
export const expectListDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (canListDomains(args) || args.authzState !== 'loaded') {
|
||||
return;
|
||||
}
|
||||
await within(canvasElement).findByText(
|
||||
/is not authorized/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
};
|
||||
|
||||
export const expectDeleteDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!listsDomains(args)) {
|
||||
return;
|
||||
}
|
||||
const [remove] = await within(canvasElement).findAllByTestId(
|
||||
'auth-domain-delete',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await userEvent.click(remove);
|
||||
const confirm = await screen.findByTestId(
|
||||
'auth-domain-delete-confirm',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expectDenied(confirm, !canDeleteDomain(args));
|
||||
};
|
||||
|
||||
export const expectDisplayNameDenied = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (args.authzState !== 'loaded') {
|
||||
return;
|
||||
}
|
||||
if (!canReadDisplayName(args)) {
|
||||
await within(canvasElement).findByText(
|
||||
/read:organization/i,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await expect(
|
||||
within(canvasElement).queryByTestId('org-display-name-input-field'),
|
||||
).toBeNull();
|
||||
return;
|
||||
}
|
||||
const denied = !canEditDisplayName(args);
|
||||
await expectDenied(
|
||||
await within(canvasElement).findByTestId(
|
||||
'org-display-name-input-field',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
denied,
|
||||
);
|
||||
if (!denied) {
|
||||
const input = await within(canvasElement).findByTestId(
|
||||
'org-display-name-input-field',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
await userEvent.type(input, ' edited');
|
||||
}
|
||||
await expectDenied(
|
||||
await within(canvasElement).findByTestId(
|
||||
'org-display-name-submit',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
),
|
||||
denied,
|
||||
);
|
||||
};
|
||||
23
frontend/src/pages/Settings/SingleSignOn/stories/__story_mockdata__/singleSignOnAuthz.ts
generated
Normal file
23
frontend/src/pages/Settings/SingleSignOn/stories/__story_mockdata__/singleSignOnAuthz.ts
generated
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { expect, waitFor } from 'storybook/test';
|
||||
|
||||
export const LIST_AUTH_DOMAIN = 'list:auth-domain';
|
||||
export const DELETE_AUTH_DOMAIN = 'delete:auth-domain';
|
||||
export const READ_ORGANIZATION = 'read:organization';
|
||||
export const UPDATE_ORGANIZATION = 'update:organization';
|
||||
|
||||
const isDisabled = (element: HTMLElement): boolean =>
|
||||
element.hasAttribute('disabled') ||
|
||||
element.getAttribute('aria-disabled') === 'true';
|
||||
|
||||
export const expectDenied = (
|
||||
element: HTMLElement,
|
||||
denied = true,
|
||||
): Promise<void> =>
|
||||
waitFor(() => expect(isDisabled(element)).toBe(denied), {
|
||||
timeout: 15_000,
|
||||
});
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user