Skip to content

Commit

Permalink
Improve tabs bars with Tabs component (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
juankaromo authored and Jesús Ángel committed Aug 22, 2019
1 parent fed2183 commit 4547d59
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 233 deletions.
66 changes: 61 additions & 5 deletions public/controllers/agent/agents.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ export class AgentsController {

this.tabVisualizations.assign('agents');

this.$scope.hostMonitoringTabs = ['general', 'fim', 'syscollector'];
this.$scope.systemAuditTabs = ['pm', 'sca', 'audit', 'oscap', 'ciscat'];
this.$scope.securityTabs = ['vuls', 'virustotal', 'osquery', 'docker'];
this.$scope.complianceTabs = ['pci', 'gdpr', 'hipaa', 'nist'];

/**
* This check if given array of items contais a single given item
* @param {Object} item
Expand Down Expand Up @@ -451,6 +446,7 @@ export class AgentsController {
};

this.$scope.expand = i => this.expand(i);
this.setTabs();
}
/**
* Create metric for given object
Expand Down Expand Up @@ -663,6 +659,66 @@ export class AgentsController {
} catch (error) {
return Promise.reject(error);
}

this.$scope.configurationTabsProps = {};
this.$scope.buildProps = tabs => {
const cleanTabs = [];
tabs.forEach(x => {
if (
this.$scope.configurationTab === 'integrity-monitoring' &&
x.id === 'fim-whodata' &&
x.agent &&
x.agent.agentPlatform !== 'linux'
)
return;

cleanTabs.push({
id: x.id,
name: x.name
});
});
this.$scope.configurationTabsProps = {
clickAction: tab => {
this.$scope.switchConfigurationSubTab(tab);
},
selectedTab:
this.$scope.configurationSubTab || (tabs && tabs.length)
? tabs[0].id
: '',
tabs: cleanTabs
};
};

this.setTabs();
}

/**
* Build the current section tabs
*/
setTabs() {
this.$scope.agentsTabsProps = false;
this.currentPanel = this.commonData.getCurrentPanel(this.$scope.tab);

if (!this.currentPanel) return;

const tabs = this.commonData.getTabsFromCurrentPanel(
this.currentPanel,
this.$scope.extensions,
this.$scope.tabNames
);

this.$scope.agentsTabsProps = {
clickAction: tab => {
this.switchTab(tab, true);
},
selectedTab:
this.$scope.tab ||
(this.currentPanel && this.currentPanel.length
? this.currentPanel[0]
: ''),
tabs
};
this.$scope.$applyAsync();
}

goDiscover() {
Expand Down
7 changes: 6 additions & 1 deletion public/controllers/agent/components/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ export class WelcomeScreen extends Component {
<EuiFlexGroup gutterSize="xs">
<EuiFlexItem />
<EuiFlexItem grow={false}>
{this.buildPopover('popoverRegulatory', ['pci', 'gdpr', 'hipaa', 'nist'])}
{this.buildPopover('popoverRegulatory', [
'pci',
'gdpr',
'hipaa',
'nist'
])}
</EuiFlexItem>
</EuiFlexGroup>
{!this.props.extensions.pci && !this.props.extensions.gdpr && (
Expand Down
14 changes: 14 additions & 0 deletions public/controllers/management/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,20 @@ export class ConfigurationController {
}
this.switchConfigurationTab(this.configurationTab, false, true);
});

this.$scope.configurationTabsProps = {};
this.$scope.buildProps = tabs => {
this.$scope.configurationTabsProps = {
clickAction: tab => {
this.$scope.switchConfigurationSubTab(tab);
},
selectedTab:
this.$scope.configurationSubTab || (tabs && tabs.length)
? tabs[0].id
: '',
tabs
};
};
}

switchConfigurationSubTab(configurationSubTab) {
Expand Down
12 changes: 12 additions & 0 deletions public/controllers/management/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,18 @@ export function GroupsController(
$scope.$broadcast('wazuhSearch', {});
};

$scope.groupsTabsProps = {
clickAction: tab => {
if (tab === 'agents') {
$scope.goBackToAgents();
} else if (tab === 'content') {
$scope.goBackFiles();
}
},
selectedTab: $scope.groupsSelectedTab || 'agents',
tabs: [{ id: 'agents', name: 'Agents' }, { id: 'content', name: 'Content' }]
};

// Come from the pencil icon on the groups table
$scope.$on('openGroupFromList', (ev, parameters) => {
$scope.editingFile = true;
Expand Down
3 changes: 2 additions & 1 deletion public/controllers/management/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class ManagementController {

this.rulesetTabsProps = {
clickAction: tab => this.setRulesTab(tab),
selectedTab: this.rulesetTab,
selectedTab: this.rulesetTab || 'rules',
tabs: [
{ id: 'rules', name: 'Rules' },
{ id: 'decoders', name: 'Decoders' },
Expand Down Expand Up @@ -297,6 +297,7 @@ export class ManagementController {
this.currentRule = false;
this.currentDecoder = false;
this.currentList = false;
this.managementTabsProps.selectedTab = this.tab;
}

this.$location.search('tab', this.tab);
Expand Down
7 changes: 6 additions & 1 deletion public/controllers/overview/components/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ export class WelcomeScreen extends Component {
<EuiFlexGroup gutterSize="xs">
<EuiFlexItem />
<EuiFlexItem grow={false}>
{this.buildPopover('popoverRegulatory', ['pci', 'gdpr', 'hipaa', 'nist'])}
{this.buildPopover('popoverRegulatory', [
'pci',
'gdpr',
'hipaa',
'nist'
])}
</EuiFlexItem>
</EuiFlexGroup>
{!this.props.extensions.pci && !this.props.extensions.gdpr && (
Expand Down
41 changes: 34 additions & 7 deletions public/controllers/overview/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ export class OverviewController {
// This object represents the number of visualizations per tab; used to show a progress bar
this.tabVisualizations.assign('overview');

this.hostMonitoringTabs = ['general', 'fim', 'aws'];
this.systemAuditTabs = ['pm', 'audit', 'oscap', 'ciscat', 'sca'];
this.securityTabs = ['vuls', 'virustotal', 'osquery', 'docker'];
this.complianceTabs = ['pci', 'gdpr', 'hipaa', 'nist'];

this.wodlesConfiguration = null;

this.init();
Expand All @@ -131,6 +126,8 @@ export class OverviewController {
this.appState.setExtensions(api, extensions)
};

this.setTabs();

this.$scope.$on('$destroy', () => {
this.visFactoryService.clearAll();
});
Expand Down Expand Up @@ -185,6 +182,35 @@ export class OverviewController {
}
}

/**
* Build the current section tabs
*/
setTabs() {
this.overviewTabsProps = false;
this.currentPanel = this.commonData.getCurrentPanel(this.tab);

if (!this.currentPanel) return;

const tabs = this.commonData.getTabsFromCurrentPanel(
this.currentPanel,
this.extensions,
this.tabNames
);

this.overviewTabsProps = {
clickAction: tab => {
this.switchTab(tab, true);
},
selectedTab:
this.tab ||
(this.currentPanel && this.currentPanel.length
? this.currentPanel[0]
: ''),
tabs
};
this.$scope.$applyAsync();
}

// Switch subtab
async switchSubtab(
subtab,
Expand All @@ -209,9 +235,9 @@ export class OverviewController {
localChange || preserveDiscover
);
} else {
this.$scope.$emit('changeTabView', {
this.$scope.$emit('changeTabView', {
tabView: this.tabView
});
});
}

this.checkMetrics(this.tab, subtab);
Expand Down Expand Up @@ -300,6 +326,7 @@ export class OverviewController {
} catch (error) {
this.errorHandler.handle(error.message || error);
}
this.setTabs();
this.$scope.$applyAsync();
return;
}
Expand Down
18 changes: 18 additions & 0 deletions public/controllers/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class SettingsController {
const location = this.$location.search();
if (location && location.tab) {
this.tab = location.tab;
this.settingsTabsProps.selectedTab = this.tab;
}

this.savingApi = false;
Expand Down Expand Up @@ -788,4 +789,21 @@ export class SettingsController {
this.errorHandler.handle(error);
}
}

settingsTabsProps = {
clickAction: tab => {
this.switchTab(tab, true);
if (tab === 'logs') {
this.refreshLogs();
}
},
selectedTab: this.tab || 'api',
tabs: [
{ id: 'api', name: 'API' },
{ id: 'pattern', name: 'Pattern' },
{ id: 'configuration', name: 'Configuration' },
{ id: 'logs', name: 'Logs' },
{ id: 'about', name: 'About' }
]
};
}
33 changes: 33 additions & 0 deletions public/services/common-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class CommonData {
this.globalState = globalState;
this.savedTimefilter = null;
this.refreshInterval = { pause: true, value: 0 };

this.hostMonitoringTabs = ['general', 'fim', 'aws'];
this.systemAuditTabs = ['pm', 'audit', 'oscap', 'ciscat', 'sca'];
this.securityTabs = ['vuls', 'virustotal', 'osquery', 'docker'];
this.complianceTabs = ['pci', 'gdpr', 'hipaa', 'nist'];
}

/**
Expand Down Expand Up @@ -352,4 +357,32 @@ export class CommonData {
getRefreshInterval() {
return this.refreshInterval;
}

getCurrentPanel(tab) {
return this.hostMonitoringTabs.includes(tab)
? this.hostMonitoringTabs
: this.systemAuditTabs.includes(tab)
? this.systemAuditTabs
: this.securityTabs.includes(tab)
? this.securityTabs
: this.complianceTabs.includes(tab)
? this.complianceTabs
: false;
}

getTabsFromCurrentPanel(currentPanel, extensions, tabNames) {
const keyExists = key => Object.keys(extensions).includes(key);
const keyIsTrue = key => (extensions || [])[key];

let tabs = [];
currentPanel.forEach(x => {
if (keyExists(x) && keyIsTrue(x)) {
tabs.push({
id: x,
name: tabNames[x]
});
}
});
return tabs;
}
}
61 changes: 5 additions & 56 deletions public/templates/agents/agents.head
Original file line number Diff line number Diff line change
Expand Up @@ -86,62 +86,11 @@
</div>
<!-- End navigation section -->

<!-- Host monitoring navigation bar -->
<md-nav-bar ng-if="inArray(tab, hostMonitoringTabs)" class="wz-nav-bar" ng-show="tab !== 'welcome'"
md-selected-nav-item="tab" nav-bar-aria-label="Host monitoring navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('general')" name="general">{{ tabNames['general'] }}
</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('fim')" name="fim">{{ tabNames['fim'] }}</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('syscollector')" name="syscollector">{{
tabNames['syscollector'] }}</md-nav-item>
</md-nav-bar>
<!-- End Host monitoring navigation bar -->

<!-- System audit navigation bar -->
<md-nav-bar ng-if="inArray(tab, systemAuditTabs) && (extensions.audit || extensions.oscap || extensions.ciscat)"
class="wz-nav-bar" ng-show="tab !== 'welcome'" md-selected-nav-item="tab"
nav-bar-aria-label="System audit navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('pm')" name="pm">{{ tabNames['pm'] }}</md-nav-item>
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('sca')" name="sca">{{
tabNames['sca'] }}</md-nav-item>
<md-nav-item ng-show="extensions.audit" class="wz-nav-item" md-nav-click="switchTab('audit')" name="audit">{{
tabNames['audit'] }}</md-nav-item>
<md-nav-item ng-show="extensions.oscap" class="wz-nav-item" md-nav-click="switchTab('oscap')" name="oscap">{{
tabNames['oscap'] }}</md-nav-item>
<md-nav-item ng-show="extensions.ciscat" class="wz-nav-item" md-nav-click="switchTab('ciscat')" name="ciscat">{{
tabNames['ciscat'] }}</md-nav-item>
</md-nav-bar>
<!-- End System audit navigation bar -->

<!-- Security navigation bar -->
<md-nav-bar ng-if="inArray(tab, securityTabs)" class="wz-nav-bar" ng-show="tab !== 'welcome'"
md-selected-nav-item="tab" nav-bar-aria-label="Security navigation links">
<md-nav-item class="wz-nav-item" md-nav-click="switchTab('vuls')" name="vuls">{{ tabNames['vuls'] }}
</md-nav-item>
<md-nav-item ng-show="extensions.virustotal" class="wz-nav-item" md-nav-click="switchTab('virustotal')"
name="virustotal">{{
tabNames['virustotal'] }}</md-nav-item>
<md-nav-item ng-show="extensions.osquery" class="wz-nav-item" md-nav-click="switchTab('osquery')"
name="osquery">{{
tabNames['osquery'] }}</md-nav-item>
<md-nav-item ng-show="extensions.docker" class="wz-nav-item" md-nav-click="switchTab('docker')" name="docker">{{
tabNames['docker'] }}</md-nav-item>
</md-nav-bar>
<!-- End Security navigation bar -->

<!-- Compliance navigation bar -->
<md-nav-bar ng-if="inArray(tab, complianceTabs) && (extensions.pci || extensions.gdpr || extensions.hipaa || extensions.nist)" class="wz-nav-bar"
ng-show="tab !== 'welcome'" md-selected-nav-item="tab" nav-bar-aria-label="Compliance navigation links">
<md-nav-item ng-show="extensions.pci" class="wz-nav-item" md-nav-click="switchTab('pci')" name="pci">{{
tabNames['pci'] }}</md-nav-item>
<md-nav-item ng-show="extensions.gdpr" class="wz-nav-item" md-nav-click="switchTab('gdpr')" name="gdpr">{{
tabNames['gdpr'] }}</md-nav-item>
<md-nav-item ng-show="extensions.hipaa" class="wz-nav-item" md-nav-click="switchTab('hipaa')" name="hipaa">{{
tabNames['hipaa'] }}</md-nav-item>
<md-nav-item ng-show="extensions.nist" class="wz-nav-item" md-nav-click="switchTab('nist')" name="nist">{{
tabNames['nist'] }}</md-nav-item>
</md-nav-bar>
<!-- End Compliance navigation bar -->
<!-- Navigation bar -->
<div ng-if="agentsTabsProps" ng-show="tab !== 'welcome'">
<react-component name="Tabs" props="agentsTabsProps" />
</div>
<!-- End of navigation bar -->

<!-- Discover search bar section -->
<kbn-dis
Expand Down
Loading

0 comments on commit 4547d59

Please sign in to comment.