Skip to content

Commit

Permalink
computed columns UI WIP 2
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin Reynolds <[email protected]>
  • Loading branch information
gsreynolds committed Jul 2, 2024
1 parent 708da0a commit a3a9929
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const App = () => {
dispatch({ type: START_QUEUE_STATS_POLLING });
}, []);

if (catastrophe) {
if (catastrophe && 1 === 2) {
return (
<CatastropheModal
errorMessage={connectionStatusMessage}
Expand Down
41 changes: 32 additions & 9 deletions src/components/ColumnsModal/ColumnsModalComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
import {
toggleColumnsModal as toggleColumnsModalConnected,
setAlertCustomDetailColumns as setAlertCustomDetailColumnsConnected,
setComputedColumns as setComputedColumnsConnected,
} from 'src/redux/settings/actions';

import ColumnsModalItem from './subcomponents/ColumnsModalItem';
Expand All @@ -61,6 +62,7 @@ import DraggableColumnsModalItem from './subcomponents/DraggableColumnsModalItem
const TableColumnsModalComponent = () => {
const displayColumnsModal = useSelector((state) => state.settings.displayColumnsModal);
const alertCustomDetailFields = useSelector((state) => state.settings.alertCustomDetailFields);
const computedFields = useSelector((state) => state.settings.computedFields);
const incidentTableColumns = useSelector((state) => state.incidentTable.incidentTableColumns);
const {
incidentTableState,
Expand All @@ -71,6 +73,9 @@ const TableColumnsModalComponent = () => {
const setAlertCustomDetailColumns = (newAlertCustomDetailFields) => {
dispatch(setAlertCustomDetailColumnsConnected(newAlertCustomDetailFields));
};
const setComputedColumns = (newComputedFields) => {
dispatch(setComputedColumnsConnected(newComputedFields));
};
const saveIncidentTable = (updatedIncidentTableColumns) => {
dispatch(saveIncidentTableConnected(updatedIncidentTableColumns));
};
Expand Down Expand Up @@ -159,19 +164,19 @@ const TableColumnsModalComponent = () => {
};

const addCustomComputedColumn = (value) => {
const [Header, accessorPath, aggregator, expression] = value.split(':');
const [Header, accessorPath, expression] = value.split(':');
const newColumn = {
Header,
accessorPath,
aggregator,
value,
// expressionType,
expressionType: 'regex-single',
expression,
// label: value,
columnType: 'alert',
columnType: 'computed',
};
const newAlertCustomDetailFields = [...alertCustomDetailFields, newColumn];
setAlertCustomDetailColumns(newAlertCustomDetailFields);
console.error('newColumn', newColumn);
const newComputedFields = [...computedFields, newColumn];
setComputedColumns(newComputedFields);
};

const removeCustomAlertColumn = (column) => {
Expand All @@ -182,6 +187,14 @@ const TableColumnsModalComponent = () => {
setAlertCustomDetailColumns(newAlertCustomDetailFields);
};

const removeCustomComputedColumn = (column) => {
unselectColumn(column);
const newComputedFields = computedFields.filter(
(c) => c.value !== column.value,
);
setComputedColumns(newComputedFields);
};

const columnTypeInputRef = useRef(null);
const headerInputRef = useRef(null);
const accessorPathInputRef = useRef(null);
Expand Down Expand Up @@ -290,6 +303,14 @@ const TableColumnsModalComponent = () => {
itemType="custom"
/>
))}
{computedFields.map((column) => (
<ColumnsModalItem
key={columnValue(column)}
column={column}
onClick={() => removeCustomComputedColumn(column)}
itemType="custom"
/>
))}
</Box>
<InputGroup>
<Select
Expand Down Expand Up @@ -336,12 +357,14 @@ const TableColumnsModalComponent = () => {
ref={addButtonRef}
isDisabled={!inputIsValid}
onClick={() => {
const value = `${headerInputRef.current.value}:`
+ `${accessorPathInputRef.current.value}`;
if (columnType === 'alert') {
const value = `${headerInputRef.current.value}:`
+ `${accessorPathInputRef.current.value}`;
addCustomAlertColumn(value);
} else {
console.error('computed submitted');
const value = `${headerInputRef.current.value}:`
+ `${accessorPathInputRef.current.value}:`
+ `${regexInputRef.current.value}`;
addCustomComputedColumn(value);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
setFuzzySearch as setFuzzySearchConnected,
setRespondersInEpFilter as setRespondersInEpFilterConnected,
setAlertCustomDetailColumns as setAlertCustomDetailColumnsConnected,
setComputedColumns as setComputedColumnsConnected,
setDarkMode as setDarkModeConnected,
setRelativeDates as setRelativeDatesConnected,
} from 'src/redux/settings/actions';
Expand Down Expand Up @@ -69,6 +70,7 @@ const SettingsModalComponent = () => {
fuzzySearch,
respondersInEpFilter,
alertCustomDetailFields,
computedFields,
darkMode,
relativeDates,
} = useSelector((state) => state.settings);
Expand Down Expand Up @@ -103,6 +105,7 @@ const SettingsModalComponent = () => {
const setFuzzySearch = (search) => dispatch(setFuzzySearchConnected(search));
const setRespondersInEpFilter = (show) => dispatch(setRespondersInEpFilterConnected(show));
const setAlertCustomDetailColumns = (columns) => dispatch(setAlertCustomDetailColumnsConnected(columns));
const setComputedColumns = (columns) => dispatch(setComputedColumnsConnected(columns));
const setDarkMode = (mode) => dispatch(setDarkModeConnected(mode));
const setRelativeDates = (relative) => dispatch(setRelativeDatesConnected(relative));
const toggleDisplayQuerySettings = () => dispatch(toggleDisplayQuerySettingsConnected());
Expand All @@ -128,6 +131,7 @@ const SettingsModalComponent = () => {
fuzzySearch: !!fuzzySearch,
respondersInEpFilter,
alertCustomDetailFields,
computedFields,
darkMode,
relativeDates,
};
Expand Down Expand Up @@ -173,6 +177,7 @@ const SettingsModalComponent = () => {
setFuzzySearch(!!presets.settings.fuzzySearch);
setRespondersInEpFilter(presets.settings.respondersInEpFilter);
setAlertCustomDetailColumns(presets.settings.alertCustomDetailFields);
setComputedColumns(presets.settings.computedFields);
setDarkMode(presets.settings.darkMode);
setColorMode(presets.settings.darkMode ? 'dark' : 'light');
setRelativeDates(presets.settings.relativeDates);
Expand Down
1 change: 1 addition & 0 deletions src/redux/incidents/sagas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const initialSettings = {
aggregator: null,
},
],
computedFields: [],
darkMode: false,
relativeDates: false,
status: '',
Expand Down
2 changes: 2 additions & 0 deletions src/redux/rootSaga.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ import {
setFuzzySearch,
setRespondersInEpFilter,
setAlertCustomDetailColumns,
setComputedColumns,
setShowIncidentAlertsModalForIncidentId,
setMaxRateLimit,
setAutoAcceptIncidentsQuery,
Expand Down Expand Up @@ -250,6 +251,7 @@ export default function* rootSaga() {
setFuzzySearch(),
setRespondersInEpFilter(),
setAlertCustomDetailColumns(),
setComputedColumns(),
setShowIncidentAlertsModalForIncidentId(),
setMaxRateLimit(),
setAutoAcceptIncidentsQuery(),
Expand Down
8 changes: 8 additions & 0 deletions src/redux/settings/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const SET_RESPONDERS_IN_EP_FILTER_COMPLETED = 'SET_RESPONDERS_IN_EP_FILTE
export const SET_ALERT_CUSTOM_DETAIL_COLUMNS_REQUESTED = 'SET_ALERT_CUSTOM_DETAIL_COLUMNS_REQUESTED';
export const SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED = 'SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED';

export const SET_COMPUTED_COLUMNS_REQUESTED = 'SET_COMPUTED_COLUMNS_REQUESTED';
export const SET_COMPUTED_COLUMNS_COMPLETED = 'SET_COMPUTED_COLUMNS_COMPLETED';

export const SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED = 'SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED';
export const SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_COMPLETED = 'SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_COMPLETED';

Expand Down Expand Up @@ -83,6 +86,11 @@ export const setAlertCustomDetailColumns = (alertCustomDetailFields) => ({
alertCustomDetailFields,
});

export const setComputedColumns = (computedFields) => ({
type: SET_COMPUTED_COLUMNS_REQUESTED,
computedFields,
});

export const setShowIncidentAlertsModalForIncidentId = (incidentId) => ({
type: SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED,
incidentId,
Expand Down
12 changes: 12 additions & 0 deletions src/redux/settings/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
SET_RESPONDERS_IN_EP_FILTER_COMPLETED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_REQUESTED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED,
SET_COMPUTED_COLUMNS_REQUESTED,
SET_COMPUTED_COLUMNS_COMPLETED,
SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED,
SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_COMPLETED,
SET_MAX_RATE_LIMIT_REQUESTED,
Expand Down Expand Up @@ -83,6 +85,15 @@ const settings = produce(
draft.status = SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED;
break;

case SET_COMPUTED_COLUMNS_REQUESTED:
draft.status = SET_COMPUTED_COLUMNS_REQUESTED;
break;

case SET_COMPUTED_COLUMNS_COMPLETED:
draft.computedFields = action.computedFields;
draft.status = SET_COMPUTED_COLUMNS_COMPLETED;
break;

case SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED:
draft.status = SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED;
break;
Expand Down Expand Up @@ -197,6 +208,7 @@ const settings = produce(
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
relativeDates: false,
Expand Down
17 changes: 17 additions & 0 deletions src/redux/settings/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
SET_RESPONDERS_IN_EP_FILTER_COMPLETED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_REQUESTED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED,
SET_COMPUTED_COLUMNS_REQUESTED,
SET_COMPUTED_COLUMNS_COMPLETED,
SET_MAX_RATE_LIMIT_REQUESTED,
SET_MAX_RATE_LIMIT_COMPLETED,
SET_AUTO_ACCEPT_INCIDENTS_QUERY_REQUESTED,
Expand Down Expand Up @@ -166,6 +168,21 @@ export function* setAlertCustomDetailColumnsImpl(action) {
});
}

export function* setComputedColumns() {
yield takeLatest(SET_COMPUTED_COLUMNS_REQUESTED, setComputedColumnsImpl);
}

export function* setComputedColumnsImpl(action) {
console.error('setComputedColumnsImpl', action);
const {
computedFields,
} = action;
yield put({
type: SET_COMPUTED_COLUMNS_COMPLETED,
computedFields,
});
}

export function* setShowIncidentAlertsModalForIncidentId() {
yield takeLatest(
SET_SHOW_INCIDENT_ALERTS_MODAL_FOR_INCIDENT_ID_REQUESTED,
Expand Down
62 changes: 62 additions & 0 deletions src/redux/settings/sagas.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
SET_DEFAULT_SINCE_DATE_TENOR_COMPLETED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_REQUESTED,
SET_ALERT_CUSTOM_DETAIL_COLUMNS_COMPLETED,
SET_COMPUTED_COLUMNS_REQUESTED,
SET_COMPUTED_COLUMNS_COMPLETED,
SET_MAX_RATE_LIMIT_REQUESTED,
SET_MAX_RATE_LIMIT_COMPLETED,
SET_AUTO_ACCEPT_INCIDENTS_QUERY_REQUESTED,
Expand All @@ -33,6 +35,7 @@ import {
import {
setDefaultSinceDateTenor,
setAlertCustomDetailColumns,
setComputedColumns,
setMaxRateLimit,
setAutoAcceptIncidentsQuery,
setAutoRefreshInterval,
Expand Down Expand Up @@ -71,6 +74,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand Down Expand Up @@ -111,6 +115,7 @@ describe('Sagas: Settings', () => {
autoAcceptIncidentsQuery: true,
autoRefreshInterval: 5,
alertCustomDetailFields,
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand All @@ -121,6 +126,58 @@ describe('Sagas: Settings', () => {
})
.silentRun();
});
it('setComputedColumns', () => {
const computedFields = [
{
label: faker.git.branch(),
value: faker.git.branch(),
columnType: 'computed',
Header: 'Regex',
accessorPath: 'details.env',
aggregator: null,
expression: '.*',
expressionType: 'regex-single',
},
];
return expectSaga(setComputedColumns)
.withReducer(settings)
.dispatch({
type: SET_COMPUTED_COLUMNS_REQUESTED,
computedFields,
})
.put({
type: SET_COMPUTED_COLUMNS_COMPLETED,
computedFields,
})
.hasFinalState({
displaySettingsModal: false,
displayLoadSavePresetsModal: false,
displayColumnsModal: false,
defaultSinceDateTenor: '1 Day',
maxRateLimit: 200,
autoAcceptIncidentsQuery: true,
autoRefreshInterval: 5,
alertCustomDetailFields: [
{
label: 'Environment:details.env',
value: 'Environment:details.env',
columnType: 'alert',
Header: 'Environment',
accessorPath: 'details.env',
aggregator: null,
},
],
computedFields,
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
fuzzySearch: false,
respondersInEpFilter: false,
relativeDates: false,
status: SET_COMPUTED_COLUMNS_COMPLETED,
})
.silentRun();
});
it('setMaxRateLimit', () => {
const maxRateLimit = faker.number.int({
min: MAX_RATE_LIMIT_LOWER,
Expand Down Expand Up @@ -154,6 +211,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand Down Expand Up @@ -194,6 +252,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand Down Expand Up @@ -237,6 +296,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand Down Expand Up @@ -277,6 +337,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: true,
searchAllCustomDetails: false,
Expand Down Expand Up @@ -317,6 +378,7 @@ describe('Sagas: Settings', () => {
aggregator: null,
},
],
computedFields: [],
showIncidentAlertsModalForIncidentId: null,
darkMode: false,
searchAllCustomDetails: false,
Expand Down

0 comments on commit a3a9929

Please sign in to comment.