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

update eslint and fix formatting errors #223

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
654 changes: 307 additions & 347 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"babel-jest": "^29.6.1",
"babel-loader": "^9.1.2",
"commander": "^3.0.2",
"eslint": "^7.23.0",
"eslint-config-airbnb": "^18.2.1",
"eslint": "^8.44.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
Expand Down
37 changes: 26 additions & 11 deletions src/components/ConnectedFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ class ConnectedFilter extends React.Component {
let filterStatusArray = [];
let filtersApplied = {};
if (this.props.userFilterFromURL && Object.keys(this.props.userFilterFromURL).length > 0) {
filterStatusArray = buildFilterStatusForURLFilter(this.props.userFilterFromURL,
this.getTabsWithSearchFields());
filterStatusArray = buildFilterStatusForURLFilter(
this.props.userFilterFromURL,
this.getTabsWithSearchFields(),
);
filtersApplied = this.props.userFilterFromURL;
initialFilter = mergeFilters(this.props.userFilterFromURL, this.props.adminAppliedPreFilters);
}
Expand Down Expand Up @@ -118,8 +120,10 @@ class ConnectedFilter extends React.Component {
this.setState({ adminAppliedPreFilters: JSON.parse(this.adminPreFiltersFrozen) });
const mergedFilterResults = mergeFilters(filterResults, JSON.parse(this.adminPreFiltersFrozen));

const newFilterStatusArray = buildFilterStatusForURLFilter(mergedFilterResults,
this.getTabsWithSearchFields());
const newFilterStatusArray = buildFilterStatusForURLFilter(
mergedFilterResults,
this.getTabsWithSearchFields(),
);

this.setState({ filtersApplied: mergedFilterResults, filterStatusArray: newFilterStatusArray });
askGuppyForAggregationData(
Expand Down Expand Up @@ -151,6 +155,7 @@ class ConnectedFilter extends React.Component {
return newTabs;
}

// eslint-disable-next-line react/no-unused-class-component-methods
setFilter(filter) {
if (this.filterGroupRef.current) {
this.filterGroupRef.current.resetFilter();
Expand All @@ -172,7 +177,8 @@ class ConnectedFilter extends React.Component {

// Get filter values
const allFilterValues = this.props.filterConfig.tabs.reduce(
(accumulator, tab) => ([...accumulator, ...tab.fields]), [],
(accumulator, tab) => ([...accumulator, ...tab.fields]),
[],
);

if (Object.keys(this.initialTabsOptions).length === 0) {
Expand Down Expand Up @@ -251,18 +257,27 @@ class ConnectedFilter extends React.Component {
}
});
// -------
processedTabsOptions = mergeTabOptions(sortTabsOptions(selectedTabsOptions),
sortTabsOptions(unselectedTabsOptions));
processedTabsOptions = mergeTabOptions(
sortTabsOptions(selectedTabsOptions),
sortTabsOptions(unselectedTabsOptions),
);
} else {
processedTabsOptions = sortTabsOptions(processedTabsOptions);
}
if (!processedTabsOptions || Object.keys(processedTabsOptions).length === 0) return null;
const { fieldMapping } = this.props;
const tabs = this.props.filterConfig.tabs.map(({ fields, searchFields }, index) => {
const sections = getFilterSections(fields, searchFields, fieldMapping, processedTabsOptions,
this.state.initialAggsData, this.state.adminAppliedPreFilters,
this.props.guppyConfig, this.arrayFields,
this.props.filterValuesToHide);
const sections = getFilterSections(
fields,
searchFields,
fieldMapping,
processedTabsOptions,
this.state.initialAggsData,
this.state.adminAppliedPreFilters,
this.props.guppyConfig,
this.arrayFields,
this.props.filterValuesToHide,
);
const filterStatus = this.state.filterStatusArray
? this.state.filterStatusArray[index] : null;
return (
Expand Down
11 changes: 9 additions & 2 deletions src/components/ConnectedFilter/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const createSearchFilterLoadOptionsFn = (field, guppyConfig) => (searchString, o
[field],
filter,
undefined,
undefined,
offset,
NUM_SEARCH_OPTIONS,
'accessible',
Expand Down Expand Up @@ -108,8 +109,14 @@ export const checkIsArrayField = (field, arrayFields) => {
};

export const getFilterSections = (
fields, searchFields, fieldMapping, tabsOptions,
initialTabsOptions, adminAppliedPreFilters, guppyConfig, arrayFields,
fields,
searchFields,
fieldMapping,
tabsOptions,
initialTabsOptions,
adminAppliedPreFilters,
guppyConfig,
arrayFields,
filterValuesToHide,
) => {
let searchFieldSections = [];
Expand Down
10 changes: 7 additions & 3 deletions src/components/GuppyWrapper/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ class GuppyWrapper extends React.Component {
super(props);
let initialFilter = this.props.adminAppliedPreFilters;
if (Object.keys(this.props.initialFilterFromURL).length > 0) {
initialFilter = mergeFilters(this.props.initialFilterFromURL,
this.props.adminAppliedPreFilters);
initialFilter = mergeFilters(
this.props.initialFilterFromURL,
this.props.adminAppliedPreFilters,
);
}

// to avoid asynchronizations, we store another filter as private var
Expand Down Expand Up @@ -197,7 +199,8 @@ class GuppyWrapper extends React.Component {
handleAskGuppyForTotalCounts(type, filter) {
return askGuppyForTotalCounts(
this.props.guppyConfig.path,
type, filter,
type,
filter,
this.state.accessibility,
);
}
Expand Down Expand Up @@ -284,6 +287,7 @@ class GuppyWrapper extends React.Component {
fields,
this.filter,
sort,
undefined,
offset,
size,
this.state.accessibility,
Expand Down
5 changes: 4 additions & 1 deletion src/components/Utils/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const mergeFilters = (userFilter, adminAppliedPreFilter) => {
* they are still checked but their counts are zero.
*/
export const updateCountsInInitialTabsOptions = (
initialTabsOptions, processedTabsOptions, filtersApplied, accessibleFieldCheckList,
initialTabsOptions,
processedTabsOptions,
filtersApplied,
accessibleFieldCheckList,
allFilterValues,
) => {
const updatedTabsOptions = {};
Expand Down
16 changes: 7 additions & 9 deletions src/components/Utils/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ const queryGuppyForSubAgg = (
path,
type,
mainField,
numericAggAsText = false,
termsFields,
missingFields,
gqlFilter,
acc,
numericAggAsText = false,
) => {
let accessibility = acc;
if (accessibility !== 'all' && accessibility !== 'accessible' && accessibility !== 'unaccessible') {
Expand Down Expand Up @@ -161,10 +161,10 @@ export const queryGuppyForRawDataAndTotalCounts = (
fields,
gqlFilter,
sort,
format,
offset = 0,
size = 20,
accessibility = 'all',
format,
) => {
let queryLine = 'query {';
if (gqlFilter || sort || format) {
Expand Down Expand Up @@ -266,9 +266,7 @@ export const getGQLFilter = (filterObj) => {
return gqlFilter;
};

export const askGuppyAboutAllFieldsAndOptions = (
path, type, fields, accessibility, filter,
) => {
export const askGuppyAboutAllFieldsAndOptions = (path, type, fields, accessibility, filter) => {
const gqlFilter = getGQLFilter(filter);
return queryGuppyForAggs(path, type, fields, gqlFilter, accessibility);
};
Expand Down Expand Up @@ -302,11 +300,11 @@ export const askGuppyForSubAggregationData = (
path,
type,
mainField,
numericAggAsText,
termsNestedFields,
missedNestedFields,
gqlFilter,
accessibility,
numericAggAsText,
);
};

Expand All @@ -316,10 +314,10 @@ export const askGuppyForRawData = (
fields,
filter,
sort,
format,
offset = 0,
size = 20,
accessibility = 'all',
format,
) => {
const gqlFilter = getGQLFilter(filter);
return queryGuppyForRawDataAndTotalCounts(
Expand All @@ -328,10 +326,10 @@ export const askGuppyForRawData = (
fields,
gqlFilter,
sort,
format,
offset,
size,
accessibility,
format,
);
};

Expand Down Expand Up @@ -373,7 +371,7 @@ export const downloadDataFromGuppy = (
.then((r) => r.json())
.then((res) => (JSON_FORMAT ? res : jsonToFormat(res, format)));
}
return askGuppyForRawData(path, type, fields, filter, sort, 0, totalCount, accessibility, format)
return askGuppyForRawData(path, type, fields, filter, sort, format, 0, totalCount, accessibility)
.then((res) => {
if (res && res.data && res.data[type]) {
return JSON_FORMAT ? res.data[type] : jsonToFormat(res.data[type], format);
Expand Down
12 changes: 10 additions & 2 deletions src/components/__tests__/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ describe('can update a small set of tabs with new counts', () => {
};

const actualUpdatedTabsOptions = updateCountsInInitialTabsOptions(
initialTabsOptions, processedTabsOptions, filtersApplied, undefined, allFilterValues,
initialTabsOptions,
processedTabsOptions,
filtersApplied,
undefined,
allFilterValues,
);

test('update tab counts', async () => {
Expand Down Expand Up @@ -184,7 +188,11 @@ describe('can update a small set of tabs with new counts, test with ranger slide
};

const actualUpdatedTabsOptions = updateCountsInInitialTabsOptions(
initialTabsOptions, processedTabsOptions, filtersApplied, undefined, allFilterValues,
initialTabsOptions,
processedTabsOptions,
filtersApplied,
undefined,
allFilterValues,
);

test('update tab counts', async () => {
Expand Down
38 changes: 20 additions & 18 deletions src/server/auth/arboristClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,30 @@ class ArboristClient {
},
).then(
(response) => response.json(),
).then((result) => {
const data = {
resources: [],
};
Object.keys(result).forEach((key) => {
).then(
(result) => {
const data = {
resources: [],
};
Object.keys(result).forEach((key) => {
// logic: you have access to a project if you have the following access:
// method 'read' (or '*' - all methods) to service 'guppy' (or '*' - all services)
// on the project resource.
if (result[key] && result[key].some((x) => (
(x.method === 'read' || x.method === '*')
if (result[key] && result[key].some((x) => (
(x.method === 'read' || x.method === '*')
&& (x.service === 'guppy' || x.service === '*')
))) {
data.resources.push(key);
}
});
log.debug('[ArboristClient] data: ', data);
return data;
},
(err) => {
log.error(err);
throw new CodedError(500, err);
});
))) {
data.resources.push(key);
}
});
log.debug('[ArboristClient] data: ', data);
return data;
},
(err) => {
log.error(err);
throw new CodedError(500, err);
},
);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/server/auth/authHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export class AuthHelper {

async getOutOfScopeResourceList(esIndex, esType, filter, filterSelf) {
const requestResourceList = await getRequestResourceListFromFilter(
esIndex, esType, filter, filterSelf,
esIndex,
esType,
filter,
filterSelf,
);
log.debug('[AuthHelper] filter:', filter);
log.debug(`[AuthHelper] request resource list: [${requestResourceList.join(', ')}]`);
Expand Down
5 changes: 4 additions & 1 deletion src/server/auth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export const getAccessibleResourcesFromArboristasync = async (jwt) => {
};

export const getRequestResourceListFromFilter = async (
esIndex, esType, filter, filterSelf,
esIndex,
esType,
filter,
filterSelf,
) => textAggregation(
{ esInstance, esIndex, esType },
{ field: config.esConfig.authFilterField, filter, filterSelf },
Expand Down
4 changes: 3 additions & 1 deletion src/server/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const downloadRouter = async (req, res, next) => {
appliedFilter = authHelper.applyAccessibleFilter(filter);
} else {
const outOfScopeResourceList = await authHelper.getOutOfScopeResourceList(
esIndexConfig.index, type, filter,
esIndexConfig.index,
type,
filter,
);
// if requesting resources > allowed resources, return 401,
if (outOfScopeResourceList.length > 0) {
Expand Down
7 changes: 6 additions & 1 deletion src/server/es/aggs.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export const numericGlobalStats = async (
const queryBody = { size: 0 };
if (!!filter || !!defaultAuthFilter) {
queryBody.query = getFilterObj(
esInstance, esIndex, filter, field, filterSelf, defaultAuthFilter,
esInstance,
esIndex,
filter,
field,
filterSelf,
defaultAuthFilter,
);
}
queryBody.query = appendAdditionalRangeQuery(field, queryBody.query, rangeStart, rangeEnd);
Expand Down
Loading