Skip to content

Commit

Permalink
[ML] Making creation of data view during file upload optional (elasti…
Browse files Browse the repository at this point in the history
…c#210208)

Adds an option override to tell the file uploader not to create a data
view once ingest has finished.
This is currently not used but should be used in the near future when
creating lookup indices from the es|ql query bar.

The PR also contains some typing clean up to remove duplication.


**Before**

![image](https://github.com/user-attachments/assets/232e8c75-c021-4b5a-ac6a-f15ebb753799)

**After**

![image](https://github.com/user-attachments/assets/de583208-410f-4fbf-94f2-a84a8ac6b690)
  • Loading branch information
jgowdyelastic authored Feb 12, 2025
1 parent d34ee93 commit 9fa8ec4
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface OpenFileUploadLiteContext {
onUploadComplete?: (results: FileUploadResults | null) => void;
indexSettings?: IndicesIndexSettings;
autoAddInference?: string;
autoCreateDataView?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class FileManager {
indexCreated: STATUS.NOT_STARTED,
pipelineCreated: STATUS.NOT_STARTED,
modelDeployed: STATUS.NA,
dataViewCreated: STATUS.NA,
dataViewCreated: STATUS.NOT_STARTED,
pipelinesDeleted: STATUS.NOT_STARTED,
fileImport: STATUS.NOT_STARTED,
filesStatus: [],
Expand All @@ -91,6 +91,7 @@ export class FileManager {
private http: HttpSetup,
private dataViewsContract: DataViewsServicePublic,
private autoAddInferenceEndpointName: string | null = null,
private autoCreateDataView: boolean = true,
private removePipelinesAfterImport: boolean = true,
indexSettingsOverride: IndicesIndexSettings | undefined = undefined
) {
Expand Down Expand Up @@ -225,10 +226,7 @@ export class FileManager {
return files.map((file) => file.getPipeline());
}

public async import(
indexName: string,
createDataView: boolean = true
): Promise<FileUploadResults | null> {
public async import(indexName: string): Promise<FileUploadResults | null> {
if (this.mappings === null || this.pipelines === null || this.commonFileFormat === null) {
this.setStatus({
overallImportStatus: STATUS.FAILED,
Expand All @@ -239,6 +237,7 @@ export class FileManager {

this.setStatus({
overallImportStatus: STATUS.STARTED,
dataViewCreated: this.autoCreateDataView ? STATUS.NOT_STARTED : STATUS.NA,
});

this.importer = await this.fileUpload.importerFactory(this.commonFileFormat, {});
Expand Down Expand Up @@ -372,7 +371,7 @@ export class FileManager {

const dataView = '';
let dataViewResp;
if (createDataView) {
if (this.autoCreateDataView) {
this.setStatus({
dataViewCreated: STATUS.STARTED,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Props {
getAdditionalLinks?: GetAdditionalLinks;
setUploadResults?: (results: FileUploadResults) => void;
autoAddInference?: string;
autoCreateDataView?: boolean;
indexSettings?: IndicesIndexSettings;
onClose?: () => void;
}
Expand All @@ -29,6 +30,7 @@ export const FileDataVisualizerLite: FC<Props> = ({
resultLinks,
setUploadResults,
autoAddInference,
autoCreateDataView,
indexSettings,
onClose,
}) => {
Expand Down Expand Up @@ -60,6 +62,7 @@ export const FileDataVisualizerLite: FC<Props> = ({
capabilities={coreStart.application.capabilities}
setUploadResults={setUploadResults}
autoAddInference={autoAddInference}
autoCreateDataView={autoCreateDataView}
indexSettings={indexSettings}
onClose={onClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createOpenFileUploadLiteAction(
async execute({
onUploadComplete,
autoAddInference,
autoCreateDataView,
indexSettings,
}: OpenFileUploadLiteContext) {
try {
Expand All @@ -52,6 +53,7 @@ export function createOpenFileUploadLiteAction(
createFlyout(coreStart, share, data, {
onUploadComplete,
autoAddInference,
autoCreateDataView,
indexSettings,
});
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface Props {
getAdditionalLinks?: GetAdditionalLinks;
setUploadResults?: (results: FileUploadResults) => void;
autoAddInference?: string;
autoCreateDataView?: boolean;
indexSettings?: IndicesIndexSettings;
onClose?: () => void;
}
Expand All @@ -58,6 +59,7 @@ export const FileUploadLiteView: FC<Props> = ({
dataStart,
setUploadResults,
autoAddInference,
autoCreateDataView,
indexSettings,
onClose,
}) => {
Expand All @@ -71,10 +73,11 @@ export const FileUploadLiteView: FC<Props> = ({
http,
dataStart.dataViews,
autoAddInference ?? null,
autoCreateDataView,
true,
indexSettings
),
[autoAddInference, dataStart.dataViews, fileUpload, http, indexSettings]
[autoAddInference, autoCreateDataView, dataStart.dataViews, fileUpload, http, indexSettings]
);
const deleteFile = useCallback((i: number) => fm.removeFile(i), [fm]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@ export const FileDataVisualizerLiteWrapper: FC<{
resultLinks?: ResultLinks;
setUploadResults?: (results: FileUploadResults) => void;
autoAddInference?: string;
autoCreateDataView?: boolean;
indexSettings?: IndicesIndexSettings;
onClose?: () => void;
}> = ({ resultLinks, setUploadResults, autoAddInference, indexSettings, onClose }) => {
}> = ({
resultLinks,
setUploadResults,
autoAddInference,
autoCreateDataView,
indexSettings,
onClose,
}) => {
return (
<React.Suspense fallback={<div />}>
<FileDataVisualizerLiteComponent
resultLinks={resultLinks}
setUploadResults={setUploadResults}
autoAddInference={autoAddInference}
autoCreateDataView={autoCreateDataView}
indexSettings={indexSettings}
onClose={onClose}
/>
Expand All @@ -38,6 +47,7 @@ export function getFileDataVisualizerLiteWrapper(
resultLinks?: ResultLinks,
setUploadResults?: (results: FileUploadResults) => void,
autoAddInference?: string,
autoCreateDataView?: boolean,
indexSettings?: IndicesIndexSettings,
onClose?: () => void
) {
Expand All @@ -46,6 +56,7 @@ export function getFileDataVisualizerLiteWrapper(
resultLinks={resultLinks}
setUploadResults={setUploadResults}
autoAddInference={autoAddInference}
autoCreateDataView={autoCreateDataView}
indexSettings={indexSettings}
onClose={onClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function createFlyout(
});

let results: FileUploadResults | null = null;
const { onUploadComplete, autoAddInference, indexSettings } = props;
const { onUploadComplete, autoAddInference, autoCreateDataView, indexSettings } = props;

const onFlyoutClose = () => {
flyoutSession.close();
Expand All @@ -54,7 +54,7 @@ export function createFlyout(
coreStart={coreStart}
share={share}
data={data}
props={{ autoAddInference, indexSettings }}
props={{ autoAddInference, autoCreateDataView, indexSettings }}
onFlyoutClose={onFlyoutClose}
setUploadResults={(res) => {
if (res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ interface Props {
onClose?: () => void;
setUploadResults?: (results: FileUploadResults) => void;
autoAddInference?: string;
autoCreateDataView?: boolean;
indexSettings?: IndicesIndexSettings;
}

export const FileUploadLiteFlyoutContents: FC<Props> = ({
onClose,
setUploadResults,
autoAddInference,
autoCreateDataView,
indexSettings,
}) => {
const Wrapper = getFileDataVisualizerLiteWrapper(
undefined,
setUploadResults,
autoAddInference,
autoCreateDataView,
indexSettings,
onClose
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const FlyoutContents: FC<Props> = ({
coreStart,
share,
data,
props: { autoAddInference, indexSettings },
props: { autoAddInference, autoCreateDataView, indexSettings },
onFlyoutClose,
setUploadResults,
}) => {
Expand All @@ -41,6 +41,7 @@ export const FlyoutContents: FC<Props> = ({
>
<FileUploadLiteFlyoutContents
autoAddInference={autoAddInference}
autoCreateDataView={autoCreateDataView}
indexSettings={indexSettings}
onClose={() => {
onFlyoutClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ export const OverallUploadStatus: FC<Props> = ({ filesStatus, uploadStatus }) =>
),
status: generateStatus([uploadStatus.fileImport]),
},
{
title: i18n.translate('xpack.dataVisualizer.file.overallUploadStatus.creatingDataView', {
defaultMessage: 'Creating data view',
}),
children: <></>,
status: generateStatus([uploadStatus.dataViewCreated]),
},
...(uploadStatus.dataViewCreated === STATUS.NA
? []
: [
{
title: i18n.translate(
'xpack.dataVisualizer.file.overallUploadStatus.creatingDataView',
{
defaultMessage: 'Creating data view',
}
),
children: <></>,
status: generateStatus([uploadStatus.dataViewCreated]),
},
]),

{
title: i18n.translate('xpack.dataVisualizer.file.overallUploadStatus.uploadComplete', {
defaultMessage: 'Upload complete',
Expand All @@ -96,9 +104,5 @@ export const OverallUploadStatus: FC<Props> = ({ filesStatus, uploadStatus }) =>
},
];

return (
<>
<EuiSteps steps={steps} titleSize="xxs" css={css} />
</>
);
return <EuiSteps steps={steps} titleSize="xxs" css={css} />;
};

0 comments on commit 9fa8ec4

Please sign in to comment.