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

refactor: Migrate legal hold dot component to React #10329

Merged
merged 7 commits into from
Jan 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/script/components/LegalHoldDot.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Wire
* Copyright (C) 2021 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

import TestPage from 'Util/test/TestPage';
import LegalHoldDot, {LegalHoldDotProps} from 'Components/LegalHoldDot';
import {LegalHoldModalViewModel} from '../view_model/content/LegalHoldModalViewModel';

class LegalHoldDotPage extends TestPage<LegalHoldDotProps> {
constructor(props?: LegalHoldDotProps) {
super(LegalHoldDot, props);
}

getPendingIcon = () => this.get('svg[data-uie-name="legal-hold-dot-pending-icon"]');
}

describe('LegalHoldDot', () => {
it('shows a pending icon', () => {
const legalHoldModal = {
showRequestModal: () => Promise.resolve(),
showUsers: () => Promise.resolve(),
} as LegalHoldModalViewModel;

const legalHoldDotPage = new LegalHoldDotPage({
isPending: true,
legalHoldModal,
});

const isPending = legalHoldDotPage.getPendingIcon().exists();
expect(isPending).toBe(true);
});
});
66 changes: 66 additions & 0 deletions src/script/components/LegalHoldDot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Wire
* Copyright (C) 2019 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

import React from 'react';
import cx from 'classnames';
import type {Conversation} from '../entity/Conversation';
import type {LegalHoldModalViewModel} from '../view_model/content/LegalHoldModalViewModel';
import NamedIcon from 'Components/NamedIcon';
import {registerReactComponent} from 'Util/ComponentUtil';

export interface LegalHoldDotProps {
conversation?: Conversation;
isPending?: boolean;
large?: boolean;
legalHoldModal?: LegalHoldModalViewModel;
}

const LegalHoldDot: React.FC<LegalHoldDotProps> = ({conversation, isPending, large, legalHoldModal}) => {
const isInteractive = !!legalHoldModal;

return (
<div
className={cx('legal-hold-dot', {
'legal-hold-dot--active': !isPending,
'legal-hold-dot--interactive': isInteractive,
'legal-hold-dot--large': large,
})}
onClick={event => {
event.stopPropagation();
if (isInteractive) {
if (isPending) {
legalHoldModal.showRequestModal(true);
return;
}
legalHoldModal.showUsers(conversation);
}
}}
>
{isPending && <NamedIcon name="pending-icon" data-uie-name="legal-hold-dot-pending-icon" />}
</div>
);
};

export default LegalHoldDot;

registerReactComponent('legal-hold-dot', {
component: LegalHoldDot,
optionalParams: ['conversation', 'isPending', 'large', 'legalHoldModal'],
template: '<div data-bind="react: {conversation, isPending: ko.unwrap(isPending), large, legalHoldModal}"></div>',
});
66 changes: 0 additions & 66 deletions src/script/components/legalHoldDot.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/script/view_model/list/ConversationListViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {Availability} from '@wireapp/protocol-messaging';
import type {WebappProperties} from '@wireapp/api-client/src/user/data';

import 'Components/AvailabilityState';
import 'Components/legalHoldDot';
import 'Components/LegalHoldDot';
import 'Components/list/groupedConversations';
import {AVATAR_SIZE} from 'Components/ParticipantAvatar';
import {getLogger, Logger} from 'Util/Logger';
Expand Down