-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #397 from openedx/kiram15/ENT-9164
Adding integrations to the Customer view page
- Loading branch information
Showing
8 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/Configuration/Customers/CustomerDetailView/CustomerIntegrations.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Container } from '@openedx/paragon'; | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import CustomerViewCard from './CustomerViewCard'; | ||
import { formatDate } from '../data/utils'; | ||
import DJANGO_ADMIN_BASE_URL from '../data/constants'; | ||
|
||
const CustomerIntegrations = ({ | ||
slug, activeIntegrations, activeSSO, apiCredentialsEnabled, | ||
}) => { | ||
const { ADMIN_PORTAL_BASE_URL } = getConfig(); | ||
const ssoDateText = ({ sso }) => (`Created ${formatDate(sso?.created)} • Last modified ${formatDate(sso?.modifed)}`); | ||
const configDateText = ({ config }) => (`Created ${formatDate(config?.created)} • Last modified ${formatDate(config?.lastModifiedAt)}`); | ||
|
||
return ( | ||
<Container className="mt-3 pr-6 mb-5"> | ||
{(activeSSO || activeIntegrations || apiCredentialsEnabled) && ( | ||
<div> | ||
<h2 className="pt-4">Associated Integrations</h2> | ||
{activeSSO && activeSSO.map((sso) => ( | ||
<CustomerViewCard | ||
slug={slug} | ||
header="SSO" | ||
title={sso.displayName} | ||
subtext={ssoDateText(sso)} | ||
buttonText="Open in Admin Portal" | ||
buttonLink={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/settings/sso`} | ||
/> | ||
))} | ||
{activeIntegrations && activeIntegrations.map((config) => ( | ||
<CustomerViewCard | ||
slug={slug} | ||
header="Learning platform" | ||
title={config.channelCode[0].toUpperCase() + config.channelCode.substr(1).toLowerCase()} | ||
subtext={configDateText(config)} | ||
buttonText="Open in Admin Portal" | ||
buttonLink={`${ADMIN_PORTAL_BASE_URL}/${slug}/admin/settings/lms`} | ||
/> | ||
))} | ||
{apiCredentialsEnabled && ( | ||
<CustomerViewCard | ||
slug={slug} | ||
header="Integration" | ||
title="API" | ||
buttonText="Open in Django" | ||
buttonLink={`${DJANGO_ADMIN_BASE_URL}/admin/enterprise/enterprisecustomerinvitekey/`} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
CustomerIntegrations.defaultProps = { | ||
slug: null, | ||
activeIntegrations: null, | ||
activeSSO: null, | ||
apiCredentialsEnabled: false, | ||
}; | ||
|
||
CustomerIntegrations.propTypes = { | ||
slug: PropTypes.string, | ||
activeIntegrations: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
channelCode: PropTypes.string, | ||
lastModifiedAt: PropTypes.string, | ||
}), | ||
), | ||
activeSSO: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
created: PropTypes.string, | ||
modified: PropTypes.string, | ||
displayName: PropTypes.string, | ||
}), | ||
), | ||
apiCredentialsEnabled: PropTypes.bool, | ||
}; | ||
|
||
export default CustomerIntegrations; |
43 changes: 43 additions & 0 deletions
43
src/Configuration/Customers/CustomerDetailView/CustomerViewCard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
Button, Card, Hyperlink, | ||
} from '@openedx/paragon'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const CustomerViewCard = ( | ||
{ | ||
header, title, subtext, buttonText, buttonLink, | ||
}, | ||
) => ( | ||
<Card className="mt-4"> | ||
<Card.Section className="pb-0"> | ||
<h6 className="mb-0">{header.toUpperCase()}</h6> | ||
<h3 className="mt-0">{title}</h3> | ||
</Card.Section> | ||
<Card.Section className="pt-0 x-small text-gray-400"> | ||
{subtext && <div>{subtext}</div>} | ||
</Card.Section> | ||
<Card.Footer> | ||
<Button> | ||
<Hyperlink | ||
destination={buttonLink} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
className="text-white" | ||
showLaunchIcon | ||
> | ||
{buttonText} | ||
</Hyperlink> | ||
</Button> | ||
</Card.Footer> | ||
</Card> | ||
); | ||
|
||
CustomerViewCard.propTypes = { | ||
header: PropTypes.string.isRequired, | ||
title: PropTypes.string.isRequired, | ||
subtext: PropTypes.string.isRequired, | ||
buttonText: PropTypes.string.isRequired, | ||
buttonLink: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default CustomerViewCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/Configuration/Customers/CustomerDetailView/tests/CustomerViewIntegrations.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* eslint-disable react/prop-types */ | ||
import { screen, render, waitFor } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
import { formatDate } from '../../data/utils'; | ||
import CustomerIntegrations from '../CustomerIntegrations'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
...jest.requireActual('react-router-dom'), | ||
useParams: () => ({ id: 'test-id' }), | ||
})); | ||
|
||
jest.mock('../../data/utils', () => ({ | ||
formatDate: jest.fn(), | ||
})); | ||
|
||
const mockSSOData = [{ | ||
enterpriseCustomer: '18005882300', | ||
created: '2024-09-15T11:01:04.501365Z', | ||
modified: '2024-09-15T11:01:04.501365Z', | ||
displayName: 'Orange cats rule', | ||
}]; | ||
|
||
const mockIntegratedChannelData = [ | ||
{ | ||
channelCode: 'MOODLE', | ||
enterpriseCustomer: '18005882300', | ||
lastModifiedAt: '2024-09-15T11:01:04.501365Z', | ||
}, | ||
{ | ||
channelCode: 'CANVAS', | ||
enterpriseCustomer: '18005882300', | ||
lastModifiedAt: '2024-09-15T11:01:04.501365Z', | ||
}, | ||
]; | ||
|
||
describe('CustomerViewIntegrations', () => { | ||
it('renders cards', async () => { | ||
formatDate.mockReturnValue('September 15, 2024'); | ||
render( | ||
<IntlProvider locale="en"> | ||
<CustomerIntegrations | ||
slug="marcel-the-shell" | ||
activeIntegrations={mockIntegratedChannelData} | ||
activeSSO={mockSSOData} | ||
apiCredentialsEnabled | ||
/> | ||
</IntlProvider>, | ||
); | ||
await waitFor(() => { | ||
expect(screen.getByText('Associated Integrations')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('SSO')).toBeInTheDocument(); | ||
expect(screen.getByText('Orange cats rule')).toBeInTheDocument(); | ||
expect(screen.getAllByText('Created September 15, 2024 • Last modified September 15, 2024')).toHaveLength(3); | ||
expect(screen.getAllByText('Open in Admin Portal')).toHaveLength(3); | ||
|
||
expect(screen.getAllByText('LEARNING PLATFORM')).toHaveLength(2); | ||
expect(screen.getByText('Moodle')).toBeInTheDocument(); | ||
expect(screen.getByText('Canvas')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('INTEGRATION')).toBeInTheDocument(); | ||
expect(screen.getByText('API')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const DJANGO_ADMIN_BASE_URL = 'https://internal.courses.edx.org'; | ||
|
||
export default DJANGO_ADMIN_BASE_URL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters