Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin UI: minor code cleanup, no functional changes #2952

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions packages/app-admin-ui/client/components/ListTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,25 +291,23 @@ const SingleCell = ({ columns, children }) => (
</tr>
);

export default function ListTable(props) {
const {
adminPath,
columnControl,
fields,
isFullWidth,
items,
queryErrors = [],
list,
onChange,
onSelectChange,
selectedItems,
currentPage,
filters,
search,
itemLink = ({ path, item }) => `${adminPath}/${path}/${item.id}`,
linkField = '_label_',
} = props;

export default function ListTable({
adminPath,
columnControl,
fields,
isFullWidth,
items,
queryErrors = [],
list,
onChange,
onSelectChange,
selectedItems,
currentPage,
filters,
search,
itemLink = ({ path, item }) => `${adminPath}/${path}/${item.id}`,
linkField = '_label_',
}) {
const [sortBy, onSortChange] = useListSort();

const handleSelectAll = () => {
Expand Down
39 changes: 14 additions & 25 deletions packages/app-admin-ui/client/pages/Item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { ItemTitle } from './ItemTitle';
import { ItemProvider } from '../../providers/Item';
import { useList } from '../../providers/List';

let Render = ({ children }) => children();
const Render = ({ children }) => children();

const Form = styled.form({
marginBottom: gridSize * 3,
Expand All @@ -61,14 +61,7 @@ const getRenderableFields = memoizeOne(list =>
.filter(({ maybeAccess, config }) => !!maybeAccess.update || !!config.isReadOnly)
);

const ItemDetails = ({
list,
item: initialData,
itemErrors,
onUpdate,
updateItem,
updateInProgress,
}) => {
const ItemDetails = ({ list, item: initialData, itemErrors, onUpdate }) => {
const [item, setItem] = useState(initialData);
const [showDeleteModal, setShowDeleteModal] = useState(false);
const [validationErrors, setValidationErrors] = useState({});
Expand All @@ -82,6 +75,11 @@ const ItemDetails = ({

const { query: listQuery } = useList();

const [updateItem, { loading: updateInProgress }] = useMutation(list.updateMutation, {
errorPolicy: 'all',
onError: error => handleCreateUpdateMutationError({ error, addToast }),
});

const getFieldsObject = memoizeOne(() =>
arrayToObject(
// NOTE: We _exclude_ read only fields
Expand Down Expand Up @@ -346,17 +344,16 @@ const ItemNotFound = ({ errorMessage, list }) => (
<Button to={list.fullPath} variant="ghost">
Back to List
</Button>
{errorMessage ? (
<p style={{ fontSize: '0.75rem', marginTop: gridSize * 4 }}>
{errorMessage && (
<p style={{ fontSize: '0.75rem', marginTop: `${gridSize * 4}px` }}>
<code>{errorMessage}</code>
</p>
) : null}
)}
</PageError>
);

const ItemPage = ({ itemId }) => {
const { list } = useList();
const { addToast } = useToasts();

const itemQuery = list.getItemQuery(itemId);

Expand All @@ -369,11 +366,6 @@ const ItemPage = ({ itemId }) => {
errorPolicy: 'all',
});

const [updateItem, { loading: updateInProgress }] = useMutation(list.updateMutation, {
errorPolicy: 'all',
onError: error => handleCreateUpdateMutationError({ error, addToast }),
});

// Now that the network request for data has been triggered, we
// try to initialise the fields. They are Suspense capable, so may
// throw Promises which will be caught by the wrapping <Suspense>
Expand Down Expand Up @@ -440,13 +432,10 @@ const ItemPage = ({ itemId }) => {
itemErrors={itemErrors}
key={itemId}
list={list}
onUpdate={() =>
refetch().then(refetchedData =>
deserializeItem(list, refetchedData.data[list.gqlNames.itemQueryName])
)
}
updateInProgress={updateInProgress}
updateItem={updateItem}
onUpdate={async () => {
const { data } = await refetch();
return deserializeItem(list, data[list.gqlNames.itemQueryName]);
}}
/>
</Container>
</main>
Expand Down