Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/wfo-ui
16,606 changes: 6,814 additions & 9,792 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React from 'react';

import { useTranslations } from 'next-intl';

import { EuiButton } from '@elastic/eui';

import { useOrchestratorTheme, useShowToastMessage } from '@/hooks';
import { useLazyGetAgentExportQuery } from '@/rtk/endpoints/agentExport';
import { GraphQLPageInfo } from '@/types';
import { getCsvFileNameWithDate } from '@/utils';
import { csvDownloadHandler } from '@/utils/csvDownload';

export type ExportData = {
action: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see only the download_url and entity_type properties are use in the button right? Or am I missing something? If so I think we should simplify this and add these to the ExportButtonProps directly.

download_url: string;
message: string;
};

export type ExportButtonProps = {
exportData: ExportData;
};

type ExportApiResponse = {
page: object[];
pageInfo?: GraphQLPageInfo;
};

export function ExportButton({ exportData }: ExportButtonProps) {
const { showToastMessage } = useShowToastMessage();
const { theme } = useOrchestratorTheme();
const tError = useTranslations('errors');
const [triggerExport, { isFetching }] = useLazyGetAgentExportQuery();

const onDownloadClick = async () => {
const data = await triggerExport(exportData.download_url).unwrap();

const keyOrder = data.page.length > 0 ? Object.keys(data.page[0]) : [];

const handleExport = csvDownloadHandler(
async () => data,
(data: ExportApiResponse) => data.page,
(data: ExportApiResponse) =>
data.pageInfo ?? {
totalItems: data.page.length,
startCursor: 0,
endCursor: data.page.length - 1,
hasNextPage: false,
hasPreviousPage: false,
sortFields: [],
filterFields: [],
},
keyOrder,
getCsvFileNameWithDate(`export`),
showToastMessage,
tError,
);

await handleExport();
};

return (
<div
style={{
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
gap: theme.size.s,
width: '100%',
}}
>
<EuiButton
onClick={onDownloadClick}
isLoading={isFetching}
fill
iconType="download"
size="m"
css={{
borderRadius: theme.border.radius.medium,
boxShadow: `0 ${theme.size.xs} ${theme.size.base} ${theme.colors.primary}35`,
}}
>
{isFetching ? 'Downloading...' : 'Download CSV'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translate?

</EuiButton>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ExportButton';
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,39 @@

import { useTranslations } from 'next-intl';

import { useCoAgent } from '@copilotkit/react-core';
import { useCoAgent, useCoAgentStateRender } from '@copilotkit/react-core';
import { CopilotSidebar } from '@copilotkit/react-ui';
import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiText } from '@elastic/eui';

import { WfoSearchResults } from '@/components/WfoSearchPage/WfoSearchResults';
import { AnySearchParameters, AnySearchResult, PathFilter } from '@/types';
import { AnySearchParameters, Group, PathFilter, SearchResult } from '@/types';

Check failure on line 10 in packages/orchestrator-ui-components/src/components/WfoAgent/WfoAgent/WfoAgent.tsx

View workflow job for this annotation

GitHub Actions / linting-and-prettier

'PathFilter' is defined but never used

import { ExportButton, ExportData } from '../ExportButton';
import { FilterDisplay } from '../FilterDisplay';

type SearchResultsData = {
action: string;
query_id: string;
results_url: string;
total_count: number;
message: string;
results: SearchResult[];
};

type SearchState = {
parameters: AnySearchParameters;
results: AnySearchResult[];
run_id?: string | null;
query_id?: string | null;
parameters: AnySearchParameters | null;
results_data?: SearchResultsData | null;
export_data?: ExportData | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

Suggested change
export_data?: ExportData | null;
exportData?: ExportData | null;

};

const initialState: SearchState = {
parameters: {
action: 'select',
entity_type: 'SUBSCRIPTION',
filters: [] as PathFilter[],
query: null,
},
results: [],
run_id: null,
query_id: null,
parameters: null,
results_data: null,
export_data: null,
};

export function WfoAgent() {
Expand All @@ -34,23 +45,26 @@
name: 'query_agent',
initialState,
});
const { parameters, results } = state;

const hasStarted = !!(
state.parameters &&
Array.isArray(state.parameters.filters) &&
state.parameters.filters.length > 0
);
const { parameters, results_data } = state;

const isLoadingResults =
hasStarted && (!state.results || state.results.length === 0);
useCoAgentStateRender<SearchState>({
name: 'query_agent',
render: ({ state }) => {
if (!state.export_data || state.export_data.action !== 'export') {
return null;
}
return <ExportButton exportData={state.export_data} />;
},
});

const displayParameters = parameters && {
...parameters,
filters: Array.isArray(parameters.filters)
? { op: 'AND' as const, children: parameters.filters }
: parameters.filters,
};
const displayParameters = parameters
? {
...parameters,
filters: Array.isArray(parameters.filters)
? ({ op: 'AND' as const, children: parameters.filters } as Group)
: parameters.filters || undefined,
}
: undefined;

return (
<EuiFlexGroup gutterSize="l" alignItems="stretch">
Expand All @@ -69,20 +83,31 @@
)}

<EuiSpacer size="m" />
<EuiText size="s">
<h2>
{tPage('results')}{' '}
{results ? `(${results.length})` : ''}
</h2>
</EuiText>
<EuiSpacer size="s" />

