Skip to content

Commit

Permalink
feat: Shared Data files (Feature PR) (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui authored May 27, 2022
1 parent a62041b commit e7dcd4e
Show file tree
Hide file tree
Showing 63 changed files with 2,238 additions and 544 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- feature/shared-files
pull_request:
branches:
- main
- feature/shared-files

jobs:
lint:
Expand Down Expand Up @@ -49,7 +51,7 @@ jobs:

- name: Run test
run: npm run test

tests-coverage:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check-commits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- feature/shared-files
types:
- opened
- edited
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [ main, feature/shared-files ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [ main, feature/shared-files ]
schedule:
- cron: '34 6 * * 4'

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/localization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- feature/shared-files
pull_request:
branches:
- main
- feature/shared-files

jobs:
missing-keys:
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"<THIRD_PARTY_MODULES>",
"^@mui/(.*)$",
"^(common|forms|layout|localization|monitoring|navigation|notifications|permissions|state)/(.*)$",
"^(account|contact|gis|group|home|landscape|terrasoBackend|tool|user)/(.*)$",
"^(account|contact|gis|group|home|landscape|sharedData|terrasoBackend|tool|user)/(.*)$",
"^(config|custom-hooks|react-hoc)$",
"^[./]",
"^assets/(.*)$",
Expand Down
1 change: 1 addition & 0 deletions local.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
REACT_APP_TERRASO_ENV=local
REACT_APP_TERRASO_API_URL=http://127.0.0.1:8000
REACT_APP_PLAUSIBLE_DOMAIN=app.local.terraso.org
REACT_APP_SHARED_DATA_ACCEPTED_EXTENSIONS=xlsx,xls,csv
16 changes: 13 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@testing-library/user-event": "^14.0.0",
"@turf/bbox": "^6.5.0",
"@turf/helpers": "^6.5.0",
"filesize": "^8.0.7",
"history": "^5.3.0",
"i18next": "^21.6.14",
"i18next-browser-languagedetector": "^6.1.4",
Expand All @@ -27,6 +28,7 @@
"leaflet-geosearch": "^3.6.0",
"lodash": "^4.17.21",
"notistack": "^2.0.3",
"path-browserify": "^1.0.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-dropzone": "^12.0.4",
Expand Down
Binary file added public/files/csv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/files/xls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/account/accountService.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const fetchUser = () => {
${userPreferences}
`;
return terrasoApi
.request(query, { email: getUserEmail() })
.requestGraphQL(query, { email: getUserEmail() })
.then(_.get('users.edges[0].node'))
.then(user => user || Promise.reject('not_found'))
.then(user => ({
Expand All @@ -65,7 +65,7 @@ export const saveUser = user => {
${userFields}
`;
return terrasoApi
.request(query, {
.requestGraphQL(query, {
input: _.omit(['profileImage', 'email', 'preferences'], user),
})
.then(response => ({
Expand All @@ -84,7 +84,7 @@ export const savePreference = ({ key, value }, currentUser) => {
${userPreferencesFields}
`;
return terrasoApi
.request(query, {
.requestGraphQL(query, {
input: {
userEmail: currentUser.email,
key,
Expand Down
20 changes: 10 additions & 10 deletions src/account/components/AccountProfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('AccountProfile: Display Avatar with missing image', async () => {
});

test('AccountProfile: Save', async () => {
terrasoApi.request.mockResolvedValue(
terrasoApi.requestGraphQL.mockResolvedValue(
_.set(
'updateUser.user',
{
Expand Down Expand Up @@ -98,8 +98,8 @@ test('AccountProfile: Save', async () => {
await act(async () =>
fireEvent.click(screen.getByRole('button', { name: 'Confirm' }))
);
expect(terrasoApi.request).toHaveBeenCalledTimes(1);
expect(terrasoApi.request.mock.calls[0][1]).toStrictEqual({
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(1);
expect(terrasoApi.requestGraphQL.mock.calls[0][1]).toStrictEqual({
input: {
id: 'user-id',
firstName: 'Pablo',
Expand All @@ -108,7 +108,7 @@ test('AccountProfile: Save', async () => {
});
});
test('AccountProfile: Save language', async () => {
terrasoApi.request.mockResolvedValueOnce(
terrasoApi.requestGraphQL.mockResolvedValueOnce(
_.set(
'updateUser.user',
{
Expand All @@ -124,7 +124,7 @@ test('AccountProfile: Save language', async () => {
{}
)
);
terrasoApi.request.mockResolvedValueOnce(
terrasoApi.requestGraphQL.mockResolvedValueOnce(
_.set(
'updateUserPreference.preference',
{ key: 'language', value: 'es-ES' },
Expand Down Expand Up @@ -164,15 +164,15 @@ test('AccountProfile: Save language', async () => {
await act(async () =>
fireEvent.click(screen.getByRole('button', { name: 'Confirm' }))
);
expect(terrasoApi.request).toHaveBeenCalledTimes(2);
expect(terrasoApi.request.mock.calls[0][1]).toStrictEqual({
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(2);
expect(terrasoApi.requestGraphQL.mock.calls[0][1]).toStrictEqual({
input: {
id: 'user-id',
firstName: 'Pablo',
lastName: 'Perez',
},
});
expect(terrasoApi.request.mock.calls[1][1]).toStrictEqual({
expect(terrasoApi.requestGraphQL.mock.calls[1][1]).toStrictEqual({
input: {
key: 'language',
userEmail: '[email protected]',
Expand All @@ -181,7 +181,7 @@ test('AccountProfile: Save language', async () => {
});
});
test('AccountProfile: Save error', async () => {
terrasoApi.request.mockRejectedValueOnce('Save Error');
terrasoApi.requestGraphQL.mockRejectedValueOnce('Save Error');

const { inputs } = await setup({
account: {
Expand All @@ -205,7 +205,7 @@ test('AccountProfile: Save error', async () => {
await act(async () =>
fireEvent.click(screen.getByRole('button', { name: 'Confirm' }))
);
expect(terrasoApi.request).toHaveBeenCalledTimes(1);
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(1);

// Test error display
expect(screen.getByText(/Save Error/i)).toBeInTheDocument();
Expand Down
10 changes: 5 additions & 5 deletions src/account/components/RequireAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test('Auth: test redirect', async () => {
useParams.mockReturnValue({
slug: 'slug-1',
});
terrasoApi.request.mockRejectedValueOnce('UNAUTHENTICATED');
terrasoApi.requestGraphQL.mockRejectedValueOnce('UNAUTHENTICATED');
global.fetch.mockResolvedValueOnce({
status: 401,
});
Expand All @@ -59,7 +59,7 @@ test('Auth: test redirect', async () => {
);

expect(global.fetch).toHaveBeenCalledTimes(2);
expect(terrasoApi.request).toHaveBeenCalledTimes(1);
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(1);
expect(screen.getByText('To: /account')).toBeInTheDocument();
});
test('Auth: test redirect referrer', async () => {
Expand All @@ -81,7 +81,7 @@ test('Auth: test refresh tokens', async () => {
useParams.mockReturnValue({
slug: 'slug-1',
});
terrasoApi.request
terrasoApi.requestGraphQL
.mockRejectedValueOnce('UNAUTHENTICATED')
.mockResolvedValueOnce({});
global.fetch.mockResolvedValueOnce({
Expand Down Expand Up @@ -114,7 +114,7 @@ test('Auth: test refresh tokens', async () => {
});
test('Auth: test fetch user', async () => {
getUserEmail.mockReturnValue(Promise.resolve('[email protected]'));
terrasoApi.request.mockReturnValue(
terrasoApi.requestGraphQL.mockReturnValue(
Promise.resolve(
_.set(
'users.edges[0].node',
Expand All @@ -141,5 +141,5 @@ test('Auth: test fetch user', async () => {
}
);

expect(terrasoApi.request).toHaveBeenCalledTimes(1);
expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(1);
});
5 changes: 3 additions & 2 deletions src/common/components/ConfirmButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ConfirmButton = props => {
loading,
buttonProps,
onConfirm,
variant,
} = props;

useEffect(() => {
Expand All @@ -39,10 +40,10 @@ const ConfirmButton = props => {
<LoadingButton
onClick={onClick}
loading={loading}
variant="outlined"
variant={variant || 'outlined'}
{...(buttonProps || {})}
>
{buttonLabel}
{buttonLabel || props.children}
</LoadingButton>
</>
);
Expand Down
Loading

0 comments on commit e7dcd4e

Please sign in to comment.