Skip to content

Commit

Permalink
Merge branch 'main' into fix/184496
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan authored Jul 3, 2024
2 parents 3cccc1a + 0ec428b commit 6f68bcd
Show file tree
Hide file tree
Showing 171 changed files with 2,589 additions and 999 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ import {
EuiTitle,
EuiToolTip,
} from '@elastic/eui';
import {
ControlWidth,
DEFAULT_CONTROL_GROW,
DEFAULT_CONTROL_WIDTH,
} from '@kbn/controls-plugin/common';
import { CONTROL_WIDTH_OPTIONS } from '@kbn/controls-plugin/public';
import { DataControlFieldRegistry } from '@kbn/controls-plugin/public/types';
import { DataViewField } from '@kbn/data-views-plugin/common';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { useBatchedPublishingSubjects } from '@kbn/presentation-publishing';
import {
LazyDataViewPicker,
LazyFieldPicker,
withSuspense,
} from '@kbn/presentation-util-plugin/public';

import {
ControlWidth,
DEFAULT_CONTROL_GROW,
DEFAULT_CONTROL_WIDTH,
} from '@kbn/controls-plugin/common';
import { CONTROL_WIDTH_OPTIONS } from '@kbn/controls-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { getAllControlTypes, getControlFactory } from '../control_factory_registry';
import { ControlGroupApi } from '../control_group/types';
import { ControlStateManager } from '../types';
Expand All @@ -69,6 +70,65 @@ export interface ControlEditorProps<
const FieldPicker = withSuspense(LazyFieldPicker, null);
const DataViewPicker = withSuspense(LazyDataViewPicker, null);

const CompatibleControlTypesComponent = ({
fieldRegistry,
selectedFieldName,
selectedControlType,
setSelectedControlType,
}: {
fieldRegistry?: DataControlFieldRegistry;
selectedFieldName: string;
selectedControlType?: string;
setSelectedControlType: (type: string) => void;
}) => {
const dataControlFactories = useMemo(() => {
return getAllControlTypes()
.map((type) => getControlFactory(type))
.filter((factory) => {
return isDataControlFactory(factory);
});
}, []);

return (
<EuiKeyPadMenu data-test-subj={`controlTypeMenu`} aria-label={'type'}>
{dataControlFactories.map((factory) => {
const disabled =
fieldRegistry && selectedFieldName
? !fieldRegistry[selectedFieldName]?.compatibleControlTypes.includes(factory.type)
: true;
const keyPadMenuItem = (
<EuiKeyPadMenuItem
key={factory.type}
id={`create__${factory.type}`}
aria-label={factory.getDisplayName()}
data-test-subj={`create__${factory.type}`}
isSelected={factory.type === selectedControlType}
disabled={disabled}
onClick={() => setSelectedControlType(factory.type)}
label={factory.getDisplayName()}
>
<EuiIcon type={factory.getIconType()} size="l" />
</EuiKeyPadMenuItem>
);

return disabled ? (
<EuiToolTip
key={`disabled__${factory.type}`}
content={DataControlEditorStrings.manageControl.dataSource.getControlTypeErrorMessage({
fieldSelected: Boolean(selectedFieldName),
controlType: factory.getDisplayName(),
})}
>
{keyPadMenuItem}
</EuiToolTip>
) : (
keyPadMenuItem
);
})}
</EuiKeyPadMenu>
);
};

