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

IDS-4707 - Switch from InputCombo to InputText if there are too many connections to list #292

Merged
merged 13 commits into from
Jun 5, 2024
2 changes: 1 addition & 1 deletion client/actions/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function requestCreateUser(memberships) {
dispatch({
type: constants.REQUEST_CREATE_USER,
payload: {
connection: connections && connections.length && connections[0].name,
connection: connections && connections.length && connections.length < 20 && connections[0].name || null,
memberships: memberships && memberships.length === 1 ? [ memberships[0] ] : [ ]
}
});
Expand Down
2 changes: 2 additions & 0 deletions client/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,5 @@ export const SUPER_ADMIN = 2;

// The list of reserved user fields that must not be rendered in the custom fields edit form
export const RESERVED_USER_FIELDS = [ 'username', 'memberships', 'connection', 'password', 'email', 'repeatPassword', 'resetPassword' ];

export const CONNECTIONS_LIST_LIMIT = 20;
11 changes: 7 additions & 4 deletions client/utils/useDefaultFields.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import _ from 'lodash';

import { CONNECTIONS_LIST_LIMIT } from "../constants";

const applyDefaults = (type, fields, property, defaults) => {
const field = _.find(fields, { property });

Expand Down Expand Up @@ -61,14 +63,15 @@ export const useConnectionsField = (isEditField, fields, connections, onConnecti
return _.remove(fields, { property: 'connection' });
}

const isConnectionListingLimitExceeded = connections.length >= CONNECTIONS_LIST_LIMIT;
const defaults = {
property: 'connection',
label: 'Connection',
label: isConnectionListingLimitExceeded ? 'Connection Name' : 'Connection',
[type]: {
required: true,
type: 'select',
component: 'InputCombo',
options: connections.map(conn => ({ value: conn.name, label: conn.name })),
type: isConnectionListingLimitExceeded ? 'text' : 'select',
component: isConnectionListingLimitExceeded ? 'InputText' : 'InputCombo',
options: isConnectionListingLimitExceeded ? undefined : connections.map(conn => ({ value: conn.name, label: conn.name })),
onChange: onConnectionChange
}
};
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
"deploy": "a0-ext deploy --package ./dist/package.zip --url http://0.0.0.0:3000/api/extensions",
"client:build": "a0-ext build:client ./client/app.jsx ./dist/client",
"extension:build": "a0-ext build:server ./webtask.js ./dist && cp ./dist/auth0-delegated-admin.extension.$npm_package_version.js ./build/bundle.js && cp ./webtask.json ./dist/webtask.json",
"serve:dev": "cross-env NODE_ENV=development nodemon -e js --ignore assets/app/ --ignore build/webpack/ --ignore client/ --ignore server/data.json --ignore node_modules/ ./build/webpack/server.js",
"serve:dev": "cross-env NODE_ENV=development NODE_OPTIONS=--openssl-legacy-provider nodemon -e js --ignore assets/app/ --ignore build/webpack/ --ignore client/ --ignore server/data.json --ignore node_modules/ ./build/webpack/server.js",
"serve:prod": "cross-env NODE_ENV=production node index.js",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov mocha --require ignore-styles tests/mocha.js './tests/**/*.tests.js'",
"test:watch": "cross-env NODE_ENV=test mocha --require ignore-styles tests/mocha.js './tests/**/*.tests.js' --watch",
"test:pre": "npm run test:clean && npm run lint:js",
"test:clean": "rimraf ./coverage && rimraf ./.nyc_output",
"extension:size": "cross-env NODE_ENV=production webpack -p --config ./build/extension/webpack.config.js --json > ./build/extension/bundle-size.json && node ./build/extension/bundle-size.js",
"snyk-protect": "snyk protect",
"prepare": "npm run snyk-protect"
"extension:size": "cross-env NODE_ENV=production webpack -p --config ./build/extension/webpack.config.js --json > ./build/extension/bundle-size.json && node ./build/extension/bundle-size.js"
},
"keywords": [
"auth0",
Expand Down
10 changes: 9 additions & 1 deletion server/lib/multipartRequest.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Promise from 'bluebird';
import { ArgumentError } from 'auth0-extension-tools';

export default function(client, entity, opts = {}, perPage = 50, concurrency = 5) {

export default function(client, entity, opts = {}, fetchOptions = {} ) {
const perPage = fetchOptions.perPage || 50;
const concurrency = fetchOptions.concurrency || 5;
const limit = fetchOptions.limit || null;
sauntimo marked this conversation as resolved.
Show resolved Hide resolved

if (client === null || client === undefined) {
throw new ArgumentError('Must provide a auth0 client object.');
}
Expand All @@ -20,6 +25,9 @@ export default function(client, entity, opts = {}, perPage = 50, concurrency = 5
getter({ ...options, include_totals: true, page: 0 })
.then((response) => {
total = response.total || 0;
if (limit) {
total = Math.min(total, limit);
}
pageCount = Math.ceil(total / perPage);
const data = response[entity] || response || [];
data.forEach(item => result.push(item));
Expand Down
3 changes: 2 additions & 1 deletion server/routes/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import _ from 'lodash';
import { Router } from 'express';

import multipartRequest from '../lib/multipartRequest';
import { CONNECTIONS_LIST_LIMIT } from "../constants";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this constant be added to the server/constants.js file? Now you have it only in the client/constants.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot - addressed in 340edf0


export default (scriptManager) => {
const api = Router();
api.get('/', (req, res, next) => {
multipartRequest(req.auth0, 'connections', { strategy: 'auth0', fields: 'id,name,strategy,options' })
multipartRequest(req.auth0, 'connections', { strategy: 'auth0', fields: 'id,name,strategy,options' }, { perPage: 100, limit: CONNECTIONS_LIST_LIMIT})
.then((connections) => {
global.connections = connections.map(conn => ({ name: conn.name, id: conn.id }));
const settingsContext = {
Expand Down