Browse Source

feat: add clear value options in google sheets block

Ahmad Kholid 2 years ago
parent
commit
27447d6245

+ 12 - 0
src/background/workflowEngine/blocksHandler/handlerGoogleSheets.js

@@ -35,6 +35,16 @@ async function getSpreadsheetRange({ spreadsheetId, range }) {
 
   return data;
 }
+async function clearSpreadsheetValues({ spreadsheetId, range }) {
+  const response = await googleSheets.clearValues({ spreadsheetId, range });
+  const result = await response.json();
+
+  if (!response.ok) {
+    throw new Error(result.message);
+  }
+
+  return result;
+}
 async function updateSpreadsheetValues(
   {
     range,
@@ -123,6 +133,8 @@ export default async function ({ data, id }, { refData }) {
       },
       refData.table
     );
+  } else if (data.type === 'clear') {
+    result = await clearSpreadsheetValues(data);
   }
 
   return {

+ 1 - 1
src/components/newtab/workflow/edit/EditGoogleSheets.vue

@@ -225,7 +225,7 @@ const emit = defineEmits(['update:data']);
 
 const { t } = useI18n();
 
-const actions = ['get', 'getRange', 'update', 'append'];
+const actions = ['get', 'getRange', 'update', 'append', 'clear'];
 const dataFrom = ['data-columns', 'custom'];
 const valueInputOptions = ['RAW', 'USER_ENTERED'];
 const insertDataOptions = ['OVERWRITE', 'INSERT_ROWS'];

+ 2 - 1
src/locales/en/blocks.json

@@ -404,7 +404,8 @@
           "get": "Get spreadsheet cell values",
           "getRange": "Get spreadsheet range",
           "update": "Update spreadsheet cell values",
-          "append": "Append spreadsheet cell values"
+          "append": "Append spreadsheet cell values",
+          "clear": "Clear spreadsheet cell values"
         }
       },
       "active-tab": {

+ 5 - 0
src/utils/api.js

@@ -49,6 +49,11 @@ export const googleSheets = {
       },
     });
   },
+  clearValues({ spreadsheetId, range }) {
+    return fetchApi(this.getUrl(spreadsheetId, range), {
+      method: 'DELETE',
+    });
+  },
   updateValues({ spreadsheetId, range, options = {}, append }) {
     const url = `${this.getUrl(spreadsheetId, range)}&${queryBuilder(
       options?.queries || {}