Skip to content

Commit

Permalink
feat: Build a container block that shows all the staging operations w…
Browse files Browse the repository at this point in the history
…ith a commit button #116
  • Loading branch information
danielstefanequilobe committed Dec 27, 2021
1 parent 3366efe commit a55f522
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/components/blocks/StagingDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const StagingDataTableContainer = styled('div')`
overflow-x: scroll;
`;

const ChangeGroupHeader = ({ headings, appStore }) => {
const ChangeGroupHeader = ({ headings, appStore, onClick }) => {
return (
<THead selectedTheme={appStore.theme}>
<Tr color="gray">
Expand All @@ -90,7 +90,9 @@ const ChangeGroupHeader = ({ headings, appStore }) => {
))}
<Th selectedTheme={appStore.theme}>
<TableCellHeaderText>
<MinusIcon width={16} height={16} />
<div onClick={onClick}>
<MinusIcon width={16} height={16} />
</div>
</TableCellHeaderText>
</Th>
</Tr>
Expand All @@ -117,7 +119,7 @@ const ChangeGroupItem = ({ headings, data, appStore, color, onClick }) => {
);
};

const StagingDataTable = withTheme(({ headings, data }) => {
const StagingDataTable = withTheme(({ headings, data, deleteStagingData }) => {
const appStore = useSelector(state => state.app);
const [getRecord, setRecord] = useState(null);

Expand All @@ -127,7 +129,11 @@ const StagingDataTable = withTheme(({ headings, data }) => {
headings &&
data.map((changeGroup, index) => (
<Table selectedTheme={appStore.theme} key={index}>
<ChangeGroupHeader headings={headings} appStore={appStore} />
<ChangeGroupHeader
headings={headings}
appStore={appStore}
onClick={() => deleteStagingData(changeGroup.uuid)}
/>
<tbody>
{changeGroup.action === 'DELETE' && (
<ChangeGroupItem
Expand Down
6 changes: 2 additions & 4 deletions src/pages/Projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import {
getProjects,
getStagingData,
deleteStagingData,
} from '../../store/actions/climateWarehouseActions';

const headings = [
Expand All @@ -43,10 +44,6 @@ const Projects = withRouter(({ history }) => {
dispatch(getStagingData({ useMockedResponse: false }));
}, []);

useEffect(() => {
console.log(climateWarehouseStore.stagingData);
}, [climateWarehouseStore.stagingData]);

if (
!climateWarehouseStore.projects ||
!climateWarehouseStore.projects.length
Expand Down Expand Up @@ -105,6 +102,7 @@ const Projects = withRouter(({ history }) => {
<StagingDataTable
headings={headings}
data={climateWarehouseStore.stagingData.projects.staging}
deleteStagingData={uuid => dispatch(deleteStagingData(uuid))}
/>
)}
</TabPanel>
Expand Down
59 changes: 59 additions & 0 deletions src/store/actions/climateWarehouseActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,65 @@ export const getStagingData = ({ useMockedResponse = false }) => {
};
};

export const commitStagingData = () => {
return async dispatch => {
try {
dispatch(activateProgressIndicator);

const url = `${constants.API_HOST}/staging/commit`;
const payload = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};

const response = await fetch(url, payload);

if (response.ok) {
console.log('yay!');
dispatch(getStagingData({ useMockedResponse: false }));
} else {
dispatch(setGlobalErrorMessage('Staging group could not be deleted'));
}
} catch {
dispatch(setGlobalErrorMessage('Something went wrong...'));
} finally {
dispatch(deactivateProgressIndicator);
}
};
};

export const deleteStagingData = uuid => {
return async dispatch => {
try {
dispatch(activateProgressIndicator);

const url = `${constants.API_HOST}/staging`;
const payload = {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ uuid }),
};

const response = await fetch(url, payload);

if (response.ok) {
console.log('yay!');
dispatch(getStagingData({ useMockedResponse: false }));
} else {
dispatch(setGlobalErrorMessage('Staging group could not be deleted'));
}
} catch {
dispatch(setGlobalErrorMessage('Something went wrong...'));
} finally {
dispatch(deactivateProgressIndicator);
}
};
};

export const postNewProject = data => {
return async dispatch => {
try {
Expand Down

0 comments on commit a55f522

Please sign in to comment.