Skip to content

Commit

Permalink
mockVite playground
Browse files Browse the repository at this point in the history
  • Loading branch information
smouillour committed Apr 15, 2024
1 parent 6eeaf7d commit d3ef679
Show file tree
Hide file tree
Showing 10 changed files with 781 additions and 2 deletions.
48 changes: 48 additions & 0 deletions packages/playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,60 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="@popperjs/core" content="2.11.8" />
<meta name="@rooks/use-mutation-observer" content="4.11.2" />
<meta name="@talend/locales-design-system" content="7.15.1" />
<meta name="@talend/locales-tui-components" content="11.4.5" />
<meta name="@talend/locales-tui-containers" content="9.1.3" />
<meta name="@talend/locales-tui-faceted-search" content="11.3.0" />
<meta name="@talend/locales-tui-forms" content="10.2.4" />
<meta name="@talend/icons" content="7.7.1" />
<meta name="ace-builds" content="1.32.6" />
<meta name="ajv" content="6.12.6" />
<meta name="ally.js" content="1.4.1" />
<meta name="axios" content="0.21.4" />
<meta name="classnames" content="2.3.1" />
<meta name="core-js-bundle" content="3.36.0" />
<meta name="d3" content="7.8.5" />
<meta name="focus-outline-manager" content="1.0.2" />
<meta name="history" content="5.3.0" />
<meta name="hoist-non-react-statics" content="3.3.2" />
<meta name="i18next" content="23.10.0" />
<meta name="immutable" content="4.3.5" />
<meta name="json-logic-js" content="2.0.2" />
<meta name="lodash" content="4.17.21" />
<meta name="platform" content="1.3.3" />
<meta name="preact" content="10.19.6" />
<meta name="prop-types" content="15.8.1" />
<meta name="react-ace" content="10.1.0" />
<meta name="react-autowhatever" content="10.2.0" />
<meta name="react-debounce-input" content="3.3.0" />
<meta name="react-dom" content="18.2.0" />
<meta name="react-draggable" content="4.4.6" />
<meta name="react-hook-form" content="7.50.1" />
<meta name="react-i18next" content="13.5.0" />
<meta name="react-is" content="17.0.2" />
<meta name="react-jsonschema-form" content="0.51.0" />
<meta name="react-lifecycles-compat" content="3.0.4" />
<meta name="react-popper" content="2.3.0" />
<meta name="react-redux" content="7.2.9" />
<meta name="react-router-dom" content="6.3.0" />
<meta name="react-router" content="6.3.0" />
<meta name="react-side-effect" content="2.1.2" />
<meta name="react-transition-group" content="4.4.5" />
<meta name="react-virtualized" content="9.22.5" />
<meta name="react" content="18.2.0" />
<meta name="recharts" content="2.12.1" />
<meta name="redux-saga" content="1.3.0" />
<meta name="redux-thunk" content="2.4.2" />
<meta name="redux" content="4.2.1" />
<meta name="regenerator-runtime" content="0.14.1" />
<meta name="rx" content="4.1.0" />
<meta name="rxjs" content="6.6.7" />
<meta name="scroll-smooth" content="1.1.1" />
<meta name="simplebar" content="6.2.5" />
<meta name="styled-components" content="5.3.11" />
<meta name="uuid" content="8.3.2" />
<script type="text/javascript">
window.basename = '/';
var process = { browser: true, env: { NODE_ENV: 'development' } };
Expand Down
162 changes: 162 additions & 0 deletions packages/playground/mockVite/kit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import http from 'https';
import url from 'url';

function getTriggerInfo(req) {
return {
...req.query,
args: req.body,
};
}

