|
@@ -1,5 +1,5 @@
|
|
<template>
|
|
<template>
|
|
- <div>
|
|
|
|
|
|
+ <div class="mb-10">
|
|
<ui-textarea
|
|
<ui-textarea
|
|
:model-value="data.description"
|
|
:model-value="data.description"
|
|
class="w-full mb-2"
|
|
class="w-full mb-2"
|
|
@@ -9,13 +9,10 @@
|
|
<ui-select
|
|
<ui-select
|
|
:model-value="data.type"
|
|
:model-value="data.type"
|
|
class="w-full mb-2"
|
|
class="w-full mb-2"
|
|
- @change="updateData({ type: $event })"
|
|
|
|
|
|
+ @change="onActionChange"
|
|
>
|
|
>
|
|
- <option value="get">
|
|
|
|
- {{ t('workflow.blocks.google-sheets.select.get') }}
|
|
|
|
- </option>
|
|
|
|
- <option value="update">
|
|
|
|
- {{ t('workflow.blocks.google-sheets.select.update') }}
|
|
|
|
|
|
+ <option v-for="action in actions" :key="action" :value="action">
|
|
|
|
+ {{ t(`workflow.blocks.google-sheets.select.${action}`) }}
|
|
</option>
|
|
</option>
|
|
</ui-select>
|
|
</ui-select>
|
|
<edit-autocomplete>
|
|
<edit-autocomplete>
|
|
@@ -84,13 +81,17 @@
|
|
<p v-if="previewDataState.status === 'error'" class="text-red-500">
|
|
<p v-if="previewDataState.status === 'error'" class="text-red-500">
|
|
{{ previewDataState.errorMessage }}
|
|
{{ previewDataState.errorMessage }}
|
|
</p>
|
|
</p>
|
|
- <shared-codemirror
|
|
|
|
- v-if="previewDataState.data && previewDataState.status !== 'error'"
|
|
|
|
- :model-value="previewDataState.data"
|
|
|
|
- :line-numbers="false"
|
|
|
|
- readonly
|
|
|
|
- class="mt-4 max-h-96 scroll"
|
|
|
|
- />
|
|
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="data.type === 'getRange'">
|
|
|
|
+ <insert-workflow-data :data="data" variables @update="updateData" />
|
|
|
|
+ <ui-button
|
|
|
|
+ :loading="previewDataState.status === 'loading'"
|
|
|
|
+ variant="accent"
|
|
|
|
+ class="mt-4"
|
|
|
|
+ @click="previewData"
|
|
|
|
+ >
|
|
|
|
+ {{ t('workflow.blocks.google-sheets.previewData') }}
|
|
|
|
+ </ui-button>
|
|
</template>
|
|
</template>
|
|
<template v-else-if="data.type === 'update'">
|
|
<template v-else-if="data.type === 'update'">
|
|
<ui-select
|
|
<ui-select
|
|
@@ -143,6 +144,17 @@
|
|
{{ t('workflow.blocks.google-sheets.insertData') }}
|
|
{{ t('workflow.blocks.google-sheets.insertData') }}
|
|
</ui-button>
|
|
</ui-button>
|
|
</template>
|
|
</template>
|
|
|
|
+ <shared-codemirror
|
|
|
|
+ v-if="
|
|
|
|
+ previewDataState.data &&
|
|
|
|
+ previewDataState.status !== 'error' &&
|
|
|
|
+ type !== 'update'
|
|
|
|
+ "
|
|
|
|
+ :model-value="previewDataState.data"
|
|
|
|
+ :line-numbers="false"
|
|
|
|
+ readonly
|
|
|
|
+ class="mt-4 max-h-96 scroll"
|
|
|
|
+ />
|
|
<ui-modal
|
|
<ui-modal
|
|
v-model="customDataState.showModal"
|
|
v-model="customDataState.showModal"
|
|
title="Custom data"
|
|
title="Custom data"
|
|
@@ -163,6 +175,7 @@ import { useI18n } from 'vue-i18n';
|
|
import { googleSheets } from '@/utils/api';
|
|
import { googleSheets } from '@/utils/api';
|
|
import { convert2DArrayToArrayObj } from '@/utils/helper';
|
|
import { convert2DArrayToArrayObj } from '@/utils/helper';
|
|
import EditAutocomplete from './EditAutocomplete.vue';
|
|
import EditAutocomplete from './EditAutocomplete.vue';
|
|
|
|
+import InsertWorkflowData from './InsertWorkflowData.vue';
|
|
|
|
|
|
const SharedCodemirror = defineAsyncComponent(() =>
|
|
const SharedCodemirror = defineAsyncComponent(() =>
|
|
import('@/components/newtab/shared/SharedCodemirror.vue')
|
|
import('@/components/newtab/shared/SharedCodemirror.vue')
|
|
@@ -178,6 +191,7 @@ const emit = defineEmits(['update:data']);
|
|
|
|
|
|
const { t } = useI18n();
|
|
const { t } = useI18n();
|
|
|
|
|
|
|
|
+const actions = ['get', 'getRange', 'update'];
|
|
const dataFrom = ['data-columns', 'custom'];
|
|
const dataFrom = ['data-columns', 'custom'];
|
|
const valueInputOptions = ['RAW', 'USER_ENTERED'];
|
|
const valueInputOptions = ['RAW', 'USER_ENTERED'];
|
|
|
|
|
|
@@ -197,10 +211,15 @@ function updateData(value) {
|
|
async function previewData() {
|
|
async function previewData() {
|
|
try {
|
|
try {
|
|
previewDataState.status = 'loading';
|
|
previewDataState.status = 'loading';
|
|
- const response = await googleSheets.getValues({
|
|
|
|
- spreadsheetId: props.data.spreadsheetId,
|
|
|
|
|
|
+
|
|
|
|
+ const isGetValues = props.data.type === 'get';
|
|
|
|
+ const params = {
|
|
range: props.data.range,
|
|
range: props.data.range,
|
|
- });
|
|
|
|
|
|
+ spreadsheetId: props.data.spreadsheetId,
|
|
|
|
+ };
|
|
|
|
+ const response = await (isGetValues
|
|
|
|
+ ? googleSheets.getValues(params)
|
|
|
|
+ : googleSheets.getRange(params));
|
|
|
|
|
|
if (!response.ok) {
|
|
if (!response.ok) {
|
|
const error = await response.json();
|
|
const error = await response.json();
|
|
@@ -208,18 +227,33 @@ async function previewData() {
|
|
throw new Error(error.statusMessage || response.statusText);
|
|
throw new Error(error.statusMessage || response.statusText);
|
|
}
|
|
}
|
|
|
|
|
|
- const { values } = await response.json();
|
|
|
|
- const sheetsData = props.data.firstRowAsKey
|
|
|
|
- ? convert2DArrayToArrayObj(values)
|
|
|
|
- : values;
|
|
|
|
|
|
+ let result = await response.json();
|
|
|
|
|
|
- previewDataState.data = JSON.stringify(sheetsData, null, 2);
|
|
|
|
|
|
+ if (isGetValues) {
|
|
|
|
+ result = props.data.firstRowAsKey
|
|
|
|
+ ? convert2DArrayToArrayObj(result.values)
|
|
|
|
+ : result.values;
|
|
|
|
+ } else {
|
|
|
|
+ result = {
|
|
|
|
+ tableRange: result.tableRange || null,
|
|
|
|
+ lastRange: result.updates.updatedRange,
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ previewDataState.data = JSON.stringify(result, null, 2);
|
|
previewDataState.status = 'idle';
|
|
previewDataState.status = 'idle';
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
|
+ console.error(error);
|
|
previewDataState.data = '';
|
|
previewDataState.data = '';
|
|
previewDataState.status = 'error';
|
|
previewDataState.status = 'error';
|
|
previewDataState.errorMessage = error.message;
|
|
previewDataState.errorMessage = error.message;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+function onActionChange(value) {
|
|
|
|
+ updateData({ type: value });
|
|
|
|
+
|
|
|
|
+ previewDataState.data = '';
|
|
|
|
+ previewDataState.status = '';
|
|
|
|
+ previewDataState.errorMessage = '';
|
|
|
|
+}
|
|
</script>
|
|
</script>
|