2021-03-11 21:29:31 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2021-03-11 21:29:31 +00:00
|
|
|
import { isBoolean } from 'lodash';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
import { storiesOf } from '@storybook/react';
|
|
|
|
import { action } from '@storybook/addon-actions';
|
|
|
|
import { number } from '@storybook/addon-knobs';
|
|
|
|
|
|
|
|
import { setup as setupI18n } from '../../../../js/modules/i18n';
|
|
|
|
import enMessages from '../../../../_locales/en/messages.json';
|
|
|
|
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
|
|
|
|
|
|
|
|
import {
|
|
|
|
ConversationDetailsMembershipList,
|
|
|
|
Props,
|
|
|
|
GroupV2Membership,
|
|
|
|
} from './ConversationDetailsMembershipList';
|
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const story = storiesOf(
|
|
|
|
'Components/Conversation/ConversationDetails/ConversationDetailsMembershipList',
|
|
|
|
module
|
|
|
|
);
|
|
|
|
|
|
|
|
const createMemberships = (
|
|
|
|
numberOfMemberships = 10
|
|
|
|
): Array<GroupV2Membership> => {
|
|
|
|
return Array.from(
|
|
|
|
new Array(number('number of memberships', numberOfMemberships))
|
|
|
|
).map(
|
|
|
|
(_, i): GroupV2Membership => ({
|
|
|
|
isAdmin: i % 3 === 0,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
metadata: {} as any,
|
2021-03-02 16:27:11 +00:00
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: i === 2,
|
|
|
|
}),
|
2021-01-29 21:19:24 +00:00
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const createProps = (overrideProps: Partial<Props>): Props => ({
|
2021-03-11 21:29:31 +00:00
|
|
|
canAddNewMembers: isBoolean(overrideProps.canAddNewMembers)
|
|
|
|
? overrideProps.canAddNewMembers
|
|
|
|
: false,
|
2021-01-29 21:19:24 +00:00
|
|
|
i18n,
|
|
|
|
memberships: overrideProps.memberships || [],
|
2021-03-02 16:27:11 +00:00
|
|
|
showContactModal: action('showContactModal'),
|
2021-03-11 21:29:31 +00:00
|
|
|
startAddingNewMembers: action('startAddingNewMembers'),
|
2021-01-29 21:19:24 +00:00
|
|
|
});
|
|
|
|
|
2021-02-01 22:57:42 +00:00
|
|
|
story.add('Few', () => {
|
|
|
|
const memberships = createMemberships(3);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
const props = createProps({ memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
|
|
|
|
2021-02-01 22:57:42 +00:00
|
|
|
story.add('Limit', () => {
|
|
|
|
const memberships = createMemberships(5);
|
|
|
|
|
|
|
|
const props = createProps({ memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Limit +1', () => {
|
|
|
|
const memberships = createMemberships(6);
|
|
|
|
|
|
|
|
const props = createProps({ memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Limit +2', () => {
|
|
|
|
const memberships = createMemberships(7);
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
const props = createProps({ memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('Many', () => {
|
|
|
|
const memberships = createMemberships(100);
|
|
|
|
|
|
|
|
const props = createProps({ memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
|
|
|
|
|
|
|
story.add('None', () => {
|
|
|
|
const props = createProps({ memberships: [] });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|
2021-03-11 21:29:31 +00:00
|
|
|
|
|
|
|
story.add('Can add new members', () => {
|
|
|
|
const memberships = createMemberships(10);
|
|
|
|
|
|
|
|
const props = createProps({ canAddNewMembers: true, memberships });
|
|
|
|
|
|
|
|
return <ConversationDetailsMembershipList {...props} />;
|
|
|
|
});
|