Skip to content

Commit

Permalink
feat: workflow parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Aug 20, 2022
1 parent 11e9960 commit f9f1375
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 117 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ get-pass-key.js
getPassKey.js

.idea

business/prod
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"crypto-js": "^4.1.1",
"css-selector-generator": "^3.6.3",
"dagre": "^0.8.5",
"dayjs": "^1.10.7",
"dayjs": "^1.11.5",
"defu": "^6.0.0",
"dexie": "^3.2.2",
"idb": "^7.0.2",
Expand Down Expand Up @@ -91,7 +91,7 @@
"core-js": "^3.23.3",
"cross-env": "^7.0.3",
"css-loader": "^6.7.1",
"eslint": "^8.21.0",
"eslint": "^8.22.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.3.0",
"eslint-friendly-formatter": "^4.0.1",
Expand All @@ -105,13 +105,13 @@
"html-webpack-plugin": "^5.5.0",
"lint-staged": "^13.0.2",
"mini-css-extract-plugin": "^2.3.0",
"postcss": "8.4.14",
"postcss": "^8.4.16",
"postcss-loader": "^7.0.0",
"prettier": "^2.7.1",
"simple-git-hooks": "^2.6.1",
"source-map-loader": "^4.0.0",
"tailwindcss": "^3.1.6",
"terser-webpack-plugin": "^5.3.3",
"terser-webpack-plugin": "^5.3.5",
"vue-loader": "^17.0.0",
"web-worker": "^1.2.0",
"webpack": "^5.73.0",
Expand Down
115 changes: 9 additions & 106 deletions src/components/newtab/workflow/edit/EditTrigger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,94 +26,29 @@
/>
</keep-alive>
</transition-expand>
<ui-button class="mt-4" @click="state.showModal = true">
<ui-button class="mt-4" @click="showModal = true">
<v-remixicon name="riCommandLine" class="mr-2 -ml-1" />
<span>Parameters</span>
</ui-button>
<ui-modal
v-model="state.showModal"
title="Parameters"
content-class="max-w-4xl"
>
<div
class="overflow-auto scroll"
style="max-height: calc(100vh - 15rem); min-height: 200px"
>
<p
v-if="state.parameters.length === 0"
class="my-4 text-center text-gray-600 dark:text-gray-200"
>
No parameters
</p>
<table v-else class="w-full">
<thead>
<tr class="text-sm text-left">
<th>Name</th>
<th>Type</th>
<th>Placeholder</th>
<th>Default Value</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="(param, index) in state.parameters" :key="index">
<td>
<ui-input
:model-value="param.name"
placeholder="Parameter name"
@change="updateParam(index, $event)"
/>
</td>
<td>
<ui-select v-model="param.type">
<option
v-for="type in paramTypes"
:key="type.id"
:value="type.id"
>
{{ type.name }}
</option>
</ui-select>
</td>
<td>
<ui-input
v-model="param.placeholder"
placeholder="A parameter"
/>
</td>
<td>
<ui-input
v-model="param.defaultValue"
:type="param.type === 'number' ? 'number' : 'text'"
placeholder="NULL"
/>
</td>
<td>
<ui-button icon @click="state.parameters.splice(index, 1)">
<v-remixicon name="riDeleteBin7Line" />
</ui-button>
</td>
</tr>
</tbody>
</table>
</div>
<ui-button variant="accent" class="mt-4" @click="addParameter">
Add parameter
</ui-button>
<ui-modal v-model="showModal" title="Parameters" content-class="max-w-4xl">
<edit-workflow-parameters
:data="data.parameters"
@update="updateData({ parameters: $event })"
/>
</ui-modal>
</div>
</template>
<script setup>
import { reactive, watch } from 'vue';
import { shallowRef } from 'vue';
import { useI18n } from 'vue-i18n';
import cloneDeep from 'lodash.clonedeep';
import TriggerDate from './Trigger/TriggerDate.vue';
import TriggerInterval from './Trigger/TriggerInterval.vue';
import TriggerVisitWeb from './Trigger/TriggerVisitWeb.vue';
import TriggerContextMenu from './Trigger/TriggerContextMenu.vue';
import TriggerSpecificDay from './Trigger/TriggerSpecificDay.vue';
// import TriggerElementChange from './Trigger/TriggerElementChange.vue';
import TriggerKeyboardShortcut from './Trigger/TriggerKeyboardShortcut.vue';
import EditWorkflowParameters from './EditWorkflowParameters.vue';
const props = defineProps({
data: {
Expand All @@ -134,44 +69,12 @@ const triggers = {
'visit-web': TriggerVisitWeb,
'keyboard-shortcut': TriggerKeyboardShortcut,
};
const paramTypes = [
{ id: 'string', name: 'String' },
{ id: 'number', name: 'Number' },
];
const { t } = useI18n();
const state = reactive({
showModal: false,
parameters: cloneDeep(props.data.parameters || []),
});
const showModal = shallowRef(false);
function updateData(value) {
emit('update:data', { ...props.data, ...value });
}
function addParameter() {
state.parameters.push({
name: 'param',
type: 'string',
placeholder: 'Text',
defaultValue: '',
});
}
function updateParam(index, value) {
state.parameters[index].name = value.replace(/\s/g, '_');
}
watch(
() => state.parameters,
(parameters) => {
updateData({ parameters });
},
{ deep: true }
);
</script>
<style scoped>
table th,
table td {
@apply p-1 font-normal;
}
</style>
152 changes: 152 additions & 0 deletions src/components/newtab/workflow/edit/EditWorkflowParameters.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<template>
<div
class="overflow-auto scroll"
style="max-height: calc(100vh - 15rem); min-height: 200px"
>
<p
v-if="state.parameters.length === 0"
class="my-4 text-center text-gray-600 dark:text-gray-200"
>
No parameters
</p>
<table v-else class="w-full">
<thead>
<tr class="text-sm text-left">
<th>Name</th>
<th>Type</th>
<th>Placeholder</th>
<th>Default Value</th>
<th></th>
</tr>
</thead>
<tbody>
<template v-for="(param, index) in state.parameters" :key="index">
<tr>
<td>
<ui-input
:model-value="param.name"
placeholder="Parameter name"
@change="updateParam(index, $event)"
/>
</td>
<td>
<ui-select v-model="param.type">
<option
v-for="type in paramTypes"
:key="type.id"
:value="type.id"
>
{{ type.name }}
</option>
</ui-select>
</td>
<td>
<ui-input v-model="param.placeholder" placeholder="A parameter" />
</td>
<td>
<component
:is="paramTypes[param.type].valueComp"
v-if="paramTypes[param.type].valueComp"
v-model="param.defaultValue"
:param-data="param"
/>
<ui-input
v-else
v-model="param.defaultValue"
:type="param.type === 'number' ? 'number' : 'text'"
placeholder="NULL"
/>
</td>
<td>
<ui-button icon @click="state.parameters.splice(index, 1)">
<v-remixicon name="riDeleteBin7Line" />
</ui-button>
</td>
</tr>
<tr v-if="paramTypes[param.type].options">
<td colspan="999" style="padding-top: 0">
<ui-expand
hide-header-icon
header-class="flex items-center focus:ring-0 w-full"
>
<template #header="{ show }">
<v-remixicon
:rotate="show ? 270 : 180"
name="riArrowLeftSLine"
class="mr-2 transition-transform -ml-1"
/>
<span>Options</span>
</template>
<div class="pl-[28px] mt-2 mb-4">
<component
:is="paramTypes[param.type].options"
v-model="param.data"
/>
</div>
</ui-expand>
</td>
</tr>
</template>
</tbody>
</table>
</div>
<ui-button variant="accent" class="mt-4" @click="addParameter">
Add parameter
</ui-button>
</template>
<script setup>
import { reactive, watch } from 'vue';
import cloneDeep from 'lodash.clonedeep';
import { workflowParameters } from '@business';
const props = defineProps({
data: {
type: Array,
default: () => [],
},
});
const emit = defineEmits(['update']);
const paramTypes = {
string: {
id: 'string',
name: 'Input (string)',
},
number: {
id: 'number',
name: 'Input (number)',
},
...workflowParameters,
};
const state = reactive({
parameters: cloneDeep(props.data || []),
});
function addParameter() {
state.parameters.push({
data: {},
name: 'param',
type: 'string',
defaultValue: '',
placeholder: 'Text',
});
}
function updateParam(index, value) {
state.parameters[index].name = value.replace(/\s/g, '_');
}
watch(
() => state.parameters,
(parameters) => {
emit('update', parameters);
},
{ deep: true }
);
</script>
<style scoped>
table th,
table td {
@apply p-1 font-normal;
}
</style>
8 changes: 1 addition & 7 deletions src/utils/handleFormElement.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sleep, objectHasKey } from '@/utils/helper';
import { sleep } from '@/utils/helper';
import { keyDefinitions } from '@/utils/USKeyboardLayout';
import simulateEvent from './simulateEvent';

Expand All @@ -7,12 +7,6 @@ const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
'value'
).set;
function reactJsEvent(element, value) {
console.dir(element);
console.log(
objectHasKey(element, '_valueTracker'),
element.parentElement.hasChildNodes(element)
);
console.log(!element._valueTracker, element._valueTracker, element);
if (!element._valueTracker) return;

const previousValue = element.value;
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const ASSET_PATH = process.env.ASSET_PATH || '/';
const alias = {
'@': path.resolve(__dirname, 'src/'),
secrets: path.join(__dirname, 'secrets.blank.js'),
'@business': path.resolve(__dirname, 'business/prod'),
};

// load the secrets
Expand Down

0 comments on commit f9f1375

Please sign in to comment.