function basicAuth(args) {
let comment;
let status;
if (!args['basicAuth.url']) {
comment = 'no url';
status = 'KO';
} else if (!args['basicAuth.password']) {
comment = 'no password';
status = 'KO';
} else if (!args['basicAuth.username']) {
comment = 'no username';
status = 'KO';
}

if (!status) {
if (args['basicAuth.username'] === args['basicAuth.password']) {
comment = 'Yes username === password';
status = 'OK';
} else {
status = 'KO';
comment = 'invalid credentials';
}
}
return { comment, status };
}

function urlValidation({ arg0 }) {
if (arg0) {
const parsed = url.parse(arg0);
if (!parsed.protocol) {
return { comment: `no protocol: ${arg0}`, status: 'KO' };
}
if (!parsed.hostname) {
return { comment: `no hostname: ${arg0}`, status: 'KO' };
}
}
return { status: 'OK' };
}

function guessTableSchema() {
return { status: 'OK' };
}

function reloadForm({ id }) {
if (!id) {
return add.ui;
}
return basic;
}

function suggestionForDemo() {
return {
cacheable: true,
items: [
{ id: 'clafoutis', label: 'Clafoutis aux poires et aux fruits' },
{ id: 'conchiglioni-au-thon', label: 'Conchiglioni au thon' },
{ id: 'coquillettes-crevettes', label: 'coquillettes aux crevettes' },
{ id: 'crumble', label: 'Crumble a la danette' },
{ id: 'pomme-savane', label: 'Pomme savane' },
{ id: 'tarte-au-citron', label: 'Tarte au citron' },
],
};
}

const cache = {};

function suggestionBig() {
if (cache.photos) {
return cache.photos;
}
return res => {
let body = '';
function onData(chunk) {
console.log('onData', chunk);
body += chunk;
}
function onEnd() {
console.log('onEnd', body);
cache.photos = {
cacheable: true,
items: JSON.parse(body).map(item => ({ id: item.id.toString(), label: item.title })),
};
res.json(cache.photos);
}
function onResponse(resp) {
console.log(`Got response: ${resp.statusCode}`);
resp.on('data', onData);
resp.on('end', onEnd);
}
function onError(e) {
console.error(e.message);
}
http.get('https://jsonplaceholder.typicode.com/photos', onResponse).on('error', onError);
};
}

function updateProperties({ type }) {
switch (type) {
case 'clafoutis':
case 'pomme-savane':
case 'crumble':
case 'tarte-au-citron':
return { data: 'yes !' };
case 'coquillettes-crevettes':
return { data: 'this is not a dessert !' };
default:
return { data: 'don t know that' };
}
}

function giveMeFive() {
return res => {
res.status(500).json({
timestamp: 1548781374412,
status: 500,
error: 'Internal Server Error',
exception: 'javax.ws.rs.ClientErrorException',
message: 'An internal server error occurs',
path: '/proxy/v1/action/execute/dataset',
});
};
}

const TRIGGERS = {
validation: {
urlValidation,
},
healthcheck: {
basicAuth,
},
schema: {
guessTableSchema,
},
reloadForm: {
'builtin::root::reloadFromId': reloadForm,
},
suggestions: {
suggestionForDemo,
suggestionBig,
},
update: {
updateProperties,
},
error: {
giveMeFive,
},
};

export function trigger(req) {
const info = getTriggerInfo(req);
return TRIGGERS[info.type][info.action](info.args);
}
26 changes: 26 additions & 0 deletions packages/playground/mockVite/mock/header-bar/products-list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"id": "TMC",
"name": "Management Console",
"url": "https://www.talend.com/products#tmc",
"icon": "tmc"
},
{
"id": "TDP",
"name": "Data Preparation",
"url": "https://www.talend.com/products#tdp",
"icon": "tdp"
},
{
"id": "TIPAAS",
"name": "TIPAAS",
"url": "https://www.talend.com/products#tipaas",
"icon": "tic"
},
{
"id": "TDC",
"name": "Catalog",
"url": "https://www.talend.com/products#tdc",
"icon": "tdc"
}
]
Loading

0 comments on commit d3ef679

Please sign in to comment.