import React, { Component } from 'react'; import { Drawer } from 'olymp-ui'; import { SecondarySidebar } from 'olymp-ui/menu/trio'; import Menu, { StackedMenu } from 'olymp-ui/menu'; import { createComponent } from 'react-fela'; import { FaDatabase, FaTrashO, FaArchive, FaClockO, FaPlus, FaAngleRight, FaChevronLeft } from 'olymp-icons'; import { Image } from 'olymp-cloudinary'; import { get } from 'lodash'; import { Icon } from 'antd'; import { compose, withPropsOnChange, withState } from 'recompose'; import isAfter from 'date-fns/isAfter'; import gql from 'graphql-tag'; import { graphql } from 'react-apollo'; import Calendar from './calendar'; import Table from './table'; import Detail from './detail'; const FlexContainer = createComponent( ({ theme }) => ({ position: 'relative', hasFlex: { display: 'flex', flex: '1 1 0%', flexDirection: 'column' }, '> .rbc-calendar': { padding: theme.space3 }, '> div': { hasFlex: { flex: '1 1 0%' }, height: 'auto !important', overflow: 'auto', '> .rbc-toolbar': { '> .rbc-toolbar-label': { color: theme.color, fontWeight: 200, fontSize: '200%' } } } }), 'div' ); const enhance = compose( withState('keys', 'setKeys', []), graphql( gql` query documentList($type: String, $app: String) { documentList(type: $type, app: $app) { id raw state image { src width height } color event { start end allDay } list { title subtitle } } } `, { options: ({ collection, app }) => ({ variables: { type: collection.name, app } }), props: ({ ownProps, data }) => ({ ...ownProps, loading: data.loading, items: data.documentList || [] }) } ), withPropsOnChange(['items'], ({ items = [] }) => { const startField = null; const endField = null; return { items: startField ? items.map(item => ({ ...item, state: item.state === 'PUBLISHED' && !isAfter(item[endField || startField], new Date()) ? 'EXPIRED' : 'PUBLISHED' })) : items }; }), withPropsOnChange( ['items', 'id', 'keys'], ({ items = [], onClick, id, keys }) => ({ menuItems: items .filter(x => x.state === (keys[0] || 'PUBLISHED')) .map(item => ({ key: item.id, image: item.image, list: item.list, color: item.color, active: item.id === id, onClick: () => onClick(item.id) })) }) ) ); @enhance export default class CollectionView extends Component { renderMenu = () => { const { collection, menuItems, updateQuery, keys, setKeys } = this.props; const isEvent = !!get(collection, 'mapping.event'); return ( ) : ( ) } large extra={ updateQuery({ [`@${collection.name.toLowerCase()}`]: 'new' }) } disabled={!!keys.length} large > } > {collection.label} } > {!!keys.length && ( } onClick={() => setKeys([])}> Zurück )} {!keys.length && !!isEvent && ( } extra={} onClick={() => setKeys(['EXPIRED'])} > Abgelaufen )} {!keys.length && ( } extra={} onClick={() => setKeys(['DRAFT'])} > Archiv )} {!keys.length && ( } extra={} onClick={() => setKeys(['REMOVED'])} > Papierkorb )} {menuItems.map(({ key, list, image, color, active, onClick }) => ( } active={active} large={!!image} > {color ? {list.title} : list.title} {!!list.subtitle && {list.subtitle}} ))} ); }; render() { const { collection, fieldNames, id, refetchQuery, isLoading, keys, items, onClick } = this.props; const isEvent = !!get(collection, 'mapping.event'); const activeItem = items.find(x => x.id === id) || {}; return ( } > {isEvent ? ( ) : ( x.state === (keys[0] || 'PUBLISHED'))} /> )} onClick()}> {collection.label} anlegen ) : ( {get(activeItem, 'list.title')} {collection.label} bearbeiten ) } headerColor headerInverted > ); } }