Skip to content

Commit

Permalink
more renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Oct 27, 2021
1 parent c2c4093 commit dbe5b2a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const FileDataVisualizerPage: FC = () => {
docLinks,
dataVisualizer,
data: {
indexPatterns: { get: getIndexPattern },
dataViews: { get: getDataView },
},
},
} = useMlKibana();
Expand Down Expand Up @@ -60,7 +60,7 @@ export const FileDataVisualizerPage: FC = () => {
},
canDisplay: async ({ indexPatternId }) => {
try {
const { timeFieldName } = await getIndexPattern(indexPatternId);
const { timeFieldName } = await getDataView(indexPatternId);
return (
isFullLicense() &&
timeFieldName !== undefined &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const IndexDataVisualizerPage: FC = () => {
docLinks,
dataVisualizer,
data: {
indexPatterns: { get: getIndexPattern },
dataViews: { get: getDataView },
},
},
} = useMlKibana();
Expand Down Expand Up @@ -74,7 +74,7 @@ export const IndexDataVisualizerPage: FC = () => {
},
canDisplay: async ({ indexPatternId }) => {
try {
const { timeFieldName } = await getIndexPattern(indexPatternId);
const { timeFieldName } = await getDataView(indexPatternId);
return (
isFullLicense() &&
timeFieldName !== undefined &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { CreateLinkWithUserDefaults } from '../../../components/custom_hooks/use
*/
export function checkViewOrCreateJobs(
moduleId: string,
indexPatternId: string,
dataViewId: string,
createLinkWithUserDefaults: CreateLinkWithUserDefaults,
navigateToPath: NavigateToPath
): Promise<any> {
Expand All @@ -36,7 +36,7 @@ export function checkViewOrCreateJobs(
await navigateToPath(url);
reject();
} else {
await navigateToPath(`/jobs/new_job/recognize?id=${moduleId}&index=${indexPatternId}`);
await navigateToPath(`/jobs/new_job/recognize?id=${moduleId}&index=${dataViewId}`);
reject();
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const PageWrapper: FC<PageProps> = ({ location, deps }) => {
};

const CheckViewOrCreateWrapper: FC<PageProps> = ({ location, deps }) => {
const { id: moduleId, index: indexPatternId }: Record<string, any> = parse(location.search, {
const { id: moduleId, index: dataViewId }: Record<string, any> = parse(location.search, {
sort: false,
});
const { createLinkWithUserDefaults } = useCreateADLinks();
Expand All @@ -78,7 +78,7 @@ const CheckViewOrCreateWrapper: FC<PageProps> = ({ location, deps }) => {
// the single resolver checkViewOrCreateJobs redirects only. so will always reject
useResolver(undefined, undefined, deps.config, deps.dataViewsContract, {
checkViewOrCreateJobs: () =>
checkViewOrCreateJobs(moduleId, indexPatternId, createLinkWithUserDefaults, navigateToPath),
checkViewOrCreateJobs(moduleId, dataViewId, createLinkWithUserDefaults, navigateToPath),
});
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('useResolver', () => {
jest.useRealTimers();
});

it('should accept undefined as indexPatternId and savedSearchId.', async () => {
it('should accept undefined as dataViewId and savedSearchId.', async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useResolver(undefined, undefined, {} as IUiSettingsClient, {} as DataViewsContract, {})
);
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('useResolver', () => {
expect(redirectToJobsManagementPage).toHaveBeenCalledTimes(0);
});

it('should add an error toast and redirect if indexPatternId is an empty string.', async () => {
it('should add an error toast and redirect if dataViewId is an empty string.', async () => {
const { result } = renderHook(() =>
useResolver('', undefined, {} as IUiSettingsClient, {} as DataViewsContract, {})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

import { DataViewsService } from '../../../../../../src/plugins/data_views/common';

export class IndexPatternHandler {
export class DataViewHandler {
constructor(private dataViewService: DataViewsService) {}
// returns a id based on an index pattern name
async getIndexPatternId(indexName: string) {
async getDataViewId(indexName: string) {
const dv = (await this.dataViewService.find(indexName)).find(
({ title }) => title === indexName
);
return dv?.id;
}

async deleteIndexPatternById(indexId: string) {
return await this.dataViewService.delete(indexId);
async deleteDataViewById(dataViewId: string) {
return await this.dataViewService.delete(dataViewId);
}
}
20 changes: 10 additions & 10 deletions x-pack/plugins/ml/server/routes/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
GetAnalyticsMapArgs,
ExtendAnalyticsMapArgs,
} from '../models/data_frame_analytics/types';
import { IndexPatternHandler } from '../models/data_frame_analytics/index_patterns';
import { DataViewHandler } from '../models/data_frame_analytics/index_patterns';
import { AnalyticsManager } from '../models/data_frame_analytics/analytics_manager';
import { validateAnalyticsJob } from '../models/data_frame_analytics/validation';
import { fieldServiceProvider } from '../models/job_service/new_job_caps/field_service';
Expand All @@ -38,14 +38,14 @@ import { getAuthorizationHeader } from '../lib/request_authorization';
import type { MlClient } from '../lib/ml_client';
import type { DataViewsService } from '../../../../../src/plugins/data_views/common';

function getIndexPatternId(dataViewsService: DataViewsService, patternName: string) {
const iph = new IndexPatternHandler(dataViewsService);
return iph.getIndexPatternId(patternName);
function getDataVIewId(dataViewsService: DataViewsService, patternName: string) {
const iph = new DataViewHandler(dataViewsService);
return iph.getDataViewId(patternName);
}

function deleteDestIndexPatternById(dataViewsService: DataViewsService, indexPatternId: string) {
const iph = new IndexPatternHandler(dataViewsService);
return iph.deleteIndexPatternById(indexPatternId);
function deleteDestDataViewById(dataViewsService: DataViewsService, dataViewId: string) {
const iph = new DataViewHandler(dataViewsService);
return iph.deleteDataViewById(dataViewId);
}

function getAnalyticsMap(
Expand Down Expand Up @@ -427,9 +427,9 @@ export function dataFrameAnalyticsRoutes({ router, mlLicense, routeGuard }: Rout
if (destinationIndex && deleteDestIndexPattern) {
try {
const dataViewsService = await getDataViewsService();
const indexPatternId = await getIndexPatternId(dataViewsService, destinationIndex);
if (indexPatternId) {
await deleteDestIndexPatternById(dataViewsService, indexPatternId);
const dataViewId = await getDataVIewId(dataViewsService, destinationIndex);
if (dataViewId) {
await deleteDestDataViewById(dataViewsService, dataViewId);
}
destIndexPatternDeleted.success = true;
} catch (deleteDestIndexPatternError) {
Expand Down

0 comments on commit dbe5b2a

Please sign in to comment.