Skip to content

Commit

Permalink
Implement resizing of configurable features (#878)
Browse files Browse the repository at this point in the history
* provision configured features

* update gql types

* enable resizing of configurable features

* set configured feature to default value if it doesn't exist on the current plan
  • Loading branch information
David Leger authored Jan 27, 2020
1 parent ee7fce5 commit 0970663
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export namespace Components {
'resourceLabel'?: string;
}
interface ManifoldDataResizeButton {
'configuredFeatures'?: ConfiguredFeatureInput[];
/**
* _(hidden)_ Passed by `<manifold-connection>`
*/
Expand Down Expand Up @@ -1268,6 +1269,7 @@ declare namespace LocalJSX {
'resourceLabel'?: string;
}
interface ManifoldDataResizeButton {
'configuredFeatures'?: ConfiguredFeatureInput[];
/**
* _(hidden)_ Passed by `<manifold-connection>`
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import {
ResourceChangePlanMutation,
ResourceIdQuery,
ResourceIdQueryVariables,
ConfiguredFeatureInput,
ResourceChangePlanMutationVariables,
} from '../../types/graphql';

interface ClickMessage {
planId?: string;
resourceId: string;
resourceLabel: string;
configuredFeatures?: ConfiguredFeatureInput[];
}

interface SuccessMessage {
Expand All @@ -31,6 +34,7 @@ interface ErrorMessage {
resourceId?: string;
resourceLabel?: string;
planId?: string;
configuredFeatures?: ConfiguredFeatureInput[];
}

@Component({ tag: 'manifold-data-resize-button' })
Expand All @@ -40,6 +44,7 @@ export class ManifoldDataResizeButton {
@Prop() graphqlFetch?: GraphqlFetch = connection.graphqlFetch;
@Prop() planId?: string;
@Prop() resourceLabel?: string;
@Prop() configuredFeatures?: ConfiguredFeatureInput[];
@Prop({ mutable: true }) resourceId?: string;
@Event({ eventName: 'manifold-resizeButton-click', bubbles: true }) click: EventEmitter;
@Event({ eventName: 'manifold-resizeButton-error', bubbles: true }) error: EventEmitter;
Expand Down Expand Up @@ -82,15 +87,19 @@ export class ManifoldDataResizeButton {
planId: this.planId,
resourceLabel: this.resourceLabel,
resourceId: this.resourceId,
configuredFeatures: this.configuredFeatures,
};
this.click.emit(clickDetail);

const variables: ResourceChangePlanMutationVariables = {
resourceId: this.resourceId,
planId: this.planId,
configuredFeatures: this.configuredFeatures,
};

const { data, errors } = await this.graphqlFetch<ResourceChangePlanMutation>({
query: updatePlan,
variables: {
resourceId: this.resourceId,
planId: this.planId,
},
variables,
element: this.el,
});

Expand All @@ -113,6 +122,7 @@ export class ManifoldDataResizeButton {
planId: this.planId,
resourceId: this.resourceId,
resourceLabel: this.resourceLabel,
configuredFeatures: this.configuredFeatures,
};
this.error.emit(error);
});
Expand Down
10 changes: 8 additions & 2 deletions src/components/manifold-data-resize-button/updatePlan.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
mutation ResourceChangePlan($resourceId: ID!, $planId: ID!) {
updateResourcePlan(input: { resourceId: $resourceId, newPlanID: $planId }) {
mutation ResourceChangePlan(
$resourceId: ID!
$planId: ID!
$configuredFeatures: [ConfiguredFeatureInput!]
) {
updateResourcePlan(
input: { resourceId: $resourceId, newPlanID: $planId, configuredFeatures: $configuredFeatures }
) {
data {
id
label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,11 @@ export class ManifoldPlanDetails {

resetFeatures = (plan: Plan, configuredFeatures: Gateway.FeatureMap = {}) => {
if (plan.configurableFeatures) {
if (this.readOnly && this.isExistingResource) {
this.features = configuredFeatures;
if (this.readOnly || this.isExistingResource) {
this.features = {
...configurableFeatureDefaults(plan.configurableFeatures.edges),
...configuredFeatures,
};
} else {
this.features = configurableFeatureDefaults(plan.configurableFeatures.edges);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ export class ManifoldPlanSelector {

return (
<manifold-active-plan
selectedResource={this.resource}
isExistingResource={!!this.resourceLabel}
plans={this.plans}
product={this.product}
regions={regions}
selectedResource={this.resource}
isExistingResource={!!this.resource}
>
<manifold-forward-slot slot="cta">
<slot name="cta" />
Expand Down
3 changes: 2 additions & 1 deletion src/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,8 @@ export type RenameResourceMutation = (

export type ResourceChangePlanMutationVariables = {
resourceId: Scalars['ID'],
planId: Scalars['ID']
planId: Scalars['ID'],
configuredFeatures?: Maybe<Array<ConfiguredFeatureInput>>
};


Expand Down

1 comment on commit 0970663

@vercel
Copy link

@vercel vercel bot commented on 0970663 Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.