Skip to content

Commit

Permalink
refactor: rename CIServiceSettings.disabled to isDisabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNowotny committed Jul 31, 2024
1 parent 7ad0716 commit 0f6574a
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 72 deletions.
10 changes: 5 additions & 5 deletions src/common/__mocks__/core.mock.configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default Rx.Observable.return([
username: '',
password: '',
projects: ['AdamNowotny/BuildReactor'],
disabled: false,
isDisabled: false,
},
{
name: 'OpenMRS',
Expand All @@ -19,7 +19,7 @@ export default Rx.Observable.return([
username: '',
password: '',
projects: ['FUNC-APPTEST', 'FUNC-BUILDPERF', 'FUNC-PERF', 'JU-CORE'],
disabled: true,
isDisabled: true,
},
{
name: 'Jenkins',
Expand All @@ -35,7 +35,7 @@ export default Rx.Observable.return([
'infra_plugins_svn_to_git',
'infra_svnsync',
],
disabled: true,
isDisabled: true,
},
{
name: 'T1',
Expand All @@ -45,7 +45,7 @@ export default Rx.Observable.return([
username: '',
password: '',
projects: ['bt308'],
disabled: true,
isDisabled: true,
branch: '',
},
{
Expand All @@ -56,7 +56,7 @@ export default Rx.Observable.return([
username: '',
password: '',
projects: ['bt607'],
disabled: true,
isDisabled: true,
branch: 'release',
},
]);
28 changes: 19 additions & 9 deletions src/service-worker/storage/service-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ beforeEach(() => {
baseUrl: 'test1',
name: 'test1',
projects: [],
disabled: false,
isDisabled: false,
},
{
baseUrl: 'test2',
name: 'test2',
projects: [],
disabled: true,
isDisabled: true,
},
];
(Storage.prototype.get as Mock).mockImplementation(() => testConfigs);
Expand Down Expand Up @@ -59,8 +59,8 @@ describe('enableService', () => {
await serviceConfig.enableService(testConfigs[DISABLED_SERVICE].name);

expect(Storage.prototype.set).toBeCalledWith([
{ ...testConfigs[0], disabled: false },
{ ...testConfigs[1], disabled: false },
{ ...testConfigs[0], isDisabled: false },
{ ...testConfigs[1], isDisabled: false },
]);
});
});
Expand All @@ -78,8 +78,8 @@ describe('disableService', () => {
await serviceConfig.disableService(testConfigs[ENABLED_SERVICE].name);

expect(Storage.prototype.set).toBeCalledWith([
{ ...testConfigs[0], disabled: true },
{ ...testConfigs[1], disabled: true },
{ ...testConfigs[0], isDisabled: true },
{ ...testConfigs[1], isDisabled: true },
]);
});
});
Expand Down Expand Up @@ -109,15 +109,22 @@ describe('saveService', () => {

await serviceConfig.saveService(newItem);

expect(Storage.prototype.set).toBeCalledWith([testConfigs[0], testConfigs[1], newItem]);
expect(Storage.prototype.set).toBeCalledWith([
testConfigs[0],
testConfigs[1],
newItem,
]);
});

it('should save existing item', async () => {
const item = { ...testConfigs[ENABLED_SERVICE], token: 'token' };

await serviceConfig.saveService(item);

expect(Storage.prototype.set).toBeCalledWith([item, testConfigs[DISABLED_SERVICE]]);
expect(Storage.prototype.set).toBeCalledWith([
item,
testConfigs[DISABLED_SERVICE],
]);
});
});

Expand Down Expand Up @@ -145,7 +152,10 @@ describe('setBuildOrder', () => {
});

