debian-mirror-gitlab/app/assets/javascripts/logs/stores/mutations.js

134 lines
3.7 KiB
JavaScript
Raw Normal View History

2020-04-08 14:13:33 +05:30
import * as types from './mutation_types';
import { convertToFixedRange } from '~/lib/utils/datetime_range';
2020-04-22 19:07:51 +05:30
const mapLine = ({ timestamp, pod, message }) => ({
2020-04-08 14:13:33 +05:30
timestamp,
2020-04-22 19:07:51 +05:30
pod,
2020-04-08 14:13:33 +05:30
message,
});
export default {
// Search Data
[types.SET_SEARCH](state, searchQuery) {
state.search = searchQuery;
},
// Time Range Data
[types.SET_TIME_RANGE](state, timeRange) {
state.timeRange.selected = timeRange;
state.timeRange.current = convertToFixedRange(timeRange);
},
2020-04-22 19:07:51 +05:30
[types.SHOW_TIME_RANGE_INVALID_WARNING](state) {
state.timeRange.invalidWarning = true;
},
[types.HIDE_TIME_RANGE_INVALID_WARNING](state) {
state.timeRange.invalidWarning = false;
},
2020-04-08 14:13:33 +05:30
// Environments Data
[types.SET_PROJECT_ENVIRONMENT](state, environmentName) {
state.environments.current = environmentName;
2020-04-22 19:07:51 +05:30
// Clear current pod options
state.pods.current = null;
state.pods.options = [];
2020-07-28 23:09:34 +05:30
// Clear current managedApps options
state.managedApps.current = null;
2020-04-08 14:13:33 +05:30
},
[types.REQUEST_ENVIRONMENTS_DATA](state) {
state.environments.options = [];
state.environments.isLoading = true;
},
[types.RECEIVE_ENVIRONMENTS_DATA_SUCCESS](state, environmentOptions) {
state.environments.options = environmentOptions;
state.environments.isLoading = false;
},
[types.RECEIVE_ENVIRONMENTS_DATA_ERROR](state) {
state.environments.options = [];
state.environments.isLoading = false;
2020-04-22 19:07:51 +05:30
state.environments.fetchError = true;
},
[types.HIDE_REQUEST_ENVIRONMENTS_ERROR](state) {
state.environments.fetchError = false;
2020-04-08 14:13:33 +05:30
},
// Logs data
[types.REQUEST_LOGS_DATA](state) {
state.timeRange.current = convertToFixedRange(state.timeRange.selected);
state.logs.lines = [];
state.logs.isLoading = true;
// start pagination from the beginning
state.logs.cursor = null;
state.logs.isComplete = false;
},
[types.RECEIVE_LOGS_DATA_SUCCESS](state, { logs = [], cursor }) {
state.logs.lines = logs.map(mapLine);
state.logs.isLoading = false;
state.logs.cursor = cursor;
if (!cursor) {
state.logs.isComplete = true;
}
},
[types.RECEIVE_LOGS_DATA_ERROR](state) {
state.logs.lines = [];
state.logs.isLoading = false;
2020-04-22 19:07:51 +05:30
state.logs.fetchError = true;
2020-04-08 14:13:33 +05:30
},
[types.REQUEST_LOGS_DATA_PREPEND](state) {
state.logs.isLoading = true;
},
[types.RECEIVE_LOGS_DATA_PREPEND_SUCCESS](state, { logs = [], cursor }) {
const lines = logs.map(mapLine);
state.logs.lines = lines.concat(state.logs.lines);
state.logs.isLoading = false;
state.logs.cursor = cursor;
if (!cursor) {
state.logs.isComplete = true;
}
},
[types.RECEIVE_LOGS_DATA_PREPEND_ERROR](state) {
state.logs.isLoading = false;
2020-04-22 19:07:51 +05:30
state.logs.fetchError = true;
},
[types.HIDE_REQUEST_LOGS_ERROR](state) {
state.logs.fetchError = false;
2020-04-08 14:13:33 +05:30
},
// Pods data
[types.SET_CURRENT_POD_NAME](state, podName) {
state.pods.current = podName;
},
[types.RECEIVE_PODS_DATA_SUCCESS](state, podOptions) {
state.pods.options = podOptions;
},
[types.RECEIVE_PODS_DATA_ERROR](state) {
state.pods.options = [];
},
2020-07-28 23:09:34 +05:30
// Managed apps data
[types.RECEIVE_MANAGED_APPS_DATA_SUCCESS](state, apps) {
state.managedApps.options = apps;
state.managedApps.isLoading = false;
},
[types.RECEIVE_MANAGED_APPS_DATA_ERROR](state) {
state.managedApps.options = [];
state.managedApps.isLoading = false;
state.managedApps.fetchError = true;
},
[types.SET_MANAGED_APP](state, managedApp) {
state.managedApps.current = managedApp;
// Clear current pod options
state.pods.current = null;
state.pods.options = [];
// Clear current environment options
state.environments.current = null;
},
2020-04-08 14:13:33 +05:30
};