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

Resource design implementation #228

Merged
merged 2 commits into from
Jan 23, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
import SpacingsStack from '@commercetools-uikit/spacings-stack';
import ApiType from '../../type';

const RequestRepresentation = ({ titleSuffix, apiKey, apiType }) => {
return (
<div>
<SpacingsStack scale="s">
<p>
<strong>
{titleSuffix ? `${titleSuffix} -` : null} {apiType}
</strong>
{titleSuffix ? `${titleSuffix}: ` : null}
<strong>{apiType}</strong>
</p>

<ApiType apiKey={apiKey} type={apiType} />
</div>
</SpacingsStack>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
import { ContentNotifications } from '@commercetools-docs/ui-kit';
import SpacingsStack from '@commercetools-uikit/spacings-stack';
import useReadResourceByResourcePath from '../../../hooks/use-read-resource-by-resource-path';
import Method from './method';

const ResourceContainer = styled.div`
display: flex;
flex-direction: column;
margin-top: 1rem;
`;

const MethodContainer = styled.div`
margin: 1rem 0;
`;

const Resource = ({ apiKey, resource }) => {
const resourceObj = useReadResourceByResourcePath(apiKey, resource);

Expand All @@ -24,30 +14,25 @@ const Resource = ({ apiKey, resource }) => {
);
}

return <ResourceContainer>{renderMethods(resourceObj)}</ResourceContainer>;
};

function renderMethods(resource) {
const methods = ['post', 'get', 'delete'];

return (
<>
<SpacingsStack scale="xl">
{methods.map(method => {
return resource[method] ? (
<MethodContainer key={method}>
<Method
apiKey={resource.apiKey}
uris={resource.uris}
resourceUriParameters={resource.allUriParameters}
method={resource[method]}
methodType={method}
/>
</MethodContainer>
return resourceObj[method] ? (
<Method
key={method}
apiKey={resourceObj.apiKey}
uris={resourceObj.uris}
resourceUriParameters={resourceObj.allUriParameters}
method={resourceObj[method]}
methodType={method}
/>
) : null;
})}
</>
</SpacingsStack>
);
}
};

Resource.propTypes = {
apiKey: PropTypes.string.isRequired,
Expand Down