Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs at pie chart and datatable #56

Merged
merged 13 commits into from
Sep 6, 2024
2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "*"
},
"homepage": ".",
"homepage": "/metrics/",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
Expand Down
18 changes: 4 additions & 14 deletions javascript/src/components/Common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,10 @@ export function calculateMinMax(dataArray) {
return [min, max]
}

export const createAnchorElement = (title, link) => {
const anchor = document.createElement('a');
const linkText = document.createTextNode(title);
anchor.appendChild(linkText);
anchor.title = title;
anchor.href = link;

// FIXME:
// Trying to pass an object directly to the datatable will fail. We need to
// get the HTML string from the element. This causes inconsistent behavior
// which we need to solve. For now we leave it as is.
return anchor.outerHTML;
// return anchor;
}
export const createAnchorElement = (title, link) => ({
title,
link,
});

export const axisChartOptions = (title, hAxisFormat, hAxisTicks) => {
return (
Expand Down
16 changes: 9 additions & 7 deletions javascript/src/components/Dashboard/loginIdpPieChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getLoginsPerIdp} from "../../utils/queries";
import {optionsPieChart} from "../../utils/helpers/enums";
import {convertDateByGroup, formatStartDate, formatEndDate} from "../Common/utils";

var idpsArray = [];

const LoginIdpPieChart = ({
spId,
tenenvId,
Expand All @@ -27,9 +27,10 @@ const LoginIdpPieChart = ({
today.setDate(today.getDate() - 1);
formatEndDate(today)

let idpsChartArray = [["Identity Provider", "Logins"], ['', 0]];
let idpsChartArray = [["Identity Provider", "Logins"]];
let idpsArray = [];
const [idps, setIdps] = useState(idpsChartArray);

const [idpsAr, setIdpsArray] = useState(idpsArray);
const params = {
params: {
'tenenv_id': tenenvId,
Expand Down Expand Up @@ -57,6 +58,7 @@ const LoginIdpPieChart = ({
idpsArray.push([element.id, element.name, element.identifier])
})
setIdps(idpsChartArray)
setIdpsArray(idpsArray)
})

}, [uniqueLogins])
Expand Down Expand Up @@ -91,8 +93,8 @@ const LoginIdpPieChart = ({
const chart = chartWrapper.getChart();

if (cookies.userinfo != undefined
&& !!permissions?.actions?.identity_providers?.['view']) {
google.visualization.events.addListener(chart, 'click', selectHandler);
&& !!permissions?.actions?.identity_providers?.['view']) {
google.visualization.events.addListener(chart, 'click', selectHandler);
}

google.visualization.events.addListener(chart, 'onmouseover', showTooltip);
Expand All @@ -112,9 +114,9 @@ const LoginIdpPieChart = ({

function selectHandler() {

var selection = chart.getSelection();
var selection = chart.getSelection();
if (selection.length) {
var identifier = idpsArray[selection[0].row];
var identifier = idpsAr[selection[0].row];
goToSpecificProviderHandler(identifier[0])
}
}
Expand Down
6 changes: 4 additions & 2 deletions javascript/src/components/Dashboard/loginSpPieChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {useQuery} from "react-query";
import {optionsPieChart} from "../../utils/helpers/enums";
import {convertDateByGroup, formatStartDate, formatEndDate} from "../Common/utils";

var spsArray = [];

const LoginSpPieChart = ({
idpId,
Expand All @@ -21,7 +20,9 @@ const LoginSpPieChart = ({
goToSpecificProviderHandler
}) => {
let spsChartArray = [["Service Provider", "Logins"]];
let spsArray = [];
const [sps, setSps] = useState(spsChartArray);
const [spsAr, setSpsArray] = useState(spsArray);
const oneYearAgo = new Date();
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
formatStartDate(oneYearAgo)
Expand Down Expand Up @@ -59,6 +60,7 @@ const LoginSpPieChart = ({
spsArray.push([element.id, element.name, element.identifier])
})
setSps(spsChartArray)
setSpsArray(spsArray)
})
}, [uniqueLogins])

Expand Down Expand Up @@ -112,7 +114,7 @@ const LoginSpPieChart = ({
function selectHandler() {
var selection = chart.getSelection();
if (selection.length) {
var identifier = spsArray[selection[0].row];
var identifier = spsAr[selection[0].row];
goToSpecificProviderHandler(identifier[0], "sp")
}
}
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/components/Idps/idpsDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const IdpsDataTable = ({
&& loginsPerIpd.isFetched
&& loginsPerIpd.isSuccess
&& loginsPerIpd?.data?.map(idp => ({
"Identity Provider Name": (cookies.userinfo == undefined && !!permissions?.actions?.identity_providers?.['view']) ? idp.name : createAnchorElement(idp.name, `/metrics/identity-providers/${idp.id}`),
"Identity Provider Name": (cookies.userinfo == undefined && !!permissions?.actions?.identity_providers?.['view']) ? idp.name : createAnchorElement(idp.name != '' ? idp.name : idp.entityid, `/metrics/identity-providers/${idp.id}`),
"Identity Provider Identifier": idp.entityid,
"Number of Logins": idp.count
}))
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/components/Sps/spsDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const SpsDataTable = ({
&& !loginsPerSp.isFetching
&& loginsPerSp.isSuccess
&& loginsPerSp?.data?.map(sp => ({
"Service Provider Name": (cookies.userinfo == undefined && !!permissions?.actions?.service_providers?.['view']) ? sp.name : createAnchorElement(sp.name, `/metrics/services/${sp.id}`),
"Service Provider Name": (cookies.userinfo == undefined && !!permissions?.actions?.service_providers?.['view']) ? sp.name : createAnchorElement(sp.name != '' ? sp.name : sp.identifier, `/metrics/services/${sp.id}`),
"Service Provider Identifier": sp.identifier,
"Number of Logins": sp.count
}))
Expand Down
5 changes: 5 additions & 0 deletions javascript/src/components/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class Datatable extends Component {
}

listNames = (names, key) => {
//console.log("listNames called with:", names.title);
if (this.props.columnSep && key == this.props.columnSep && typeof names === 'string') {
return renderToString(
<ul>
Expand All @@ -161,6 +162,10 @@ class Datatable extends Component {

</ul>
)
} else if (names && typeof names === 'object' && names.title && names.link) {
return renderToString(
<a href={names.link} title={names.title}>{names.title}</a>
);
} else return (
names
)
Expand Down
Loading