+export const PROJECT_PANEL_ID = "projectPanel";
+
+interface ProjectPanelDataProps {
+ currentItemId: string;
+ resources: ResourcesState;
+}
+
+type ProjectPanelProps = ProjectPanelDataProps & DispatchProp
+ & WithStyles<CssRules> & RouteComponentProps<{ id: string }>;
+
+export const ProjectPanel = withStyles(styles)(
+ connect((state: RootState) => ({
+ currentItemId: getProperty(PROJECT_PANEL_CURRENT_UUID)(state.properties),
+ resources: state.resources
+ }))(
+ class extends React.Component<ProjectPanelProps> {
+ render() {
+ const { classes } = this.props;
+ return <div className={classes.root}>
+ <div className={classes.toolbar}>
+ <Button color="primary" onClick={this.handleNewCollectionClick} variant="raised" className={classes.button}>
+ New collection
+ </Button>
+ <Button color="primary" variant="raised" className={classes.button}>
+ Run a process
+ </Button>
+ <Button color="primary" onClick={this.handleNewProjectClick} variant="raised" className={classes.button}>
+ New project
+ </Button>
+ </div>
+ {this.hasAnyItems()
+ ? <DataExplorer
+ id={PROJECT_PANEL_ID}
+ onRowClick={this.handleRowClick}
+ onRowDoubleClick={this.handleRowDoubleClick}
+ onContextMenu={this.handleContextMenu}
+ contextMenuColumn={true} />
+ : <DefaultView
+ icon={ProjectIcon}
+ messages={['Your project is empty.', 'Please create a project or create a collection and upload a data.']} />
+ }
+
+ </div>;
+ }
+
+ hasAnyItems = () => {
+ const resources = filterResources(this.isCurrentItemChild)(this.props.resources);
+ return resources.length > 0;
+ }
+
+ isCurrentItemChild = (resource: Resource) => {
+ return resource.ownerUuid === this.props.currentItemId;
+ }
+
+ handleNewProjectClick = () => {
+ this.props.dispatch<any>(openProjectCreateDialog(this.props.currentItemId));
+ }
+
+ handleNewCollectionClick = () => {
+ this.props.dispatch<any>(openCollectionCreateDialog(this.props.currentItemId));
+ }
+
+ handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
+ const menuKind = resourceKindToContextMenuKind(resourceUuid);
+ const resource = getResource<ProjectResource>(resourceUuid)(this.props.resources);
+ if (menuKind && resource) {
+ this.props.dispatch<any>(openContextMenu(event, {
+ name: resource.name,
+ uuid: resource.uuid,
+ ownerUuid: resource.ownerUuid,
+ isTrashed: resource.isTrashed,
+ kind: resource.kind,
+ menuKind
+ }));
+ }
+ }
+
+ handleRowDoubleClick = (uuid: string) => {
+ this.props.dispatch<any>(navigateTo(uuid));
+ }
+
+ handleRowClick = (uuid: string) => {
+ this.props.dispatch(loadDetailsPanel(uuid));
+ }
+
+ }
+ )
+);