export const DataControlEditor = ({
controlId,
controlType,
Expand Down Expand Up @@ -139,57 +199,6 @@ export const DataControlEditor = ({
);
}, [selectedFieldName, setControlEditorValid, selectedDataView, selectedControlType]);

const dataControlFactories = useMemo(() => {
return getAllControlTypes()
.map((type) => getControlFactory(type))
.filter((factory) => {
return isDataControlFactory(factory);
});
}, []);

const CompatibleControlTypesComponent = useMemo(() => {
return (
<EuiKeyPadMenu data-test-subj={`controlTypeMenu`} aria-label={'type'}>
{dataControlFactories.map((factory) => {
const disabled =
fieldRegistry && selectedFieldName
? !fieldRegistry[selectedFieldName]?.compatibleControlTypes.includes(factory.type)
: true;
const keyPadMenuItem = (
<EuiKeyPadMenuItem
key={factory.type}
id={`create__${factory.type}`}
aria-label={factory.getDisplayName()}
data-test-subj={`create__${factory.type}`}
isSelected={factory.type === selectedControlType}
disabled={disabled}
onClick={() => setSelectedControlType(factory.type)}
label={factory.getDisplayName()}
>
<EuiIcon type={factory.getIconType()} size="l" />
</EuiKeyPadMenuItem>
);

return disabled ? (
<EuiToolTip
key={`disabled__${controlType}`}
content={DataControlEditorStrings.manageControl.dataSource.getControlTypeErrorMessage(
{
fieldSelected: Boolean(selectedFieldName),
controlType,
}
)}
>
{keyPadMenuItem}
</EuiToolTip>
) : (
keyPadMenuItem
);
})}
</EuiKeyPadMenu>
);
}, [selectedFieldName, fieldRegistry, selectedControlType, controlType, dataControlFactories]);

const CustomSettingsComponent = useMemo(() => {
if (!selectedControlType || !selectedFieldName || !fieldRegistry) return;

Expand Down Expand Up @@ -254,6 +263,7 @@ export const DataControlEditor = ({
selectedDataViewId={selectedDataViewId}
onChangeDataViewId={(newDataViewId) => {
stateManager.dataViewId.next(newDataViewId);
setSelectedControlType(undefined);
}}
trigger={{
label:
Expand Down Expand Up @@ -300,7 +310,15 @@ export const DataControlEditor = ({
<EuiFormRow
label={DataControlEditorStrings.manageControl.dataSource.getControlTypeTitle()}
>
{CompatibleControlTypesComponent}
{/* wrapping in `div` so that focus gets passed properly to the form row */}
<div>
<CompatibleControlTypesComponent
fieldRegistry={fieldRegistry}
selectedFieldName={selectedFieldName}
selectedControlType={selectedControlType}
setSelectedControlType={setSelectedControlType}
/>
</div>
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
{{~/if~}}

{{~#if $ref~}}
{{referenceName}}Input
{{referenceName}}
{{~#if (isCircularRef $ref)}}Input{{/if~}}
{{~#if nullable}} | null {{/if~}}
{{~/if~}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ export * from './knowledge_base/bulk_crud_knowledge_base_route.gen';
export * from './knowledge_base/common_attributes.gen';
export * from './knowledge_base/crud_knowledge_base_route.gen';
export * from './knowledge_base/find_knowledge_base_entries_route.gen';

export * from './prompts/find_prompts_route.gen';
export { PromptResponse, PromptTypeEnum } from './prompts/bulk_crud_prompts_route.gen';
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const PromptDetailsInError = z.object({
name: z.string().optional(),
});

/**
* Prompt type
*/
export type PromptType = z.infer<typeof PromptType>;
export const PromptType = z.enum(['system', 'quick']);
export type PromptTypeEnum = typeof PromptType.enum;
export const PromptTypeEnum = PromptType.enum;

export type NormalizedPromptError = z.infer<typeof NormalizedPromptError>;
export const NormalizedPromptError = z.object({
message: z.string(),
Expand All @@ -47,11 +55,13 @@ export const PromptResponse = z.object({
id: NonEmptyString,
timestamp: NonEmptyString.optional(),
name: z.string(),
promptType: z.string(),
promptType: PromptType,
content: z.string(),
categories: z.array(z.string()).optional(),
color: z.string().optional(),
isNewConversationDefault: z.boolean().optional(),
isDefault: z.boolean().optional(),
isShared: z.boolean().optional(),
consumer: z.string().optional(),
updatedAt: z.string().optional(),
updatedBy: z.string().optional(),
createdAt: z.string().optional(),
Expand Down Expand Up @@ -107,20 +117,24 @@ export const BulkActionBase = z.object({
export type PromptCreateProps = z.infer<typeof PromptCreateProps>;
export const PromptCreateProps = z.object({
name: z.string(),
promptType: z.string(),
promptType: PromptType,
content: z.string(),
color: z.string().optional(),
categories: z.array(z.string()).optional(),
isNewConversationDefault: z.boolean().optional(),
isDefault: z.boolean().optional(),
isShared: z.boolean().optional(),
consumer: z.string().optional(),
});

export type PromptUpdateProps = z.infer<typeof PromptUpdateProps>;
export const PromptUpdateProps = z.object({
id: z.string(),
content: z.string().optional(),
color: z.string().optional(),
categories: z.array(z.string()).optional(),
isNewConversationDefault: z.boolean().optional(),
isDefault: z.boolean().optional(),
isShared: z.boolean().optional(),
consumer: z.string().optional(),
});

export type PerformBulkActionRequestBody = z.infer<typeof PerformBulkActionRequestBody>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ components:
required:
- id

PromptType:
type: string
description: Prompt type
enum:
- system
- quick

NormalizedPromptError:
type: object
properties:
Expand Down Expand Up @@ -111,15 +118,21 @@ components:
name:
type: string
promptType:
type: string
$ref: '#/components/schemas/PromptType'
content:
type: string
categories:
type: array
items:
type: string
color:
type: string
isNewConversationDefault:
type: boolean
isDefault:
type: boolean
isShared:
type: boolean
consumer:
type: string
updatedAt:
type: string
updatedBy:
Expand Down Expand Up @@ -231,15 +244,21 @@ components:
name:
type: string
promptType:
type: string
$ref: '#/components/schemas/PromptType'
content:
type: string
color:
type: string
categories:
type: array
items:
type: string
isNewConversationDefault:
type: boolean
isDefault:
type: boolean
isShared:
type: boolean
consumer:
type: string

PromptUpdateProps:
type: object
Expand All @@ -250,9 +269,15 @@ components:
type: string
content:
type: string
color:
type: string
categories:
type: array
items:
type: string
isNewConversationDefault:
type: boolean
isDefault:
type: boolean
isShared:
type: boolean
consumer:
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { API_ERROR } from '../translations';
import { getOptionalRequestParams } from '../helpers';
import { TraceOptions } from '../types';
export * from './conversations';
export * from './prompts';

export interface FetchConnectorExecuteAction {
conversationId: string;
Expand Down
Loading

0 comments on commit 6f68bcd

Please sign in to comment.