Skip to content

Commit

Permalink
Implement Code feature control (#35115)
Browse files Browse the repository at this point in the history
* update security api tests

* rough POC to migrate Code to use Feature Controls

* fix tests

* [Code]: Integrate with Feature control

* Rename callWithRequest to callCluster
  • Loading branch information
zfy0701 authored Apr 16, 2019
1 parent e4a8c7a commit ce8a46a
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 388 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/code/public/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export * from './search';
export * from './file';
export * from './structure';
export * from './editor';
export * from './user';
export * from './commit';
export * from './status';
export * from './project_config';
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/code/public/actions/user.ts

This file was deleted.

11 changes: 5 additions & 6 deletions x-pack/plugins/code/public/components/admin_page/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiTab, EuiTabs } from '@elastic/eui';
import { parse as parseQuery } from 'querystring';
import React from 'react';
import { connect } from 'react-redux';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import styled from 'styled-components';
import url from 'url';

import { EuiTab, EuiTabs } from '@elastic/eui';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import { parse as parseQuery } from 'querystring';
import { RouteComponentProps, withRouter } from 'react-router-dom';

import { Repository } from '../../../model';
import { RootState } from '../../reducers';
import { EmptyProject } from './empty_project';
Expand All @@ -39,7 +40,6 @@ enum AdminTabs {
interface Props extends RouteComponentProps {
repositories: Repository[];
repositoryLoading: boolean;
isAdmin: boolean;
}

interface State {
Expand Down Expand Up @@ -120,7 +120,7 @@ class AdminPage extends React.PureComponent<Props, State> {
const repositoriesCount = this.props.repositories.length;
const showEmpty = repositoriesCount === 0 && !this.props.repositoryLoading;
if (showEmpty) {
return <EmptyProject isAdmin={this.props.isAdmin} />;
return <EmptyProject />;
}
return <ProjectTab />;
}
Expand All @@ -142,7 +142,6 @@ class AdminPage extends React.PureComponent<Props, State> {
const mapStateToProps = (state: RootState) => ({
repositories: state.repository.repositories,
repositoryLoading: state.repository.loading,
isAdmin: state.userProfile.isCodeAdmin,
});

export const Admin = withRouter(connect(mapStateToProps)(AdminPage));
42 changes: 24 additions & 18 deletions x-pack/plugins/code/public/components/admin_page/empty_project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,32 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiButton, EuiFlexGroup, EuiSpacer, EuiText } from '@elastic/eui';
import React from 'react';
import { Link } from 'react-router-dom';

import { EuiButton, EuiFlexGroup, EuiSpacer, EuiText } from '@elastic/eui';
import { uiCapabilities } from 'ui/capabilities';

import { ImportProject } from './import_project';

export const EmptyProject = ({ isAdmin }: { isAdmin: boolean }) => (
<div className="code-projects-tab">
<EuiSpacer size="xl" />
<div className="code-projects-tab__empty_header">
<EuiText>
<h1>You don't have any projects yet</h1>
</EuiText>
<EuiText color="subdued">{isAdmin && <p>Let's import your first one</p>}</EuiText>
export const EmptyProject = () => {
const isAdmin = uiCapabilities.code.admin as boolean;
return (
<div className="code-projects-tab">
<EuiSpacer size="xl" />
<div className="code-projects-tab__empty_header">
<EuiText>
<h1>You don't have any projects yet</h1>
</EuiText>
<EuiText color="subdued">{isAdmin && <p>Let's import your first one</p>}</EuiText>
</div>
{isAdmin && <ImportProject />}
<EuiSpacer />
<EuiFlexGroup justifyContent="center">
<Link to="/setup-guide">
<EuiButton>View the Setup Guide</EuiButton>
</Link>
</EuiFlexGroup>
</div>
{isAdmin && <ImportProject />}
<EuiSpacer />
<EuiFlexGroup justifyContent="center">
<Link to="/setup-guide">
<EuiButton>View the Setup Guide</EuiButton>
</Link>
</EuiFlexGroup>
</div>
);
);
};
10 changes: 5 additions & 5 deletions x-pack/plugins/code/public/components/admin_page/project_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import moment from 'moment';
import React, { ChangeEvent } from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';
import { uiCapabilities } from 'ui/capabilities';

import { Repository } from '../../../model';
import { closeToast, importRepo } from '../../actions';
import { RepoStatus, RootState } from '../../reducers';
Expand Down Expand Up @@ -77,7 +79,6 @@ const sortOptions = [
interface Props {
projects: Repository[];
status: { [key: string]: RepoStatus };
isAdmin: boolean;
importRepo: (repoUrl: string) => void;
importLoading: boolean;
toastMessage?: string;
Expand Down Expand Up @@ -192,7 +193,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
};

public render() {
const { projects, isAdmin, status, toastMessage, showToast, toastType } = this.props;
const { projects, status, toastMessage, showToast, toastType } = this.props;
const projectsCount = projects.length;
const modal = this.state.showImportProjectModal && this.renderImportModal();

Expand All @@ -205,7 +206,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
project={repo}
showStatus={true}
status={status[repo.uri]}
enableManagement={isAdmin}
enableManagement={uiCapabilities.code.admin as boolean}
/>
));

Expand Down Expand Up @@ -243,7 +244,7 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
<EuiFlexItem grow />
<EuiFlexItem grow />
<EuiFlexItem>
{isAdmin && (
{(uiCapabilities.code.admin as boolean) && (
// @ts-ignore
<NewProjectButton onClick={this.openModal} data-test-subj="newProjectButton">
Add New Project
Expand All @@ -270,7 +271,6 @@ class CodeProjectTab extends React.PureComponent<Props, State> {
const mapStateToProps = (state: RootState) => ({
projects: state.repository.repositories,
status: state.status.status,
isAdmin: state.userProfile.isCodeAdmin,
importLoading: state.repository.importLoading,
toastMessage: state.repository.toastMessage,
toastType: state.repository.toastType,
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/code/public/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { setup, SetupState } from './setup';
import { shortcuts, ShortcutsState } from './shortcuts';
import { RepoState, RepoStatus, status, StatusState } from './status';
import { symbol, SymbolState } from './symbol';
import { userProfile, UserProfileState } from './user';

export { RepoState, RepoStatus };

Expand All @@ -30,7 +29,6 @@ export interface RootState {
editor: EditorState;
route: RouteState;
status: StatusState;
userProfile: UserProfileState;
commit: CommitState;
blame: BlameState;
languageServer: LanguageServerState;
Expand All @@ -46,7 +44,6 @@ const reducers = {
search,
route,
status,
userProfile,
commit,
blame,
languageServer,
Expand Down
55 changes: 0 additions & 55 deletions x-pack/plugins/code/public/reducers/user.ts

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/plugins/code/public/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import { watchRootRoute } from './setup';
import { watchRepoCloneSuccess, watchRepoDeleteFinished } from './status';
import { watchLoadStructure } from './structure';
import { watchLoadUserProfile } from './user';

export function* rootSaga() {
yield fork(watchRootRoute);
Expand All @@ -63,7 +62,6 @@ export function* rootSaga() {
yield fork(watchInitRepoCmd);
yield fork(watchGotoRepo);
yield fork(watchLoadRepo);
yield fork(watchLoadUserProfile);
yield fork(watchSearchRouteChange);
yield fork(watchAdminRouteChange);
yield fork(watchMainRouteChange);
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/code/public/sagas/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
indexRepoFailed,
indexRepoSuccess,
initRepoCommand,
loadUserProfile,
updateCloneProgress,
updateDeleteProgress,
updateIndexProgress,
Expand Down Expand Up @@ -171,7 +170,6 @@ export function* watchGotoRepo() {
}

function* handleAdminRouteChange() {
yield put(loadUserProfile());
yield put(fetchRepos());
yield put(fetchRepoConfigs());
yield put(loadLanguageServers());
Expand Down
31 changes: 0 additions & 31 deletions x-pack/plugins/code/public/sagas/user.ts

This file was deleted.

Loading

0 comments on commit ce8a46a

Please sign in to comment.