mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-06 01:15:28 +02:00
feat: make API request component work without payloads
There's been no previous need for GET or DELETE requests, but now that we do need them, the payload shouldn't show up as `undefined`
This commit is contained in:
parent
d167de76d8
commit
cfbe04272a
@ -16,41 +16,40 @@ const Template = (args) => (
|
|||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
|
|
||||||
export const Step1 = Template.bind({});
|
export const GET = Template.bind({});
|
||||||
Step1.args = {
|
GET.args = {
|
||||||
open: true,
|
verb: 'get',
|
||||||
seedData: {
|
url: 'api/admin/segments',
|
||||||
currentStep: 1,
|
title: 'List all segments (example).',
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Step2 = Template.bind({});
|
export const POST = Template.bind({});
|
||||||
Step2.args = {
|
POST.args = {
|
||||||
seedData: {
|
verb: 'post',
|
||||||
currentStep: 2,
|
payload: { name: '<feature-toggle-name>', impressionData: true },
|
||||||
},
|
url: 'api/admin/projects/<project-id>/features',
|
||||||
open: true,
|
title: 'Create a feature toggle with impression data enabled. (example)',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Step3 = Template.bind({});
|
export const PUT = Template.bind({});
|
||||||
Step3.args = {
|
PUT.args = {
|
||||||
seedData: {
|
verb: 'put',
|
||||||
currentStep: 3,
|
payload: { name: '<feature-toggle-name>', impressionData: true },
|
||||||
},
|
url: 'api/admin/projects/<project-id>/features/<feature-id>',
|
||||||
open: true,
|
title: 'Create a feature toggle with impression data enabled (example).',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Step4 = Template.bind({});
|
export const PATCH = Template.bind({});
|
||||||
Step4.args = {
|
PATCH.args = {
|
||||||
seedData: {
|
verb: 'patch',
|
||||||
currentStep: 4,
|
payload: [{ op: 'replace', path: '/impressionData', value: true }],
|
||||||
},
|
url: 'api/admin/projects/<project-id>/features/<feature-toggle-name>',
|
||||||
open: true,
|
title: 'Enable impression data on an existing toggle (example).',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithLocalStorage = Template.bind({});
|
export const DELETE = Template.bind({});
|
||||||
WithLocalStorage.args = {
|
DELETE.args = {
|
||||||
open: true,
|
verb: 'delete',
|
||||||
|
url: 'api/admin/projects/<project-id>/features/<feature-toggle-id>',
|
||||||
|
title: 'Create a feature toggle with impression data enabled.',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Closed = Template.bind({});
|
|
||||||
|
@ -17,40 +17,67 @@ import CodeBlock from '@theme/CodeBlock';
|
|||||||
|
|
||||||
const indentation = 2;
|
const indentation = 2;
|
||||||
|
|
||||||
const Component = ({ verb, payload, url, title }) => {
|
type Props = {
|
||||||
|
verb: string,
|
||||||
|
payload?: any,
|
||||||
|
url: string,
|
||||||
|
title?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type PropsWithoutPayload = Omit<Props, 'payload'>
|
||||||
|
|
||||||
|
|
||||||
|
const Component: React.FC<Props> = ({ verb, payload, url, title }) => {
|
||||||
const verbUpper = verb?.toUpperCase() || '';
|
const verbUpper = verb?.toUpperCase() || '';
|
||||||
const prettyPayload = JSON.stringify(payload, null, indentation);
|
const prettyPayload = JSON.stringify(payload, null, indentation);
|
||||||
|
|
||||||
|
const httpBlock = (payload ? `
|
||||||
|
${verbUpper} <unleash-url>/${url}
|
||||||
|
Authorization: <API-token>
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
${prettyPayload}` :`
|
||||||
|
${verbUpper} <unleash-url>/${url}
|
||||||
|
Authorization: <API-token>
|
||||||
|
content-type: application/json`).trim()
|
||||||
|
|
||||||
|
const curlBlock = (payload ? `
|
||||||
|
curl -H "Content-Type: application/json" \\
|
||||||
|
-H "Authorization: <API-token>" \\
|
||||||
|
-X ${verbUpper} \\
|
||||||
|
-d '${prettyPayload}' \\
|
||||||
|
<unleash-url>/${url}` : `
|
||||||
|
curl -H "Content-Type: application/json" \\
|
||||||
|
-H "Authorization: <API-token>" \\
|
||||||
|
-X ${verbUpper} \\
|
||||||
|
<unleash-url>/${url}` ).trim()
|
||||||
|
|
||||||
|
const httpieBlock = (payload ?
|
||||||
|
`echo '${prettyPayload}' \\
|
||||||
|
| http ${verbUpper} \\
|
||||||
|
<unleash-url>/${url} \\
|
||||||
|
Authorization:<API-token>`
|
||||||
|
: `
|
||||||
|
http ${verbUpper} \\
|
||||||
|
<unleash-url>/${url} \\
|
||||||
|
Authorization:<API-token>`.trim()
|
||||||
|
).trim()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<TabItem value="http" label="HTTP">
|
<TabItem value="http" label="HTTP">
|
||||||
<CodeBlock language="http" title={title}>
|
<CodeBlock language="http" title={title}>
|
||||||
{`
|
{httpBlock}
|
||||||
${verbUpper} <unleash-url>/${url}
|
|
||||||
Authorization: <API-token>
|
|
||||||
content-type: application/json
|
|
||||||
|
|
||||||
${prettyPayload}
|
|
||||||
`.trim()}
|
|
||||||
</CodeBlock>
|
</CodeBlock>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="curl" label="cURL">
|
<TabItem value="curl" label="cURL">
|
||||||
<CodeBlock language="bash" title={title}>
|
<CodeBlock language="bash" title={title}>
|
||||||
{`
|
{curlBlock}
|
||||||
curl -H "Content-Type: application/json" \\
|
|
||||||
-H "Authorization: <API-token>" \\
|
|
||||||
-X ${verbUpper} \\
|
|
||||||
-d '${prettyPayload}' \\
|
|
||||||
<unleash-url>/${url}
|
|
||||||
`.trim()}
|
|
||||||
</CodeBlock>
|
</CodeBlock>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
<TabItem value="httpie" label="HTTPie">
|
<TabItem value="httpie" label="HTTPie">
|
||||||
<CodeBlock language="bash" title={title}>
|
<CodeBlock language="bash" title={title}>
|
||||||
{`echo '${prettyPayload}' \\
|
{httpieBlock}
|
||||||
| http ${verbUpper} \\
|
|
||||||
<unleash-url>/${url} \\
|
|
||||||
Authorization:<API-token>`.trim()}
|
|
||||||
</CodeBlock>
|
</CodeBlock>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
Loading…
Reference in New Issue
Block a user