Skip to content

Commit

Permalink
Add prompt to delete
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-yeager committed Nov 22, 2024
1 parent c4c8c44 commit f134846
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions commands/customObject/schema/delete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-nocheck
import { EXIT_CODES } from '../../../lib/enums/exitCodes';
import { confirmPrompt, inputPrompt } from '../../../lib/prompts/promptUtils';
import { confirmPrompt, listPrompt } from '../../../lib/prompts/promptUtils';
import { fetchObjectSchemas } from '@hubspot/local-dev-lib/api/customObjects';

const { logger } = require('@hubspot/local-dev-lib/logger');
const { loadAndValidateOptions } = require('../../../lib/validation');
Expand All @@ -23,18 +24,27 @@ exports.handler = async options => {

trackCommandUsage('custom-object-schema-delete', null, derivedAccountId);

// TODO: Fetch the schemas and show a list. Allow the user to select one.
const name =
providedName || (await inputPrompt(i18n(`${i18nKey}.selectSchema`)));
const shouldDelete =
force || (await confirmPrompt(i18n(`${i18nKey}.confirmDelete`, { name })));
let name;
try {
const {
data: { results },
} = await fetchObjectSchemas(derivedAccountId);
const schemaNames = results?.map(({ name: schemaName }) => schemaName);
name =
providedName ||
(await listPrompt(i18n(`${i18nKey}.selectSchema`), {
choices: schemaNames,
}));

if (!shouldDelete) {
logger.success(i18n(`${i18nKey}.deleteCancelled`, { name }));
return process.exit(EXIT_CODES.SUCCESS);
}
const shouldDelete =
force ||
(await confirmPrompt(i18n(`${i18nKey}.confirmDelete`, { name })));

if (!shouldDelete) {
logger.success(i18n(`${i18nKey}.deleteCancelled`, { name }));
return process.exit(EXIT_CODES.SUCCESS);
}

try {
await deleteObjectSchema(derivedAccountId, name);
logger.success(
i18n(`${i18nKey}.success.delete`, {
Expand Down

0 comments on commit f134846

Please sign in to comment.