Skip to content

Commit

Permalink
Merge branch '8.14' into backport/8.14/pr-182876
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeOberti committed May 8, 2024
2 parents 037f670 + 9e1d156 commit 73f123a
Show file tree
Hide file tree
Showing 24 changed files with 421 additions and 172 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/common/authz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ export const calculateAuthz = ({
removePackages: writeIntegrationPolicies && integrations.all,
uploadPackages: writeIntegrationPolicies && integrations.all,

readPackageSettings: hasFleetAll && integrations.all,
writePackageSettings: hasFleetAll && integrations.all,
readPackageSettings: integrations.read,
writePackageSettings: writeIntegrationPolicies && integrations.all,

readIntegrationPolicies,
writeIntegrationPolicies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function Detail() {
const prerelease = useMemo(() => Boolean(queryParams.get('prerelease')), [queryParams]);

const authz = useAuthz();
const canAddAgent = authz.fleet.addAgents;
const canInstallPackages = authz.integrations.installPackages;
const canReadPackageSettings = authz.integrations.readPackageSettings;
const canReadIntegrationPolicies = authz.integrations.readIntegrationPolicies;
Expand Down Expand Up @@ -268,7 +269,8 @@ export function Detail() {
useUIExtension(packageInfoData?.item?.name ?? '', 'package-detail-custom') !== undefined;

// Only show config tab if package has `inputs`
const showConfigTab = packageInfo ? packageToPackagePolicyInputs(packageInfo).length > 0 : false;
const showConfigTab =
canAddAgent && (packageInfo ? packageToPackagePolicyInputs(packageInfo).length > 0 : false);

// Only show API references tab if it is allowed & has documentation to show
const showDocumentationTab =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,21 @@ const UpdatesAvailableMsg = ({
defaultMessage: 'New version available',
})}
>
<EuiFlexGroup gutterSize="xs">
<EuiFlexItem grow={false}>
<FormattedMessage
id="xpack.fleet.integration.settings.versionInfo.updatesAvailableBody"
defaultMessage="Upgrade to version {latestVersion} to get the latest features."
values={{ latestVersion }}
/>
</EuiFlexItem>
<EuiFlexItem>
<p>
<EuiLink onClick={toggleChangelogModal}>{'View changelog.'}</EuiLink>
</p>
</EuiFlexItem>
</EuiFlexGroup>
<FormattedMessage
id="xpack.fleet.integration.settings.versionInfo.updatesAvailableBody"
defaultMessage="Upgrade to version {latestVersion} to get the latest features. {changelogLink}"
values={{
latestVersion,
changelogLink: (
<EuiLink onClick={toggleChangelogModal}>
<FormattedMessage
id="xpack.fleet.integration.settings.versionInfo.updatesAvailableChangelogLink"
defaultMessage="View changelog."
/>
</EuiLink>
),
}}
/>
</EuiCallOut>
);

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/routes/epm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
.put({
path: EPM_API_ROUTES.INFO_PATTERN,
fleetAuthz: {
integrations: { upgradePackages: true, writePackageSettings: true },
integrations: { writePackageSettings: true },
},
})
.addVersion(
Expand Down Expand Up @@ -359,7 +359,7 @@ export const registerRoutes = (router: FleetAuthzRouter) => {
path: EPM_API_ROUTES.INFO_PATTERN_DEPRECATED,

fleetAuthz: {
integrations: { upgradePackages: true, writePackageSettings: true },
integrations: { writePackageSettings: true },
},
})
.addVersion(
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/search_playground/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface QuerySourceFields {
dense_vector_query_fields: ModelFields[];
bm25_query_fields: string[];
source_fields: string[];
skipped_fields: number;
}

export enum APIRoutes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jest.mock('../../hooks/use_indices_fields', () => ({
bm25_query_fields: ['field1', 'field2'],
source_fields: ['context_field1', 'context_field2'],
},
index2: {
elser_query_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: ['field1', 'field2'],
source_fields: ['context_field1', 'context_field2'],
},
},
}),
}));
Expand All @@ -36,6 +42,11 @@ const MockFormProvider = ({ children }: { children: React.ReactElement }) => {
const methods = useForm({
values: {
indices: ['index1'],
docSize: 1,
sourceFields: {
index1: ['context_field1'],
index2: ['context_field2'],
},
},
});
return <FormProvider {...methods}>{children}</FormProvider>;
Expand All @@ -55,13 +66,14 @@ describe('EditContextFlyout component tests', () => {
});

it('calls onClose when the close button is clicked', () => {
fireEvent.click(screen.getByTestId('euiFlyoutCloseButton'));
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
expect(onCloseMock).toHaveBeenCalledTimes(1);
});

it('should see the context fields', async () => {
expect(screen.getByTestId('contextFieldsSelectable')).toBeInTheDocument();
expect(screen.getByTestId('contextFieldsSelectable')).toHaveTextContent(`context_field2`);
expect(screen.getByTestId('contextFieldsSelectable')).toHaveTextContent(`context_field1`);
expect(screen.getByTestId('contextFieldsSelectable_index1')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('contextFieldsSelectable_index1'));
expect(screen.getByRole('option', { name: 'context_field1' })).toBeInTheDocument();
expect(screen.getByRole('option', { name: 'context_field2' })).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import {
EuiLink,
EuiSpacer,
EuiText,
EuiPanel,
EuiAccordion,
EuiSelectable,
EuiSelect,
EuiSelectableOption,
EuiSuperSelect,
EuiFormRow,
} from '@elastic/eui';
import { useController, useFormContext } from 'react-hook-form';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -62,10 +60,10 @@ export const EditContextFlyout: React.FC<EditContextFlyoutProps> = ({ onClose })

const [tempSourceFields, setTempSourceFields] = useState(sourceFields);

const toggleSourceField = (index: string, f: EuiSelectableOption[]) => {
const updateSourceField = (index: string, field: string) => {
setTempSourceFields({
...tempSourceFields,
[index]: f.filter(({ checked }) => checked === 'on').map(({ label }) => label),
[index]: [field],
});
usageTracker?.click(AnalyticsEvents.editContextFieldToggled);
};
Expand All @@ -76,6 +74,7 @@ export const EditContextFlyout: React.FC<EditContextFlyoutProps> = ({ onClose })
onChangeSize(docSize);
onClose();
};

const handleDocSizeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
usageTracker?.click(AnalyticsEvents.editContextDocSizeChanged);
setDocSize(Number(e.target.value));
Expand Down Expand Up @@ -119,71 +118,69 @@ export const EditContextFlyout: React.FC<EditContextFlyoutProps> = ({ onClose })
<EuiFlyoutBody>
<EuiFlexGroup>
<EuiFlexItem grow={3}>
<EuiFlexGroup direction="column">
<EuiFlexGroup direction="column" gutterSize="l">
<EuiFlexItem grow={false}>
<EuiSelect
prepend={i18n.translate(
<EuiFormRow
label={i18n.translate(
'xpack.searchPlayground.editContext.flyout.docsRetrievedCount',
{
defaultMessage: 'Retrieved documents',
defaultMessage: 'Number of documents to retrieve',
}
)}
options={[
{
value: 3,
text: '3',
},
{
value: 5,
text: '5',
},
{
value: 10,
text: '10',
},
]}
value={docSize}
onChange={handleDocSizeChange}
/>
</EuiFlexItem>
<EuiText>
<h5>
<FormattedMessage
id="xpack.searchPlayground.editContext.flyout.table.title"
defaultMessage="Selected fields"
>
<EuiSelect
options={[
{
value: 1,
text: '1',
},
{
value: 3,
text: '3',
},
{
value: 5,
text: '5',
},
{
value: 10,
text: '10',
},
]}
value={docSize}
onChange={handleDocSizeChange}
/>
</h5>
</EuiText>
{Object.entries(fields).map(([index, group], i) => (
<EuiFlexItem grow={false} key={index}>
<EuiPanel grow={false} hasShadow={false} hasBorder>
<EuiAccordion
initialIsOpen={i === 0}
id={index}
buttonContent={
<EuiText>
<h5>{index}</h5>
</EuiText>
}
>
<EuiSpacer size="s" />
<EuiSelectable
aria-label="Select context fields"
data-test-subj="contextFieldsSelectable"
options={group.source_fields.map((field) => ({
label: field,
checked: tempSourceFields[index]?.includes(field) ? 'on' : undefined,
}))}
onChange={(newOptions) => toggleSourceField(index, newOptions)}
listProps={{ bordered: false }}
singleSelection="always"
>
{(list) => list}
</EuiSelectable>
</EuiAccordion>
</EuiPanel>
</EuiFlexItem>
))}
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup direction="column" gutterSize="m">
<EuiFlexItem>
<EuiText>
<h5>
<FormattedMessage
id="xpack.searchPlayground.editContext.flyout.table.title"
defaultMessage="Select fields"
/>
</h5>
</EuiText>
</EuiFlexItem>
{Object.entries(fields).map(([index, group]) => (
<EuiFlexItem grow={false} key={index}>
<EuiFormRow label={index}>
<EuiSuperSelect
data-test-subj={`contextFieldsSelectable_${index}`}
options={group.source_fields.map((field) => ({
value: field,
inputDisplay: field,
}))}
valueOfSelected={tempSourceFields[index]?.[0]}
onChange={(value) => updateSourceField(index, value)}
/>
</EuiFormRow>
</EuiFlexItem>
))}
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ jest.mock('../../hooks/use_indices_fields', () => ({
elser_query_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: ['field1', 'field2'],
skipped_fields: 1,
},
index2: {
elser_query_fields: [],
dense_vector_query_fields: [],
bm25_query_fields: ['field1', 'field2'],
skipped_fields: 0,
},
},
}),
Expand All @@ -34,7 +41,7 @@ jest.mock('../../hooks/use_usage_tracker', () => ({
const MockFormProvider = ({ children }: { children: React.ReactElement }) => {
const methods = useForm({
values: {
indices: ['index1'],
indices: ['index1', 'index2'],
},
});
return <FormProvider {...methods}>{children}</FormProvider>;
Expand All @@ -61,7 +68,19 @@ describe('ViewQueryFlyout component tests', () => {
it('should see the view elasticsearch query', async () => {
expect(screen.getByTestId('ViewElasticsearchQueryResult')).toBeInTheDocument();
expect(screen.getByTestId('ViewElasticsearchQueryResult')).toHaveTextContent(
`{ "retriever": { "standard": { "query": { "multi_match": { "query": "{query}", "fields": [ "field1" ] } } } } }`
`{ "retriever": { "rrf": { "retrievers": [ { "standard": { "query": { "multi_match": { "query": "{query}", "fields": [ "field1" ] } } } }, { "standard": { "query": { "multi_match": { "query": "{query}", "fields": [ "field1" ] } } } } ] } } }`
);
});

it('displays query fields and indicates hidden fields', () => {
expect(screen.getByTestId('queryFieldsSelectable_index1')).toBeInTheDocument();
expect(screen.getByTestId('queryFieldsSelectable_index2')).toBeInTheDocument();

// Check if hidden fields indicator is shown
expect(screen.getByTestId('skipped_fields_index1')).toBeInTheDocument();
expect(screen.getByTestId('skipped_fields_index1')).toHaveTextContent('1 fields are hidden.');

// Check if hidden fields indicator is shown
expect(screen.queryByTestId('skipped_fields_index2')).not.toBeInTheDocument();
});
});

0 comments on commit 73f123a

Please sign in to comment.