mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-24 01:00:58 +00:00
Compare commits
3 Commits
fix/noz-se
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb0adcc618 | ||
|
|
b14b634bce | ||
|
|
7ea0d57417 |
@@ -137,6 +137,8 @@ window.getComputedStyle = function (
|
||||
return {
|
||||
display: '',
|
||||
visibility: '',
|
||||
width: '',
|
||||
height: '',
|
||||
opacity: '1',
|
||||
animationName: 'none',
|
||||
getPropertyValue: () => '',
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
"@sentry/vite-plugin": "5.3.0",
|
||||
"@signozhq/design-tokens": "2.8.0",
|
||||
"@signozhq/icons": "0.4.0",
|
||||
"@signozhq/noz-client": "1.13.0",
|
||||
"@signozhq/ui": "0.4.0-rc.5",
|
||||
"@tanstack/react-table": "8.21.3",
|
||||
"@tanstack/react-virtual": "3.13.22",
|
||||
|
||||
16
frontend/pnpm-lock.yaml
generated
16
frontend/pnpm-lock.yaml
generated
@@ -82,6 +82,9 @@ importers:
|
||||
'@signozhq/icons':
|
||||
specifier: 0.4.0
|
||||
version: 0.4.0
|
||||
'@signozhq/noz-client':
|
||||
specifier: 1.13.0
|
||||
version: 1.13.0(axios@1.21.1)(react-query@3.39.3(react-dom@18.2.0(react@18.2.0))(react@18.2.0))(react@18.2.0)
|
||||
'@signozhq/ui':
|
||||
specifier: 0.4.0-rc.5
|
||||
version: 0.4.0-rc.5(@date-fns/tz@1.4.1)(@signozhq/design-tokens@2.8.0)(@signozhq/icons@0.4.0)(@types/react@18.0.26)(date-fns@4.1.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)
|
||||
@@ -3248,6 +3251,13 @@ packages:
|
||||
'@signozhq/icons@0.4.0':
|
||||
resolution: {integrity: sha512-QctNvNPlQlsefFdIVmSy/P/7a1IcQ3IryKP0KPMqtoqew3q89FGUmFa5IfEJ7Z3CHhtG1zaXwBKqP72QkLyA3g==}
|
||||
|
||||
'@signozhq/noz-client@1.13.0':
|
||||
resolution: {integrity: sha512-130L2xomHnQZK8ZtAst34qFz9d2rSF/JYpg9gKvJkZVS9+46CPZeTW8Va9PNS9Oa5owezVHIXZStTEbsHIxnwg==}
|
||||
peerDependencies:
|
||||
axios: ^1.20.0
|
||||
react: ^18.2.0
|
||||
react-query: ^3.39.3
|
||||
|
||||
'@signozhq/ui@0.4.0-rc.5':
|
||||
resolution: {integrity: sha512-WlJMfeDfvL2hjMpTpHhhND/tuK7X0sfXQlx6E1ZG+6E/DYHpuhYljfvW3E6/BohIlHFlTyCs/ZMl9wnV2k9Zcw==}
|
||||
peerDependencies:
|
||||
@@ -12373,6 +12383,12 @@ snapshots:
|
||||
|
||||
'@signozhq/icons@0.4.0': {}
|
||||
|
||||
'@signozhq/noz-client@1.13.0(axios@1.21.1)(react-query@3.39.3(react-dom@18.2.0(react@18.2.0))(react@18.2.0))(react@18.2.0)':
|
||||
dependencies:
|
||||
axios: 1.21.1
|
||||
react: 18.2.0
|
||||
react-query: 3.39.3(react-dom@18.2.0(react@18.2.0))(react@18.2.0)
|
||||
|
||||
'@signozhq/ui@0.4.0-rc.5(@date-fns/tz@1.4.1)(@signozhq/design-tokens@2.8.0)(@signozhq/icons@0.4.0)(@types/react@18.0.26)(date-fns@4.1.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)':
|
||||
dependencies:
|
||||
'@base-ui/react': 1.8.0(@date-fns/tz@1.4.1)(@types/react@18.0.26)(date-fns@4.1.0)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* to resume, which each return a new executionId to open a fresh SSE stream.
|
||||
*
|
||||
* Types in this file re-use the OpenAPI-generated DTOs in
|
||||
* `src/api/ai-assistant/sigNozAIAssistantAPI.schemas.ts`.
|
||||
* `@signozhq/noz-client`.
|
||||
* Local types are defined only when the UI needs a different shape — for
|
||||
* example, the SSE event union adds a literal `type` discriminator that the
|
||||
* generated event DTOs leave loose.
|
||||
@@ -60,7 +60,7 @@ import type {
|
||||
PageTypeDTO,
|
||||
ToolCallEventDTO,
|
||||
ToolResultEventDTO,
|
||||
} from './sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
||||
|
||||
import {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1
frontend/src/auto-import-registry.d.ts
vendored
1
frontend/src/auto-import-registry.d.ts
vendored
@@ -12,4 +12,5 @@
|
||||
|
||||
import '@signozhq/design-tokens';
|
||||
import '@signozhq/icons';
|
||||
import '@signozhq/noz-client';
|
||||
import '@signozhq/ui';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { lazy } from 'react';
|
||||
import { navigate } from 'lib/router/navigation';
|
||||
import { fireEvent, render, screen } from 'tests/test-utils';
|
||||
|
||||
@@ -98,4 +99,30 @@ describe('RouteTab component', () => {
|
||||
fireEvent.click(screen.getByRole('tab', { name: 'Tab2' }));
|
||||
expect(onChangeHandler).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('keeps the tab bar while a lazy tab loads', async () => {
|
||||
let resolveTab: (module: { default: () => JSX.Element }) => void = () => {};
|
||||
const LazyTab = lazy(
|
||||
() =>
|
||||
new Promise<{ default: () => JSX.Element }>((resolve) => {
|
||||
resolveTab = resolve;
|
||||
}),
|
||||
);
|
||||
render(
|
||||
<RouteTab
|
||||
routes={[{ ...testRoutes[0], Component: LazyTab }, testRoutes[1]]}
|
||||
activeKey="Tab1"
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole('tab', { name: 'Tab1' })).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByLabelText('loading').closest('.ant-spin')?.parentElement,
|
||||
).toHaveStyle({ height: '100%' });
|
||||
|
||||
resolveTab({ default: DummyComponent1 });
|
||||
await expect(
|
||||
screen.findByText('Dummy Component 1'),
|
||||
).resolves.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Suspense } from 'react';
|
||||
import { Tabs, TabsProps } from 'antd';
|
||||
import cx from 'classnames';
|
||||
import HeaderRightSection from 'components/HeaderRightSection/HeaderRightSection';
|
||||
import OverlayScrollbar from 'components/OverlayScrollbar/OverlayScrollbar';
|
||||
import Spinner from 'components/Spinner';
|
||||
import { buildRoutePath } from 'lib/router/buildRoutePath';
|
||||
import { matchRoute } from 'lib/router/matchRoute';
|
||||
import { navigate } from 'lib/router/navigation';
|
||||
@@ -58,7 +60,11 @@ function RouteTab({
|
||||
tabKey: route,
|
||||
children: (
|
||||
<OverlayScrollbar>
|
||||
<Component />
|
||||
<Suspense
|
||||
fallback={<Spinner size="large" tip="Loading..." height="100%" />}
|
||||
>
|
||||
<Component />
|
||||
</Suspense>
|
||||
</OverlayScrollbar>
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { PageTypeDTO } from '@signozhq/noz-client';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import ROUTES from 'constants/routes';
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ import {
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Tooltip } from '@signozhq/ui/tooltip';
|
||||
import type { MessageActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { MessageActionDTO } from '@signozhq/noz-client';
|
||||
import {
|
||||
ApplyFilterSignalDTO,
|
||||
MessageActionKindDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import {
|
||||
restoreExecution,
|
||||
revertExecution,
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import {
|
||||
MessageActionDTO,
|
||||
MessageActionKindDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { MessageActionDTO, MessageActionKindDTO } from '@signozhq/noz-client';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { getCurrentLocation, navigate } from 'lib/router/navigation';
|
||||
import { act, render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { undoExecution } from 'api/ai-assistant/chat';
|
||||
import type { MessageActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { MessageActionDTO } from '@signozhq/noz-client';
|
||||
import {
|
||||
ApplyFilterSignalDTO,
|
||||
MessageActionKindDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApplyFilterSignalDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { ApplyFilterSignalDTO } from '@signozhq/noz-client';
|
||||
import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
ApplyFilterSignalDTO,
|
||||
MessageActionKindDTO,
|
||||
SavedViewEntityDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import {
|
||||
getSavedView,
|
||||
listSavedViews,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
type MessageActionDTO,
|
||||
MessageActionKindDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
|
||||
import {
|
||||
isSavedViewOpenAction,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
ApplyFilterSignalDTO,
|
||||
type MessageActionDTOQuery,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { MessageActionDTOQuery } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { MessageActionDTOQuery } from '@signozhq/noz-client';
|
||||
import { normalizeTimeToMs } from 'utils/timeUtils';
|
||||
|
||||
export interface ActionTimeRange {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { MessageActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import {
|
||||
ApplyFilterSignalDTO,
|
||||
SavedViewEntityDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { MessageActionDTO } from '@signozhq/noz-client';
|
||||
import { ApplyFilterSignalDTO, SavedViewEntityDTO } from '@signozhq/noz-client';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
|
||||
import { ResourceType } from './resourceRoute';
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Tooltip } from '@signozhq/ui/tooltip';
|
||||
import type {
|
||||
ApprovalEventDTO,
|
||||
ApprovalEventDTODiff,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import {
|
||||
Check,
|
||||
Columns2,
|
||||
|
||||
@@ -6,11 +6,11 @@ import { Input } from '@signozhq/ui/input';
|
||||
import { Select } from '@signozhq/ui/select';
|
||||
import type { SelectItemType } from '@signozhq/ui/select';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import { ClarificationFieldTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { ClarificationFieldTypeDTO } from '@signozhq/noz-client';
|
||||
import type {
|
||||
ClarificationEventDTO,
|
||||
ClarificationFieldEventDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import { CircleHelp, Send, X } from '@signozhq/icons';
|
||||
|
||||
import { AIAssistantEvents } from '../../events';
|
||||
|
||||
@@ -5,7 +5,7 @@ import remarkGfm from 'remark-gfm';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { RotateCw, TriangleAlert } from '@signozhq/icons';
|
||||
|
||||
import { RetryActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { RetryActionDTO } from '@signozhq/noz-client';
|
||||
|
||||
// Side-effect: registers all built-in block types into the BlockRegistry
|
||||
import '../blocks';
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import React from 'react';
|
||||
import { render, screen, userEvent } from 'tests/test-utils';
|
||||
import {
|
||||
ErrorCodeDTO,
|
||||
RetryActionDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { ErrorCodeDTO, RetryActionDTO } from '@signozhq/noz-client';
|
||||
|
||||
import { Message } from '../../../types';
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useTimezone } from 'providers/Timezone';
|
||||
|
||||
import logEvent from 'api/common/logEvent';
|
||||
|
||||
import { FeedbackRatingDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { FeedbackRatingDTO } from '@signozhq/noz-client';
|
||||
import { AIAssistantEvents } from '../../events';
|
||||
import { useAIAssistantAnalyticsContext } from '../../hooks/useAIAssistantAnalyticsContext';
|
||||
import { useAIAssistantStore } from '../../store/useAIAssistantStore';
|
||||
|
||||
@@ -6,7 +6,7 @@ import remarkGfm from 'remark-gfm';
|
||||
import type {
|
||||
ApprovalEventDTO,
|
||||
ClarificationEventDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
|
||||
import { useVariant } from '../../VariantContext';
|
||||
import { StreamingEventItem } from '../../types';
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ArrowDown } from '@signozhq/icons';
|
||||
import type {
|
||||
ApprovalEventDTO,
|
||||
ClarificationEventDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
|
||||
import { AIAssistantEvents } from '../../events';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ChipDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { ChipDTO } from '@signozhq/noz-client';
|
||||
|
||||
/** Static empty-state chips used when the contextual chips API is unavailable. */
|
||||
export const EMPTY_STATE_CHIPS_FALLBACK: ChipDTO[] = [
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
|
||||
import { useQuery } from 'react-query';
|
||||
|
||||
import { getEmptyStateChips } from 'api/ai-assistant/chat';
|
||||
import type { ChipDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { ChipDTO } from '@signozhq/noz-client';
|
||||
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
||||
|
||||
import { useResolvePageType } from 'hooks/aiAssistant/useResolvePageType';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { PageTypeDTO } from '@signozhq/noz-client';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { matchRoute } from 'lib/router/matchRoute';
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
MessageContextDTOType,
|
||||
MessageRoleDTO,
|
||||
RetryActionDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import type {
|
||||
MessageContext,
|
||||
SSEEvent,
|
||||
|
||||
@@ -7,8 +7,8 @@ import { immer } from 'zustand/middleware/immer';
|
||||
import type {
|
||||
MessageActionDTO,
|
||||
MessageSummaryDTOBlocksAnyOfItem,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { RetryActionDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import { RetryActionDTO } from '@signozhq/noz-client';
|
||||
|
||||
import {
|
||||
approveExecution,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
/**
|
||||
* UI types for the AI Assistant.
|
||||
*
|
||||
* Wherever the OpenAPI-generated DTOs in
|
||||
* `src/api/ai-assistant/sigNozAIAssistantAPI.schemas.ts`
|
||||
* Wherever the OpenAPI-generated DTOs in `@signozhq/noz-client`
|
||||
* already capture the right shape, this module re-exports them.
|
||||
*
|
||||
* A type is defined locally only when the UI needs a different shape than
|
||||
@@ -20,7 +19,7 @@ import type {
|
||||
MessageActionDTO,
|
||||
MessageActionKindDTO,
|
||||
RetryActionDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import type { MessageContext } from 'api/ai-assistant/chat';
|
||||
|
||||
/** Client-only file attachment — no API equivalent (uploads happen via data URLs). */
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { AxiosError } from 'axios';
|
||||
import {
|
||||
ErrorCodeDTO,
|
||||
RetryActionDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { ErrorCodeDTO, RetryActionDTO } from '@signozhq/noz-client';
|
||||
|
||||
import { resolveAssistantError } from '../resolveAssistantError';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
RetryActionDTO,
|
||||
type ErrorBodyDTO,
|
||||
type ErrorResponseDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
|
||||
export interface AssistantErrorResolution {
|
||||
/** User-facing copy: code-specific FE copy → backend message → caller fallback. */
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { customRoleResponse } from 'mocks-server/__mockdata__/roles';
|
||||
import { server } from 'mocks-server/server';
|
||||
import { rest } from 'msw';
|
||||
import { render, screen, userEvent, waitFor, within } from 'tests/test-utils';
|
||||
import { setupAuthzAdmin } from 'lib/authz/utils/authz-test-utils';
|
||||
import {
|
||||
act,
|
||||
render,
|
||||
screen,
|
||||
userEvent,
|
||||
waitFor,
|
||||
within,
|
||||
} from 'tests/test-utils';
|
||||
import {
|
||||
AUTHZ_CHECK_URL,
|
||||
authzMockResponse,
|
||||
setupAuthzAdmin,
|
||||
} from 'lib/authz/utils/authz-test-utils';
|
||||
import { getCurrentLocation } from 'lib/router/navigation';
|
||||
|
||||
import CreateEditRolePage from '../CreateEditRolePage';
|
||||
|
||||
jest.mock('@monaco-editor/react', () => ({
|
||||
__esModule: true,
|
||||
default: ({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (next?: string) => void;
|
||||
}): JSX.Element => (
|
||||
<textarea
|
||||
data-testid="monaco-editor"
|
||||
value={value}
|
||||
onChange={(e): void => onChange(e.target.value)}
|
||||
/>
|
||||
),
|
||||
}));
|
||||
|
||||
const CUSTOM_ROLE_ID = '019c24aa-3333-0001-aaaa-111111111111';
|
||||
const rolesApiBase = '*/api/v1/roles';
|
||||
const VIEW_ROLE_URL = `${ROUTES.ROLE_DETAILS.replace(
|
||||
@@ -408,4 +437,125 @@ describe('EditRolePage', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('JSON view opened from the URL', () => {
|
||||
const roleGrants = roleWithTransactionGroups.data.transactionGroups;
|
||||
|
||||
function renderJsonView(client?: QueryClient): ReturnType<typeof render> {
|
||||
const page = <CreateEditRolePage />;
|
||||
return render(
|
||||
client ? (
|
||||
<QueryClientProvider client={client}>{page}</QueryClientProvider>
|
||||
) : (
|
||||
page
|
||||
),
|
||||
undefined,
|
||||
{
|
||||
initialRoute: `/settings/roles/${CUSTOM_ROLE_ID}/edit?name=Custom%20Role&viewMode=json`,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function readBuffer(editor: HTMLElement): unknown {
|
||||
return JSON.parse((editor as HTMLTextAreaElement).value);
|
||||
}
|
||||
|
||||
it('shows the role grants when the role loads after the authz check', async () => {
|
||||
server.use(
|
||||
rest.get(`${rolesApiBase}/:id`, (_req, res, ctx) =>
|
||||
res(ctx.delay(300), ctx.status(200), ctx.json(roleWithTransactionGroups)),
|
||||
),
|
||||
);
|
||||
|
||||
renderJsonView();
|
||||
|
||||
const editor = await screen.findByTestId('monaco-editor');
|
||||
expect(readBuffer(editor)).toStrictEqual(roleGrants);
|
||||
});
|
||||
|
||||
it('shows the role grants when the role loads before the authz check', async () => {
|
||||
server.use(
|
||||
rest.post(AUTHZ_CHECK_URL, async (req, res, ctx) => {
|
||||
const payload = await req.json();
|
||||
return res(
|
||||
ctx.delay(300),
|
||||
ctx.status(200),
|
||||
ctx.json(
|
||||
authzMockResponse(
|
||||
payload,
|
||||
payload.map(() => true),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
renderJsonView();
|
||||
|
||||
const editor = await screen.findByTestId('monaco-editor');
|
||||
expect(readBuffer(editor)).toStrictEqual(roleGrants);
|
||||
});
|
||||
|
||||
it('saves what was typed in the buffer even when the role refetches afterwards', async () => {
|
||||
const updatedBodies: unknown[] = [];
|
||||
let roleReads = 0;
|
||||
server.use(
|
||||
rest.get(`${rolesApiBase}/:id`, (_req, res, ctx) => {
|
||||
roleReads += 1;
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json(
|
||||
roleReads === 1
|
||||
? roleWithTransactionGroups
|
||||
: {
|
||||
...roleWithTransactionGroups,
|
||||
data: {
|
||||
...roleWithTransactionGroups.data,
|
||||
transactionGroups: [
|
||||
{
|
||||
objectGroup: {
|
||||
resource: { kind: 'role', type: 'role' },
|
||||
selectors: ['*'],
|
||||
},
|
||||
relation: 'update',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
}),
|
||||
rest.put(`${rolesApiBase}/:id`, async (req, res, ctx) => {
|
||||
updatedBodies.push(await req.json());
|
||||
return res(ctx.status(200), ctx.json({ status: 'success' }));
|
||||
}),
|
||||
);
|
||||
|
||||
const user = userEvent.setup();
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
renderJsonView(client);
|
||||
|
||||
const editor = await screen.findByTestId('monaco-editor');
|
||||
await user.type(editor, '[[]', {
|
||||
initialSelectionStart: 0,
|
||||
initialSelectionEnd: (editor as HTMLTextAreaElement).value.length,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await client.invalidateQueries();
|
||||
});
|
||||
await waitFor(() => {
|
||||
expect(roleReads).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
await user.click(screen.getByTestId('save-button'));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(updatedBodies).toHaveLength(1);
|
||||
});
|
||||
expect(updatedBodies[0]).toMatchObject({ transactionGroups: [] });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,6 +86,9 @@ export function useCreateEditRolePageActions(
|
||||
const { mutateAsync: updateRole, isLoading: isUpdating } =
|
||||
useUpdateRolePermissions();
|
||||
const isSaving = isCreating || isUpdating;
|
||||
// Editors read their initial value once, so stay loading until the fetched
|
||||
// role has been copied into local state.
|
||||
const isSeedingFromRole = !!rolePermissionsData && !isInitialized;
|
||||
|
||||
useEffect(() => {
|
||||
if (rolePermissionsData && !isInitialized) {
|
||||
@@ -229,7 +232,7 @@ export function useCreateEditRolePageActions(
|
||||
setEditorMode: handleModeChange,
|
||||
resources: localResources,
|
||||
setResources: handleResourcesChange,
|
||||
isLoading: isLoadingPermissions,
|
||||
isLoading: isLoadingPermissions || isSeedingFromRole,
|
||||
isSaving,
|
||||
hasUnsavedChanges,
|
||||
handleSave,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { PageTypeDTO } from '@signozhq/noz-client';
|
||||
import type { AIAssistantVariant } from 'container/AIAssistant/VariantContext';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { mockAppLocation } from 'tests/router-mocks';
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useMemo } from 'react';
|
||||
|
||||
import { useAppLocation } from 'lib/router/useAppLocation';
|
||||
|
||||
import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import { PageTypeDTO } from '@signozhq/noz-client';
|
||||
import { resolvePageType } from 'container/AIAssistant/resolvePageType';
|
||||
import { useVariant } from 'container/AIAssistant/VariantContext';
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import type {
|
||||
MessageSummaryDTO,
|
||||
ThreadDetailResponseDTO,
|
||||
ThreadListResponseDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import {
|
||||
ApplyFilterSignalDTO,
|
||||
ApprovalActionTypeDTO,
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
MessageActionKindDTO,
|
||||
MessageContentTypeDTO,
|
||||
MessageRoleDTO,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import type {
|
||||
Conversation,
|
||||
ConversationStreamState,
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import type { MessageSummaryDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
import type { MessageSummaryDTO } from '@signozhq/noz-client';
|
||||
import {
|
||||
MessageContextDTOSource,
|
||||
MessageContextDTOType,
|
||||
} from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
|
||||
} from '@signozhq/noz-client';
|
||||
import type { MessageBlock } from 'container/AIAssistant/types';
|
||||
|
||||
/** The opening question's contexts: the thread shows the @-picked ones, not the page it was asked from. */
|
||||
|
||||
Reference in New Issue
Block a user