This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add project list dropdown to chrome
- Loading branch information
1 parent
54970fe
commit 1017ddf
Showing
5 changed files
with
99 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,50 @@ | ||
import List, { Label, Li, ListItemProps, Ul, Value } from '../../lsg/patterns/list'; | ||
import Dropdown from '../../lsg/patterns/dropdown'; | ||
import DropdownItem, { | ||
DropdownItemLinkAttribute, | ||
DropdownItemLinkAttributeItem | ||
} from '../../lsg/patterns/dropdown-item'; | ||
import { IconName } from '../../lsg/patterns/icons'; | ||
import { observer } from 'mobx-react'; | ||
import { PageRef } from '../../store/project/page_ref'; | ||
import { Project } from '../../store/project'; | ||
import * as React from 'react'; | ||
import Space, { Size } from '../../lsg/patterns/space'; | ||
import { Store } from '../../store'; | ||
|
||
export interface ProjectListProps { | ||
store: Store; | ||
visible?: boolean; | ||
} | ||
|
||
@observer | ||
export class ProjectList extends React.Component<ProjectListProps> { | ||
public constructor(props: ProjectListProps) { | ||
super(props); | ||
} | ||
|
||
public render(): JSX.Element { | ||
const items: ListItemProps[] = this.props.store.getProjects().map((project: Project) => ({ | ||
label: 'Project', | ||
value: project.getName(), | ||
children: project.getPages().map((page: PageRef) => ({ | ||
label: 'Page', | ||
value: page.getName(), | ||
children: [], | ||
onClick: (event: React.MouseEvent<HTMLElement>) => { | ||
this.props.store.openPage(page.getId()); | ||
} | ||
})) | ||
})); | ||
|
||
const list = this.createList(items); | ||
|
||
return <List headline="Projects">{list}</List>; | ||
this.handleProjectClick = this.handleProjectClick.bind(this); | ||
} | ||
|
||
public createList(items: ListItemProps[]): JSX.Element { | ||
public render(): JSX.Element { | ||
return ( | ||
<Space sizeLeft={Size.M}> | ||
<Ul> | ||
{items.map((props: ListItemProps, index: number) => { | ||
const labelComponent = props.label ? <Label>{props.label}:</Label> : null; | ||
const nextLevel = props.children ? this.createList(props.children) : null; | ||
|
||
return ( | ||
<Li | ||
handleDragStart={props.handleDragStart} | ||
key={index} | ||
active={props.active} | ||
onClick={props.onClick} | ||
> | ||
{labelComponent} | ||
<Value>{props.value}</Value> | ||
{nextLevel} | ||
</Li> | ||
); | ||
})} | ||
</Ul> | ||
</Space> | ||
<Dropdown chrome visible={this.props.visible}> | ||
{this.props.store.getProjects().map((project: Project, index) => ( | ||
<DropdownItem | ||
name={project.getName()} | ||
key={index} | ||
handleClick={(e: React.MouseEvent<HTMLElement>) => { | ||
e.preventDefault(); | ||
this.handleProjectClick(project.getId()); | ||
}} | ||
> | ||
<DropdownItemLinkAttribute> | ||
<DropdownItemLinkAttributeItem>Edit</DropdownItemLinkAttributeItem> | ||
<DropdownItemLinkAttributeItem>Delete</DropdownItemLinkAttributeItem> | ||
</DropdownItemLinkAttribute> | ||
</DropdownItem> | ||
))} | ||
<DropdownItem name="New project" icon={IconName.Robo} /> | ||
</Dropdown> | ||
); | ||
} | ||
protected handleProjectClick(id: string): void { | ||
this.props.store.openFirstPage(id); | ||
} | ||
} |
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