<WfoSearchResults
results={results ?? []}
loading={isLoadingResults}
selectedRecordIndex={-1}
onRecordSelect={() => {}}
/>
{results_data && results_data.action === 'view_results' && (
<>
<EuiText size="s">
<h2>
{tPage('results')} ({results_data.total_count})
</h2>
</EuiText>
<EuiSpacer size="s" />
{results_data.message && (
<>
<EuiText size="s">
<p>{results_data.message}</p>
</EuiText>
<EuiSpacer size="s" />
</>
)}
<WfoSearchResults
results={results_data.results}
loading={false}
selectedRecordIndex={-1}
onRecordSelect={() => {}}
/>
</>
)}
</EuiFlexItem>

<EuiFlexItem grow={1}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import { WfoBadge } from '@/components/WfoBadges';
import {
ENTITY_TABS,
findResultIndexById,
getRecordId,
isSubscriptionSearchResult,
} from '@/components/WfoSearchPage/utils';
import { TreeProvider } from '@/contexts';
Expand Down Expand Up @@ -172,9 +170,8 @@
useEffect(() => {
if (results.data.length > 0) {
if (selectedRecordId) {
const foundIndex = findResultIndexById(
results.data,
selectedRecordId,
const foundIndex = results.data.findIndex(
(result) => result.entity_id === selectedRecordId,
);

if (foundIndex !== -1) {
Expand All @@ -190,7 +187,7 @@
}
}
}
}, [results.data, selectedRecordId, urlParams]);

Check warning on line 190 in packages/orchestrator-ui-components/src/components/WfoSearchPage/WfoSearch/WfoSearch.tsx

View workflow job for this annotation

GitHub Actions / linting-and-prettier

React Hook useEffect has missing dependencies: 'setSelectedRecordId' and 'setSelectedRecordIndex'. Either include them or remove the dependency array

useEffect(() => {
setShowDetailPanel(
Expand Down Expand Up @@ -368,9 +365,7 @@
setSelectedRecordIndex(index);
const record = results.data[index];
if (record) {
const recordId =
getRecordId(record);
setSelectedRecordId(recordId);
setSelectedRecordId(record.entity_id);
}
}}
/>
Expand All @@ -395,8 +390,7 @@
subscriptionId={
results.data[
selectedRecordIndex
].subscription
.subscription_id
].entity_id
}
/>
</TreeProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {

import { WfoBadge } from '@/components/WfoBadges';
import { useOrchestratorTheme } from '@/hooks';
import { AnySearchResult } from '@/types';
import { SearchResult } from '@/types';

import { getDescription, getDetailUrl } from '../utils';
import { getDetailUrl } from '../utils';
import { WfoHighlightedText } from './WfoHighlightedText';
import { WfoPathBreadcrumb } from './WfoPathBreadcrumb';

interface WfoSearchResultItemProps {
result: AnySearchResult;
result: SearchResult;
index: number;
isSelected?: boolean;
onSelect?: () => void;
Expand Down Expand Up @@ -79,7 +79,7 @@ export const WfoSearchResultItem: FC<WfoSearchResultItemProps> = ({
fontWeight: theme.font.weight.semiBold,
}}
>
{getDescription(result)}
{result.entity_title}
</EuiText>
</EuiFlexItem>
{matchingField && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useState } from 'react';

import { EuiFlexGroup, EuiPanel } from '@elastic/eui';

import { AnySearchResult } from '@/types';
import { SearchResult } from '@/types';

import { WfoSearchEmptyState } from './WfoSearchEmptyState';
import { WfoSearchLoadingState } from './WfoSearchLoadingState';
import { WfoSearchResultItem } from './WfoSearchResultItem';
import { WfoSubscriptionDetailModal } from './WfoSubscriptionDetailModal';

interface WfoSearchResultsProps {
results: AnySearchResult[];
results: SearchResult[];
loading: boolean;
selectedRecordIndex?: number;
onRecordSelect?: (index: number) => void;
Expand All @@ -22,10 +22,7 @@ export const WfoSearchResults = ({
selectedRecordIndex = 0,
onRecordSelect,
}: WfoSearchResultsProps) => {
const [modalData, setModalData] = useState<{
subscription: unknown;
matchingField?: unknown;
} | null>(null);
const [modalData, setModalData] = useState<unknown | null>(null);

const handleCloseModal = () => {
setModalData(null);
Expand All @@ -49,16 +46,17 @@ export const WfoSearchResults = ({
result={result}
index={idx}
isSelected={idx === selectedRecordIndex}
onSelect={() => onRecordSelect?.(idx)}
onSelect={() => {
onRecordSelect?.(idx);
}}
/>
))}
</EuiFlexGroup>
</EuiPanel>
<WfoSubscriptionDetailModal
isVisible={!!modalData}
onClose={handleCloseModal}
subscriptionData={modalData?.subscription}
matchingField={modalData?.matchingField}
resultData={modalData}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@ import { TreeProvider } from '@/contexts';
interface WfoSubscriptionDetailModalProps {
isVisible: boolean;
onClose: () => void;
subscriptionData: unknown | null;
matchingField?: unknown;
resultData?: unknown;
}

export const WfoSubscriptionDetailModal: FC<
WfoSubscriptionDetailModalProps
> = ({ isVisible, onClose, subscriptionData }) => {
> = ({ isVisible, onClose, resultData }) => {
const t = useTranslations('search.page');
if (!isVisible || !subscriptionData) return null;
if (!isVisible || !resultData) return null;

const subscriptionId =
subscriptionData &&
(subscriptionData as { subscription_id: string }).subscription_id;
(resultData as { entity_id: string } | undefined)?.entity_id || '';

return (
<EuiModal onClose={onClose} maxWidth={800}>
Expand Down
Loading
Loading