Skip to content

Commit

Permalink
[Enterprise Search] Tech debt/cleanup: remove I/E/T Typescript prefix…
Browse files Browse the repository at this point in the history
…es (#83099)

* [All] Remove prefixes on simple self-contained type defs

- Types should not be exported
- Types should not be used outside each affected file

* [All][kea] Remove ts prefixes and unnecessary exports

Kea now takes care of type checking for us, so there should virtually never be a need to export our values and actions interfaces going forward

* [shared] Remove createHref type prefixes

* [shared] Remove breadcrumb prefixes

* [shared] Remove telemetry prefixes

* [shared] remove types.ts

Opionionated change: it was only being used for IFlashMessage, and at this point I think it's more useful to go in one level deeper to grab the type you need

* [server] remove route dependencies prefixes

* [server] Various type cleanups

- plugin.ts - remove unnecessary export
- MockRouter - remove prefix for request type, change IMockRouter to match Kibana's IRouter
- check_access - remove prefixes
- callEnterpriseSearchConfigAPI - remove prefixes
- EnterpriseSearchRequestHandler - remove prefixes

* [common] Remove InitialAppData prefix

+ remove unnecessary export from public/plugin.ts

* [common] Remove Meta prefixes

* [common] Remove configured limits prefixes

* [AS] Remove Account and Role prefixes

* [AS] Remove Engine prefixes

* [AS] Remove credentials prefixes

* [AS] Remove log settings prefixes

* [WS] Remove account/organization/initial data prefixes

* [WS] Remove group(s), user, & content source prefixes

+ GroupLogic and GroupsLogic refactor - remove unnecessary defs in actions, it's already defined in the Actions interface above and in some cases (e.g. old History param) is causing out of date issues

* [WS] Misc type fixes

- TSpacerSize -> SpaceSizeTypes
- SourcePriority - remove prefixes
- IComponentLoader - this isn't used anywhere else and appears to be component props so it probably should live only within component_loader.tsx
- Remove recent feed activity prefix

* [WS][Opinionated] Move interfaces not used in server/ out of common/ and to public/

* Fix recently rebased types
  • Loading branch information
Constance authored Nov 10, 2020
1 parent 5dde31a commit 2d5de2b
Show file tree
Hide file tree
Showing 120 changed files with 618 additions and 646 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/enterprise_search/common/types/app_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export interface IAccount {
export interface Account {
accountId: string;
onboardingComplete: boolean;
role: {
Expand All @@ -21,7 +21,7 @@ export interface IAccount {
};
}

export interface IConfiguredLimits {
export interface ConfiguredLimits {
engine: {
maxDocumentByteSize: number;
maxEnginesPerMetaEngine: number;
Expand Down
28 changes: 14 additions & 14 deletions x-pack/plugins/enterprise_search/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,39 @@
*/

import {
IAccount as IAppSearchAccount,
IConfiguredLimits as IAppSearchConfiguredLimits,
Account as AppSearchAccount,
ConfiguredLimits as AppSearchConfiguredLimits,
} from './app_search';
import {
IWorkplaceSearchInitialData,
IConfiguredLimits as IWorkplaceSearchConfiguredLimits,
WorkplaceSearchInitialData,
ConfiguredLimits as WorkplaceSearchConfiguredLimits,
} from './workplace_search';

export interface IInitialAppData {
export interface InitialAppData {
readOnlyMode?: boolean;
ilmEnabled?: boolean;
isFederatedAuth?: boolean;
configuredLimits?: IConfiguredLimits;
configuredLimits?: ConfiguredLimits;
access?: {
hasAppSearchAccess: boolean;
hasWorkplaceSearchAccess: boolean;
};
appSearch?: IAppSearchAccount;
workplaceSearch?: IWorkplaceSearchInitialData;
appSearch?: AppSearchAccount;
workplaceSearch?: WorkplaceSearchInitialData;
}

export interface IConfiguredLimits {
appSearch: IAppSearchConfiguredLimits;
workplaceSearch: IWorkplaceSearchConfiguredLimits;
export interface ConfiguredLimits {
appSearch: AppSearchConfiguredLimits;
workplaceSearch: WorkplaceSearchConfiguredLimits;
}

export interface IMetaPage {
export interface MetaPage {
current: number;
size: number;
total_pages: number;
total_results: number;
}

export interface IMeta {
page: IMetaPage;
export interface Meta {
page: MetaPage;
}
58 changes: 6 additions & 52 deletions x-pack/plugins/enterprise_search/common/types/workplace_search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export interface IAccount {
export interface Account {
id: string;
groups: string[];
isAdmin: boolean;
Expand All @@ -14,65 +14,19 @@ export interface IAccount {
viewedOnboardingPage: boolean;
}

export interface IOrganization {
export interface Organization {
name: string;
defaultOrgName: string;
}

export interface IWorkplaceSearchInitialData {
organization: IOrganization;
account: IAccount;
export interface WorkplaceSearchInitialData {
organization: Organization;
account: Account;
}

export interface IConfiguredLimits {
export interface ConfiguredLimits {
customApiSource: {
maxDocumentByteSize: number;
totalFields: number;
};
}

export interface IGroup {
id: string;
name: string;
createdAt: string;
updatedAt: string;
contentSources: IContentSource[];
users: IUser[];
usersCount: number;
color?: string;
}

export interface IGroupDetails extends IGroup {
contentSources: IContentSourceDetails[];
canEditGroup: boolean;
canDeleteGroup: boolean;
}

export interface IUser {
id: string;
name: string | null;
initials: string;
pictureUrl: string | null;
color: string;
email: string;
role?: string;
groupIds: string[];
}

export interface IContentSource {
id: string;
serviceType: string;
name: string;
}

export interface IContentSourceDetails extends IContentSource {
status: string;
statusMessage: string;
documentCount: string;
isFederatedSource: boolean;
searchable: boolean;
supportedByLicense: boolean;
errorReason: number;
allowsReauth: boolean;
boost: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { mountWithIntl } from './';
* const wrapper = mountAsync(<Component />);
*/

interface IOptions {
interface Options {
i18n?: boolean;
}

export const mountAsync = async (
children: React.ReactElement,
options: IOptions
options: Options
): Promise<ReactWrapper> => {
let wrapper: ReactWrapper | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@

import { kea, MakeLogicType } from 'kea';

import { IInitialAppData } from '../../../common/types';
import { IConfiguredLimits, IAccount, IRole } from './types';
import { InitialAppData } from '../../../common/types';
import { ConfiguredLimits, Account, Role } from './types';

import { getRoleAbilities } from './utils/role';

export interface IAppValues {
interface AppValues {
hasInitialized: boolean;
ilmEnabled: boolean;
configuredLimits: Partial<IConfiguredLimits>;
account: Partial<IAccount>;
myRole: Partial<IRole>;
configuredLimits: Partial<ConfiguredLimits>;
account: Partial<Account>;
myRole: Partial<Role>;
}
export interface IAppActions {
initializeAppData(props: IInitialAppData): Required<IInitialAppData>;
interface AppActions {
initializeAppData(props: InitialAppData): Required<InitialAppData>;
setOnboardingComplete(): boolean;
}

export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
export const AppLogic = kea<MakeLogicType<AppValues, AppActions>>({
path: ['enterprise_search', 'app_search', 'app_logic'],
actions: {
initializeAppData: (props) => props,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiCheckbox, EuiText, EuiTitle, EuiSpacer, EuiPanel } from '@elastic/eu
import { i18n } from '@kbn/i18n';

import { CredentialsLogic } from '../../credentials_logic';
import { ITokenReadWrite } from '../../types';
import { TokenReadWrite } from '../../types';

export const FormKeyReadWriteAccess: React.FC = () => {
const { setTokenReadWrite } = useActions(CredentialsLogic);
Expand All @@ -37,7 +37,7 @@ export const FormKeyReadWriteAccess: React.FC = () => {
name="read"
id="read"
checked={activeApiToken.read}
onChange={(e) => setTokenReadWrite(e.target as ITokenReadWrite)}
onChange={(e) => setTokenReadWrite(e.target as TokenReadWrite)}
label={i18n.translate(
'xpack.enterpriseSearch.appSearch.credentials.formReadWrite.readLabel',
{ defaultMessage: 'Read Access' }
Expand All @@ -47,7 +47,7 @@ export const FormKeyReadWriteAccess: React.FC = () => {
name="write"
id="write"
checked={activeApiToken.write}
onChange={(e) => setTokenReadWrite(e.target as ITokenReadWrite)}
onChange={(e) => setTokenReadWrite(e.target as TokenReadWrite)}
label={i18n.translate(
'xpack.enterpriseSearch.appSearch.credentials.formReadWrite.writeLabel',
{ defaultMessage: 'Write Access' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { shallow } from 'enzyme';
import { EuiFlyoutHeader } from '@elastic/eui';

import { ApiTokenTypes } from '../constants';
import { IApiToken } from '../types';
import { ApiToken } from '../types';

import { CredentialsFlyoutHeader } from './header';

describe('CredentialsFlyoutHeader', () => {
const apiToken: IApiToken = {
const apiToken: ApiToken = {
name: '',
type: ApiTokenTypes.Private,
read: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import React from 'react';
import { shallow } from 'enzyme';
import { EuiBasicTable, EuiCopy, EuiEmptyPrompt } from '@elastic/eui';

import { IApiToken } from '../types';
import { ApiToken } from '../types';
import { ApiTokenTypes } from '../constants';

import { HiddenText } from '../../../../shared/hidden_text';
import { Key } from './key';
import { CredentialsList } from './credentials_list';

describe('Credentials', () => {
const apiToken: IApiToken = {
const apiToken: ApiToken = {
name: '',
type: ApiTokenTypes.Private,
read: true,
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('Credentials', () => {
});
const wrapper = shallow(<CredentialsList />);
const { items } = wrapper.find(EuiBasicTable).props();
expect(items.map((i: IApiToken) => i.id)).toEqual([undefined, 1, 2]);
expect(items.map((i: ApiToken) => i.id)).toEqual([undefined, 1, 2]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';
import { CredentialsLogic } from '../credentials_logic';
import { Key } from './key';
import { HiddenText } from '../../../../shared/hidden_text';
import { IApiToken } from '../types';
import { ApiToken } from '../types';
import { TOKEN_TYPE_DISPLAY_NAMES } from '../constants';
import { apiTokenSort } from '../utils/api_token_sort';
import { getModeDisplayText, getEnginesDisplayText } from '../utils';
Expand All @@ -26,21 +26,21 @@ export const CredentialsList: React.FC = () => {

const items = useMemo(() => apiTokens.slice().sort(apiTokenSort), [apiTokens]);

const columns: Array<EuiBasicTableColumn<IApiToken>> = [
const columns: Array<EuiBasicTableColumn<ApiToken>> = [
{
name: 'Name',
width: '12%',
render: (token: IApiToken) => token.name,
render: (token: ApiToken) => token.name,
},
{
name: 'Type',
width: '15%',
render: (token: IApiToken) => TOKEN_TYPE_DISPLAY_NAMES[token.type],
render: (token: ApiToken) => TOKEN_TYPE_DISPLAY_NAMES[token.type],
},
{
name: 'Key',
width: '36%',
render: (token: IApiToken) => {
render: (token: ApiToken) => {
const { key } = token;
if (!key) return null;
return (
Expand All @@ -64,12 +64,12 @@ export const CredentialsList: React.FC = () => {
{
name: 'Modes',
width: '10%',
render: (token: IApiToken) => getModeDisplayText(token),
render: (token: ApiToken) => getModeDisplayText(token),
},
{
name: 'Engines',
width: '18%',
render: (token: IApiToken) => getEnginesDisplayText(token),
render: (token: ApiToken) => getEnginesDisplayText(token),
},
{
actions: [
Expand All @@ -83,7 +83,7 @@ export const CredentialsList: React.FC = () => {
type: 'icon',
icon: 'pencil',
color: 'primary',
onClick: (token: IApiToken) => showCredentialsForm(token),
onClick: (token: ApiToken) => showCredentialsForm(token),
},
{
name: i18n.translate('xpack.enterpriseSearch.actions.delete', {
Expand All @@ -95,7 +95,7 @@ export const CredentialsList: React.FC = () => {
type: 'icon',
icon: 'trash',
color: 'danger',
onClick: (token: IApiToken) => deleteApiKey(token.name),
onClick: (token: ApiToken) => deleteApiKey(token.name),
},
],
},
Expand All @@ -108,7 +108,7 @@ export const CredentialsList: React.FC = () => {
hidePerPageOptions: true,
};

const onTableChange = ({ page }: CriteriaWithPagination<IApiToken>) => {
const onTableChange = ({ page }: CriteriaWithPagination<ApiToken>) => {
const { index: current } = page;
fetchCredentials(current + 1);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import React from 'react';
import { EuiButtonIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

interface IProps {
interface Props {
copy: () => void;
toggleIsHidden: () => void;
isHidden: boolean;
text: React.ReactNode;
}

export const Key: React.FC<IProps> = ({ copy, toggleIsHidden, isHidden, text }) => {
export const Key: React.FC<Props> = ({ copy, toggleIsHidden, isHidden, text }) => {
const hideIcon = isHidden ? 'eye' : 'eyeClosed';
const hideIconLabel = isHidden
? i18n.translate('xpack.enterpriseSearch.appSearch.credentials.showApiKey', {
Expand Down
Loading

0 comments on commit 2d5de2b

Please sign in to comment.