Skip to content

Commit

Permalink
Config input update (#33)
Browse files Browse the repository at this point in the history
* Update config create.

* 2.0.3
  • Loading branch information
novalisdenahi authored Aug 2, 2024
1 parent 1de4c8f commit 77fdc3a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "configcat-feature-flags",
"displayName": "ConfigCat Feature Flags",
"description": "ConfigCat Visual Studio Code extension to manage feature flags from Visual Studio Code.",
"version": "2.0.2",
"version": "2.0.3",
"publisher": "ConfigCat",
"repository": "https://github.com/configcat/vscode-extension-configcat",
"preview": false,
Expand Down
25 changes: 12 additions & 13 deletions src/configs/config-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export class ConfigProvider implements vscode.TreeDataProvider<Resource> {

const productsService = this.publicApiService.createProductsService(publicApiConfiguration, workspaceConfiguration.publicApiBaseUrl);
return productsService.getProducts().then(products => {
const items = products.data.map((p, index) => new Resource(p.productId ?? '', '', p.name ?? '', ResourceType.product, index === 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed));
const items = products.data.map((p, index) => new Resource(p.productId ?? '', '', p.name ?? '', ResourceType.product, index === 0 ? vscode.TreeItemCollapsibleState.Expanded : vscode.TreeItemCollapsibleState.Collapsed, p.description ?? ''));
statusBar.hide();
if (!items.length) {
items.push(new Resource('-1', '', 'Could not find any Products.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None));
items.push(new Resource('-1', '', 'Could not find any Products.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None, ''));
}
return items;
}, error => {
handleError('Could not load Products.', error);
statusBar.hide();
return [new Resource('-1', '', 'Could not load Products.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None)];
return [new Resource('-1', '', 'Could not load Products.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None, '')];
});
}, () => {
return [];
Expand All @@ -97,16 +97,16 @@ export class ConfigProvider implements vscode.TreeDataProvider<Resource> {

const configsService = this.publicApiService.createConfigsService(publicApiConfiguration, workspaceConfiguration.publicApiBaseUrl);
return configsService.getConfigs(productId).then(configs => {
const items = configs.data.map(c => new Resource(c.configId ?? '', productId, c.name ?? '', ResourceType.config, vscode.TreeItemCollapsibleState.None));
const items = configs.data.map(c => new Resource(c.configId ?? '', productId, c.name ?? '', ResourceType.config, vscode.TreeItemCollapsibleState.None, c.description ?? ''));
statusBar.hide();
if (!items.length) {
items.push(new Resource('-1', '', 'Could not find any Configs.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None));
items.push(new Resource('-1', '', 'Could not find any Configs.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None, ''));
}
return items;
}, error => {
handleError('Could not load Configs.', error);
statusBar.hide();
return [new Resource('-1', '', 'Could not load Configs.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None)];
return [new Resource('-1', '', 'Could not load Configs.', ResourceType.unknown, vscode.TreeItemCollapsibleState.None, '')];
});
}, () => {
return [];
Expand Down Expand Up @@ -198,21 +198,18 @@ export class ConfigProvider implements vscode.TreeDataProvider<Resource> {
return;
}

let evaluationVersion: EvaluationVersion;
let configDescription: string;

try {
evaluationVersion = await ConfigInput.configVersionInput();
configDescription = await ConfigInput.configDescriptionInput();
} catch (error) {
return;
}
if (!evaluationVersion) {
return;
}

const configsService = this.publicApiService.createConfigsService(authenticationConfiguration, workspaceConfiguration.publicApiBaseUrl);
let config = null;
try {
config = await configsService.createConfig(productId, { name: configName, evaluationVersion: evaluationVersion });
config = await configsService.createConfig(productId, { name: configName, evaluationVersion: EvaluationVersion.V2, description: configDescription });
} catch (error) {
handleError('Could not create Config.', error)
}
Expand Down Expand Up @@ -320,8 +317,10 @@ class Resource extends vscode.TreeItem {
public readonly label: string,
public resourceType: ResourceType,
public readonly collapsibleState: vscode.TreeItemCollapsibleState,
public readonly tooltip: string,
) {
super(label, collapsibleState);
super.tooltip = tooltip;
super.contextValue = resourceType;
}
}
}
31 changes: 14 additions & 17 deletions src/inputs/config-input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigModel, EvaluationVersion } from 'configcat-publicapi-node-client';
import { ConfigModel } from 'configcat-publicapi-node-client';
import * as vscode from 'vscode';

export class ConfigInput {
Expand Down Expand Up @@ -37,23 +37,20 @@ export class ConfigInput {
return Promise.resolve(name);
}


static async configVersionInput(): Promise<EvaluationVersion> {

const pick = await vscode.window.showQuickPick(
[{label: "V2"}, {label:"V1", description: "(Legacy)"} ],
{
canPickMany: false,
placeHolder: 'Select the config version'
});

if (!pick) {
return Promise.reject();
}

return Promise.resolve(EvaluationVersion[pick.label]);
}
static async configDescriptionInput(): Promise<string> {

const description = await vscode.window.showInputBox({
prompt: 'Please enter the description of the Config',
placeHolder: 'This config is responsible for...',
ignoreFocusOut: true,
value: ''
});
if (description === undefined) {
return Promise.reject();
}

return Promise.resolve(description);
}

static async askConnect(): Promise<string> {

Expand Down

0 comments on commit 77fdc3a

Please sign in to comment.