mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 01:07:27 +00:00
add the read icon to see the read view with enabled fields
This commit is contained in:
parent
9ee1a1be8c
commit
1000f6aed3
@ -0,0 +1,62 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { useIntl } from 'react-intl';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { Link } from '@strapi/helper-plugin';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
|
const MESSAGES_MAP = {
|
||||||
|
edit: {
|
||||||
|
id: 'app.component.table.edit',
|
||||||
|
defaultMessage: 'Edit {target}',
|
||||||
|
},
|
||||||
|
read: {
|
||||||
|
id: 'app.component.table.read',
|
||||||
|
defaultMessage: 'Read {target}',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const LinkStyled = styled(Link)`
|
||||||
|
svg {
|
||||||
|
path {
|
||||||
|
fill: ${({ theme }) => theme.colors.neutral500};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
svg {
|
||||||
|
path {
|
||||||
|
fill: ${({ theme }) => theme.colors.neutral800};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const DefaultButton = ({ tokenName, tokenId, buttonType, children }) => {
|
||||||
|
const { formatMessage } = useIntl();
|
||||||
|
const {
|
||||||
|
location: { pathname },
|
||||||
|
} = useHistory();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LinkStyled
|
||||||
|
to={`${pathname}/${tokenId}`}
|
||||||
|
title={formatMessage(MESSAGES_MAP[buttonType], { target: `${tokenName}` })}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</LinkStyled>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
DefaultButton.propTypes = {
|
||||||
|
tokenName: PropTypes.string.isRequired,
|
||||||
|
tokenId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||||
|
buttonType: PropTypes.string,
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
DefaultButton.defaultProps = {
|
||||||
|
buttonType: 'edit',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default DefaultButton;
|
@ -0,0 +1,19 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import Eye from '@strapi/icons/Eye';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import DefaultButton from '../DefaultButton';
|
||||||
|
|
||||||
|
const ReadButton = ({ tokenName, tokenId }) => {
|
||||||
|
return (
|
||||||
|
<DefaultButton tokenName={tokenName} tokenId={tokenId}>
|
||||||
|
<Eye />
|
||||||
|
</DefaultButton>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ReadButton.propTypes = {
|
||||||
|
tokenName: PropTypes.string.isRequired,
|
||||||
|
tokenId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ReadButton;
|
@ -1,46 +1,13 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Pencil from '@strapi/icons/Pencil';
|
import Pencil from '@strapi/icons/Pencil';
|
||||||
import { useIntl } from 'react-intl';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Link } from '@strapi/helper-plugin';
|
import DefaultButton from '../DefaultButton';
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const LinkUpdate = styled(Link)`
|
|
||||||
svg {
|
|
||||||
path {
|
|
||||||
fill: ${({ theme }) => theme.colors.neutral500};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
svg {
|
|
||||||
path {
|
|
||||||
fill: ${({ theme }) => theme.colors.neutral800};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const UpdateButton = ({ tokenName, tokenId }) => {
|
const UpdateButton = ({ tokenName, tokenId }) => {
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
const {
|
|
||||||
location: { pathname },
|
|
||||||
} = useHistory();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LinkUpdate
|
<DefaultButton tokenName={tokenName} tokenId={tokenId}>
|
||||||
to={`${pathname}/${tokenId}`}
|
|
||||||
title={formatMessage(
|
|
||||||
{
|
|
||||||
id: 'app.component.table.edit',
|
|
||||||
defaultMessage: 'Edit {target}',
|
|
||||||
},
|
|
||||||
{ target: `${tokenName}` }
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Pencil />
|
<Pencil />
|
||||||
</LinkUpdate>
|
</DefaultButton>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,8 +14,9 @@ import PropTypes from 'prop-types';
|
|||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import DeleteButton from './DeleteButton';
|
import DeleteButton from './DeleteButton';
|
||||||
import UpdateButton from './UpdateButton';
|
import UpdateButton from './UpdateButton';
|
||||||
|
import ReadButton from './ReadButton';
|
||||||
|
|
||||||
const TableRows = ({ canDelete, canUpdate, onClickDelete, withBulkActions, rows }) => {
|
const TableRows = ({ canDelete, canUpdate, canRead, onClickDelete, withBulkActions, rows }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [{ query }] = useQueryParams();
|
const [{ query }] = useQueryParams();
|
||||||
const [, sortOrder] = query.sort.split(':');
|
const [, sortOrder] = query.sort.split(':');
|
||||||
@ -73,6 +74,9 @@ const TableRows = ({ canDelete, canUpdate, onClickDelete, withBulkActions, rows
|
|||||||
<Td>
|
<Td>
|
||||||
<Flex justifyContent="end">
|
<Flex justifyContent="end">
|
||||||
{canUpdate && <UpdateButton tokenName={apiToken.name} tokenId={apiToken.id} />}
|
{canUpdate && <UpdateButton tokenName={apiToken.name} tokenId={apiToken.id} />}
|
||||||
|
{!canUpdate && canRead && (
|
||||||
|
<ReadButton tokenName={apiToken.name} tokenId={apiToken.id} />
|
||||||
|
)}
|
||||||
{canDelete && (
|
{canDelete && (
|
||||||
<DeleteButton
|
<DeleteButton
|
||||||
tokenName={apiToken.name}
|
tokenName={apiToken.name}
|
||||||
@ -92,6 +96,7 @@ const TableRows = ({ canDelete, canUpdate, onClickDelete, withBulkActions, rows
|
|||||||
TableRows.defaultProps = {
|
TableRows.defaultProps = {
|
||||||
canDelete: false,
|
canDelete: false,
|
||||||
canUpdate: false,
|
canUpdate: false,
|
||||||
|
canRead: false,
|
||||||
onClickDelete: () => {},
|
onClickDelete: () => {},
|
||||||
rows: [],
|
rows: [],
|
||||||
withBulkActions: false,
|
withBulkActions: false,
|
||||||
@ -100,6 +105,7 @@ TableRows.defaultProps = {
|
|||||||
TableRows.propTypes = {
|
TableRows.propTypes = {
|
||||||
canDelete: PropTypes.bool,
|
canDelete: PropTypes.bool,
|
||||||
canUpdate: PropTypes.bool,
|
canUpdate: PropTypes.bool,
|
||||||
|
canRead: PropTypes.bool,
|
||||||
onClickDelete: PropTypes.func,
|
onClickDelete: PropTypes.func,
|
||||||
rows: PropTypes.array,
|
rows: PropTypes.array,
|
||||||
withBulkActions: PropTypes.bool,
|
withBulkActions: PropTypes.bool,
|
||||||
|
@ -135,15 +135,16 @@ const ApiTokenListView = () => {
|
|||||||
headers={tableHeaders}
|
headers={tableHeaders}
|
||||||
contentType="api-tokens"
|
contentType="api-tokens"
|
||||||
rows={apiTokens}
|
rows={apiTokens}
|
||||||
withBulkActions={canDelete || canUpdate}
|
withBulkActions={canDelete || canUpdate || canRead}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
onConfirmDelete={id => deleteMutation.mutateAsync(id)}
|
onConfirmDelete={id => deleteMutation.mutateAsync(id)}
|
||||||
>
|
>
|
||||||
<TableRows
|
<TableRows
|
||||||
|
canRead={canRead}
|
||||||
canDelete={canDelete}
|
canDelete={canDelete}
|
||||||
canUpdate={canUpdate}
|
canUpdate={canUpdate}
|
||||||
rows={apiTokens}
|
rows={apiTokens}
|
||||||
withBulkActions={canDelete || canUpdate}
|
withBulkActions={canDelete || canUpdate || canRead}
|
||||||
/>
|
/>
|
||||||
</DynamicTable>
|
</DynamicTable>
|
||||||
)}
|
)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user