From 75fcb73f259e61e3a3e398e9b579ceab594d9e13 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 11:10:17 -0500 Subject: [PATCH 01/14] chore: Updated shared version --- package-lock.json | 15 ++++++++------- package.json | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0d4333e14..99dda6810 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#5e56086", + "terraso-client-shared": "github:techmatters/terraso-client-shared#f211e372131f71d40f66b5e3a77f629db879d837", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", @@ -27391,20 +27391,21 @@ }, "node_modules/terraso-backend": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#4929e5f4599cebc2f107873dd0075885c4df5e46" + "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#88c5e4a630c9ac5d1b206130bc2c96ad75b737b8", + "integrity": "sha512-XZZcn/sQ7vVYRJx0jUiKpLnBFjKc4Zum/7k6O7EPSPhiPx68E3JKrCtXsAZ+km1kGA/Feh6vVLvtOi7IfwkS8w==" }, "node_modules/terraso-client-shared": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#b86117e3735b2d8b2f85ffdb68547eb9738b9f77", - "integrity": "sha512-33236wvHVdvHmd6R0icNzt1PWtVhqZq8nkRguDfhq5bYrH8H3MCKf1umcsJQHJ+Y4csYw6VlFSHKrIzbayIrZw==", + "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#f211e372131f71d40f66b5e3a77f629db879d837", + "integrity": "sha512-TxaNj0v7KGvUhFmE6qViwnJtyXTG2U4WlSiPlfzVvNDXV6vXMSrimwNAP/ehN37NnjnQFUGzXU3bv0m+5hagPA==", "dependencies": { - "@reduxjs/toolkit": "^1.9.6", + "@reduxjs/toolkit": "^1.9.7", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", "react": "^18.2.0", "react-redux": "^8.1.2", - "terraso-backend": "github:techmatters/terraso-backend#4929e5f", - "uuid": "^9.0.0" + "terraso-backend": "github:techmatters/terraso-backend#88c5e4a630c9ac5d1b206130bc2c96ad75b737b8", + "uuid": "^9.0.1" } }, "node_modules/terser": { diff --git a/package.json b/package.json index d508b240b..935bd4ed3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#5e56086", + "terraso-client-shared": "github:techmatters/terraso-client-shared#f211e372131f71d40f66b5e3a77f629db879d837", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", From e4624cb654fa896be6e467f31fc077936cf547d4 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 11:11:43 -0500 Subject: [PATCH 02/14] refactor: Landscape data entries --- .../components/LandscapeSharedDataUpload.js | 4 +++ .../LandscapeSharedDataUploadLinks.test.js | 13 +++++++ .../components/LandscapeView.test.js | 35 ++++++++----------- src/landscape/landscapeFragments.js | 17 +++++++++ src/landscape/landscapeService.js | 2 ++ src/landscape/landscapeSlice.js | 2 ++ src/sharedData/components/SharedDataCard.js | 11 +----- .../components/SharedDataUpload/index.js | 8 ++--- src/sharedData/sharedDataService.js | 24 +++++++++---- src/sharedData/sharedDataSlice.js | 10 +++++- .../sharedDataUtils.js} | 17 ++++----- 11 files changed, 89 insertions(+), 54 deletions(-) rename src/{group/groupUtils.ts => sharedData/sharedDataUtils.js} (61%) diff --git a/src/landscape/components/LandscapeSharedDataUpload.js b/src/landscape/components/LandscapeSharedDataUpload.js index 243032a0a..f1f949230 100644 --- a/src/landscape/components/LandscapeSharedDataUpload.js +++ b/src/landscape/components/LandscapeSharedDataUpload.js @@ -90,6 +90,10 @@ const LandscapeSharedDataUpload = () => { groupSlug={_.get('defaultGroup.slug', landscape)} onCancel={onCancel} onCompleteSuccess={onCompleteSuccess} + targetInput={{ + targetType: 'landscape', + targetSlug: slug, + }} /> diff --git a/src/landscape/components/LandscapeSharedDataUploadLinks.test.js b/src/landscape/components/LandscapeSharedDataUploadLinks.test.js index bdb6f8c6b..9f20b87d8 100644 --- a/src/landscape/components/LandscapeSharedDataUploadLinks.test.js +++ b/src/landscape/components/LandscapeSharedDataUploadLinks.test.js @@ -255,4 +255,17 @@ test('LandscapeSharedDataUpload: Complete Success', async () => { search: 'scrollTo=shared-data-card-title', }, ]); + expect(terrasoApi.requestGraphQL).toHaveBeenCalledTimes(3); + const saveCall = terrasoApi.requestGraphQL.mock.calls[2]; + expect(saveCall[1]).toStrictEqual({ + input: { + description: '', + entryType: 'link', + targetType: 'landscape', + targetSlug: 'slug-1', + name: 'name 1', + resourceType: 'link', + url: 'https://test1.com', + }, + }); }); diff --git a/src/landscape/components/LandscapeView.test.js b/src/landscape/components/LandscapeView.test.js index a1434ad39..0ca7feef0 100644 --- a/src/landscape/components/LandscapeView.test.js +++ b/src/landscape/components/LandscapeView.test.js @@ -108,19 +108,21 @@ const baseViewTest = async (userRole = 'MEMBER') => { membershipStatus: 'APPROVED', }; - const dataEntries = { + const sharedResources = { edges: Array(6) .fill(0) .map((item, index) => ({ node: { - id: `de-${index}`, - createdAt: '2022-05-20T16:25:21.536679+00:00', - name: `Data Entry ${index}`, - createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' }, - description: `Description ${index}`, - size: 3456, - entryType: 'FILE', - visualizations: { edges: [] }, + source: { + id: `de-${index}`, + createdAt: '2022-05-20T16:25:21.536679+00:00', + name: `Data Entry ${index}`, + createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' }, + description: `Description ${index}`, + size: 3456, + entryType: 'FILE', + visualizations: { edges: [] }, + }, }, })), }; @@ -141,6 +143,7 @@ const baseViewTest = async (userRole = 'MEMBER') => { accountMembership, membershipsCount: 6, }, + sharedResources, }, }, ], @@ -161,17 +164,7 @@ const baseViewTest = async (userRole = 'MEMBER') => { memberships, accountMembership, }, - }, - }, - ], - }, - }) - .mockResolvedValueOnce({ - groups: { - edges: [ - { - node: { - dataEntries, + sharedResources, }, }, ], @@ -310,7 +303,7 @@ test('LandscapeView: Update Shared Data', async () => { }) ) ); - const saveCall = terrasoApi.requestGraphQL.mock.calls[3]; + const saveCall = terrasoApi.requestGraphQL.mock.calls[2]; expect(saveCall[1].input).toEqual({ id: 'de-3', diff --git a/src/landscape/landscapeFragments.js b/src/landscape/landscapeFragments.js index c9d292f57..6b50b7f2b 100644 --- a/src/landscape/landscapeFragments.js +++ b/src/landscape/landscapeFragments.js @@ -116,3 +116,20 @@ export const defaultGroupWithMembersSample = /* GraphQL */ ` } } `; + +export const landscapeDataEntries = /* GraphQL */ ` + fragment landscapeDataEntries on LandscapeNode { + sharedResources(source_DataEntry_ResourceType_In: $resourceTypes) { + edges { + node { + source { + ... on DataEntryNode { + ...dataEntry + ...dataEntryVisualizations + } + } + } + } + } + } +`; diff --git a/src/landscape/landscapeService.js b/src/landscape/landscapeService.js index f79784227..c69f7c4ad 100644 --- a/src/landscape/landscapeService.js +++ b/src/landscape/landscapeService.js @@ -24,6 +24,7 @@ import { graphql } from 'terrasoApi/shared/graphqlSchema'; import { countryNameForCode } from 'common/countries'; import * as gisService from 'gis/gisService'; +import { extractDataEntries } from 'sharedData/sharedDataUtils'; import { extractTerms } from 'taxonomies/taxonomiesUtils'; import { ALL_PARTNERSHIP_STATUS } from './landscapeConstants'; @@ -170,6 +171,7 @@ export const fetchLandscapeToView = slug => { : null, partnershipStatus: ALL_PARTNERSHIP_STATUS[landscape.partnershipStatus], partnership: extractPartnership(landscape), + dataEntries: extractDataEntries(landscape), })) .then(landscape => { if (landscape.areaPolygon || !landscape.location) { diff --git a/src/landscape/landscapeSlice.js b/src/landscape/landscapeSlice.js index f8450a958..8240d04c6 100644 --- a/src/landscape/landscapeSlice.js +++ b/src/landscape/landscapeSlice.js @@ -21,6 +21,7 @@ import * as membershipsUtils from 'terraso-client-shared/memberships/memberships import { createAsyncThunk } from 'terraso-client-shared/store/utils'; import * as landscapeService from 'landscape/landscapeService'; +import { setList } from 'sharedData/sharedDataSlice'; const initialState = { list: { @@ -82,6 +83,7 @@ export const fetchLandscapeView = createAsyncThunk( currentUser ); dispatch(setMemberships(getMemberships([landscape]))); + dispatch(setList(landscape.dataEntries)); return landscape; } ); diff --git a/src/sharedData/components/SharedDataCard.js b/src/sharedData/components/SharedDataCard.js index 865db59f6..9161a3401 100644 --- a/src/sharedData/components/SharedDataCard.js +++ b/src/sharedData/components/SharedDataCard.js @@ -14,12 +14,11 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ -import React, { useCallback } from 'react'; +import React from 'react'; import _ from 'lodash/fp'; import { usePermission } from 'permissions'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; -import { useFetchData } from 'terraso-client-shared/store/utils'; import { Button, Card, @@ -33,7 +32,6 @@ import { import List from 'common/components/List'; import { ScrollTo } from 'navigation/scrollTo'; import { useGroupContext } from 'group/groupContext'; -import { fetchGroupSharedData } from 'sharedData/sharedDataSlice'; import SharedDataEntryFile from './SharedDataEntryFile'; import SharedDataEntryLink from './SharedDataEntryLink'; @@ -48,13 +46,6 @@ const SharedFilesCard = props => { const { data: sharedFiles, fetching } = useSelector(_.get('sharedData.list')); const hasFiles = !_.isEmpty(sharedFiles); - useFetchData( - useCallback( - () => (allowed ? fetchGroupSharedData({ slug: group.slug }) : null), - [group.slug, allowed] - ) - ); - if (!allowed) { return null; } diff --git a/src/sharedData/components/SharedDataUpload/index.js b/src/sharedData/components/SharedDataUpload/index.js index e98b74b64..94de342e7 100644 --- a/src/sharedData/components/SharedDataUpload/index.js +++ b/src/sharedData/components/SharedDataUpload/index.js @@ -51,7 +51,7 @@ const SharedDataUpload = props => { const { trackEvent } = useAnalytics(); const { owner, entityType } = useGroupContext(); - const { groupSlug, onCancel, onCompleteSuccess } = props; + const { targetInput, onCancel, onCompleteSuccess } = props; const [section, setSection] = useState('files'); @@ -103,10 +103,10 @@ const SharedDataUpload = props => { const onSave = useCallback(() => { setShowSummary(false); const linksPromises = toUpload.links.map(link => - dispatch(addSharedDataLink({ groupSlug, link })) + dispatch(addSharedDataLink({ ...targetInput, link })) ); const filesPromises = toUpload.files.map(file => - dispatch(uploadSharedDataFile({ groupSlug, file })) + dispatch(uploadSharedDataFile({ ...targetInput, file })) ); const allPromises = [...filesPromises, ...linksPromises]; @@ -134,7 +134,7 @@ const SharedDataUpload = props => { }); setShowSummary(true); }); - }, [entityType, owner.slug, toUpload, groupSlug, dispatch, trackEvent]); + }, [entityType, owner.slug, toUpload, targetInput, dispatch, trackEvent]); const hasBlockingErrors = useMemo( () => diff --git a/src/sharedData/sharedDataService.js b/src/sharedData/sharedDataService.js index 5de08bca0..28c2134cd 100644 --- a/src/sharedData/sharedDataService.js +++ b/src/sharedData/sharedDataService.js @@ -18,18 +18,27 @@ import _ from 'lodash/fp'; import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; import { graphql } from 'terrasoApi/shared/graphqlSchema'; -import { extractDataEntry, extractGroupDataEntries } from 'group/groupUtils'; +import { extractDataEntries, extractDataEntry } from './sharedDataUtils'; import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; const ALL_RESOURCE_TYPES = [...SHARED_DATA_ACCEPTED_EXTENSIONS, 'link']; -export const uploadSharedDataFile = async ({ groupSlug, file }) => { +export const uploadSharedDataFile = async ({ + groupSlug, + landscapeSlug, + file, +}) => { const path = '/shared-data/upload/'; const body = new FormData(); const filename = `${file.name}${file.resourceType}`; - body.append('groups', groupSlug); + if (groupSlug) { + body.append('groups', groupSlug); + } + if (landscapeSlug) { + body.append('landscapes', landscapeSlug); + } body.append('name', file.name); if (file.description) { body.append('description', file.description); @@ -61,7 +70,7 @@ export const deleteSharedData = ({ dataEntry }) => { }); }; -export const addSharedDataLink = ({ groupSlug, link }) => { +export const addSharedDataLink = ({ targetType, targetSlug, link }) => { const query = graphql(` mutation addDataEntry($input: DataEntryAddMutationInput!) { addDataEntry(input: $input) { @@ -80,7 +89,8 @@ export const addSharedDataLink = ({ groupSlug, link }) => { ..._.pick(['name', 'url', 'description'], link), entryType: 'link', resourceType: 'link', - groupSlug, + targetType, + targetSlug, }, }) .then(_.get('addDataEntry.dataEntry')); @@ -131,7 +141,7 @@ export const fetchGroupSharedData = ({ .requestGraphQL(query, { slug, resourceTypes }) .then(_.get('groups.edges[0].node')) .then(group => group || Promise.reject('not_found')) - .then(group => extractGroupDataEntries(group)); + .then(group => extractDataEntries(group)); }; export const addVisualizationConfig = ({ @@ -189,7 +199,7 @@ export const fetchVisualizationConfig = ({ groupSlug, configSlug }) => { const query = graphql(` query fetchVisualizationConfig($groupSlug: String!, $configSlug: String!) { visualizationConfigs( - dataEntry_Groups_Slug: $groupSlug + dataEntry_SharedResources_Target_Slug: $groupSlug slug: $configSlug ) { edges { diff --git a/src/sharedData/sharedDataSlice.js b/src/sharedData/sharedDataSlice.js index 3c1870146..1e58b4fb5 100644 --- a/src/sharedData/sharedDataSlice.js +++ b/src/sharedData/sharedDataSlice.js @@ -124,6 +124,13 @@ const sharedDataSlice = createSlice({ ...state, processing: _.omit(action.payload, state.processing), }), + setList: (state, action) => ({ + ...state, + list: { + data: action.payload, + fetching: false, + }, + }), }, extraReducers: builder => { @@ -278,6 +285,7 @@ const sharedDataSlice = createSlice({ }, }); -export const { resetUploads, resetProcessing } = sharedDataSlice.actions; +export const { resetUploads, resetProcessing, setList } = + sharedDataSlice.actions; export default sharedDataSlice.reducer; diff --git a/src/group/groupUtils.ts b/src/sharedData/sharedDataUtils.js similarity index 61% rename from src/group/groupUtils.ts rename to src/sharedData/sharedDataUtils.js index d533b627a..0cd316907 100644 --- a/src/group/groupUtils.ts +++ b/src/sharedData/sharedDataUtils.js @@ -14,18 +14,13 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ -import { - DataEntriesFragment, - DataEntryFragment, - DataEntryVisualizationsFragment, -} from 'terrasoApi/shared/graphqlSchema/graphql'; -export const extractDataEntry = ( - dataEntry: DataEntryFragment & DataEntryVisualizationsFragment -) => ({ +export const extractDataEntry = dataEntry => ({ ...dataEntry, - visualizations: dataEntry.visualizations?.edges?.map(edge => edge.node), + visualizations: dataEntry?.visualizations?.edges?.map(edge => edge.node), }); -export const extractGroupDataEntries = (group: DataEntriesFragment) => - group.dataEntries.edges.map(edge => extractDataEntry(edge.node)); +export const extractDataEntries = parent => + parent.sharedResources?.edges + .map(edge => edge.node.source) + .map(dataEntry => extractDataEntry(dataEntry)); From d27162b8f4b1b3b56b539bb7ffb019d238649295 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 11:26:07 -0500 Subject: [PATCH 03/14] refactor: Group data entries --- src/group/components/GroupView.test.js | 40 ++++++++++++++++++++++++-- src/group/groupService.ts | 3 ++ src/group/groupSlice.ts | 2 ++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/group/components/GroupView.test.js b/src/group/components/GroupView.test.js index a02762582..95d74ea69 100644 --- a/src/group/components/GroupView.test.js +++ b/src/group/components/GroupView.test.js @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ -import { render, screen } from 'tests/utils'; +import { render, screen, within } from 'tests/utils'; import React from 'react'; import { useParams } from 'react-router-dom'; import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; @@ -98,6 +98,29 @@ test('GroupView: Display data', async () => { }, })), }; + const accountMembership = { + id: 'user-id', + userRole: 'MEMBER', + membershipStatus: 'APPROVED', + }; + const sharedResources = { + edges: Array(6) + .fill(0) + .map((item, index) => ({ + node: { + source: { + id: `de-${index}`, + createdAt: '2022-05-20T16:25:21.536679+00:00', + name: `Data Entry ${index}`, + createdBy: { id: 'user-id', firstName: 'First', lastName: 'Last' }, + description: `Description ${index}`, + size: 3456, + entryType: 'FILE', + visualizations: { edges: [] }, + }, + }, + })), + }; terrasoApi.requestGraphQL.mockReturnValue( Promise.resolve({ groups: { @@ -109,6 +132,8 @@ test('GroupView: Display data', async () => { website: 'https://www.group.org', email: 'email@email.com', memberships, + accountMembership, + sharedResources, }, }, ], @@ -135,6 +160,17 @@ test('GroupView: Display data', async () => { ).toBeInTheDocument(); expect(screen.getByText(/\+2/i)).toBeInTheDocument(); expect( - screen.getByRole('button', { name: 'Join Group' }) + screen.getByRole('button', { name: 'Leave: Group name' }) + ).toBeInTheDocument(); + + // Shared Data + const sharedDataRegion = within( + screen.getByRole('region', { name: 'Shared files and Links' }) + ); + expect( + sharedDataRegion.getByRole('heading', { name: 'Shared files and Links' }) ).toBeInTheDocument(); + const entriesList = within(sharedDataRegion.getByRole('list')); + const items = entriesList.getAllByRole('listitem'); + expect(items.length).toBe(6); }); diff --git a/src/group/groupService.ts b/src/group/groupService.ts index 19bd1f1e9..91b4e8af5 100644 --- a/src/group/groupService.ts +++ b/src/group/groupService.ts @@ -23,6 +23,8 @@ import { import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; import { graphql } from 'terrasoApi/shared/graphqlSchema'; +import { extractDataEntries } from 'sharedData/sharedDataUtils'; + import type { Group } from './groupSlice'; export const fetchGroupToUpdate = (slug: string) => { @@ -66,6 +68,7 @@ export const fetchGroupToView = async (slug: string) => { ..._.omit(['memberships', 'membershipsCount'], group), membersInfo: extractMembersInfo(group), accountMembership: extractAccountMembership(group), + dataEntries: extractDataEntries(group), })); }; diff --git a/src/group/groupSlice.ts b/src/group/groupSlice.ts index 2b5f2402a..33ad9e79f 100644 --- a/src/group/groupSlice.ts +++ b/src/group/groupSlice.ts @@ -25,6 +25,7 @@ import type { Message } from 'terraso-client-shared/notifications/notificationsS import { createAsyncThunk } from 'terraso-client-shared/store/utils'; import * as groupService from 'group/groupService'; +import { setList } from 'sharedData/sharedDataSlice'; export type Group = { slug: string; @@ -45,6 +46,7 @@ export const fetchGroupView = createAsyncThunk( async (slug: string, user, { dispatch }) => { const group = await groupService.fetchGroupToView(slug); dispatch(setMemberships(getMemberships([group]))); + dispatch(setList(group.dataEntries)); return group; } ); From 8dd37f2f347460a9d9f02a34ec4f9a5eda99366d Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 14:10:36 -0500 Subject: [PATCH 04/14] fix: Removed group visualization dependency --- package-lock.json | 12 ++-- package.json | 2 +- src/group/groupFragments.ts | 14 +++-- src/group/groupService.ts | 10 +++- .../LandscapeSharedDataVisualization.js | 3 +- .../LandscapeSharedDataVisualization.test.js | 8 +++ .../LandscapeSharedDataVisualizationConfig.js | 2 +- ...scapeSharedDataVisualizationConfig.test.js | 47 ++++++++-------- src/landscape/landscapeService.js | 10 +++- src/permissions/rules.js | 3 +- src/sharedData/sharedDataService.js | 56 +++++++++++++------ src/sharedData/sharedDataSlice.js | 10 ++-- .../VisualizationConfigForm/PreviewStep.js | 8 ++- .../SelectDataFileStep.js | 11 ++-- .../components/VisualizationWrapper.js | 16 ++++-- 15 files changed, 135 insertions(+), 77 deletions(-) diff --git a/package-lock.json b/package-lock.json index 99dda6810..a6ba4e9da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#f211e372131f71d40f66b5e3a77f629db879d837", + "terraso-client-shared": "github:techmatters/terraso-client-shared#6cc1a24717090875f8d1822986529eeb6237c746", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", @@ -27391,20 +27391,20 @@ }, "node_modules/terraso-backend": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#88c5e4a630c9ac5d1b206130bc2c96ad75b737b8", - "integrity": "sha512-XZZcn/sQ7vVYRJx0jUiKpLnBFjKc4Zum/7k6O7EPSPhiPx68E3JKrCtXsAZ+km1kGA/Feh6vVLvtOi7IfwkS8w==" + "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#93e844d8c4f031320b9f04c98b89144cdc51caba", + "integrity": "sha512-z0VltMm7mu82rpMyaVYKiXYKD/GLhMdigqIkOfcpABW6KbwlTjbOvyeWvqNxivw3ONkcWvKgNl+u6kkX9qiWSw==" }, "node_modules/terraso-client-shared": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#f211e372131f71d40f66b5e3a77f629db879d837", - "integrity": "sha512-TxaNj0v7KGvUhFmE6qViwnJtyXTG2U4WlSiPlfzVvNDXV6vXMSrimwNAP/ehN37NnjnQFUGzXU3bv0m+5hagPA==", + "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#6cc1a24717090875f8d1822986529eeb6237c746", + "integrity": "sha512-L8z7HzeP5uf8SmRc/udT+MeG4u2QTdjFrEwJVtyEyldpjOTqtjNdaMwgn4VGENBxXp/qpplTgKubm/F/JbelVA==", "dependencies": { "@reduxjs/toolkit": "^1.9.7", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", "react": "^18.2.0", "react-redux": "^8.1.2", - "terraso-backend": "github:techmatters/terraso-backend#88c5e4a630c9ac5d1b206130bc2c96ad75b737b8", + "terraso-backend": "github:techmatters/terraso-backend#93e844d8c4f031320b9f04c98b89144cdc51caba", "uuid": "^9.0.1" } }, diff --git a/package.json b/package.json index 935bd4ed3..a47e9aee6 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#f211e372131f71d40f66b5e3a77f629db879d837", + "terraso-client-shared": "github:techmatters/terraso-client-shared#6cc1a24717090875f8d1822986529eeb6237c746", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", diff --git a/src/group/groupFragments.ts b/src/group/groupFragments.ts index 66d7e6cec..c2b0de442 100644 --- a/src/group/groupFragments.ts +++ b/src/group/groupFragments.ts @@ -35,13 +35,17 @@ export const groupsListFields = /* GraphQL */ ` } `; -export const dataEntries = /* GraphQL */ ` - fragment dataEntries on GroupNode { - dataEntries(resourceType_In: $resourceTypes) { +export const groupDataEntries = /* GraphQL */ ` + fragment groupDataEntries on GroupNode { + sharedResources(source_DataEntry_ResourceType_In: $resourceTypes) { edges { node { - ...dataEntry - ...dataEntryVisualizations + source { + ... on DataEntryNode { + ...dataEntry + ...dataEntryVisualizations + } + } } } } diff --git a/src/group/groupService.ts b/src/group/groupService.ts index 91b4e8af5..38571e6bc 100644 --- a/src/group/groupService.ts +++ b/src/group/groupService.ts @@ -27,6 +27,8 @@ import { extractDataEntries } from 'sharedData/sharedDataUtils'; import type { Group } from './groupSlice'; +import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; + export const fetchGroupToUpdate = (slug: string) => { const query = graphql(` query groupToUpdate($slug: String!) { @@ -48,7 +50,7 @@ export const fetchGroupToUpdate = (slug: string) => { export const fetchGroupToView = async (slug: string) => { const query = graphql(` - query groupToView($slug: String!) { + query groupToView($slug: String!, $resourceTypes: [String]!) { groups(slug: $slug) { edges { node { @@ -56,13 +58,17 @@ export const fetchGroupToView = async (slug: string) => { ...groupMembersInfo ...groupMembersPending ...accountMembership + ...groupDataEntries } } } } `); return terrasoApi - .requestGraphQL(query, { slug }) + .requestGraphQL(query, { + slug, + resourceTypes: SHARED_DATA_ACCEPTED_EXTENSIONS, + }) .then(resp => resp.groups?.edges.at(0)?.node || Promise.reject('not_found')) .then(group => ({ ..._.omit(['memberships', 'membershipsCount'], group), diff --git a/src/landscape/components/LandscapeSharedDataVisualization.js b/src/landscape/components/LandscapeSharedDataVisualization.js index 918bfe184..bdafc4a46 100644 --- a/src/landscape/components/LandscapeSharedDataVisualization.js +++ b/src/landscape/components/LandscapeSharedDataVisualization.js @@ -58,10 +58,9 @@ const LandscapeSharedDataVisualization = () => { } return ( - + navigate(`/landscapes/${landscapeSlug}`)} /> diff --git a/src/landscape/components/LandscapeSharedDataVisualization.test.js b/src/landscape/components/LandscapeSharedDataVisualization.test.js index 41e3443e4..c00ac98a1 100644 --- a/src/landscape/components/LandscapeSharedDataVisualization.test.js +++ b/src/landscape/components/LandscapeSharedDataVisualization.test.js @@ -256,4 +256,12 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => { expect(domElement.querySelector('p').textContent).toEqual( 'Custom Label: val11' ); + + // Validate fetch input + const fetchCall = terrasoApi.requestGraphQL.mock.calls[3]; + expect(fetchCall[1]).toStrictEqual({ + configSlug: 'config-slug', + ownerSlug: 'jose-landscape-deafult-test-4', + ownerType: 'landscape', + }); }); diff --git a/src/landscape/components/LandscapeSharedDataVisualizationConfig.js b/src/landscape/components/LandscapeSharedDataVisualizationConfig.js index 232ea2cc3..47d095ad1 100644 --- a/src/landscape/components/LandscapeSharedDataVisualizationConfig.js +++ b/src/landscape/components/LandscapeSharedDataVisualizationConfig.js @@ -71,7 +71,7 @@ const LandscapeSharedDataVisualizationConfig = () => { return ( - + }, }); } - if (trimmedQuery.startsWith('query group')) { + if (trimmedQuery.startsWith('query dataEntries')) { return Promise.resolve({ - groups: { + dataEntries: { edges: [ { node: { - dataEntries: { - edges: [ - { - node: { - createdAt: '2022-05-17T23:32:50.606587+00:00', - createdBy: { - id: 'dc695d00-d6b4-45b2-ab8d-f48206d998da', - lastName: 'Buitrón', - firstName: 'José', - }, - description: '', - id: 'f00c5564-cf93-471a-94c2-b930cbb0a4f8', - name: 'File 1', - resourceType: 'text/csv', - size: 3565, - url: 'https://file-url', - visualizations: { edges: [] }, - }, - }, - ], + createdAt: '2022-05-17T23:32:50.606587+00:00', + createdBy: { + id: 'dc695d00-d6b4-45b2-ab8d-f48206d998da', + lastName: 'Buitrón', + firstName: 'José', }, + description: '', + id: 'f00c5564-cf93-471a-94c2-b930cbb0a4f8', + name: 'File 1', + resourceType: 'text/csv', + size: 3565, + url: 'https://file-url', + visualizations: { edges: [] }, }, }, ], @@ -327,6 +319,14 @@ test('LandscapeSharedDataVisualizationConfig: Create visualization', async () => await testAnnotateStep(); await testPreviewStep(map, events); + // Fetch data entries validation + const fetchCall = terrasoApi.requestGraphQL.mock.calls[3]; + expect(fetchCall[1]).toStrictEqual({ + resourceTypes: ['csv', 'xls', 'xlsx'], + slug: 'landscape-slug', + type: 'landscape', + }); + // Save await act(async () => fireEvent.click(screen.getByRole('button', { name: 'Publish' })) @@ -335,7 +335,8 @@ test('LandscapeSharedDataVisualizationConfig: Create visualization', async () => const saveCall = terrasoApi.requestGraphQL.mock.calls[4]; expect(saveCall[1]).toStrictEqual({ input: { - groupId: '6a625efb-4ec8-45e8-ad6a-eb052cc3fe65', + ownerId: 'e9a65bef-4ef1-4058-bba3-fc73b53eb779', + ownerType: 'landscape', title: 'Test Title', configuration: JSON.stringify({ datasetConfig: { diff --git a/src/landscape/landscapeService.js b/src/landscape/landscapeService.js index c69f7c4ad..0310fc038 100644 --- a/src/landscape/landscapeService.js +++ b/src/landscape/landscapeService.js @@ -34,6 +34,8 @@ import { extractPartnership, } from './landscapeUtils'; +import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; + const cleanLandscape = landscape => _.flow( _.pick([ @@ -143,13 +145,14 @@ const getDefaultGroup = landscape => { export const fetchLandscapeToView = slug => { const query = graphql(` - query landscapesToView($slug: String!) { + query landscapesToView($slug: String!, $resourceTypes: [String]!) { landscapes(slug: $slug) { edges { node { ...landscapeFields ...landscapePartnershipField ...defaultGroupWithMembersSample + ...landscapeDataEntries areaPolygon } } @@ -157,7 +160,10 @@ export const fetchLandscapeToView = slug => { } `); return terrasoApi - .requestGraphQL(query, { slug }) + .requestGraphQL(query, { + slug, + resourceTypes: SHARED_DATA_ACCEPTED_EXTENSIONS, + }) .then(_.get('landscapes.edges[0].node')) .then(landscape => landscape || Promise.reject('not_found')) .then(landscape => ({ diff --git a/src/permissions/rules.js b/src/permissions/rules.js index fea53fc96..5e7ca0cb5 100644 --- a/src/permissions/rules.js +++ b/src/permissions/rules.js @@ -66,9 +66,10 @@ const isAllowedToDeleteSharedData = ({ resource, user }) => { }; const isAllowedToDeleteVisualization = ({ - resource: { group, visualizationConfig }, + resource: { owner, visualizationConfig }, user, }) => { + const group = owner.defaultGroup || owner; const isManager = hasRole({ group, role: ROLE_MANAGER }); const isOwner = _.get('createdBy.id', visualizationConfig) === _.get('id', user); diff --git a/src/sharedData/sharedDataService.js b/src/sharedData/sharedDataService.js index 28c2134cd..814ea4d0d 100644 --- a/src/sharedData/sharedDataService.js +++ b/src/sharedData/sharedDataService.js @@ -18,7 +18,7 @@ import _ from 'lodash/fp'; import * as terrasoApi from 'terraso-client-shared/terrasoApi/api'; import { graphql } from 'terrasoApi/shared/graphqlSchema'; -import { extractDataEntries, extractDataEntry } from './sharedDataUtils'; +import { extractDataEntry } from './sharedDataUtils'; import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; @@ -122,31 +122,45 @@ export const updateSharedData = ({ dataEntry }) => { .then(extractDataEntry); }; -export const fetchGroupSharedData = ({ - slug, +export const fetchSharedData = ({ + targetSlug, + targetType, resourceTypes = ALL_RESOURCE_TYPES, }) => { const query = graphql(` - query group($slug: String!, $resourceTypes: [String]!) { - groups(slug: $slug) { + query dataEntries( + $slug: String! + $type: String! + $resourceTypes: [String]! + ) { + dataEntries( + sharedResources_Target_Slug: $slug + sharedResources_TargetContentType: $type + resourceType_In: $resourceTypes + ) { edges { node { - ...dataEntries + ...dataEntry + ...dataEntryVisualizations } } } } `); return terrasoApi - .requestGraphQL(query, { slug, resourceTypes }) - .then(_.get('groups.edges[0].node')) - .then(group => group || Promise.reject('not_found')) - .then(group => extractDataEntries(group)); + .requestGraphQL(query, { + slug: targetSlug, + type: targetType, + resourceTypes, + }) + .then(_.get('dataEntries.edges')) + .then(edges => edges.map(edge => extractDataEntry(edge.node))); }; export const addVisualizationConfig = ({ title, - group, + ownerId, + ownerType, selectedFile, visualizationConfig, }) => { @@ -171,7 +185,8 @@ export const addVisualizationConfig = ({ title, configuration, dataEntryId: selectedFile.id, - groupId: group.id, + ownerId, + ownerType, }, }) .then(response => ({ @@ -195,11 +210,20 @@ export const deleteVisualizationConfig = config => { }); }; -export const fetchVisualizationConfig = ({ groupSlug, configSlug }) => { +export const fetchVisualizationConfig = ({ + ownerSlug, + ownerType, + configSlug, +}) => { const query = graphql(` - query fetchVisualizationConfig($groupSlug: String!, $configSlug: String!) { + query fetchVisualizationConfig( + $ownerSlug: String! + $ownerType: String! + $configSlug: String! + ) { visualizationConfigs( - dataEntry_SharedResources_Target_Slug: $groupSlug + dataEntry_SharedResources_Target_Slug: $ownerSlug + dataEntry_SharedResources_TargetContentType: $ownerType slug: $configSlug ) { edges { @@ -214,7 +238,7 @@ export const fetchVisualizationConfig = ({ groupSlug, configSlug }) => { } `); return terrasoApi - .requestGraphQL(query, { groupSlug, configSlug }) + .requestGraphQL(query, { ownerSlug, ownerType, configSlug }) .then(_.get('visualizationConfigs.edges[0].node')) .then( visualizationConfig => visualizationConfig || Promise.reject('not_found') diff --git a/src/sharedData/sharedDataSlice.js b/src/sharedData/sharedDataSlice.js index 1e58b4fb5..3f697702d 100644 --- a/src/sharedData/sharedDataSlice.js +++ b/src/sharedData/sharedDataSlice.js @@ -74,9 +74,9 @@ export const updateSharedData = createAsyncThunk( params: { name: dataEntry.name }, }) ); -export const fetchGroupSharedData = createAsyncThunk( - 'sharedData/fetchGroupSharedData', - sharedDataService.fetchGroupSharedData +export const fetchSharedData = createAsyncThunk( + 'sharedData/fetchSharedData', + sharedDataService.fetchSharedData ); export const addVisualizationConfig = createAsyncThunk( @@ -226,7 +226,7 @@ const sharedDataSlice = createSlice({ ) ); - builder.addCase(fetchGroupSharedData.pending, (state, action) => ({ + builder.addCase(fetchSharedData.pending, (state, action) => ({ ...state, list: { fetching: true, @@ -234,7 +234,7 @@ const sharedDataSlice = createSlice({ }, })); - builder.addCase(fetchGroupSharedData.fulfilled, (state, action) => ({ + builder.addCase(fetchSharedData.fulfilled, (state, action) => ({ ...state, list: { fetching: false, diff --git a/src/sharedData/visualization/components/VisualizationConfigForm/PreviewStep.js b/src/sharedData/visualization/components/VisualizationConfigForm/PreviewStep.js index a7415f963..3e5fa35cf 100644 --- a/src/sharedData/visualization/components/VisualizationConfigForm/PreviewStep.js +++ b/src/sharedData/visualization/components/VisualizationConfigForm/PreviewStep.js @@ -44,7 +44,7 @@ const PreviewStep = props => { const [viewportConfig, setViewportConfig] = useState( visualizationConfig.viewportConfig ); - const { owner, entityTypeLocalized, group } = useGroupContext(); + const { owner, entityTypeLocalized, entityType } = useGroupContext(); useEffect(() => { setViewportConfig(visualizationConfig.viewportConfig); @@ -88,7 +88,8 @@ const PreviewStep = props => { title: _.get('annotateConfig.mapTitle', completeConfig), visualizationConfig: filteredConfig, selectedFile, - group, + ownerId: owner.id, + ownerType: entityType, }) ).then(data => { const success = _.get('meta.requestStatus', data) === 'fulfilled'; @@ -106,9 +107,10 @@ const PreviewStep = props => { }); }, [ dispatch, - group, onSaved, owner.name, + owner.id, + entityType, selectedFile, trackEvent, viewportConfig, diff --git a/src/sharedData/visualization/components/VisualizationConfigForm/SelectDataFileStep.js b/src/sharedData/visualization/components/VisualizationConfigForm/SelectDataFileStep.js index e49bfe7d2..0de9732a6 100644 --- a/src/sharedData/visualization/components/VisualizationConfigForm/SelectDataFileStep.js +++ b/src/sharedData/visualization/components/VisualizationConfigForm/SelectDataFileStep.js @@ -36,7 +36,7 @@ import PageLoader from 'layout/PageLoader'; import { formatDate } from 'localization/utils'; import { useGroupContext } from 'group/groupContext'; import SharedFileIcon from 'sharedData/components/SharedFileIcon'; -import { fetchGroupSharedData } from 'sharedData/sharedDataSlice'; +import { fetchSharedData } from 'sharedData/sharedDataSlice'; import { useVisualizationContext } from 'sharedData/visualization/visualizationContext'; const ACCEPTED_RESOURCE_TYPES = ['csv', 'xls', 'xlsx']; @@ -50,7 +50,7 @@ const SelectDataFileStep = props => { const { i18n, t } = useTranslation(); const { visualizationConfig } = useVisualizationContext(); const { onNext, onBack } = props; - const { group } = useGroupContext(); + const { owner, entityType } = useGroupContext(); const { data: sharedFiles, fetching } = useSelector(_.get('sharedData.list')); const [selected, setSelected] = useState(); @@ -62,12 +62,13 @@ const SelectDataFileStep = props => { useEffect(() => { dispatch( - fetchGroupSharedData({ - slug: group.slug, + fetchSharedData({ + targetSlug: owner.slug, + targetType: entityType, resourceTypes: ACCEPTED_RESOURCE_TYPES, }) ); - }, [dispatch, group.slug]); + }, [dispatch, owner.slug, entityType]); // If there are no files to map, go back to the landscape/group index page. useEffect(() => { diff --git a/src/sharedData/visualization/components/VisualizationWrapper.js b/src/sharedData/visualization/components/VisualizationWrapper.js index 1971787c9..05ad6f619 100644 --- a/src/sharedData/visualization/components/VisualizationWrapper.js +++ b/src/sharedData/visualization/components/VisualizationWrapper.js @@ -60,16 +60,22 @@ const VisualizationWrapper = props => { const dispatch = useDispatch(); const { i18n, t } = useTranslation(); const { downloadFile } = useSharedData(); - const { groupSlug, configSlug, onDeleted } = props; + const { configSlug, onDeleted } = props; const { data, fetching, deleting } = useSelector( state => state.sharedData.visualizationConfig ); - const { group, owner, entityType } = useGroupContext(); + const { owner, entityType } = useGroupContext(); const [imagePrinter, setImagePrinter] = useState(); useEffect(() => { - dispatch(fetchVisualizationConfig({ groupSlug, configSlug })); - }, [dispatch, groupSlug, configSlug]); + dispatch( + fetchVisualizationConfig({ + ownerSlug: owner.slug, + ownerType: entityType, + configSlug, + }) + ); + }, [dispatch, owner.slug, entityType, configSlug]); const visualizationConfig = useMemo( () => @@ -133,7 +139,7 @@ const VisualizationWrapper = props => { Date: Tue, 17 Oct 2023 16:36:16 -0500 Subject: [PATCH 05/14] fix: Send target for group uploads --- src/group/components/GroupSharedDataUpload.js | 7 +++++-- .../components/GroupSharedDataUploadFiles.test.js | 4 ++++ .../components/LandscapeSharedDataUpload.js | 3 +-- src/sharedData/sharedDataService.js | 12 ++++-------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/group/components/GroupSharedDataUpload.js b/src/group/components/GroupSharedDataUpload.js index 29e78d8e8..baff96190 100644 --- a/src/group/components/GroupSharedDataUpload.js +++ b/src/group/components/GroupSharedDataUpload.js @@ -79,9 +79,12 @@ const GroupSharedDataUpload = () => { - + diff --git a/src/group/components/GroupSharedDataUploadFiles.test.js b/src/group/components/GroupSharedDataUploadFiles.test.js index da4338ad9..9e408f23f 100644 --- a/src/group/components/GroupSharedDataUploadFiles.test.js +++ b/src/group/components/GroupSharedDataUploadFiles.test.js @@ -215,6 +215,10 @@ test('GroupSharedDataUpload: Complete Success', async () => { await waitFor(() => expect(uploadButton).not.toHaveAttribute('disabled')); await act(async () => fireEvent.click(uploadButton)); expect(navigate.mock.calls[0]).toEqual(['/groups/slug-1']); + + const saveCall = terrasoApi.request.mock.calls[0]; + expect(saveCall[0].body.get('target_type')).toBe('group'); + expect(saveCall[0].body.get('target_slug')).toBe('slug-1'); }); test('GroupSharedDataUpload: PDF Success', async () => { diff --git a/src/landscape/components/LandscapeSharedDataUpload.js b/src/landscape/components/LandscapeSharedDataUpload.js index f1f949230..8188185ad 100644 --- a/src/landscape/components/LandscapeSharedDataUpload.js +++ b/src/landscape/components/LandscapeSharedDataUpload.js @@ -85,9 +85,8 @@ const LandscapeSharedDataUpload = () => { name: landscape.name, })} /> - + { const path = '/shared-data/upload/'; const body = new FormData(); const filename = `${file.name}${file.resourceType}`; - if (groupSlug) { - body.append('groups', groupSlug); - } - if (landscapeSlug) { - body.append('landscapes', landscapeSlug); - } + body.append('target_type', targetType); + body.append('target_slug', targetSlug); body.append('name', file.name); if (file.description) { body.append('description', file.description); From 1530aba571e7838f38a7191bd5bb10cefff90e96 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 16:38:50 -0500 Subject: [PATCH 06/14] fix: Linter fix --- src/landscape/components/LandscapeSharedDataUpload.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/landscape/components/LandscapeSharedDataUpload.js b/src/landscape/components/LandscapeSharedDataUpload.js index 8188185ad..f7f56d2f9 100644 --- a/src/landscape/components/LandscapeSharedDataUpload.js +++ b/src/landscape/components/LandscapeSharedDataUpload.js @@ -15,7 +15,6 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { useCallback, useEffect, useMemo } from 'react'; -import _ from 'lodash/fp'; import { usePermissionRedirect } from 'permissions'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; From f1d5367e7ff193ad4bae169fc02a48e4da4ac0fc Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 17:07:20 -0500 Subject: [PATCH 07/14] fix: Added missing field to fetch landscape --- src/landscape/landscapeService.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/landscape/landscapeService.test.ts b/src/landscape/landscapeService.test.ts index 692a4675e..e62cae446 100644 --- a/src/landscape/landscapeService.test.ts +++ b/src/landscape/landscapeService.test.ts @@ -43,6 +43,7 @@ test('LandscapeService: Fetch landscape with missing fields', async () => { description: 'Landscape description', website: 'https://www.landscape.org', areaPolygon: null, + dataEntries: undefined, defaultGroup: { membersInfo: { accountMembership: undefined, From d1fe5c5e12da852a7ce8356761c57124f64f1fc1 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 17:17:07 -0500 Subject: [PATCH 08/14] fix: Remove data entry type filter from view pages --- src/group/groupFragments.ts | 2 +- src/group/groupService.ts | 5 +---- src/landscape/landscapeFragments.js | 2 +- src/landscape/landscapeService.js | 5 +---- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/group/groupFragments.ts b/src/group/groupFragments.ts index c2b0de442..1a5723fb1 100644 --- a/src/group/groupFragments.ts +++ b/src/group/groupFragments.ts @@ -37,7 +37,7 @@ export const groupsListFields = /* GraphQL */ ` export const groupDataEntries = /* GraphQL */ ` fragment groupDataEntries on GroupNode { - sharedResources(source_DataEntry_ResourceType_In: $resourceTypes) { + sharedResources { edges { node { source { diff --git a/src/group/groupService.ts b/src/group/groupService.ts index 38571e6bc..a5f1ce769 100644 --- a/src/group/groupService.ts +++ b/src/group/groupService.ts @@ -27,8 +27,6 @@ import { extractDataEntries } from 'sharedData/sharedDataUtils'; import type { Group } from './groupSlice'; -import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; - export const fetchGroupToUpdate = (slug: string) => { const query = graphql(` query groupToUpdate($slug: String!) { @@ -50,7 +48,7 @@ export const fetchGroupToUpdate = (slug: string) => { export const fetchGroupToView = async (slug: string) => { const query = graphql(` - query groupToView($slug: String!, $resourceTypes: [String]!) { + query groupToView($slug: String!) { groups(slug: $slug) { edges { node { @@ -67,7 +65,6 @@ export const fetchGroupToView = async (slug: string) => { return terrasoApi .requestGraphQL(query, { slug, - resourceTypes: SHARED_DATA_ACCEPTED_EXTENSIONS, }) .then(resp => resp.groups?.edges.at(0)?.node || Promise.reject('not_found')) .then(group => ({ diff --git a/src/landscape/landscapeFragments.js b/src/landscape/landscapeFragments.js index 6b50b7f2b..a998e7232 100644 --- a/src/landscape/landscapeFragments.js +++ b/src/landscape/landscapeFragments.js @@ -119,7 +119,7 @@ export const defaultGroupWithMembersSample = /* GraphQL */ ` export const landscapeDataEntries = /* GraphQL */ ` fragment landscapeDataEntries on LandscapeNode { - sharedResources(source_DataEntry_ResourceType_In: $resourceTypes) { + sharedResources { edges { node { source { diff --git a/src/landscape/landscapeService.js b/src/landscape/landscapeService.js index 0310fc038..246a85149 100644 --- a/src/landscape/landscapeService.js +++ b/src/landscape/landscapeService.js @@ -34,8 +34,6 @@ import { extractPartnership, } from './landscapeUtils'; -import { SHARED_DATA_ACCEPTED_EXTENSIONS } from 'config'; - const cleanLandscape = landscape => _.flow( _.pick([ @@ -145,7 +143,7 @@ const getDefaultGroup = landscape => { export const fetchLandscapeToView = slug => { const query = graphql(` - query landscapesToView($slug: String!, $resourceTypes: [String]!) { + query landscapesToView($slug: String!) { landscapes(slug: $slug) { edges { node { @@ -162,7 +160,6 @@ export const fetchLandscapeToView = slug => { return terrasoApi .requestGraphQL(query, { slug, - resourceTypes: SHARED_DATA_ACCEPTED_EXTENSIONS, }) .then(_.get('landscapes.edges[0].node')) .then(landscape => landscape || Promise.reject('not_found')) From 082b6daeeca65dfeb716ffc4d972e66722f0ed3a Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 17 Oct 2023 17:36:29 -0500 Subject: [PATCH 09/14] chore: Updated shared version --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6ba4e9da..e381dc686 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#6cc1a24717090875f8d1822986529eeb6237c746", + "terraso-client-shared": "github:techmatters/terraso-client-shared#976e5118b11bb664b5f9c66305beb9a75ab2848a", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", @@ -27391,20 +27391,20 @@ }, "node_modules/terraso-backend": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#93e844d8c4f031320b9f04c98b89144cdc51caba", - "integrity": "sha512-z0VltMm7mu82rpMyaVYKiXYKD/GLhMdigqIkOfcpABW6KbwlTjbOvyeWvqNxivw3ONkcWvKgNl+u6kkX9qiWSw==" + "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#2a351b303913cff208982ba8b6c6f2c157834d42", + "integrity": "sha512-LLf/sDir8NkZaiC34DNE/DOc3gFsSEsGxBzmomDEKtvI4ZtqokxVQ6GsopsjPMVtT/ftJO2QJ40NrXOWWIT/+Q==" }, "node_modules/terraso-client-shared": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#6cc1a24717090875f8d1822986529eeb6237c746", - "integrity": "sha512-L8z7HzeP5uf8SmRc/udT+MeG4u2QTdjFrEwJVtyEyldpjOTqtjNdaMwgn4VGENBxXp/qpplTgKubm/F/JbelVA==", + "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#976e5118b11bb664b5f9c66305beb9a75ab2848a", + "integrity": "sha512-YQdEsIu0jAcbQO90C7lWcJzqUXgtX5uNeUsckC8HrSbY8O0qFsTUN3tWQKbIQBoq0/1N7yRlz5WLB53hjJTUbw==", "dependencies": { "@reduxjs/toolkit": "^1.9.7", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", "react": "^18.2.0", "react-redux": "^8.1.2", - "terraso-backend": "github:techmatters/terraso-backend#93e844d8c4f031320b9f04c98b89144cdc51caba", + "terraso-backend": "github:techmatters/terraso-backend#2a351b303913cff208982ba8b6c6f2c157834d42", "uuid": "^9.0.1" } }, diff --git a/package.json b/package.json index a47e9aee6..acd4769d3 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#6cc1a24717090875f8d1822986529eeb6237c746", + "terraso-client-shared": "github:techmatters/terraso-client-shared#976e5118b11bb664b5f9c66305beb9a75ab2848a", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", From 1d823589d66de506ccca825271979a941aac29f2 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Mon, 23 Oct 2023 11:08:16 -0500 Subject: [PATCH 10/14] fix: Improved test comment --- .../components/LandscapeSharedDataVisualization.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/landscape/components/LandscapeSharedDataVisualization.test.js b/src/landscape/components/LandscapeSharedDataVisualization.test.js index c00ac98a1..7f56934fc 100644 --- a/src/landscape/components/LandscapeSharedDataVisualization.test.js +++ b/src/landscape/components/LandscapeSharedDataVisualization.test.js @@ -257,7 +257,8 @@ test('LandscapeSharedDataVisualization: Display visualization', async () => { 'Custom Label: val11' ); - // Validate fetch input + // Validate api call input to fetch visualization config + // It should contain the owner slug and type const fetchCall = terrasoApi.requestGraphQL.mock.calls[3]; expect(fetchCall[1]).toStrictEqual({ configSlug: 'config-slug', From cbc2d2d0c63df6ba706abae03fe298661b493d3b Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 24 Oct 2023 12:17:04 -0500 Subject: [PATCH 11/14] fix: Updated shared version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index acd4769d3..2717296fe 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#976e5118b11bb664b5f9c66305beb9a75ab2848a", + "terraso-client-shared": "github:techmatters/terraso-client-shared#311e68aee3ab78628f40b848d4a77e1a40b80362", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", From 37f2e49a18c5b275be69c2c4a7a4c1ccf5ff9f86 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 24 Oct 2023 14:06:40 -0500 Subject: [PATCH 12/14] chore: Updated shared version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2717296fe..a5ea10154 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#311e68aee3ab78628f40b848d4a77e1a40b80362", + "terraso-client-shared": "github:techmatters/terraso-client-shared#8ca7559da49aafeaaf78ccccfa54e2aaf89dd1b4", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", From c71bc71ff2ea8c50d3e9567fd9cef35b3fd021de Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 24 Oct 2023 14:15:24 -0500 Subject: [PATCH 13/14] fix: Updated package-lock --- package-lock.json | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index e381dc686..90b908c53 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#976e5118b11bb664b5f9c66305beb9a75ab2848a", + "terraso-client-shared": "github:techmatters/terraso-client-shared#8ca7559da49aafeaaf78ccccfa54e2aaf89dd1b4", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", @@ -27391,20 +27391,19 @@ }, "node_modules/terraso-backend": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#2a351b303913cff208982ba8b6c6f2c157834d42", - "integrity": "sha512-LLf/sDir8NkZaiC34DNE/DOc3gFsSEsGxBzmomDEKtvI4ZtqokxVQ6GsopsjPMVtT/ftJO2QJ40NrXOWWIT/+Q==" + "resolved": "git+ssh://git@github.com/techmatters/terraso-backend.git#3d323b5d204a8a7d33579cde27d4498c5b307ecb" }, "node_modules/terraso-client-shared": { "version": "0.1.0", - "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#976e5118b11bb664b5f9c66305beb9a75ab2848a", - "integrity": "sha512-YQdEsIu0jAcbQO90C7lWcJzqUXgtX5uNeUsckC8HrSbY8O0qFsTUN3tWQKbIQBoq0/1N7yRlz5WLB53hjJTUbw==", + "resolved": "git+ssh://git@github.com/techmatters/terraso-client-shared.git#8ca7559da49aafeaaf78ccccfa54e2aaf89dd1b4", + "integrity": "sha512-ZOa8+yzrfIn+nwdlhBMxDS9p6OTqfAodvCgj3wJvSifKsUyoq056+H7mGmKmcjJjrLJOzPYNrv4X4BhcnwvfcQ==", "dependencies": { "@reduxjs/toolkit": "^1.9.7", "jwt-decode": "^3.1.2", "lodash": "^4.17.21", "react": "^18.2.0", - "react-redux": "^8.1.2", - "terraso-backend": "github:techmatters/terraso-backend#2a351b303913cff208982ba8b6c6f2c157834d42", + "react-redux": "^8.1.3", + "terraso-backend": "github:techmatters/terraso-backend#3d323b5", "uuid": "^9.0.1" } }, From 182e605eace07af4077a1f070fc82791cddd276a Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Tue, 24 Oct 2023 14:18:13 -0500 Subject: [PATCH 14/14] chore: Updated shared version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90b908c53..a6873cfc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -49,7 +49,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#8ca7559da49aafeaaf78ccccfa54e2aaf89dd1b4", + "terraso-client-shared": "github:techmatters/terraso-client-shared#d577669", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0", diff --git a/package.json b/package.json index a5ea10154..7449624c0 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "slate-history": "^0.100.0", "slate-hyperscript": "^0.100.0", "slate-react": "^0.100.0", - "terraso-client-shared": "github:techmatters/terraso-client-shared#8ca7559da49aafeaaf78ccccfa54e2aaf89dd1b4", + "terraso-client-shared": "github:techmatters/terraso-client-shared#d577669", "use-debounce": "^9.0.4", "uuid": "^9.0.1", "web-vitals": "^3.5.0",