The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/client/components/SortList.js

138 lines
5.6 KiB

import React, { useCallback } from 'react';
import { Icon, ToggleSwitch, RadioButton, Box, Flex, Margins, CheckBox, Divider } from '@rocket.chat/fuselage';
import { useTranslation } from '../contexts/TranslationContext';
import { useUserPreference } from '../contexts/UserContext';
import { useMethod } from '../contexts/ServerContext';
import { useSetting } from '../contexts/SettingsContext';
function SortListItem({ text, icon, input }) {
return <Flex.Container>
<Box is='li'>
<Flex.Container>
[IMPROVE] New sidebar layout (#19089) * wip * wip * more work in progress * lint * Fix IE11 support livechat widget * More wip * lint * Add correct buttons and fix some errors * fix import * Fix error with empty department agents * fix title and tags * more fixes * fix agents save * Fix agentlist not saving * First Review * update fuselage * Sidebar variations * Fix Stories * Sidebar Header * Initial data * Fix paddings * sidebar search * Wip Chats * Added more logic * Fix Memo * Virtual List * switch to VariableSizeList * Fix Size * Te acalma Gabriel * Badges * Menu actions * Do not group by type option * Highligthed state * Fix menu * Item Skeletons * Search list * Omnichannel to virtualList * Sidebar header * SidebarHeader * Better Ominichannel Context usage * Revome livechat template * Remove discussion Room List * alert and open prop * Menu as renderprop * ReactiveUserPresence * Update components * Update cachedCollection * Fiz discussions * update cachedcolletion * Header color * Fix unread * Presence * Fix presence * Fix Admin * [wip] Search bar * get usernames in subscription * Local an spotlight search * Fix avatar id prop * Fix multi users on search * Livechat RoomMenu * Fix Header in anonymous sessions * Fix sidebar * update base old * Sidebar variations * Fix Stories * Sidebar Header * Initial data * Fix paddings * sidebar search * Wip Chats * Added more logic * Virtual List * Fix Memo * switch to VariableSizeList * Fix Size * Te acalma Gabriel * Badges * Menu actions * Do not group by type option * Highligthed state * Item Skeletons * Search list * Fix menu * Omnichannel to virtualList * Sidebar header * SidebarHeader * Better Ominichannel Context usage * Revome livechat template * Remove discussion Room List * alert and open prop * Menu as renderprop * ReactiveUserPresence * Update components * Update cachedCollection * Fiz discussions * update cachedcolletion * Header color * Fix unread * Presence * Fix presence * Fix Admin * [wip] Search bar * get usernames in subscription * Local an spotlight search * Fix avatar id prop * [FIX] Missing "Bio" in user's profile view (#19166) * [FIX] Omnichannel: triggers page not rendering (#19134) * [FIX] VisitorAutoComplete component (#19133) * [FIX] Admin Sidebar overflowing (#19101) * [FIX] Integrations history page not reacting to changes. (#19114) * [FIX] Selecting the same department for multiple units (#19168) * [FIX] Error when editing priority and required description (#19170) * [FIX] Thread view in a channel user haven't joined (#19172) * [FIX] Livechat Appearance label and reset button (#19171) * Refactor: Omnichannel departments (#18920) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> Co-authored-by: Gabriel Henriques <gabriel.henriques@rocket.chat> Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com> * Fix multi users on search * Livechat RoomMenu * Fix Header in anonymous sessions * Fix sidebar * Fix admin user Info * update base old * fix sidebar size * Fix sidebar tests * Lint * Package-lock * package-lock * Fix callback * Removed useless files * Fix LGTM * Isolate userpresence to dont leak react and fuselage * Fix Alert * update fuselage * fix hide modal not closing * Sort by name and activity * Fix reset * Arrow controls (#19239) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> * Fixes * ActionButton * ActionButton[2] * ActionButton [3] * Support anonymous * Open menu by keyboard * Login button for anonymous users * Login button for anonymous users * Update code * ShouldUpdate * Change login Icon, fix badge * Update fuselage * Fix storybook * Fix storybook * Use Style and renamed * wip stories sidebar * Types * wip * Testing IE11 * WIP * Fix Typo * Use Layout colors * Lint * Fix * Remove CallProvider * Remove CallContext Co-authored-by: Martin <martin.schoeler@rocket.chat> Co-authored-by: Gabriel Henriques <gabriel.henriques@rocket.chat> Co-authored-by: Douglas Fabris <deefabris@gmail.com> Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
5 years ago
<Box is='label' className='rc-popover__label' style={{ width: '100%' }}>
<Flex.Item grow={0}>
[IMPROVE] New sidebar layout (#19089) * wip * wip * more work in progress * lint * Fix IE11 support livechat widget * More wip * lint * Add correct buttons and fix some errors * fix import * Fix error with empty department agents * fix title and tags * more fixes * fix agents save * Fix agentlist not saving * First Review * update fuselage * Sidebar variations * Fix Stories * Sidebar Header * Initial data * Fix paddings * sidebar search * Wip Chats * Added more logic * Fix Memo * Virtual List * switch to VariableSizeList * Fix Size * Te acalma Gabriel * Badges * Menu actions * Do not group by type option * Highligthed state * Fix menu * Item Skeletons * Search list * Omnichannel to virtualList * Sidebar header * SidebarHeader * Better Ominichannel Context usage * Revome livechat template * Remove discussion Room List * alert and open prop * Menu as renderprop * ReactiveUserPresence * Update components * Update cachedCollection * Fiz discussions * update cachedcolletion * Header color * Fix unread * Presence * Fix presence * Fix Admin * [wip] Search bar * get usernames in subscription * Local an spotlight search * Fix avatar id prop * Fix multi users on search * Livechat RoomMenu * Fix Header in anonymous sessions * Fix sidebar * update base old * Sidebar variations * Fix Stories * Sidebar Header * Initial data * Fix paddings * sidebar search * Wip Chats * Added more logic * Virtual List * Fix Memo * switch to VariableSizeList * Fix Size * Te acalma Gabriel * Badges * Menu actions * Do not group by type option * Highligthed state * Item Skeletons * Search list * Fix menu * Omnichannel to virtualList * Sidebar header * SidebarHeader * Better Ominichannel Context usage * Revome livechat template * Remove discussion Room List * alert and open prop * Menu as renderprop * ReactiveUserPresence * Update components * Update cachedCollection * Fiz discussions * update cachedcolletion * Header color * Fix unread * Presence * Fix presence * Fix Admin * [wip] Search bar * get usernames in subscription * Local an spotlight search * Fix avatar id prop * [FIX] Missing "Bio" in user's profile view (#19166) * [FIX] Omnichannel: triggers page not rendering (#19134) * [FIX] VisitorAutoComplete component (#19133) * [FIX] Admin Sidebar overflowing (#19101) * [FIX] Integrations history page not reacting to changes. (#19114) * [FIX] Selecting the same department for multiple units (#19168) * [FIX] Error when editing priority and required description (#19170) * [FIX] Thread view in a channel user haven't joined (#19172) * [FIX] Livechat Appearance label and reset button (#19171) * Refactor: Omnichannel departments (#18920) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> Co-authored-by: Gabriel Henriques <gabriel.henriques@rocket.chat> Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com> * Fix multi users on search * Livechat RoomMenu * Fix Header in anonymous sessions * Fix sidebar * Fix admin user Info * update base old * fix sidebar size * Fix sidebar tests * Lint * Package-lock * package-lock * Fix callback * Removed useless files * Fix LGTM * Isolate userpresence to dont leak react and fuselage * Fix Alert * update fuselage * fix hide modal not closing * Sort by name and activity * Fix reset * Arrow controls (#19239) Co-authored-by: Guilherme Gazzo <guilherme@gazzo.xyz> * Fixes * ActionButton * ActionButton[2] * ActionButton [3] * Support anonymous * Open menu by keyboard * Login button for anonymous users * Login button for anonymous users * Update code * ShouldUpdate * Change login Icon, fix badge * Update fuselage * Fix storybook * Fix storybook * Use Style and renamed * wip stories sidebar * Types * wip * Testing IE11 * WIP * Fix Typo * Use Layout colors * Lint * Fix * Remove CallProvider * Remove CallContext Co-authored-by: Martin <martin.schoeler@rocket.chat> Co-authored-by: Gabriel Henriques <gabriel.henriques@rocket.chat> Co-authored-by: Douglas Fabris <deefabris@gmail.com> Co-authored-by: gabriellsh <40830821+gabriellsh@users.noreply.github.com> Co-authored-by: Renato Becker <renato.augusto.becker@gmail.com> Co-authored-by: Tasso Evangelista <tasso.evangelista@rocket.chat>
5 years ago
<Box className='rc-popover__icon'><Icon name={icon} size={20}/></Box>
</Flex.Item>
<Margins inline='x8'>
<Flex.Item grow={1}>
<Box is='span' fontScale='p2'>{text}</Box>
</Flex.Item>
</Margins>
<Flex.Item grow={0}>
{input}
</Flex.Item>
</Box>
</Flex.Container>
</Box>
</Flex.Container>;
}
const style = {
textTransform: 'uppercase',
};
export function SortList() {
return <>
<div className='rc-popover__column'>
<ViewModeList/>
<Divider/>
<SortModeList/>
<Divider/>
<GroupingList/>
</div>
</>;
}
SortList.displayName = 'SortList';
function SortModeList() {
const t = useTranslation();
const saveUserPreferences = useMethod('saveUserPreferences');
const sidebarSortBy = useUserPreference('sidebarSortby', 'activity');
const useHandleChange = (value) => useCallback(() => saveUserPreferences({ sidebarSortby: value }), [value]);
const setToAlphabetical = useHandleChange('alphabetical');
const setToActivity = useHandleChange('activity');
return <>
<Margins block='x8'>
<Box is='p' style={style} fontScale='micro'>{t('Sort_By')}</Box>
</Margins>
<ul className='rc-popover__list'>
<Margins block='x8'>
<SortListItem icon={'sort'} text={t('Alphabetical')} input={<RadioButton name='sidebarSortby' onChange={setToAlphabetical} checked={sidebarSortBy === 'alphabetical'} />} />
<SortListItem icon={'clock'} text={t('Activity')} input={<RadioButton name='sidebarSortby' onChange={setToActivity} checked={sidebarSortBy === 'activity'} />} />
</Margins>
</ul>
</>;
}
function ViewModeList() {
const t = useTranslation();
const saveUserPreferences = useMethod('saveUserPreferences');
const useHandleChange = (value) => useCallback(() => saveUserPreferences({ sidebarViewMode: value }), [value]);
const sidebarViewMode = useUserPreference('sidebarViewMode', 'extended');
const sidebarHideAvatar = useUserPreference('sidebarHideAvatar', false);
const setToExtended = useHandleChange('extended');
const setToMedium = useHandleChange('medium');
const setToCondensed = useHandleChange('condensed');
const handleChangeSidebarHideAvatar = useCallback(() => saveUserPreferences({ sidebarHideAvatar: !sidebarHideAvatar }), [saveUserPreferences, sidebarHideAvatar]);
return <>
<Margins block='x8'>
<Box is='p' style={style} fontScale='micro'>{t('View_mode')}</Box>
</Margins>
<ul className='rc-popover__list'>
<Margins block='x8'>
<SortListItem icon={'th-list'} text={t('Extended')} input={<RadioButton onChange={setToExtended} name='sidebarViewMode' value='extended' checked={sidebarViewMode === 'extended'} />} />
<SortListItem icon={'list'} text={t('Medium')} input={<RadioButton onChange={setToMedium} name='sidebarViewMode' value='medium' checked={sidebarViewMode === 'medium'} />} />
<SortListItem icon={'list-alt'} text={t('Condensed')} input={<RadioButton onChange={setToCondensed} name='sidebarViewMode' value='condensed' checked={sidebarViewMode === 'condensed'} />} />
<SortListItem icon={'user-rounded'} text={t('Hide_Avatars')} input={<ToggleSwitch onChange={handleChangeSidebarHideAvatar} name='sidebarHideAvatar' checked={sidebarHideAvatar} />} />
</Margins>
</ul>
</>;
}
function GroupingList() {
const isDiscussionEnabled = useSetting('Discussion_enabled');
const sidebarShowDiscussion = useUserPreference('sidebarShowDiscussion');
const sidebarGroupByType = useUserPreference('sidebarGroupByType');
const sidebarShowFavorites = useUserPreference('sidebarShowFavorites');
const sidebarShowUnread = useUserPreference('sidebarShowUnread');
const saveUserPreferences = useMethod('saveUserPreferences');
const useHandleChange = (key, value) => useCallback(() => saveUserPreferences({ [key]: value }), [key, value]);
const handleChangeShowDicussion = useHandleChange('sidebarShowDiscussion', !sidebarShowDiscussion);
const handleChangeGroupByType = useHandleChange('sidebarGroupByType', !sidebarGroupByType);
const handleChangeShoFavorite = useHandleChange('sidebarShowFavorites', !sidebarShowFavorites);
const handleChangeShowUnread = useHandleChange('sidebarShowUnread', !sidebarShowUnread);
const t = useTranslation();
return <>
<Margins block='x8'>
<Box is='p' style={style} fontScale='micro'>{t('Group_by')}</Box>
</Margins>
<ul className='rc-popover__list'>
<Margins block='x8'>
{isDiscussionEnabled && <SortListItem icon={'discussion'} text={t('Discussions')} input={<CheckBox onChange={handleChangeShowDicussion} name='sidebarShowDiscussion' checked={sidebarShowDiscussion} />} />}
<SortListItem icon={'group-by-type'} text={t('Type')} input={<CheckBox onChange={handleChangeGroupByType} name='sidebarGroupByType' checked={sidebarGroupByType} />} />
<SortListItem icon={'star'} text={t('Favorites')} input={<CheckBox onChange={handleChangeShoFavorite} name='sidebarShowFavorites' checked={sidebarShowFavorites} />} />
<SortListItem icon={'eye-off'} text={t('Unread_on_top')} input={<CheckBox onChange={handleChangeShowUnread} name='sidebarShowUnread' checked={sidebarShowUnread} />} />
</Margins>
</ul>
</>;
}
export default SortList;