Skip to content

Commit e65ef36

Browse files
Merge pull request #1729 from CleverCloud/cc-network-group-list/handle-addons-with-dev-plans
feat(cc-network-group-list): show notice if add-on plan is dev
2 parents 01da001 + 8db21d8 commit e65ef36

11 files changed

Lines changed: 306 additions & 159 deletions

demo-smart/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,16 @@ <h2 class="ctx-group-title">Network</h2>
967967
<span class="ctx-subtitle">ownerId, networkGroupId</span>
968968
</button>
969969
</div>
970+
<div class="ctx-group">
971+
<button
972+
class="ctx-btn"
973+
title="ownerId, networkGroupId"
974+
data-context='{"ownerId":"orga_3547a882-d464-4c34-8168-add4b3e0c135","networkGroupId":"ng_b8711640-f593-437f-bae1-5b5e52d0fcc1","resourceId":"addon_50bfc371-d5b7-46b5-920b-2796a2ee9660","networkGroupDashboardUrlPattern":"/organisations/orga_3547a882-d464-4c34-8168-add4b3e0c135/network-groups/:id","appOverviewUrlPattern":"/organisations/orga_3547a882-d464-4c34-8168-add4b3e0c135/applications/:id","addonDashboardUrlPattern":"/organisations/orga_3547a882-d464-4c34-8168-add4b3e0c135/addons/:id","networkGroupCreationUrl":"/network-groups/new","addonMigrationScreenUrl":"/organisations/orga_3547a882-d464-4c34-8168-add4b3e0c135/addons/postgresql/addon_50bfc371-d5b7-46b5-920b-2796a2ee9660/migrations"}'
975+
>
976+
<span class="ctx-label">Network Group (add-on with dev plan)</span>
977+
<span class="ctx-subtitle">ownerId, networkGroupId</span>
978+
</button>
979+
</div>
970980
</div>
971981

972982
<!-- OAuth -->

src/components/cc-network-group-list/cc-network-group-list.js

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import '../cc-select/cc-select.js';
2525
import { CcNetworkGroupLinkEvent, CcNetworkGroupUnlinkEvent } from './cc-network-group-list.events.js';
2626

2727
/**
28-
* @import { NetworkGroupListState, NetworkGroupLinkFormState, NetworkGroup } from './cc-network-group-list.types.js'
28+
* @import { NetworkGroupListState, NetworkGroup } from './cc-network-group-list.types.js'
2929
* @import { Ref } from 'lit/directives/ref.js'
3030
* @import { Option } from '../cc-select/cc-select.types.js'
3131
* @import { CcLink } from '../cc-link/cc-link.js'
@@ -47,21 +47,18 @@ import { CcNetworkGroupLinkEvent, CcNetworkGroupUnlinkEvent } from './cc-network
4747
export class CcNetworkGroupList extends LitElement {
4848
static get properties() {
4949
return {
50-
linkFormState: { type: Object, attribute: 'link-form-state' },
51-
listState: { type: Object, attribute: 'list-state' },
5250
resourceId: { type: String, attribute: 'resource-id' },
51+
state: { type: Object },
52+
_isUnlinkDialogOpen: { type: Boolean, state: true },
5353
_networkGroupIdToUnlink: { type: String, state: true },
5454
};
5555
}
5656

5757
constructor() {
5858
super();
5959

60-
/** @type {NetworkGroupLinkFormState} Sets the state of the form */
61-
this.linkFormState = { type: 'loading' };
62-
63-
/** @type {NetworkGroupListState} Sets the state of the list */
64-
this.listState = { type: 'loading' };
60+
/** @type {NetworkGroupListState} Sets the state of the component */
61+
this.state = { type: 'loading' };
6562

