Skip to content

Commit 4430dad

Browse files
ClemsazertSimonClo
authored andcommitted
💄 revamp db source selector
1 parent fc4ad24 commit 4430dad

File tree

2 files changed

+126
-38
lines changed

2 files changed

+126
-38
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/DatabaseSelector.tsx

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Button } from '@openfun/cunningham-react';
22
import React from 'react';
3+
import styled from 'styled-components';
34

4-
import { Box, Text } from '@/components';
5+
import { Box, Icon, Text } from '@/components';
56
import { DatabaseSourceSelector } from '@/docs/doc-editor/components/DatabaseSourceSelector';
67
import { useGristCreateDocAndTable } from '@/features/grist/useGristCreateTable';
78

@@ -32,20 +33,89 @@ export const DatabaseSelector = ({
3233
};
3334

3435
return (
35-
<Box
36-
style={{
37-
flexDirection: 'column',
38-
gap: 10,
39-
alignItems: 'center',
40-
justifyContent: 'center',
41-
width: '100%',
42-
}}
43-
>
44-
<Button onClick={handleCreateNewDatabase}>
45-
Créer une nouvelle base de données vide
46-
</Button>
47-
<Text>ou</Text>
48-
<DatabaseSourceSelector onSourceSelected={onDatabaseSelected} />
49-
</Box>
36+
<Wrapper>
37+
<Box
38+
style={{
39+
width: 40,
40+
height: 40,
41+
borderRadius: 20,
42+
alignItems: 'center',
43+
justifyContent: 'center',
44+
backgroundColor: 'rgb(133, 184, 255)',
45+
}}
46+
>
47+
<Icon iconName="storage" color="rgb(62, 152, 255)" />
48+
</Box>
49+
<Title>Source de données</Title>
50+
<Description>Choisissez votre méthode de création</Description>
51+
<OptionsWrapper>
52+
<Option>
53+
<Box
54+
style={{ flexDirection: 'row', justifyContent: 'space-between' }}
55+
>
56+
<Box>
57+
<OptionTitle>Créer une nouvelle base de données vide</OptionTitle>
58+
<Description>
59+
Partir d&apos;une base de données vierge
60+
</Description>
61+
</Box>
62+
<Button
63+
onClick={handleCreateNewDatabase}
64+
icon={<Icon iconName="add" $color="white" />}
65+
></Button>
66+
</Box>
67+
</Option>
68+
<Text style={{ fontWeight: 600, fontSize: 14 }}>ou</Text>
69+
<Option>
70+
<Box style={{ marginBottom: 10 }}>
71+
<OptionTitle>
72+
Sélectionner une base de données existante
73+
</OptionTitle>
74+
<Description>
75+
Connecter une base de données Grist déjà créée
76+
</Description>
77+
</Box>
78+
<DatabaseSourceSelector onSourceSelected={onDatabaseSelected} />
79+
</Option>
80+
</OptionsWrapper>
81+
</Wrapper>
5082
);
5183
};
84+
85+
const Wrapper = styled(Box)`
86+
border: 2px solid rgb(160, 207, 255);
87+
background-color: rgb(230, 243, 255);
88+
border-radius: 4px;
89+
width: 100%;
90+
padding: 16px;
91+
align-items: center;
92+
gap: 10px;
93+
`;
94+
95+
const Title = styled(Text)`
96+
font-weight: 800;
97+
font-size: 18px;
98+
`;
99+
100+
const Description = styled(Text)`
101+
color: rgb(110, 110, 110);
102+
font-size: 14px;
103+
`;
104+
105+
const OptionTitle = styled(Text)`
106+
font-weight: 600;
107+
font-size: 14px;
108+
`;
109+
110+
const Option = styled(Box)`
111+
width: 100%;
112+
border: 1px solid rgb(180, 180, 180);
113+
border-radius: 4px;
114+
padding: 8px 16px;
115+
`;
116+
117+
const OptionsWrapper = styled(Box)`
118+
width: 100%;
119+
gap: 5px;
120+
align-items: center;
121+
`;

src/frontend/apps/impress/src/features/docs/doc-editor/components/DatabaseSourceSelector.tsx

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { Spinner } from '@gouvfr-lasuite/ui-kit';
2+
import { Select } from '@openfun/cunningham-react';
13
import { useState } from 'react';
24

3-
import { Box, DropdownMenu, Text } from '@/components';
5+
import { Box, Text } from '@/components';
46
import { useListGristTables } from '@/features/grist';
57
import { Doc, useListGristDocs } from '@/features/grist/useListGristDocs';
68

@@ -12,19 +14,32 @@ const TableSelector = ({
1214
documentId,
1315
onSourceSelected,
1416
}: { documentId: number } & DatabaseSourceSelectorProps) => {
15-
const { tables } = useListGristTables(documentId);
16-
return tables ? (
17-
<DropdownMenu
18-
options={tables.map(({ id }) => ({
19-
label: id,
20-
value: id,
21-
callback: () => onSourceSelected({ documentId, tableId: id }),
22-
}))}
23-
showArrow
24-
>
25-
<Text>Sélectionner une table Grist existante</Text>
26-
</DropdownMenu>
27-
) : (
17+
const { tables, isLoading } = useListGristTables(documentId);
18+
if (tables) {
19+
return (
20+
<Select
21+
label="Sélectionner une table Grist existante"
22+
options={tables.map(({ id }) => ({
23+
label: id,
24+
value: id,
25+
render: () => <Text style={{ padding: 10 }}>{id}</Text>,
26+
}))}
27+
onChange={(e) => {
28+
// TODO: handle better :)
29+
// @ts-expect-error target value type not specified here
30+
onSourceSelected({ documentId, tableId: e.target.value });
31+
}}
32+
/>
33+
);
34+
}
35+
if (isLoading) {
36+
return (
37+
<Box style={{ flexDirection: 'row', alignItems: 'center', gap: '10px' }}>
38+
<Spinner /> <Text>Chargement des tables...</Text>
39+
</Box>
40+
);
41+
}
42+
return (
2843
<Box>
2944
<Text>No tables available</Text>
3045
</Box>
@@ -38,17 +53,20 @@ export const DatabaseSourceSelector = ({
3853
const { docs } = useListGristDocs();
3954

4055
return (
41-
<Box>
42-
<DropdownMenu
56+
<Box style={{ flexDirection: 'row', alignItems: 'center', gap: '10px' }}>
57+
<Select
58+
label={selectedDoc?.name ?? 'Sélectionner un document Grist'}
4359
options={docs.map((doc) => ({
4460
label: doc.name,
45-
value: doc.id,
46-
callback: () => setSelectedDoc(doc),
61+
value: doc.id.toString(),
62+
render: () => <Text style={{ padding: 10 }}>{doc.name}</Text>,
4763
}))}
48-
showArrow
49-
>
50-
<Text>{selectedDoc?.name ?? 'Sélectionner un document Grist'}</Text>
51-
</DropdownMenu>
64+
onChange={(e) =>
65+
setSelectedDoc(
66+
docs.find((doc) => doc.id.toString() === e.target.value),
67+
)
68+
}
69+
/>
5270
{selectedDoc && (
5371
<TableSelector
5472
documentId={selectedDoc.id}

0 commit comments

Comments
 (0)