-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* delete resource button application * added routes for deleted resources * locales update * locales update and redirection * locales update and redirection * init Deleted Detail container * init Resources Deleted List container * translations update * locales update * locales update for breadcrumbs and sidebar * delete call params update * layout update * locales update * Deleted resources sidebar item removal * deletedResourcesList button in ResourcesListContainer * adjustment of action buttons layout * translations and Deleted Resources button in card header * CHANGELOG.md update * locales update * translations update, obsolete code removal, button titles * go back button init, translations update, datatable icon update * submodule update * locales update * init retrive rerource prompt before the call * locales update * translations update * comments, syntax update * indentaion, comments, retrievePrompt renamed to confirmationPrompt * isolating ButtonWithAuthz's resource to a variable * isolating ButtonWithAuthz's resource to a variable * rerouting path update, useEffect applied to condition where resource is falsy * routes update * routes update * rendering condition update to prevent undefined * link pathname update * conditional rendering, console.log removal * ButtonWithAuthz resource as a variable * styling update - min height for .resource-detail-description * inline styling removal * locales update * route update for resource deletion * path update from /resources/deleted/ to /resources-deleted/ * whitespace removal * naming unification * naming unification * grid area in resource detail container * resoure update for delete button * resoure update, improved code defence * css grid application * button with authz resource as a variable * renaming container * deleted resource detail container route update * resource renaming * .DS_Store removal * resources renaming * locales update * create resource result check * get deleted resoures params update * button with authz instead of regular button in DeleteResourceButton * get resources api call adjusment * get data for deleted resources list call update * obsolete code removal * DeletedResourceDetailConatiner naming update * obsolete code removal * access resource update * substituing regular buttons with ButtonWithAuthz * locales udpate * Button title update * obsolete code removal - extra resource removal * overengineered code removal - removal contentloader delay function * resource update for DeletedResources routes in index.js * naming update * reosurce update * routes resources update --------- Co-authored-by: Petr Kavulok <petrkavulok@Petrs-MacBook-Pro.local>
- Loading branch information
1 parent
28a52a5
commit a262085
Showing
11 changed files
with
657 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/modules/auth/resources/DeletedResourceDetailContainer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { | ||
Container, Row, Col, Card, | ||
CardHeader, CardBody, Button, | ||
CardFooter, ButtonGroup | ||
} from 'reactstrap'; | ||
|
||
import { DateTime, ButtonWithAuthz } from 'asab-webui'; | ||
|
||
const DeletedResourceDetailContainer = (props) => { | ||
const { t } = useTranslation(); | ||
const SeaCatAuthAPI = props.app.axiosCreate('seacat_auth'); | ||
const [resource, setResource] = useState(undefined); | ||
const [editMode, setEditMode] = useState(false); | ||
const { resource_id } = props.match.params; | ||
|
||
const editResource = "authz:superuser"; | ||
const resources = useSelector(state => state.auth?.resources); | ||
|
||
useEffect(() => { | ||
getResourceDetail(resource_id); | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (!resource) return null; | ||
}, [resource]); | ||
|
||
const getResourceDetail = async (resourceId) => { | ||
try { | ||
let response = await SeaCatAuthAPI.get(`resource/${resourceId}`); | ||
setResource(response.data); | ||
} catch(e) { | ||
console.error(e); | ||
props.app.addAlert("warning", `${t("ResourcesDeletedDetailContainer|Can't fetch resource details")}. ${e?.response?.data?.message}`, 30); | ||
} | ||
} | ||
|
||
// Set delete resource dialog | ||
const confirmForm = (type) => { | ||
var r = confirm(t(`ResourcesDeletedDetailContainer|Do you really want to ${type === "delete" ? 'hard-delete' : 'retrieve'} this resource`)); | ||
if (r == true) { | ||
if (type === "delete") { | ||
hardDelete(); | ||
} else { | ||
retrieveResource(); | ||
} | ||
} | ||
} | ||
|
||
// Retrieve the resource | ||
const retrieveResource = async () => { | ||
try { | ||
let response = await SeaCatAuthAPI.post(`/resource/${resource_id}`, {}); | ||
if (response.data.result !== "OK") { | ||
throw new Error(t("ResourcesDeletedDetailContainer|Failed to retrieve resource")); | ||
} | ||
props.app.addAlert("success", t("ResourcesDeletedDetailContainer|Resource retrieved successfuly")); | ||
props.history.push("/auth/resources"); | ||
} catch(e) { | ||
console.error(e); | ||
props.app.addAlert("warning", `${t("ResourcesDeletedDetailContainer|Failed to retrieve resource")}. ${e?.response?.data?.message}`, 30); | ||
} | ||
} | ||
|
||
// Hard-deletes selected resource. After this action, the resource cannot be retrieved anymore. | ||
const hardDelete = async () => { | ||
try { | ||
let response = await SeaCatAuthAPI.delete(`/resource/${resource_id}`, { params: { hard_delete: true } }); | ||
if (response.data.result !== "OK") { | ||
throw new Error(t("ResourcesDeletedDetailContainer|Failed to hard-delete this resource")); | ||
} | ||
props.app.addAlert("success", t("ResourcesDeletedDetailContainer|Resource was successfully hard-deleted")); | ||
props.history.push("/auth/resources"); | ||
} catch(e) { | ||
console.error(e); | ||
props.app.addAlert("warning", `${t("ResourcesDeletedDetailContainer|Failed to hard-delete this resource")}. ${e?.response?.data?.message}`, 30); | ||
} | ||
} | ||
|
||
return ( | ||
<Container className="resource-container"> | ||
<Card className='reosurce-detail-description'> | ||
<CardHeader className="border-bottom"> | ||
<div className="card-header-title"> | ||
<i className="cil-lock-locked pr-2"></i> | ||
{t("ResourcesDeletedDetailContainer|Resource")} | ||
</div> | ||
</CardHeader> | ||
|
||
<CardBody> | ||
<Row> | ||
<Col md={3}>{t("Name")}</Col> | ||
<Col>{resource?._id}</Col> | ||
</Row> | ||
<Row className="mt-3"> | ||
<Col md={3}>{t("Created at")}</Col> | ||
<Col><DateTime value={resource?._c} /></Col> | ||
</Row> | ||
<Row> | ||
<Col md={3}>{t("Modified at")}</Col> | ||
<Col><DateTime value={resource?._m} /></Col> | ||
</Row> | ||
<Row className='mt-3'> | ||
<Col sm={3}>{t("Description")}</Col> | ||
<Col sm={6} className="resource-detail-description">{resource?.description}</Col> | ||
</Row> | ||
</CardBody> | ||
|
||
<CardFooter> | ||
{editMode ? | ||
<> | ||
<ButtonGroup> | ||
<Button | ||
color="outline-primary" | ||
type="button" | ||
title={t("Cancel")} | ||
onClick={(e) => (setEditMode(false))} | ||
> | ||
{t("Cancel")} | ||
</Button> | ||
</ButtonGroup> | ||
<div className="actions-right"> | ||
<Button | ||
color="primary" | ||
onClick={() => confirmForm("retrieve")} | ||
title={t("ResourcesDeletedDetailContainer|Retrieve")} | ||
> | ||
{t("ResourcesDeletedDetailContainer|Retrieve")} | ||
</Button> | ||
<Button | ||
color="danger" | ||
type="button" | ||
onClick={() => confirmForm("delete")} | ||
title={t("ResourcesDeletedDetailContainer|Hard-delete")} | ||
> | ||
{t("ResourcesDeletedDetailContainer|Hard-delete")} | ||
</Button> | ||
</div> | ||
</> | ||
: | ||
<ButtonWithAuthz | ||
color="primary" | ||
outline | ||
type="button" | ||
onClick={(e) => (e.preventDefault(), setEditMode(true))} | ||
resources={resources} | ||
resource={editResource} | ||
title={t("Edit")} | ||
> | ||
{t("Edit")} | ||
</ButtonWithAuthz> | ||
} | ||
</CardFooter> | ||
</Card> | ||
</Container> | ||
); | ||
} | ||
|
||
export default DeletedResourceDetailContainer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.