Skip to content

Commit

Permalink
fix: Renamed state fields and service function names to avoid confusi…
Browse files Browse the repository at this point in the history
…on betwen fetching shared resources and fetching data entries (#1577)
  • Loading branch information
josebui authored Feb 28, 2024
1 parent 571e269 commit 1b4c8a7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/group/groupSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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';
import { setSharedResourcesList } from 'sharedData/sharedDataSlice';

export type Group = {
slug: string;
Expand All @@ -46,7 +46,7 @@ export const fetchGroupView = createAsyncThunk(
'group/fetchGroupView',
async (slug: string, user, { dispatch }) => {
const group = await groupService.fetchGroupToView(slug, user);
dispatch(setList(group.sharedResources));
dispatch(setSharedResourcesList(group.sharedResources));
return group;
}
);
Expand Down
4 changes: 2 additions & 2 deletions src/landscape/landscapeSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import _ from 'lodash/fp';
import { createAsyncThunk } from 'terraso-client-shared/store/utils';

import * as landscapeService from 'landscape/landscapeService';
import { setList } from 'sharedData/sharedDataSlice';
import { setSharedResourcesList } from 'sharedData/sharedDataSlice';

const initialState = {
list: {
Expand Down Expand Up @@ -73,7 +73,7 @@ export const fetchLandscapeView = createAsyncThunk(
params,
currentUser
);
dispatch(setList(landscape.sharedResources));
dispatch(setSharedResourcesList(landscape.sharedResources));
return landscape;
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/sharedData/components/SharedDataCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const SharedDataCard = props => {
const { owner, entityTypeLocalized } = useCollaborationContext();
const { allowed } = usePermission(`sharedData.viewFiles`, owner);
const { data: sharedResources, fetching } = useSelector(
_.get('sharedData.list')
_.get('sharedData.sharedResources')
);
const hasSharedData = !_.isEmpty(sharedResources);

Expand Down
4 changes: 2 additions & 2 deletions src/sharedData/sharedDataService.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const updateSharedData = ({ dataEntry }) => {
.then(extractDataEntry);
};

export const fetchSharedData = ({
export const fetchDataEntries = ({
targetSlug,
targetType,
resourceTypes = ALL_RESOURCE_TYPES,
Expand Down Expand Up @@ -153,7 +153,7 @@ export const fetchSharedData = ({
.then(edges => edges.map(edge => extractDataEntry(edge.node)));
};

export const fetchSharedDataWithGeojson = ({ id }) => {
export const fetchDataEntriesWithGeojson = ({ id }) => {
const query = graphql(`
query dataEntryWithGeojson($id: ID!) {
dataEntry(id: $id) {
Expand Down
44 changes: 24 additions & 20 deletions src/sharedData/sharedDataSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ const initialState = {
links: {},
},
processing: {},
list: {
sharedResources: {
fetching: true,
data: null,
},
dataEntries: {
fetching: true,
data: null,
},
Expand Down Expand Up @@ -78,9 +82,9 @@ export const updateSharedData = createAsyncThunk(
params: { name: dataEntry.name },
})
);
export const fetchSharedData = createAsyncThunk(
'sharedData/fetchSharedData',
sharedDataService.fetchSharedData
export const fetchDataEntries = createAsyncThunk(
'sharedData/fetchDataEntries',
sharedDataService.fetchDataEntries
);

export const addVisualizationConfig = createAsyncThunk(
Expand Down Expand Up @@ -134,9 +138,9 @@ const sharedDataSlice = createSlice({
...state,
processing: _.omit(action.payload, state.processing),
}),
setList: (state, action) => ({
setSharedResourcesList: (state, action) => ({
...state,
list: {
sharedResources: {
data: action.payload,
fetching: false,
},
Expand All @@ -160,9 +164,9 @@ const sharedDataSlice = createSlice({
);
builder.addCase(updateSharedData.fulfilled, (state, action) => ({
...state,
list: {
...state.list,
data: state.list.data.map(item =>
sharedResources: {
...state.sharedResources,
data: state.sharedResources.data.map(item =>
item.id === action.meta.arg.sharedResource.id
? { ...item, dataEntry: action.payload }
: item
Expand Down Expand Up @@ -190,9 +194,9 @@ const sharedDataSlice = createSlice({
processing: _.omit(action.meta.arg.sharedResource.id, {
...state.processing,
}),
list: {
...state.list,
data: state.list.data.map(item =>
sharedResources: {
...state.sharedResources,
data: state.sharedResources.data.map(item =>
item.id === action.meta.arg.sharedResource.id
? action.payload
: item
Expand All @@ -218,9 +222,9 @@ const sharedDataSlice = createSlice({

builder.addCase(deleteSharedData.fulfilled, (state, action) => ({
...state,
list: {
...state.list,
data: state.list.data.filter(
sharedResources: {
...state.sharedResources,
data: state.sharedResources.data.filter(
item => item.id !== action.meta.arg.sharedResource.id
),
},
Expand Down Expand Up @@ -292,17 +296,17 @@ const sharedDataSlice = createSlice({
)
);

builder.addCase(fetchSharedData.pending, (state, action) => ({
builder.addCase(fetchDataEntries.pending, (state, action) => ({
...state,
list: {
dataEntries: {
fetching: true,
data: null,
},
}));

builder.addCase(fetchSharedData.fulfilled, (state, action) => ({
builder.addCase(fetchDataEntries.fulfilled, (state, action) => ({
...state,
list: {
dataEntries: {
fetching: false,
data: action.payload,
},
Expand Down Expand Up @@ -368,7 +372,7 @@ const sharedDataSlice = createSlice({
},
});

export const { resetUploads, resetProcessing, setList } =
export const { resetUploads, resetProcessing, setSharedResourcesList } =
sharedDataSlice.actions;

export default sharedDataSlice.reducer;
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import StepperStep from 'common/components/StepperStep';
import PageLoader from 'layout/PageLoader';
import { formatDate } from 'localization/utils';
import SharedFileIcon from 'sharedData/components/SharedFileIcon';
import { fetchSharedData } from 'sharedData/sharedDataSlice';
import { fetchDataEntries } from 'sharedData/sharedDataSlice';
import { useVisualizationContext } from 'sharedData/visualization/visualizationContext';

import {
Expand Down Expand Up @@ -77,7 +77,9 @@ const SelectDataFileStep = props => {
const { visualizationConfig } = useVisualizationContext();
const { onNext, onBack } = props;
const { owner, entityType } = useCollaborationContext();
const { data: sharedFiles, fetching } = useSelector(_.get('sharedData.list'));
const { data: sharedFiles, fetching } = useSelector(
_.get('sharedData.dataEntries')
);
const [selected, setSelected] = useState();

useEffect(() => {
Expand All @@ -88,7 +90,7 @@ const SelectDataFileStep = props => {

useEffect(() => {
dispatch(
fetchSharedData({
fetchDataEntries({
targetSlug: owner.slug,
targetType: entityType,
resourceTypes: ACCEPTED_RESOURCE_TYPES,
Expand Down
4 changes: 2 additions & 2 deletions src/sharedData/visualization/visualizationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as yup from 'yup';

import { normalizeLongitude } from 'gis/gisUtils';
import mapboxgl from 'gis/mapbox';
import { fetchSharedDataWithGeojson } from 'sharedData/sharedDataService';
import { fetchDataEntriesWithGeojson } from 'sharedData/sharedDataService';

export const readFile = async file => {
const response = await fetch(file.url);
Expand Down Expand Up @@ -61,7 +61,7 @@ export const readDataSetFile = async file => {
};

export const readMapFile = async dataEntry => {
const response = await fetchSharedDataWithGeojson({ id: dataEntry.id });
const response = await fetchDataEntriesWithGeojson({ id: dataEntry.id });
const geojson = JSON.parse(response.geojson);
return { geojson };
};
Expand Down

0 comments on commit 1b4c8a7

Please sign in to comment.