-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Get submodule names tokens/model/handlers * Fix submodule return * Remove null * Add submodules to UI * Temp spot to get submodule list * Update submodule command * Make submodule display conditional * Move where listSubModules() gets called * Add submodules to model in test * Add doc comments * Have GitPanel manage submodule state * Add/update tests * Add header and style * Fix submodule fetching when update hasn't been run * Change casing for submodules handler * Change casing
- Loading branch information
Showing
12 changed files
with
391 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { nullTranslator } from '@jupyterlab/translation'; | ||
import '@testing-library/jest-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import 'jest'; | ||
import * as React from 'react'; | ||
import { | ||
ISubmoduleMenuProps, | ||
SubmoduleMenu | ||
} from '../../components/SubmoduleMenu'; | ||
import { GitExtension } from '../../model'; | ||
import { IGitExtension } from '../../tokens'; | ||
import { DEFAULT_REPOSITORY_PATH } from '../utils'; | ||
|
||
jest.mock('../../git'); | ||
jest.mock('@jupyterlab/apputils'); | ||
|
||
const SUBMODULES = [ | ||
{ | ||
name: 'cli/bench' | ||
}, | ||
{ | ||
name: 'test/util' | ||
} | ||
]; | ||
|
||
async function createModel() { | ||
const model = new GitExtension(); | ||
model.pathRepository = DEFAULT_REPOSITORY_PATH; | ||
|
||
await model.ready; | ||
return model; | ||
} | ||
|
||
describe('Submodule Menu', () => { | ||
let model: GitExtension; | ||
const trans = nullTranslator.load('jupyterlab_git'); | ||
|
||
beforeEach(async () => { | ||
jest.restoreAllMocks(); | ||
|
||
model = await createModel(); | ||
}); | ||
|
||
function createProps( | ||
props?: Partial<ISubmoduleMenuProps> | ||
): ISubmoduleMenuProps { | ||
return { | ||
model: model as IGitExtension, | ||
trans: trans, | ||
submodules: SUBMODULES, | ||
...props | ||
}; | ||
} | ||
|
||
describe('render', () => { | ||
it('should display a list of submodules', () => { | ||
render(<SubmoduleMenu {...createProps()} />); | ||
|
||
const submodules = SUBMODULES; | ||
expect(screen.getAllByRole('listitem').length).toEqual(submodules.length); | ||
|
||
// Should contain the submodule names... | ||
for (let i = 0; i < submodules.length; i++) { | ||
expect( | ||
screen.getByText(submodules[i].name, { exact: true }) | ||
).toBeDefined(); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { TranslationBundle } from '@jupyterlab/translation'; | ||
import ListItem from '@mui/material/ListItem'; | ||
import * as React from 'react'; | ||
import { FixedSizeList, ListChildComponentProps } from 'react-window'; | ||
import { | ||
listItemClass, | ||
listItemIconClass, | ||
nameClass, | ||
wrapperClass | ||
} from '../style/BranchMenu'; | ||
import { submoduleHeaderStyle } from '../style/SubmoduleMenuStyle'; | ||
import { desktopIcon } from '../style/icons'; | ||
import { Git, IGitExtension } from '../tokens'; | ||
|
||
const ITEM_HEIGHT = 24.8; // HTML element height for a single item | ||
const MIN_HEIGHT = 150; // Minimal HTML element height for the list | ||
const MAX_HEIGHT = 400; // Maximal HTML element height for the list | ||
|
||
/** | ||
* Interface describing component properties. | ||
*/ | ||
export interface ISubmoduleMenuProps { | ||
/** | ||
* Git extension data model. | ||
*/ | ||
model: IGitExtension; | ||
|
||
/** | ||
* The list of submodules in the repo | ||
*/ | ||
submodules: Git.ISubmodule[]; | ||
|
||
/** | ||
* The application language translator. | ||
*/ | ||
trans: TranslationBundle; | ||
} | ||
|
||
/** | ||
* Interface describing component state. | ||
*/ | ||
export interface ISubmoduleMenuState {} | ||
|
||
/** | ||
* React component for rendering a submodule menu. | ||
*/ | ||
export class SubmoduleMenu extends React.Component< | ||
ISubmoduleMenuProps, | ||
ISubmoduleMenuState | ||
> { | ||
/** | ||
* Returns a React component for rendering a submodule menu. | ||
* | ||
* @param props - component properties | ||
* @returns React component | ||
*/ | ||
constructor(props: ISubmoduleMenuProps) { | ||
super(props); | ||
} | ||
|
||
/** | ||
* Renders the component. | ||
* | ||
* @returns React element | ||
*/ | ||
render(): React.ReactElement { | ||
return <div className={wrapperClass}>{this._renderSubmoduleList()}</div>; | ||
} | ||
|
||
/** | ||
* Renders list of submodules. | ||
* | ||
* @returns React element | ||
*/ | ||
private _renderSubmoduleList(): React.ReactElement { | ||
const submodules = this.props.submodules; | ||
|
||
return ( | ||
<> | ||
<div className={submoduleHeaderStyle}>Submodules</div> | ||
<FixedSizeList | ||
height={Math.min( | ||
Math.max(MIN_HEIGHT, submodules.length * ITEM_HEIGHT), | ||
MAX_HEIGHT | ||
)} | ||
itemCount={submodules.length} | ||
itemData={submodules} | ||
itemKey={(index, data) => data[index].name} | ||
itemSize={ITEM_HEIGHT} | ||
style={{ | ||
overflowX: 'hidden', | ||
paddingTop: 0, | ||
paddingBottom: 0 | ||
}} | ||
width={'auto'} | ||
> | ||
{this._renderItem} | ||
</FixedSizeList> | ||
</> | ||
); | ||
} | ||
|
||
/** | ||
* Renders a menu item. | ||
* | ||
* @param props Row properties | ||
* @returns React element | ||
*/ | ||
private _renderItem = (props: ListChildComponentProps): JSX.Element => { | ||
const { data, index, style } = props; | ||
const submodule = data[index] as Git.ISubmodule; | ||
|
||
return ( | ||
<ListItem | ||
title={this.props.trans.__('Submodule: %1', submodule.name)} | ||
className={listItemClass} | ||
role="listitem" | ||
style={style} | ||
> | ||
<desktopIcon.react className={listItemIconClass} tag="span" /> | ||
<span className={nameClass}>{submodule.name}</span> | ||
</ListItem> | ||
); | ||
}; | ||
} |
Oops, something went wrong.