it('should reorder builds', async () => {
await serviceConfig.setBuildOrder(testConfigs[ENABLED_SERVICE].name, ['build1', 'build2']);
await serviceConfig.setBuildOrder(testConfigs[ENABLED_SERVICE].name, [
'build1',
'build2',
]);

expect(Storage.prototype.set).toBeCalledWith([
{ ...testConfigs[ENABLED_SERVICE], projects: ['build1', 'build2'] },
Expand Down
4 changes: 2 additions & 2 deletions src/service-worker/storage/service-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const enableService = async (serviceName: string) => {
if (!config) {
throw new Error(`Service ${serviceName} not found`);
}
config.disabled = false;
config.isDisabled = false;
await setItem(serviceName, config);
};

Expand All @@ -42,7 +42,7 @@ const disableService = async (serviceName: string) => {
if (!config) {
throw new Error(`Service ${serviceName} not found`);
}
config.disabled = true;
config.isDisabled = true;
await setItem(serviceName, config);
};

Expand Down
4 changes: 2 additions & 2 deletions src/services/service-monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const alarmHandler = async (alarm: chrome.alarms.Alarm) => {
const configChangedHandler = async (value: StorageChangeEvent<CIServiceSettings[]>) => {
logger.log('service-monitor.onChanged', value);
const serviceNames = value.newValue
.filter(config => !config.disabled)
.filter(config => !config.isDisabled)
.map(config => config.name);
await stateStorage.reset(serviceNames);
await updateAll(value.newValue);
Expand All @@ -35,7 +35,7 @@ const updateAll = async (allConfigs: CIServiceSettings[]) => {
await chrome.alarms.clearAll();
const updatedServices = await Promise.all(
allConfigs
.filter(config => !config.disabled)
.filter(config => !config.isDisabled)
.map(async config => {
const serviceState = await serviceRepository.getLatestBuilds(config);
await stateStorage.updateService(config.name, serviceState);
Expand Down
2 changes: 1 addition & 1 deletion src/services/service-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface CIServiceSettings {
username?: string;
password?: string;
projects: string[];
disabled?: boolean;
isDisabled?: boolean;
repository?: string;
}

Expand Down
25 changes: 19 additions & 6 deletions src/settings/directives/sidebar/sidebar.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
<div class="sidebar-nav">
<div class="scrollable">
<ul ng-sortable="sortableConfig" class="service-list nav nav-pills nav-stacked" ng-model="configs">
<li ng-repeat="config in configs" ng-class="{ muted: config.disabled, active: view == 'service' && config.name === currentConfig.name }">
<ul
ng-sortable="sortableConfig"
class="service-list nav nav-pills nav-stacked"
ng-model="configs"
>
<li
ng-repeat="config in configs"
ng-class="{ muted: config.isDisabled, active: view == 'service' && config.name === currentConfig.name }"
>
<a ng-href="#!/service/{{ config.name }}" class="nav-pill">
<span class="handle">::</span>
<img class="pill-icon" ng-src="{{ serviceIcons[config.baseUrl] }}">
<img class="pill-icon" ng-src="{{ serviceIcons[config.baseUrl] }}" />
<span class="pill-name">{{ config.name }}</span>
</a>
</li>
</ul>
<hr class="service-list-separator" ng-show="configs.length">
<hr class="service-list-separator" ng-show="configs.length" />
<ul class="actions nav nav-pills nav-stacked">
<li ng-class="{ active: view == 'new', muted: currentConfig.disabled }" ng-show="view == 'new' && currentConfig">
<li
ng-class="{ active: view == 'new', muted: currentConfig.isDisabled }"
ng-show="view == 'new' && currentConfig"
>
<a href="#">
<img class="pill-icon" ng-src="{{ serviceIcons[currentConfig.baseUrl] }}">
<img
class="pill-icon"
ng-src="{{ serviceIcons[currentConfig.baseUrl] }}"
/>
<span class="pill-name">{{ currentConfig.name }}</span>
</a>
</li>
Expand Down
96 changes: 49 additions & 47 deletions src/settings/directives/topnav/topnav.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,56 @@ import renameTemplate from 'settings/directives/topnav/renameModal.html';
import template from 'settings/directives/topnav/topnav.html';

export default app.directive('topnav', ($uibModal, $location) => ({
scope: {
service: '=currentService',
showActions: '='
},
templateUrl: template,
controller($scope, $element, $attrs, $transclude) {
scope: {
service: '=currentService',
showActions: '=',
},
templateUrl: template,
controller($scope, $element, $attrs, $transclude) {
$scope.$watch('service', selectedService => {
$scope.isEnabled = selectedService && !selectedService.isDisabled;
});

$scope.$watch('service', (selectedService) => {
$scope.isEnabled = selectedService && !selectedService.disabled;
});
$scope.$on('onOffSwitch.change', (event, isEnabled) => {
if (!$scope.service) {
return;
}
if (isEnabled) {
core.enableService($scope.service.name);
} else {
core.disableService($scope.service.name);
}
});

$scope.$on('onOffSwitch.change', (event, isEnabled) => {
if (!$scope.service) {
return;
}
if (isEnabled) {
core.enableService($scope.service.name);
} else {
core.disableService($scope.service.name);
}
});
$scope.remove = function () {
$uibModal
.open({
templateUrl: removeTemplate,
controller: 'RemoveModalCtrl',
scope: $scope,
resolve: {
serviceName: () => $scope.service.name,
},
})
.result.then(serviceName => {
core.removeService(serviceName);
$location.path('#!/new').replace();
});
};

$scope.remove = function() {
$uibModal.open({
templateUrl: removeTemplate,
controller: 'RemoveModalCtrl',
scope: $scope,
resolve: {
serviceName: () => $scope.service.name
}
}).result.then((serviceName) => {
core.removeService(serviceName);
$location.path('#!/new').replace();
});
};

$scope.rename = function() {
$uibModal.open({
templateUrl: renameTemplate,
controller: 'RenameModalCtrl',
resolve: {
serviceName: () => $scope.service.name
}
}).result.then((serviceName) => {
core.renameService($scope.service.name, serviceName);
$location.path(`#!/service/${serviceName}/`).replace();
});
};

}
$scope.rename = function () {
$uibModal
.open({
templateUrl: renameTemplate,
controller: 'RenameModalCtrl',
resolve: {
serviceName: () => $scope.service.name,
},
})
.result.then(serviceName => {
core.renameService($scope.service.name, serviceName);
$location.path(`#!/service/${serviceName}/`).replace();
});
};
},
}));

0 comments on commit 0f6574a

Please sign in to comment.