Skip to content

Commit

Permalink
[CPCN-177] - Add Source column to Content Activity report (#904)
Browse files Browse the repository at this point in the history
* Minor code clean up

CPCN-177

* Add `Source` column to Content Activity report

This adds the column `source` to the content activity report both in the frontend UI and in the CSV export.

CPCN-177

* Fix format with black

CPCN-177

* Implement typings for props and remove `_.get` usage

CPCN-177

* Extract report filter into separate component

The intention is to simplify and to improve the `ContentActivity.tsx` component from using UNSAFE cycle methods.

CPCN-177

* Remove unnecessary state of `ContentActivity.tsx`

CPCN-177

* Small UI/UX improvements

CPCN-177
  • Loading branch information
eos87 authored May 28, 2024
1 parent 88060ca commit 6845cca
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 264 deletions.
11 changes: 3 additions & 8 deletions assets/company-reports/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function runReport() {
};
}

export function fetchAggregations(url: any) {
export function fetchAggregations(url: string) {
return function(dispatch: any, getState: any) {
const queryString = getReportQueryString(getState(), 0, false, notify);

Expand All @@ -144,7 +144,6 @@ export function fetchReport(url: any, next?: any, exportReport?: any) {
}

const queryString = getReportQueryString(getState(), next, exportReport, notify);
let apiRequest: any;

if (exportReport) {
if (getState().results.length <= 0) {
Expand All @@ -156,18 +155,14 @@ export function fetchReport(url: any, next?: any, exportReport?: any) {
return;
}

if (queryString) {
apiRequest = server.get(`${url}?${queryString}`);
} else {
apiRequest = server.get(url);
}
const apiRequest = server.get(queryString ? `${url}?${queryString}` : url);

return apiRequest.then((data: any) => {
if (!next) {
dispatch(receivedData(data));
} else {
dispatch(isLoading(false));
dispatch(addResults(get(data, 'results', [])));
dispatch(addResults(data?.results ?? []));
}
})
.catch((error: any) => errorHandler(error, dispatch, setError));
Expand Down
19 changes: 10 additions & 9 deletions assets/company-reports/components/CompanyReportsApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {gettext} from 'utils';
import {panels} from '../utils';

const options = [
{value: '', text: ''},
{value: '', text: gettext('Select a report')},
{value: REPORTS_NAMES.COMPANY_SAVED_SEARCHES, text: gettext('Saved searches per company')},
{value: REPORTS_NAMES.USER_SAVED_SEARCHES, text: gettext('Saved searches per user')},
{value: REPORTS_NAMES.COMPANY_PRODUCTS, text: gettext('Products per company')},
Expand All @@ -27,16 +27,11 @@ const options = [

class CompanyReportsApp extends React.Component<any, any> {
static propTypes: any;
constructor(props: any, context: any) {
super(props, context);

this.getPanel = this.getPanel.bind(this);
}

getPanel() {
getPanel = () => {
const Panel = panels[this.props.activeReport];
return Panel && this.props.results && <Panel key="panel" {...this.props}/>;
}
};

render() {
const reportOptions = !this.props.apiEnabled ? options :
Expand All @@ -54,8 +49,14 @@ class CompanyReportsApp extends React.Component<any, any> {
id={'company-reports'}
name={'company-reports'}
value={this.props.activeReport || ''}

onChange={(event: any) => this.props.setActiveReport(event.target.value)}>
{reportOptions.map((option: any) => <option key={option.value} value={option.value}>{option.text}</option>)}
{reportOptions
.map((option: any) =>
<option key={option.value} value={option.value}>
{option.text}
</option>
)}
</select>
</div>

Expand Down
Loading

0 comments on commit 6845cca

Please sign in to comment.