Skip to content

Commit 3690cac

Browse files
feat(cc-addon-credentials-beta.smart-otoroshi): adapt to the new state shape
- Replace `SKELETON_DATA` with `LOADING_STATE` to match new state shape, - Move credentials under `tabs[tabName].content` instead of `tabs[tabName]`, - Update `docLink` handling to be part of `LOADING_STATE`, - Refactor loaded state mapping to update `tabs[tabName].content` while preserving `tabs[tabName].docLink`.
1 parent c30e54c commit 3690cac

File tree

1 file changed

+76
-53
lines changed

1 file changed

+76
-53
lines changed

src/components/cc-addon-credentials-beta/cc-addon-credentials-beta.smart-otoroshi.js

Lines changed: 76 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,56 @@ import './cc-addon-credentials-beta.js';
1010
const LOADING_STATE = {
1111
type: 'loading',
1212
tabs: {
13-
admin: [
14-
{
15-
code: 'user',
16-
value: fakeString(10),
17-
},
18-
{
19-
code: 'password',
20-
value: fakeString(10),
21-
},
22-
{
23-
code: 'ng',
24-
kind: 'standard',
25-
value: { status: 'disabled' },
26-
},
27-
],
28-
api: [
29-
{
30-
code: 'api-client-user',
31-
value: fakeString(10),
32-
},
33-
{
34-
code: 'api-client-secret',
35-
value: fakeString(10),
36-
},
37-
{
38-
code: 'api-url',
39-
value: fakeString(10),
40-
},
41-
{
42-
code: 'open-api-url',
43-
value: fakeString(10),
13+
admin: {
14+
content: [
15+
{
16+
code: 'user',
17+
value: fakeString(10),
18+
},
19+
{
20+
code: 'password',
21+
value: fakeString(10),
22+
},
23+
{
24+
code: 'ng',
25+
kind: 'standard',
26+
value: { status: 'disabled' },
27+
},
28+
],
29+
docLink: {
30+
text: i18n('cc-addon-credentials-beta.doc-link.otoroshi'),
31+
href: 'https://www.clever-cloud.com/developers/doc/addons/otoroshi/',
4432
},
45-
{
46-
code: 'ng',
47-
kind: 'standard',
48-
value: { status: 'disabled' },
33+
},
34+
api: {
35+
content: [
36+
{
37+
code: 'api-client-user',
38+
value: fakeString(10),
39+
},
40+
{
41+
code: 'api-client-secret',
42+
value: fakeString(10),
43+
},
44+
{
45+
code: 'api-url',
46+
value: fakeString(10),
47+
},
48+
{
49+
code: 'open-api-url',
50+
value: fakeString(10),
51+
},
52+
{
53+
code: 'ng',
54+
kind: 'standard',
55+
value: { status: 'disabled' },
56+
},
57+
],
58+
docLink: {
59+
text: i18n('cc-addon-credentials-beta.doc-link.otoroshi'),
60+
href: 'https://www.clever-cloud.com/developers/doc/addons/otoroshi/',
4961
},
50-
],
62+
},
5163
},
5264
};
5365
const PROVIDER_ID = 'otoroshi';
@@ -88,35 +100,46 @@ defineSmartComponent({
88100
state.tabs = Object.fromEntries(
89101
Object.entries(state.tabs).map(([tabName, tabValue]) => [
90102
tabName,
91-
tabValue.map((addonInfo) => {
92-
if (addonInfo.code === 'ng') {
93-
if (typeof newNgInfoOrCallback === 'function') {
94-
return newNgInfoOrCallback(addonInfo);
95-
} else {
96-
return newNgInfoOrCallback;
103+
{
104+
...tabValue,
105+
content: tabValue.content.map((addonInfo) => {
106+
if (addonInfo.code === 'ng') {
107+
if (typeof newNgInfoOrCallback === 'function') {
108+
return newNgInfoOrCallback(addonInfo);
109+
} else {
110+
return newNgInfoOrCallback;
111+
}
97112
}
98-
}
99-
return addonInfo;
100-
}),
113+
return addonInfo;
114+
}),
115+
},
101116
]),
102117
);
103118
},
104119
);
105120
}
106121

107122
updateComponent('state', LOADING_STATE);
108-
updateComponent('docLink', {
109-
text: i18n('cc-addon-credentials-beta.doc-link.otoroshi'),
110-
href: 'https://www.clever-cloud.com/developers/doc/addons/otoroshi/',
111-
});
112123

113124
api
114125
.getAllCredentials()
115126
.then((tabs) => {
116-
updateComponent('state', {
117-
type: 'loaded',
118-
tabs,
119-
});
127+
updateComponent(
128+
'state',
129+
/** @param {AddonCredentialsBetaStateLoaded|AddonCredentialsBetaStateLoading} state */
130+
(state) => {
131+
state.type = 'loaded';
132+
state.tabs = Object.fromEntries(
133+
Object.entries(state.tabs).map(([tabName, tabValue]) => [
134+
tabName,
135+
{
136+
...tabValue,
137+
content: tabs[/** @type {'admin'|'api'} */ (tabName)],
138+
},
139+
]),
140+
);
141+
},
142+
);
120143
})
121144
.catch((error) => {
122145
console.error(error);

0 commit comments

Comments
 (0)