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

Update demo #59

Merged
merged 33 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4891a5d
Update demo -> WIP
erwanMarmelab Jun 7, 2024
0a5fcaf
fix seed and schema definition
adguernier Jun 17, 2024
37cd222
fix login process
adguernier Jun 17, 2024
8f98a40
update demo and fix errors
adguernier Jun 20, 2024
5f92ee1
fix postpone task
adguernier Jun 20, 2024
c1462fd
fix dashboard test
adguernier Jun 20, 2024
b346d7f
fix lists test
adguernier Jun 20, 2024
7d8bb02
remove nb_task and nb_notes, fetch in database instead
adguernier Jun 20, 2024
7fe510c
remove useless change
adguernier Jun 24, 2024
36d7435
fix db-seed ts errors
slax57 Jun 28, 2024
809692d
revert loginPage change
slax57 Jun 28, 2024
247a28f
reintroduce fts
slax57 Jun 28, 2024
4acb363
reintroduce changes from #47
slax57 Jun 28, 2024
5c1059e
reintroduce tags@cs
slax57 Jun 28, 2024
2b3fc21
fix at least 1/3rd of companies for Jane Doe
slax57 Jun 28, 2024
1b27d07
fix React 18 syntax
slax57 Jun 28, 2024
3bf02ea
fix import from react-admin instead of ra-core
slax57 Jun 28, 2024
d4881f2
remove console.log
slax57 Jun 28, 2024
f4e8b6f
remove useless update in Note
slax57 Jun 28, 2024
7a90bab
update changelog to mention removal of useRedirectIfAuthenticated
slax57 Jun 28, 2024
b4ffb95
Merge remote-tracking branch 'origin/main' into update-demo
slax57 Jun 28, 2024
e838caf
fix erroneous deprecation warning about faker.random.number
slax57 Jun 28, 2024
1bfa013
fix Jane Doe sales id
slax57 Jun 28, 2024
3e9476a
fix validateDOMNesting in ContactList
slax57 Jun 28, 2024
9f93ad1
fix company selection in contact create
slax57 Jun 28, 2024
da4d01b
fix contact create should set a status
slax57 Jun 28, 2024
ca39b10
fix nb_contacts and nb_deals in company show
slax57 Jun 28, 2024
5b5f7bc
introduce useNbRelations and fix nb_contacts and nb_deals in company …
slax57 Jun 28, 2024
42a82e1
fix unused import in LoginPage
slax57 Jun 28, 2024
0c1f799
fix adding a new deal note throws a dataProvider error
slax57 Jun 28, 2024
019877e
Merge remote-tracking branch 'origin/main' into update-demo
slax57 Jun 28, 2024
56bae46
fix import from react-query
slax57 Jun 28, 2024
c1a124a
fix e2e tests (slow because of the numerous calls to getManyReference)
slax57 Jun 28, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 3.0.0

- The `<LoginPage>` will no longer automatically redirect to the app if the user is already authenticated.

## 2.3.0

