1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00
unleash.unleash/frontend/src/component/demo/demo-setup.ts
Nuno Góis 0c620656ef
fix: small fixes for the interactive demo guide (#3713)
https://linear.app/unleash/issue/2-1005/small-ui-improvements

https://linear.app/unleash/issue/2-1020/fix-issues-with-interactive-demo-guide

Tackles the 2 tasks above, which include items such as:
 - Change drop-shadow of step tooltips;
 - Change transparency of overlay;
 - Change box-shadow of topics "widget";
 - Gradual rollout should use `default` stickiness;
 - Improve last step behavior when redirecting (add optional delay);

Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#3537
2023-05-09 10:04:39 +03:00

113 lines
3.7 KiB
TypeScript

import { IFeatureToggle } from 'interfaces/featureToggle';
import { formatApiPath } from 'utils/formatPath';
const PROJECT = 'demo-app';
const ENVIRONMENT = 'dev';
export const gradualRollout = async () => {
const featureId = 'demoApp.step3';
const { environments }: IFeatureToggle = await fetch(
formatApiPath(
`api/admin/projects/${PROJECT}/features/${featureId}?variantEnvironments=true`
)
).then(res => res.json());
const strategies =
environments.find(({ name }) => name === ENVIRONMENT)?.strategies || [];
if (!strategies.find(({ name }) => name === 'flexibleRollout')) {
await fetch(
formatApiPath(
`api/admin/projects/${PROJECT}/features/${featureId}/environments/${ENVIRONMENT}/strategies`
),
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'flexibleRollout',
constraints: [],
parameters: {
rollout: '50',
stickiness: 'default',
groupId: featureId,
},
}),
}
);
}
};
export const variants = async () => {
const featureId = 'demoApp.step4';
const { variants }: IFeatureToggle = await fetch(
formatApiPath(
`api/admin/projects/${PROJECT}/features/${featureId}?variantEnvironments=true`
)
).then(res => res.json());
if (!variants.length) {
await fetch(
formatApiPath(
`api/admin/projects/${PROJECT}/features/${featureId}/environments/${ENVIRONMENT}/variants`
),
{
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify([
{
op: 'add',
path: '/0',
value: {
name: 'red',
weightType: 'variable',
weight: 333,
overrides: [],
stickiness: 'default',
payload: {
type: 'string',
value: 'red',
},
},
},
{
op: 'add',
path: '/1',
value: {
name: 'green',
weightType: 'variable',
weight: 333,
overrides: [],
stickiness: 'default',
payload: {
type: 'string',
value: 'green',
},
},
},
{
op: 'add',
path: '/2',
value: {
name: 'blue',
weightType: 'variable',
weight: 333,
overrides: [],
stickiness: 'default',
payload: {
type: 'string',
value: 'blue',
},
},
},
]),
}
);
}
};