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

Chore: Prune Messages contextualBar rewrite #25757

Merged
merged 2 commits into from
Jun 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export const Default = Template.bind({});

export const WithCallout = Template.bind({});
WithCallout.args = {
pinned: true,
values: { pinned: true },
callOutText: 'This is a callout',
};
Original file line number Diff line number Diff line change
@@ -1,36 +1,51 @@
import { IUser } from '@rocket.chat/core-typings';
import { Field, ButtonGroup, Button, CheckBox, Callout } from '@rocket.chat/fuselage';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import { useTranslation } from '@rocket.chat/ui-contexts';
import React from 'react';
import React, { ReactElement } from 'react';

import UserAutoCompleteMultiple from '../../../../components/UserAutoCompleteMultiple';
import VerticalBar from '../../../../components/VerticalBar';
import DateTimeRow from './DateTimeRow';
import PruneMessagesDateTimeRow from './PruneMessagesDateTimeRow';
import { initialValues } from './PruneMessagesWithData';

type PruneMessagesProps = {
callOutText?: string;
validateText?: string;
users: IUser['username'][];
values: Record<string, unknown>;
handlers: Record<string, (eventOrValue: unknown) => void>;
onClickClose: () => void;
onClickPrune: () => void;
onChangeUsers: (value: IUser['username'], action?: string) => void;
};

const PruneMessages = ({
callOutText,
validateText,
newerDateTime,
handleNewerDateTime,
olderDateTime,
handleOlderDateTime,
users,
inclusive,
pinned,
discussion,
threads,
attached,
handleInclusive,
handlePinned,
handleDiscussion,
handleThreads,
handleAttached,
values,
handlers,
onClickClose,
onClickPrune,
onChangeUsers,
}) => {
}: PruneMessagesProps): ReactElement => {
const t = useTranslation();

const { newerDate, newerTime, olderDate, olderTime, users, inclusive, pinned, discussion, threads, attached } =
values as typeof initialValues;

const {
handleNewerDate,
handleNewerTime,
handleOlderDate,
handleOlderTime,
handleInclusive,
handlePinned,
handleDiscussion,
handleThreads,
handleAttached,
} = handlers;

const inclusiveCheckboxId = useUniqueId();
const pinnedCheckboxId = useUniqueId();
const discussionCheckboxId = useUniqueId();
Expand All @@ -45,55 +60,56 @@ const PruneMessages = ({
{onClickClose && <VerticalBar.Close onClick={onClickClose} />}
</VerticalBar.Header>
<VerticalBar.ScrollableContent>
<DateTimeRow label={t('Newer_than')} dateTime={newerDateTime} handleDateTime={handleNewerDateTime} />
<DateTimeRow label={t('Older_than')} dateTime={olderDateTime} handleDateTime={handleOlderDateTime} />

<PruneMessagesDateTimeRow
label={t('Newer_than')}
dateTime={{ date: newerDate, time: newerTime }}
handleDateTime={{ date: handleNewerDate, time: handleNewerTime }}
/>
<PruneMessagesDateTimeRow
label={t('Older_than')}
dateTime={{ date: olderDate, time: olderTime }}
handleDateTime={{ date: handleOlderDate, time: handleOlderTime }}
/>
<Field>
<Field.Label flexGrow={0}>{t('Only_from_users')}</Field.Label>
<UserAutoCompleteMultiple value={users} onChange={onChangeUsers} placeholder={t('Please_enter_usernames')} />
</Field>

<Field>
<Field.Row>
<CheckBox id={inclusiveCheckboxId} checked={inclusive} onChange={handleInclusive} />
<Field.Label htmlFor={inclusiveCheckboxId}>{t('Inclusive')}</Field.Label>
</Field.Row>
</Field>

<Field>
<Field.Row>
<CheckBox id={pinnedCheckboxId} checked={pinned} onChange={handlePinned} />
<Field.Label htmlFor={pinnedCheckboxId}>{t('RetentionPolicy_DoNotPrunePinned')}</Field.Label>
</Field.Row>
</Field>

<Field>
<Field.Row>
<CheckBox id={discussionCheckboxId} checked={discussion} onChange={handleDiscussion} />
<Field.Label htmlFor={discussionCheckboxId}>{t('RetentionPolicy_DoNotPruneDiscussion')}</Field.Label>
</Field.Row>
</Field>

<Field>
<Field.Row>
<CheckBox id={threadsCheckboxId} checked={threads} onChange={handleThreads} />
<Field.Label htmlFor={threadsCheckboxId}>{t('RetentionPolicy_DoNotPruneThreads')}</Field.Label>
</Field.Row>
</Field>

<Field>
<Field.Row>
<CheckBox id={attachedCheckboxId} checked={attached} onChange={handleAttached} />
<Field.Label htmlFor={attachedCheckboxId}>{t('Files_only')}</Field.Label>
</Field.Row>
</Field>

{callOutText && !validateText && <Callout type='warning'>{callOutText}</Callout>}
{validateText && <Callout type='warning'>{validateText}</Callout>}
</VerticalBar.ScrollableContent>
<VerticalBar.Footer>
<ButtonGroup stretch>
<Button primary danger disabled={validateText && true} onClick={onClickPrune}>
<Button primary danger disabled={Boolean(validateText)} onClick={onClickPrune}>
{t('Prune')}
</Button>
</ButtonGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { Field, InputBox, Box, Margins } from '@rocket.chat/fuselage';
import React from 'react';
import React, { ReactElement } from 'react';

const DateTimeRow = ({ label, dateTime, handleDateTime }) => (
type PruneMessagesDateTimeRowProps = {
label: string;
dateTime: {
date: string;
time: string;
};
handleDateTime: {
date: (eventOrValue: unknown) => void;
time: (eventOrValue: unknown) => void;
};
};

const PruneMessagesDateTimeRow = ({ label, dateTime, handleDateTime }: PruneMessagesDateTimeRowProps): ReactElement => (
<Field>
<Field.Label flexGrow={0}>{label}</Field.Label>
<Box display='flex' mi='neg-x4'>
Expand All @@ -13,4 +25,4 @@ const DateTimeRow = ({ label, dateTime, handleDateTime }) => (
</Field>
);

export default DateTimeRow;
export default PruneMessagesDateTimeRow;
Loading