* Update supabase-js dev to match new auth system ([#55](https://github.com/marmelab/ra-supabase/pull/55)) ([Revarh](https://github.com/Revarh))
Expand Down
17 changes: 8 additions & 9 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ describe('Dashboard spec', () => {
cy.visit('/');
login();
cy.findByText('Upcoming Deal Revenue').should('exist');
cy.findByRole('list', { description: 'My Latest Notes' }).within(() => {
cy.findAllByRole('listitem').should('have.length.gt', 0);
});
cy.findByRole('list', { description: 'Hot contacts' }).within(() => {
cy.findAllByRole('listitem').should('have.length.gt', 0);
});
cy.findByRole('list', { description: 'Deals Pipeline' }).within(() => {
cy.findAllByRole('listitem').should('have.length.gt', 0);
});
cy.findByText('My Latest Notes').should('exist');
cy.findByText('Upcoming tasks').should('exist');
cy.findByText('Hot contacts').should('exist');
cy.findByTestId('my-latest-notes')
.find('p')
.should('have.length.gt', 0);
cy.findByTestId('tasks-list').find('li').should('have.length.gt', 0);
cy.findByTestId('hot-contacts').find('li').should('have.length.gt', 0);
});
});
4 changes: 3 additions & 1 deletion cypress/e2e/lists.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Lists', () => {
getPaginationText().then(el => {
const count = parseInt(el.text().split('of')[1].trim());

cy.findByText('Earlier').click();
cy.findByText('Before last month').click();
// Use should here to allow built-in retry as it may take a few ms for the list to update
getPaginationText().should(el => {
const countFiltered = parseInt(el.text().split('of')[1].trim());
Expand Down Expand Up @@ -65,6 +65,8 @@ describe('Lists', () => {
cy.visit('/');
login();
cy.findByText('Contacts').click();
cy.findByRole('button', { name: /rows per page/i }).click();
cy.findByRole('option', { name: '10' }).click();
getPaginationText().then(el => {
const page = parseInt(el.text().split('-')[0].trim());
cy.findByLabelText('Go to page 4').click();
Expand Down
9 changes: 5 additions & 4 deletions packages/demo/db-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ async function main() {
new Date(a.date).valueOf() - new Date(b.date).valueOf()
)
.map(note => {
const relatedContact = persistedContacts.find(
contact => contact.id === note.contact_id
);
return supabase.from('contacts').update({
...persistedContacts.find(
contact => contact.id === note.contact_id
),
...relatedContact,
status: note.status,
});
})
Expand All @@ -107,7 +108,7 @@ async function main() {
});
const { data: persistedDeals, error: errorDeals } = await supabase
.from('deals')
.insert(deals.map(({ nb_notes, id, ...deal }) => deal))
.insert(deals.map(({ id, ...deal }) => deal))
.select();

if (errorDeals) {
Expand Down
3 changes: 1 addition & 2 deletions packages/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="theme-color" content="#000000" />
<link rel="manifest" href="./manifest.json" />
<link rel="shortcut icon" href="./favicon.ico" />
<title>Posters Galore Administration</title>
<title>Atomic CRM</title>
<style>
body {
margin: 0;
Expand Down Expand Up @@ -121,6 +121,5 @@
</div>
</div>
</body>
<script>window.global = window</script>
<script type="module" src="/src/index.tsx"></script>
</html>
9 changes: 5 additions & 4 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.3.0",
"private": true,
"dependencies": {
"@hello-pangea/dnd": "^16.3.0",
"@mui/icons-material": "^5.0.1",
"@mui/material": "^5.0.2",
"@nivo/bar": "^0.80.0",
Expand All @@ -13,10 +14,10 @@
"faker": "~5.4.0",
"lodash": "~4.17.5",
"prop-types": "^15.7.2",
"ra-data-fakerest": "^4.0.0",
"ra-data-fakerest": "^4.16.19",
"ra-supabase": "^2.3.0",
"react": "^18.2.0",
"react-admin": "^4.0.0",
"react-admin": "^4.16.19",
"react-beautiful-dnd": "^13.0.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^3.1.4",
Expand All @@ -29,15 +30,15 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/faker": "^5.1.7",
"@types/faker": "~5.1.7",
"@types/jest": "^26.0.19",
"@types/lodash": "~4.14.168",
"@types/react": "^18.0.0",
"@types/react-beautiful-dnd": "^13.0.0",
"@types/react-dom": "^18.0.0",
"source-map-explorer": "^2.0.0",
"tsx": "^3.12.2",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"web-vitals": "^1.0.1"
},
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ const App = () => (
<Resource name="contacts" {...contacts} />
<Resource name="companies" {...companies} />
<Resource name="tasks" list={ListGuesser} />
<Resource name="sales" list={ListGuesser} />
<Resource
name="sales"
list={ListGuesser}
recordRepresentation={(record: any) =>
`${record.first_name} ${record.last_name}`
}
/>
<Resource name="tags" list={ListGuesser} />
</Admin>
</BrowserRouter>
Expand Down
10 changes: 2 additions & 8 deletions packages/demo/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ const Header = () => {
/>
</Tabs>
</Box>
<Box display="flex">
<LoadingIndicator
sx={{
'& .RaLoadingIndicator-loader': {
marginTop: 2,
},
}}
/>
<Box display="flex" alignItems="center">
<LoadingIndicator />
<UserMenu>
<Logout />
</UserMenu>
Expand Down
38 changes: 18 additions & 20 deletions packages/demo/src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import React, { HtmlHTMLAttributes } from 'react';
import React, { Suspense, HtmlHTMLAttributes } from 'react';
import { CssBaseline, Container } from '@mui/material';
import { CoreLayoutProps } from 'react-admin';
import { CoreLayoutProps, CheckForApplicationUpdate } from 'react-admin';
import { ErrorBoundary } from 'react-error-boundary';

import { Error } from 'react-admin';
import { Error, Loading } from 'react-admin';
import Header from './Header';

const Layout = (props: LayoutProps) => {
const { children } = props;
return (
<>
<CssBaseline />
<Header />
<Container sx={{ maxWidth: { xl: 1280 } }}>
<main id="main-content">
{/* @ts-ignore */}
<ErrorBoundary FallbackComponent={Error}>
{children}
</ErrorBoundary>
</main>
</Container>
</>
);
};
const Layout = ({ children }: LayoutProps) => (
<>
<CssBaseline />
<Header />
<Container sx={{ maxWidth: { xl: 1280 } }}>
<main id="main-content">
{/* @ts-ignore */}
<ErrorBoundary FallbackComponent={Error}>
<Suspense fallback={<Loading />}>{children}</Suspense>
</ErrorBoundary>
</main>
</Container>
<CheckForApplicationUpdate interval={30 * 1000} />
</>
);

export interface LayoutProps
extends CoreLayoutProps,
Expand Down
22 changes: 15 additions & 7 deletions packages/demo/src/companies/CompanyAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,19 @@ export const CompanyAside = ({ link = 'edit' }: CompanyAsideProps) => {

<Box mt={2}>
<Typography variant="body2">
Website: <Link href={record.website}>{record.website}</Link>
<br />
LinkedIn: <Link href={record.linkedIn}>LinkedIn</Link>
{record.website && (
<>
Website:{' '}
<Link href={record.website}>{record.website}</Link>
</>
)}
{record.linkedIn && (
<>
<br />
LinkedIn:{' '}
<Link href={record.linkedIn}>LinkedIn</Link>
</>
)}
</Typography>
</Box>

Expand All @@ -47,7 +57,7 @@ export const CompanyAside = ({ link = 'edit' }: CompanyAsideProps) => {
color="textSecondary"
component="span"
>
Main
Main Address
</Typography>
</Box>

Expand Down Expand Up @@ -86,9 +96,7 @@ export const CompanyAside = ({ link = 'edit' }: CompanyAsideProps) => {
<FunctionField<Sale>
source="last_name"
render={record =>
record
? `${record.first_name} ${record.last_name}`
: ''
`${record.first_name} ${record.last_name}`
}
/>
</ReferenceField>
Expand Down
38 changes: 26 additions & 12 deletions packages/demo/src/companies/CompanyCard.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@
import * as React from 'react';
import { useState } from 'react';
import { Paper, Typography, Link as MuiLink, Box } from '@mui/material';
import { Paper, Typography, Box } from '@mui/material';
import ContactsIcon from '@mui/icons-material/AccountCircle';
import DealIcon from '@mui/icons-material/MonetizationOn';
import { useCreatePath, SelectField, useRecordContext } from 'react-admin';
import { Link } from 'react-router-dom';
import {
useCreatePath,
SelectField,
useRecordContext,
Link,
} from 'react-admin';

import { sectors } from './sectors';
import { CompanyAvatar } from './CompanyAvatar';
import { Company } from '../types';
import { useNbRelations } from '../misc/useNbRelations';

export const CompanyCard = (props: { record?: Company }) => {
const [elevation, setElevation] = useState(1);
const createPath = useCreatePath();
const record = useRecordContext<Company>(props);
const { total: nb_contacts } = useNbRelations({
label: 'Contact',
reference: 'contacts',
target: 'company_id',
record,
});
const { total: nb_deals } = useNbRelations({
label: 'Deal',
reference: 'deals',
target: 'company_id',
record,
});
if (!record) return null;

return (
<MuiLink
component={Link}
<Link
to={createPath({
resource: 'companies',
id: record.id,
Expand Down Expand Up @@ -57,28 +73,26 @@ export const CompanyCard = (props: { record?: Company }) => {
<ContactsIcon color="disabled" sx={{ mr: 1 }} />
<div>
<Typography variant="subtitle2" sx={{ mb: -1 }}>
{record.nb_contacts}
{nb_contacts}
</Typography>
<Typography variant="caption" color="textSecondary">
{record.nb_contacts > 1
? 'contacts'
: 'contact'}
{nb_contacts > 1 ? 'contacts' : 'contact'}
</Typography>
</div>
</Box>
<Box sx={{ display: 'flex', alignItems: 'center' }}>
<DealIcon color="disabled" sx={{ mr: 1 }} />
<div>
<Typography variant="subtitle2" sx={{ mb: -1 }}>
{record.nb_deals}
{nb_deals}
</Typography>
<Typography variant="caption" color="textSecondary">
{record.nb_deals > 1 ? 'deals' : 'deal'}
{nb_deals > 1 ? 'deals' : 'deal'}
</Typography>
</div>
</Box>
</Box>
</Paper>
</MuiLink>
</Link>
);
};
43 changes: 17 additions & 26 deletions packages/demo/src/companies/CompanyEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@ import { CompanyForm } from './CompanyForm';
import { CompanyAside } from './CompanyAside';
import { LogoField } from './LogoField';

export const CompanyEdit = () => {
return (
<Edit
aside={<CompanyAside link="show" />}
actions={false}
redirect="show"
// Remove the fts (full text search) column as it is a generated one
// see https://www.postgresql.org/docs/current/ddl-generated-columns.html
transform={({ fts, ...record }) => record}
>
<Form>
<CardContent>
<Stack direction="row">
<Avatar sx={{ mt: 1 }}>
<LogoField />
</Avatar>
<Box ml={2} flex="1" maxWidth={796}>
<CompanyForm />
</Box>
</Stack>
</CardContent>
<Toolbar />
</Form>
</Edit>
);
};
export const CompanyEdit = () => (
<Edit aside={<CompanyAside link="show" />} actions={false} redirect="show">
<Form>
<CardContent>
<Stack direction="row">
<Avatar sx={{ mt: 1 }}>
<LogoField />
</Avatar>
<Box ml={2} flex="1" maxWidth={796}>
<CompanyForm />
</Box>
</Stack>
</CardContent>
<Toolbar />
</Form>
</Edit>
);
4 changes: 2 additions & 2 deletions packages/demo/src/companies/CompanyListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { sectors } from './sectors';
export const CompanyListFilter = () => {
const { identity } = useGetIdentity();
return (
<Box width="13em" minWidth="13em" order={-1} mr={2} mt={7}>
<FilterLiveSearch source="fts@fts" />
slax57 marked this conversation as resolved.
Show resolved Hide resolved
<Box width="13em" minWidth="13em" order={-1} mr={2} mt={5}>
<FilterLiveSearch source="fts@fts" hiddenLabel />

<FilterList label="Size" icon={<BusinessIcon />}>
{sizes.map(size => (
Expand Down
Loading
Loading