Skip to content

Commit e16437b

Browse files
author
Pierre DE SOYRES
committed
feat(cc-cellar-explorer): integrate cc-cellar-object-list
1 parent c249fbf commit e16437b

File tree

4 files changed

+75
-7
lines changed

4 files changed

+75
-7
lines changed

src/components/cc-cellar-bucket-list/cc-cellar-bucket-list.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { accessibilityStyles } from '../../styles/accessibility.js';
1414
import { i18n } from '../../translations/translation.js';
1515
import '../cc-badge/cc-badge.js';
1616
import '../cc-button/cc-button.js';
17+
import { CcCellarNavigateToBucketEvent } from '../cc-cellar-object-list/cc-cellar-object-list.events.js';
1718
import '../cc-clipboard/cc-clipboard.js';
1819
import '../cc-dialog-confirm-actions/cc-dialog-confirm-actions.js';
1920
import '../cc-dialog/cc-dialog.js';
@@ -98,7 +99,7 @@ export class CcCellarBucketList extends LitElement {
9899
this.updateComplete.then(() => {
99100
if (this.state.type === 'loaded') {
100101
const index = this.state.buckets.findIndex((b) => b.name === bucketName);
101-
this._gridRef?.value.scrollToIndex(index);
102+
this._gridRef.value?.scrollToIndex(index);
102103
}
103104
});
104105
}
@@ -155,6 +156,13 @@ export class CcCellarBucketList extends LitElement {
155156

156157
//#region Event handlers
157158

159+
/**
160+
* @param {string} bucketName
161+
*/
162+
_onBucketClick(bucketName) {
163+
this.dispatchEvent(new CcCellarNavigateToBucketEvent(bucketName));
164+
}
165+
158166
/**
159167
* @param {string} bucketName
160168
*/
@@ -339,10 +347,11 @@ export class CcCellarBucketList extends LitElement {
339347
{
340348
header: i18n('cc-cellar-bucket-list.grid.column.name'),
341349
cellAt: (bucketState) => ({
342-
type: 'text',
350+
type: 'link',
343351
value: bucketState.name,
344352
icon: iconBucket,
345353
enableCopyToClipboard: true,
354+
onClick: () => this._onBucketClick(bucketState.name),
346355
}),
347356
width: 'minmax(max-content, 1fr)',
348357
sort: getSort('name'),
@@ -598,7 +607,7 @@ export class CcCellarBucketList extends LitElement {
598607
.details-wrapper {
599608
display: flex;
600609
flex-direction: column;
601-
width: 25em;
610+
max-width: 25em;
602611
}
603612
604613
.details-wrapper .details-icon-wrapper {

src/components/cc-cellar-explorer/cc-cellar-explorer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { css, html, LitElement } from 'lit';
22
import { createRef, ref } from 'lit/directives/ref.js';
33
import { i18n } from '../../translations/translation.js';
44
import '../cc-cellar-bucket-list/cc-cellar-bucket-list.js';
5+
import '../cc-cellar-object-list/cc-cellar-object-list.js';
56
import '../cc-loader/cc-loader.js';
67
import '../cc-notice/cc-notice.js';
78

@@ -58,7 +59,10 @@ export class CcCellarExplorer extends LitElement {
5859
></cc-cellar-bucket-list-beta>`;
5960
}
6061

61-
return html``;
62+
return html`<cc-cellar-object-list-beta
63+
class="main"
64+
.state=${this.state.level.state}
65+
></cc-cellar-object-list-beta>`;
6266
}
6367

6468
static get styles() {

src/components/cc-cellar-explorer/cc-cellar-explorer.smart.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getAllEnvVars } from '@clevercloud/client/esm/api/v2/addon.js';
22
import { sendToApi } from '../../lib/send-to-api.js';
33
import { defineSmartComponent } from '../../lib/smart/define-smart-component.js';
44
import { BucketsListController } from '../cc-cellar-bucket-list/cc-cellar-bucket-list.ctrl.js';
5+
import { ObjectListController } from '../cc-cellar-object-list/cc-cellar-object-list.ctrl.js';
56
import { CellarExplorerClient } from './cc-cellar-explorer.client.js';
67
import './cc-cellar-explorer.js';
78

@@ -10,7 +11,9 @@ import './cc-cellar-explorer.js';
1011
* @import { CellarExplorerStateLoaded } from './cc-cellar-explorer.types.js'
1112
* @import { CellarEndpoint } from './cc-cellar-explorer.client.types.js'
1213
* @import { CcCellarBucketList } from '../cc-cellar-bucket-list/cc-cellar-bucket-list.js'
14+
* @import { CcCellarObjectList } from '../cc-cellar-object-list/cc-cellar-object-list.js'
1315
* @import { CellarBucketListState } from '../cc-cellar-bucket-list/cc-cellar-bucket-list.types.js'
16+
* @import { CellarObjectListState } from '../cc-cellar-object-list/cc-cellar-object-list.types.js'
1417
* @import { EnvVar } from '../common.types.js'
1518
* @import { UpdateCallback } from '../common.types.js'
1619
* @import { ApiConfig } from '../../lib/send-to-api.js'
@@ -42,7 +45,7 @@ defineSmartComponent({
4245
const cellarClient = new CellarExplorerClient(cellarProxyUrl, cellarEndpoint);
4346

4447
/** @type {() => CcCellarBucketList} */
45-
const getComponent = () => component.shadowRoot.querySelector('cc-cellar-bucket-list-beta');
48+
const getBucketListComponent = () => component.shadowRoot.querySelector('cc-cellar-bucket-list-beta');
4649
/** @type {UpdateCallback<CellarBucketListState>} */
4750
const updateBucketComponent = (newState) => {
4851
updateComponent(
@@ -62,16 +65,62 @@ defineSmartComponent({
6265
);
6366
};
6467

65-
const bucketsListController = new BucketsListController(cellarClient, getComponent, updateBucketComponent);
68+
const bucketsListController = new BucketsListController(
69+
cellarClient,
70+
getBucketListComponent,
71+
updateBucketComponent,
72+
);
6673
bucketsListController.init(onEvent);
6774

75+
/** @type {UpdateCallback<CellarObjectListState>} */
76+
const updateObjectListComponent = (newState) => {
77+
updateComponent(
78+
'state',
79+
/** @param {CellarExplorerStateLoaded} state*/ (state) => {
80+
if (state.level.type === 'objects') {
81+
if (typeof newState === 'function') {
82+
const result = newState(/** @type {any} */ (state.level.state));
83+
if (result != null && typeof result === 'object') {
84+
state.level.state = result;
85+
}
86+
} else {
87+
state.level.state = newState;
88+
}
89+
}
90+
},
91+
);
92+
};
93+
94+
/** @type {() => CcCellarObjectList} */
95+
const getObjectListComponent = () => component.shadowRoot.querySelector('cc-cellar-object-list-beta');
96+
const objectListController = new ObjectListController(
97+
cellarClient,
98+
getObjectListComponent,
99+
updateObjectListComponent,
100+
);
101+
objectListController.init(onEvent);
102+
68103
onEvent('cc-cellar-bucket-created', (bucketName) => {
69104
component.scrollToBucket(bucketName);
70105
});
71106

107+
onEvent('cc-cellar-navigate-to-home', () => {
108+
updateComponent('state', { type: 'loaded', level: { type: 'buckets', state: { type: 'loading' } } });
109+
bucketsListController.initialFetch();
110+
});
111+
112+
onEvent('cc-cellar-navigate-to-bucket', (bucketName) => {
113+
updateComponent('state', {
114+
type: 'loaded',
115+
level: { type: 'objects', state: { type: 'loading', bucketName, path: [] } },
116+
});
117+
objectListController.changeBucket(bucketName);
118+
});
119+
72120
signal.onabort = () => {
73121
cellarClient.close();
74122
bucketsListController.abort();
123+
objectListController.abort();
75124
};
76125
})
77126
.catch((error) => {

src/components/cc-cellar-explorer/cc-cellar-explorer.types.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CellarBucketListState } from '../cc-cellar-bucket-list/cc-cellar-bucket-list.types.js';
2+
import { CellarObjectListState } from '../cc-cellar-object-list/cc-cellar-object-list.types.js';
23

34
export type CellarExplorerState = CellarExplorerStateLoading | CellarExplorerStateError | CellarExplorerStateLoaded;
45

@@ -15,9 +16,14 @@ export interface CellarExplorerStateLoaded {
1516
level: CellarExplorerLevel;
1617
}
1718

18-
export type CellarExplorerLevel = CellarExplorerLevelBuckets;
19+
export type CellarExplorerLevel = CellarExplorerLevelBuckets | CellarExplorerLevelObjects;
1920

2021
export interface CellarExplorerLevelBuckets {
2122
type: 'buckets';
2223
state: CellarBucketListState;
2324
}
25+
26+
export interface CellarExplorerLevelObjects {
27+
type: 'objects';
28+
state: CellarObjectListState;
29+
}

0 commit comments

Comments
 (0)