Skip to content

Commit

Permalink
add latest alert at column, fix some related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
martindstone committed Jul 20, 2023
1 parent 8d7f637 commit 2570ad5
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const PersonInitialsComponent = ({
// initials: getInitials(user.summary),
id: user.id,
html_url: user.html_url,
email: usersMap[user.id].email,
email: usersMap[user.id]?.email || '',
color: CSS.supports && CSS.supports('color', color) ? color : 'black',
};
})
Expand Down
22 changes: 22 additions & 0 deletions src/config/column-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,25 @@ export const defaultIncidentColumns = () => [
},
minWidth: 120,
}),
incidentColumn({
id: 'latest_alert_at',
header: 'Latest Alert At',
accessor: (incident) => {
if (incident.alerts && incident.alerts instanceof Array && incident.alerts.length > 0) {
const alertDates = incident.alerts.map((x) => new Date(x.created_at));
const maxAlertDate = new Date(Math.max(...alertDates));
return maxAlertDate.toISOString();
}
return '';
},
minWidth: 200,
renderer: ({
value,
}) => renderDateCell({
iso8601Date: value,
}),
sortType: dateValueSortType,
}),
];

export const defaultAlertsColumns = () => [
Expand Down Expand Up @@ -829,6 +848,9 @@ export const incidentColumnsTranslations = [
i18next.t('Latest Note At'),
i18next.t('External References'),
i18next.t('Responders'),
i18next.t('Latest Log Entry At'),
i18next.t('Latest Log Entry Type'),
i18next.t('Latest Alert At'),
i18next.t('Severity'),
i18next.t('Component'),
i18next.t('Source'),
Expand Down
1 change: 1 addition & 0 deletions src/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "JSON-Pfad",
"Last Status Change At": "Letzte Statusänderung um",
"Last Status Change By": "Letzte Statusänderung durch",
"Latest Alert At": "Neueste Benachrichtigung um",
"Latest Log Entry At": "Neuester Protokolleintrag um",
"Latest Log Entry Type": "Neuester Protokolleintragstyp",
"Latest Note": "Neueste Notiz",
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "JSON Path",
"Last Status Change At": "Last Status Change At",
"Last Status Change By": "Last Status Change By",
"Latest Alert At": "Latest Alert At",
"Latest Log Entry At": "Latest Log Entry At",
"Latest Log Entry Type": "Latest Log Entry Type",
"Latest Note": "Latest Note",
Expand Down
1 change: 1 addition & 0 deletions src/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "Ruta JSON",
"Last Status Change At": "Último Cambio de Estado en",
"Last Status Change By": "Último Cambio de Estado por",
"Latest Alert At": "Última Alerta en",
"Latest Log Entry At": "Última Entrada de Registro en",
"Latest Log Entry Type": "Último Tipo de Entrada de Registro",
"Latest Note": "Última Nota",
Expand Down
1 change: 1 addition & 0 deletions src/locales/fr/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "Chemin JSON",
"Last Status Change At": "Dernier changement de statut à",
"Last Status Change By": "Dernier changement de statut par",
"Latest Alert At": "Dernière alerte à",
"Latest Log Entry At": "Dernière entrée de journal à",
"Latest Log Entry Type": "Dernier type d'entrée de journal",
"Latest Note": "Dernière note",
Expand Down
1 change: 1 addition & 0 deletions src/locales/id/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "Lokasi JSON",
"Last Status Change At": "Perubahan status terakhir pada",
"Last Status Change By": "Perubahan status terakhir oleh",
"Latest Alert At": "Peringatan terakhir pada",
"Latest Log Entry At": "Entri log terakhir pada",
"Latest Log Entry Type": "Tipe entri log terakhir",
"Latest Note": "Catatan terkini",
Expand Down
1 change: 1 addition & 0 deletions src/locales/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "JSONパス",
"Last Status Change At": "最終ステータス更新日時",
"Last Status Change By": "最終ステータス更新者",
"Latest Alert At": "最新のアラート日時",
"Latest Log Entry At": "最新のログエントリー日時",
"Latest Log Entry Type": "最新のログエントリータイプ",
"Latest Note": "最新のメモ",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt-br/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "Caminho JSON",
"Last Status Change At": "Última Alteração de Estado às",
"Last Status Change By": "Última Alteração de Estado por",
"Latest Alert At": "Último Alerta às",
"Latest Log Entry At": "Última Entrada de Registro às",
"Latest Log Entry Type": "Último Tipo de Entrada de Registro",
"Latest Note": "Última Anotação",
Expand Down
1 change: 1 addition & 0 deletions src/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"JSON Path": "Caminho JSON",
"Last Status Change At": "Última Alteração de Estado às",
"Last Status Change By": "Última Alteração de Estado por",
"Latest Alert At": "Último Alerta às",
"Latest Log Entry At": "Última Entrada de Registo às",
"Latest Log Entry Type": "Último Tipo de Entrada de Registo",
"Latest Note": "Última Nota",
Expand Down
2 changes: 1 addition & 1 deletion src/redux/escalation_policies/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function* getEscalationPolicies() {
});
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: FETCH_ESCALATION_POLICIES_ERROR, message: e.message });
Expand Down
2 changes: 1 addition & 1 deletion src/redux/extensions/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function* getExtensions() {
yield put({ type: MAP_SERVICES_TO_EXTENSIONS_REQUESTED });
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: FETCH_EXTENSIONS_ERROR, message: e.message });
Expand Down
2 changes: 1 addition & 1 deletion src/redux/priorities/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function* getPriorities() {
}
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: FETCH_PRIORITIES_ERROR, message: e.message });
Expand Down
2 changes: 1 addition & 1 deletion src/redux/response_plays/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function* getResponsePlays() {
});
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
if (e.response.status === 301) {
Expand Down
2 changes: 1 addition & 1 deletion src/redux/services/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function* getServices(action) {
yield put({ type: FETCH_EXTENSIONS_REQUESTED });
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: FETCH_SERVICES_ERROR, message: e.message });
Expand Down
2 changes: 1 addition & 1 deletion src/redux/teams/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function* getTeams() {
});
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: FETCH_TEAMS_ERROR, message: e.message });
Expand Down
2 changes: 1 addition & 1 deletion src/redux/users/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function* getUsers(action) {
});
} catch (e) {
// Handle API auth failure
if (e.status === 401) {
if (e.response?.status === 401) {
e.message = i18next.t('Unauthorized Access');
}
yield put({ type: GET_USERS_ERROR, message: e.message });
Expand Down
22 changes: 18 additions & 4 deletions src/util/pd-api-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const pdAxiosRequest = async (method, endpoint, params = {}, data = {}) =
},
params: { ...params, rand: Math.random().toString(36).substring(2, 7) },
data,
// never throw, just return the error
validateStatus: () => true,
});

