Skip to content

Commit

Permalink
Added UI text to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav-from-contentstack committed Mar 12, 2021
1 parent 990ffbb commit 1a86577
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions packages/export-to-csv/src/commands/cm/export-to-csv.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const {Command} = require('@contentstack/cli-command')
const util = require('../../util/index')
const ContentstackManagementSDK = require('@contentstack/management')
const config = require('../../util/config.js')

class ExportToCsvCommand extends Command {

Expand All @@ -15,7 +16,7 @@ class ExportToCsvCommand extends Command {
const action = await util.startupQuestions()

switch(action) {
case 'Export Entries to CSV': {
case config.exportEntries: {
const organization = await util.chooseOrganization(this.managementAPIClient) // prompt for organization
const stack = await util.chooseStack(this.managementAPIClient, organization.uid) // prompt for stack
const contentTypes = await util.chooseContentType(this.managementAPIClient, stack.apiKey) // prompt for content Type
Expand All @@ -31,7 +32,7 @@ class ExportToCsvCommand extends Command {
}
break;
}
case 'Export Organization Users to CSV': {
case config.exportUsers: {
try {
const organization = await util.chooseOrganization(this.managementAPIClient, action) // prompt for organization
const orgUsers = await util.getOrgUsers(this.managementAPIClient, organization.uid)
Expand Down
5 changes: 4 additions & 1 deletion packages/export-to-csv/src/util/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
module.exports = {
cancelString: 'Cancel and Exit'
cancelString: 'Cancel and Exit',
exportEntries: 'Export entries to a .CSV file',
exportUsers: 'Export organization users\' data to a .CSV file',
adminError: 'Unable to export data. Make sure you\'re an admin or owner of this organization'
}
8 changes: 4 additions & 4 deletions packages/export-to-csv/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const delimeter = (os.platform() === 'win32') ? '\\' : '/'
function chooseOrganization(managementAPIClient, action) {
return new Promise(async resolve => {
let organizations
if (action === 'Export Organization Users to CSV') {
if (action === config.exportUsers) {
organizations = await getOrganizationsWhereUserIsAdmin(managementAPIClient)
} else {
organizations = await getOrganizations(managementAPIClient)
Expand Down Expand Up @@ -260,7 +260,7 @@ function startupQuestions() {
type: 'list',
name: 'action',
message: 'Choose Action',
choices: ['Export entries to a .CSV file', 'Export organization users\' data to a .CSV file', 'Exit'],
choices: [config.exportEntries, config.exportUsers, 'Exit'],
}]
inquirer.prompt(actions).then(answers => {
if(answers.action === 'Exit')
Expand All @@ -277,7 +277,7 @@ function getOrgUsers(managementAPIClient, orgUid) {
.then(response => {
let organization = response.organizations.filter(org => org.uid === orgUid).pop()
if (!organization.getInvitations) {
return reject(new Error('You need to be an admin for exporting this organization\'s users'))
return reject(new Error(config.adminError))
}
organization.getInvitations().then(users => resolve(users))
})
Expand All @@ -304,7 +304,7 @@ function getOrgRoles(managementAPIClient, orgUid) {
.then(response => {
let organization = response.organizations.filter(org => org.uid === orgUid).pop()
if (!organization.roles) {
return reject(new Error('You need to be an admin for exporting this organization\'s users'))
return reject(new Error(config.adminError))
}
organization.roles().then(roles => resolve(roles))
})
Expand Down

0 comments on commit 1a86577

Please sign in to comment.