Skip to content

Commit

Permalink
Added feature flag for builder UI
Browse files Browse the repository at this point in the history
Signed-off-by: sougata-progress <sougatab@progress.com>
  • Loading branch information
sougata-progress committed Oct 3, 2024
1 parent 554d22c commit 8b70e81
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ habitatConfig({
www_url: "{{cfg.www_url}}",
enable_builder_events: {{cfg.enable_builder_events}},
enable_builder_events_saas: {{cfg.enable_builder_events_saas}},
enable_lts: {{cfg.enable_lts}},
});
1 change: 1 addition & 0 deletions components/builder-api-proxy/habitat/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enable_builder_events = false
# Enable/Disable the builder events from SaaS
# The 'enable_builder_events' property also needs to be set to enable SaaS events.
enable_builder_events_saas = false
enable_lts = false
# How we connect to the proxied backend API service.
# When true, connect to all backend API services via their IPs provided
# via the bind
Expand Down
4 changes: 4 additions & 0 deletions components/builder-web/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export class AppComponent implements OnInit, OnDestroy {
return this.state.features.saasEvents;
}

get enabledLTS() {
return this.state.features.enableLTS;
}

ngOnDestroy() {
this.sub.unsubscribe();
}
Expand Down
1 change: 1 addition & 0 deletions components/builder-web/app/initial-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export default Record({
events: false,
saasEvents: false,
visibility: false,
enableLTS: false,
})(),
notifications: Record({
all: List(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ export class PackageDetailComponent {
}

handlePromote(channel) {
let state = this.store.getState();
const filteredAllChannel = this.getAllChannel(channel);
if (state.features.enableLTS) {
this.confirmDialog
.open(PromoteConfirmDialog, {
width: '480px',
Expand All @@ -117,6 +119,27 @@ export class PackageDetailComponent {
}
}
});
} else {
this.confirmDialog
.open(SimpleConfirmDialog, {
width: '480px',
data: {
heading: 'Confirm promote',
body: `Are you sure you want to promote this artifact? Doing so will add the artifact to the stable channel.`,
action: 'Promote it'
}
})
.afterClosed()
.subscribe((confirmed) => {
if (confirmed) {
this.updating = true;
let token = this.store.getState().session.token;
this.store.dispatch(
promotePackage(this.package.ident.origin, this.package.ident.name, this.package.ident.version, this.package.ident.release, this.package.target, 'stable', token)
);
}
});
}
}

getAllChannel(currentChannel) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<span class="package-promote-component" (click)="prompt($event)">
<span *ngIf="!promoting">
<hab-icon symbol="star-circle"></hab-icon>
Promote
<hab-icon symbol="star-circle"></hab-icon>
<span>{{ promote }}</span>
</span>
<span class="promoting" *ngIf="promoting">
<hab-icon symbol="loading" class="spinning"></hab-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Input } from '@angular/core';
import { MatDialog } from '@angular/material';
import { AppStore } from '../../app.store';
import { promotePackage } from '../../actions/index';
import { SimpleConfirmDialog } from '../../shared/dialog/simple-confirm/simple-confirm.dialog';
import { PromoteConfirmDialog } from '../../shared/dialog/promote-confirm/promote-confirm.dialog';

@Component({
Expand All @@ -15,6 +16,7 @@ export class PackagePromoteComponent {
@Input() release: string;
@Input() target: string;
@Input() channels: string[];
@Input() enabledLTS;

promoting: boolean = false;

Expand All @@ -24,37 +26,66 @@ export class PackagePromoteComponent {
) { }

prompt(evt) {
let state = this.store.getState();
evt.stopPropagation();

const filteredAllChannel = this.getAllChannel();
this.confirmDialog
.open(PromoteConfirmDialog, {
width: '480px',
data: {
heading: 'Confirm promote',
body: `Select channel to promote. Promoted artifact will be added to the selected channel.`,
channelList: filteredAllChannel,
action: 'Promote'
if (!state.features.enableLTS) {
this.confirmDialog
.open(SimpleConfirmDialog, {
width: '480px',
data: {
heading: 'Confirm promote',
body: `Are you sure you want to promote this artifact? Doing so will add the artifact to the stable channel.`,
action: 'promote it'
}
})
.afterClosed()
.subscribe((confirmed) => {
if (confirmed) {
this.promoting = true;
setTimeout(() => {
this.store.dispatch(
promotePackage(this.origin, this.name, this.version, this.release, this.target, 'stable', this.store.getState().session.token)
);
}, 1000);
}
});
} else {
this.confirmDialog
.open(PromoteConfirmDialog, {
width: '480px',
data: {
heading: 'Confirm promote',
body: `Select channel to promote. Promoted artifact will be added to the selected channel.`,
channelList: filteredAllChannel,
action: 'Promote'
}
})
.afterClosed()
.subscribe((data) => {
if (data) {
const {confirmed, selectedChannel} = data;
if (confirmed && selectedChannel) {
this.promoting = true;
let token = this.store.getState().session.token;
this.store.dispatch(
promotePackage(this.origin, this.name, this.version, this.release, this.target, selectedChannel, token)
);
}
}
});
}
})
.afterClosed()
.subscribe((data) => {
if (data) {
const {confirmed, selectedChannel} = data;
if (confirmed && selectedChannel) {
this.promoting = true;
let token = this.store.getState().session.token;
this.store.dispatch(
promotePackage(this.origin, this.name, this.version, this.release, this.target, selectedChannel, token)
);
}
}
});
}

getAllChannel() {
return this.store.getState().origins.current.channels.filter((channel) => {
return channel.name !== 'unstable' && this.channels.indexOf(channel.name) === -1;
});
}

get promote(): string {
let state = this.store.getState();
return state.features.enableLTS ? 'Promote' : 'Promote to stable';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3>Settings</h3>
</ul>
</section>
<h3>Latest</h3>
<div class="sidebar-section" style="margin-left: 12px;">
<div class="sidebar-section" style="margin-left: 12px;" >
<section class="latest-stable" *ngIf="isLTSChannelExist">
<h3 style="margin-bottom: 0px;"> {{ latestLTS }}</h3>
<div *ngIf="currentLts">
Expand Down
3 changes: 2 additions & 1 deletion components/builder-web/app/reducers/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function builds(state = initialState['features'], action) {
.set('builder', !!config['enable_builder'])
.set('visibility', !!config['enable_visibility'])
.set('events', !!config['enable_builder_events'])
.set('saasEvents', !!config['enable_builder_events_saas']);
.set('saasEvents', !!config['enable_builder_events_saas'])
.set('enableLTS', !!config['enable_lts']);
default:
return state;
}
Expand Down
5 changes: 4 additions & 1 deletion components/builder-web/habitat.conf.sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ habitatConfig({

// Enable/Disable builder events from SaaS
// The 'enable_builder_events' property also needs to be set to enable SaaS events.
enable_builder_events_saas: false
enable_builder_events_saas: false,

// Enable/Disable LTS channel from SaaS
enable_lts: false
});

0 comments on commit 8b70e81

Please sign in to comment.