Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-4852] Limit calendar and agenda display in lists #1444

Merged
merged 2 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions client/components/Agendas/AgendaNameList.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
/* eslint-disable react/no-multi-comp */
import React from 'react';
import PropTypes from 'prop-types';
import {get, sortBy} from 'lodash';
import {gettext} from '../../utils';
import {OverlayTrigger, Tooltip} from 'react-bootstrap';

export const AgendaNameList = ({agendas}) => (
<span>
{get(agendas, 'length', 0) === 0 ? gettext('No Agenda Assigned.') :
sortBy(agendas.filter((a) => a), [(a) => get(a, 'name', '').toLowerCase()])
.map((agenda, index, arr) => {
const className = !agenda.is_enabled ? 'sd-list-item__text--disabled' : '';
export const AgendaNameList = ({agendas}) => {
let tooltipElem = (agendas || []).map((a) =>
<div key={a._id}>{a.name}{!a.is_enabled ? ' (Disabled)' : ''}</div>);

return (
<span key={index} className={className}>
{agenda.name}{arr.length - 1 > index && ', '}
</span>
);
})
return (<span>
{get(agendas, 'length', 0) === 0 ? gettext('No Agenda Assigned.') :
(<OverlayTrigger
placement="left"
overlay={<Tooltip id="agenda_tooltip" className="tooltip--text-left">
{tooltipElem}
</Tooltip>}>
<span>
{sortBy(agendas.filter((a) => a), [(a) => get(a, 'name', '').toLowerCase()])
.map((a, index, arr) => (<span
key={a._id}
className={!a.is_enabled ? 'sd-list-item__text--disabled' : ''}>
{a.name}{index === arr.length - 1 ? '' : ', '}
</span>))}</span>
</OverlayTrigger>)
}
</span>
);
</span>);
};

AgendaNameList.propTypes = {
agendas: PropTypes.array,
Expand Down
8 changes: 4 additions & 4 deletions client/components/fields/agendas.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react';
import React, {Fragment} from 'react';
import PropTypes from 'prop-types';
import {get} from 'lodash';

import {AgendaNameList} from '../Agendas';

export const agendas = ({item, fieldsProps}) => (
<div className="sd-list-item--element-grow">
<Fragment>
<span className="sd-list-item__text-label">Agenda:</span>
<span className="sd-overflow-ellipsis sd-list-item__text-strong">
<span className="sd-overflow-ellipsis sd-list-item__text-strong sd-list-item--element-grow">
<AgendaNameList agendas={get(fieldsProps, 'agendas.agendas')}/>
</span>
</div>
</Fragment>

);

Expand Down
32 changes: 21 additions & 11 deletions client/components/fields/calendars.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
/* eslint-disable react/no-multi-comp */

import React, {Fragment} from 'react';
import PropTypes from 'prop-types';
import {get} from 'lodash';
import {OverlayTrigger, Tooltip} from 'react-bootstrap';

export const calendars = ({item, calendars, grow}) => {
const isCalendarActive = (cal) => (get((calendars || []).find((c) => c.qcode === cal.qcode), 'is_active', false));
let tooltipElem = get(item, 'calendars', []).map((c) =>
<div key={c.qcode}>{c.name}{!isCalendarActive(c) ? ' (Disabled)' : ''}</div>);

return (<div className={classNames({'sd-list-item--element-grow sd-overflow-ellipsis': grow})}>
return (<Fragment>
<span className="sd-list-item__text-label">{gettext('Calendar:')}</span>
{<span className="sd-overflow-ellipsis sd-list-item__text-strong sd-list-item--element-rm-10">
{get(item, 'calendars.length', 0) > 0 && item.calendars.map((c, index, arr) =>
<span key={c.qcode}
className={!isCalendarActive(c) ? 'sd-list-item__text--disabled' : ''}>
{c.name}{arr.length - 1 > index && ', '}
</span>)
}
{get(item, 'calendars.length', 0) > 0 && (<OverlayTrigger
placement="left" overlay={<Tooltip id="location_tooltip" className="tooltip--text-left">
{tooltipElem}
</Tooltip>}>
<span>
{item.calendars.map((c, index, arr) => (
<span
key={c.qcode}
className={!isCalendarActive(c) ? 'sd-list-item__text--disabled' : ''}>
{c.name}{index === arr.length - 1 ? '' : ', '}
</span>
))}</span>
</OverlayTrigger>)}
{get(item, 'calendars.length', 0) === 0 && <span>{gettext('No calendar assigned')}</span>}
</span>}
</div>);
</Fragment>);
};

calendars.propTypes = {
Expand Down