6663
/** @type {string} Sets the resource ID for CLI command documentation */
6764
this.resourceId = '<RESOURCE_ID>';
@@ -75,6 +72,9 @@ export class CcNetworkGroupList extends LitElement {
7572
/** @type {Ref<HTMLElement>} */
7673
this._emptyListRef = createRef();
7774

75+
/** @type {boolean} */
76+
this._isUnlinkDialogOpen = false;
77+
7878
new LostFocusController(this, '.unlink-btn', ({ suggestedElement }) => {
7979
if (suggestedElement == null) {
8080
this._emptyListRef.value?.focus();
@@ -92,18 +92,31 @@ export class CcNetworkGroupList extends LitElement {
9292
});
9393
}
9494

95+
/**
96+
* @param {NetworkGroupListState} state
97+
* @returns {Option[]}
98+
**/
99+
_getSelectOptions(state) {
100+
if (state.type !== 'loaded' || state.linkFormState.type === 'empty') {
101+
return [];
102+
}
103+
104+
return state.linkFormState.selectOptions;
105+
}
106+
95107
/** @param {{ 'network-group': string }} formData */
96108
_onLink(formData) {
97109
this.dispatchEvent(new CcNetworkGroupLinkEvent(formData['network-group']));
98110
}
99111

100112
/** @param {string} networkGroupId */
101113
_onUnlinkRequest(networkGroupId) {
114+
this._isUnlinkDialogOpen = true;
102115
this._networkGroupIdToUnlink = networkGroupId;
103116
}
104117

105118
_onDialogClose() {
106-
this._networkGroupIdToUnlink = null;
119+
this._isUnlinkDialogOpen = false;
107120
}
108121

109122
_onDialogConfirm() {
@@ -114,50 +127,62 @@ export class CcNetworkGroupList extends LitElement {
114127

115128
/** @param {PropertyValues<CcNetworkGroupList>} changedProperties */
116129
willUpdate(changedProperties) {
117-
if (changedProperties.has('listState')) {
118-
const previousListState = changedProperties.get('listState');
119-
const wasUnlinking = previousListState?.type === 'unlinking';
120-
const isNotUnlinking = this.listState.type !== 'unlinking';
130+
if (changedProperties.has('state')) {
131+
const previousState = changedProperties.get('state');
132+
const wasUnlinking = previousState?.type === 'loaded' && previousState?.listState?.type === 'unlinking';
133+
const isNotUnlinking = this.state.type !== 'loaded' || this.state.listState.type !== 'unlinking';
121134
if (wasUnlinking && isNotUnlinking) {
135+
this._isUnlinkDialogOpen = false;
122136
this._networkGroupIdToUnlink = null;
123137
}
124138
}
125139
}
126140

127141
render() {
128-
const isUnlinking = this.listState.type === 'unlinking';
142+
if (this.state.type === 'unsupported') {
143+
return html`
144+
<cc-notice intent="info" heading="${i18n('cc-network-group-list.unsupported-notice.heading')}">
145+
<div slot="message">
146+
${i18n('cc-network-group-list.unsupported-notice.message', {
147+
addonMigrationScreenUrl: this.state.addonMigrationScreenUrl,
148+
})}
149+
</div>
150+
</cc-notice>
151+
`;
152+
}
129153

130-
const selectOptions =
131-
this.linkFormState.type === 'idle' || this.linkFormState.type === 'linking'
132-
? this.linkFormState.selectOptions
133-
: [];
154+
const isLoading = this.state.type === 'loading';
155+
const isError = this.state.type === 'error';
156+
const isLoaded = this.state.type === 'loaded';
157+
const linkFormState = this.state.type === 'loaded' ? this.state.linkFormState : null;
158+
const listState = this.state.type === 'loaded' ? this.state.listState : null;
159+
const isUnlinking = isLoaded && listState.type === 'unlinking';
160+
const selectOptions = this._getSelectOptions(this.state);
134161

135162
return html`
136163
<cc-block>
137164
<div slot="header-title">${i18n('cc-network-group-list.form.heading')}</div>
138165
<div slot="content">
139166
<p class="intro">${i18n('cc-network-group-list.form.description')}</p>
140-
${this.linkFormState.type === 'error'
167+
${isError
141168
? html`<cc-notice intent="warning" message="${i18n('cc-network-group-list.form.error')}"></cc-notice>`
142169
: ''}
143-
${this.linkFormState.type === 'empty'
170+
${isLoaded && linkFormState.type === 'empty'
144171
? html`<cc-link
145172
class="link-create-network-group"
146173
mode="button"
147-
href="${this.linkFormState.networkGroupDashboardUrl}"
174+
href="${linkFormState.networkGroupDashboardUrl}"
148175
${ref(this._createNetworkGroupLinkRef)}
149176
>
150177
${i18n('cc-network-group-list.create')}
151178
</cc-link>`
152179
: ''}
153-
${this.linkFormState.type === 'idle' ||
154-
this.linkFormState.type === 'loading' ||
155-
this.linkFormState.type === 'linking'
180+
${isLoading || (isLoaded && (linkFormState.type === 'idle' || linkFormState.type === 'linking'))
156181
? this._renderNetworkGroupLinkForm({
157182
selectOptions,
158-
isLoading: this.linkFormState.type === 'loading',
159-
isLinking: this.linkFormState.type === 'linking',
160-
isDisabled: this.listState.type === 'unlinking',
183+
isLoading,
184+
isLinking: isLoaded && linkFormState.type === 'linking',
185+
isDisabled: isLoaded && listState.type === 'unlinking',
161186
})
162187
: ''}
163188
</div>
@@ -202,12 +227,12 @@ export class CcNetworkGroupList extends LitElement {
202227
<cc-block>
203228
<div slot="header-title">${i18n('cc-network-group-list.list.heading')}</div>
204229
<div slot="content">
205-
${this.listState.type === 'error'
230+
${isError
206231
? html`<cc-notice intent="warning" message="${i18n('cc-network-group-list.list.error')}"></cc-notice>`
207232
: ''}
208-
${this.listState.type === 'loading' ? html`<cc-loader></cc-loader>` : ''}
209-
${this.listState.type === 'loaded' || this.listState.type === 'unlinking'
210-
? this._renderNetworkGroupList(this.listState.linkedNetworkGroupList, isUnlinking)
233+
${isLoading ? html`<cc-loader></cc-loader>` : ''}
234+
${isLoaded && (listState.type === 'loaded' || listState.type === 'unlinking')
235+
? this._renderNetworkGroupList(listState.linkedNetworkGroupList, isUnlinking)
211236
: ''}
212237
</div>
213238
<div slot="footer-right">
@@ -217,7 +242,7 @@ export class CcNetworkGroupList extends LitElement {
217242
</div>
218243
</cc-block>
219244
220-
${this._renderUnlinkDialog(this._networkGroupIdToUnlink, isUnlinking)}
245+
${this._renderUnlinkDialog(this._isUnlinkDialogOpen, isUnlinking)}
221246
`;
222247
}
223248

@@ -312,7 +337,8 @@ export class CcNetworkGroupList extends LitElement {
312337
class="unlink-btn"
313338
danger
314339
outlined
315-
?waiting="${isUnlinking}"
340+
?disabled="${isUnlinking && this._networkGroupIdToUnlink !== networkGroup.id}"
341+
?waiting="${isUnlinking && this._networkGroupIdToUnlink === networkGroup.id}"
316342
a11y-name="${i18n('cc-network-group-list.list.unlink.a11y-name', { name: networkGroup.name })}"
317343
@cc-click="${() => this._onUnlinkRequest(networkGroup.id)}"
318344
>
@@ -327,13 +353,13 @@ export class CcNetworkGroupList extends LitElement {
327353
}
328354
329355
/**
330-
* @param {string|null} networkGroupIdToUnlink
356+
* @param {boolean} isOpen
331357
* @param {boolean} isUnlinking
332358
*/
333-
_renderUnlinkDialog(networkGroupIdToUnlink, isUnlinking) {
359+
_renderUnlinkDialog(isOpen, isUnlinking) {
334360
return html`
335361
<cc-dialog
336-
?open="${networkGroupIdToUnlink != null}"
362+
?open="${isOpen}"
337363
heading="${i18n('cc-network-group-list.unlink.dialog.heading')}"
338364
@cc-close="${this._onDialogClose}"
339365
>

0 commit comments

Comments
 (0)