Expand Down Expand Up @@ -143,12 +144,25 @@ export const pdParallelFetch = async (
let reversedSortOrder = false;
if (endpoint.indexOf('log_entries') > -1) reversedSortOrder = true;

const firstPage = (
await throttledPdAxiosRequest('GET', endpoint, requestParams, undefined, axiosRequestOptions)
).data;
const firstPageResponse = await throttledPdAxiosRequest(
'GET',
endpoint,
requestParams,
undefined,
axiosRequestOptions,
);

if (!(firstPageResponse.status >= 200 && firstPageResponse.status < 300)) {
const e = new Error(`Error fetching ${endpoint}: ${firstPageResponse.status}`
+ `${firstPageResponse.data ? `: ${firstPageResponse.data}` : ''}`);
e.response = firstPageResponse;
throw e;
}
const firstPage = firstPageResponse.data;
if (options.maxRecords && firstPage.total > options.maxRecords) {
throw new Error(`Too many records: ${firstPage.total} > ${options.maxRecords}`);
}

const fetchedData = firstPage[endpointIdentifier(endpoint)];

const promises = [];
Expand Down Expand Up @@ -181,7 +195,7 @@ export const pdParallelFetch = async (
}
}
await Promise.all(promises);
if (!options.skipSort) {
if (!options.skipSort && fetchedData.length > 0) {
fetchedData.sort((a, b) => (reversedSortOrder ? compareCreatedAt(b, a) : compareCreatedAt(a, b)));
}
return fetchedData;
Expand Down

0 comments on commit 2570ad5

Please sign in to comment.