Skip to content

Commit

Permalink
Feature/cldn 1609 (#195)
Browse files Browse the repository at this point in the history
* Add row number option to CCCS-Grid (#181)

* Add row number option to CCCS-Grid

* Have row numbers show by default

Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>

Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>

* Use new build agent (#187)

* Use new build agent

* Remove quotes

* Display datahub link for datasets with defined URN (#177)

* Display datahub link for datasets with defined URN

* Add datahub SVG

* Reorder imports

* Add datahub link to dashboards

* Convert to camel case

* Add tests for DatasetList

* Add tests for dashboard header

* Provide explanation for empty catch

* [CLDN-1540] Added ability for multiple user emails to be filtered on at once

* [CLDN-1540] temp update to docker image tag so that we can deploy code changes to PB-stg

* [CLDN-1540] revert of temp update to docker image tag so that we can deploy code changes to PB-stg

* Add path to url (#193)

* [CLDN-1609] Fixing post merge build errors

* Update cccs-build/superset-base/azure-pipelines.yml

Co-authored-by: Reese <10563996+reesercollins@users.noreply.github.com>

* Update superset-frontend/src/cccs-viz/plugins/plugin-chart-at-a-glance-user-id/src/styles.js

Co-authored-by: Reese <10563996+reesercollins@users.noreply.github.com>

Co-authored-by: Reese <10563996+reesercollins@users.noreply.github.com>
Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
  • Loading branch information
3 people authored and GITHUB_USERNAME committed Feb 7, 2023
1 parent a576ebe commit ffff759
Show file tree
Hide file tree
Showing 19 changed files with 201 additions and 54 deletions.
7 changes: 3 additions & 4 deletions cccs-build/superset-base/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ variables:
buildTimestamp: $[format('{0:yyyyMMddHHmmss}', pipeline.startTime)]
DOCKER_BUILDKIT: 1

pool:
vmImage: ubuntu-latest
pool: cauldron-vmss

steps:
- bash: |
Expand All @@ -32,7 +31,7 @@ steps:
- task: Docker@2
displayName: Build image
inputs:
command: 'build'
command: build
repository: $(imageRepository)
arguments: --progress=plain
dockerfile: $(dockerfile)
Expand All @@ -42,7 +41,7 @@ steps:
- task: Docker@2
displayName: Push image
inputs:
command: 'push'
command: push
repository: $(imageRepository)
tags: |
$(BRANCH_NAME)
Expand Down
1 change: 1 addition & 0 deletions cccs-build/superset/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG VAULT_CA_CONTAINER=uchimera.azurecr.io/cccs/hogwarts/vault-ca:master_2921_22
FROM $VAULT_CA_CONTAINER AS vault_ca
FROM uchimera.azurecr.io/cccs/superset-base:cccs-2.0_20220808144709_b4476


USER root

COPY *requirements.txt /tmp/
Expand Down
3 changes: 1 addition & 2 deletions cccs-build/superset/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ variables:
buildTimestamp: $[format('{0:yyyyMMddHHmmss}', pipeline.startTime)]
DOCKER_BUILDKIT: 1

pool:
vmImage: ubuntu-latest
pool: cauldron-vmss

steps:
- bash: |
Expand Down
65 changes: 65 additions & 0 deletions superset-frontend/src/assets/images/icons/datahub.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,27 @@ const getPayloadField = (field: string, payload: any) => {
};

const formatList = (ipList: any) => {
const updatedList: { 'IP Address': string; Count: number }[] = [];
const updatedList: {
'IP Address': string;
Count: number;
'User Email': string;
}[] = [];
const ipDictionary = {};
let counter = 0;

ipList.forEach(function (obj: any) {
const key = JSON.stringify(obj.client_ip);
const key = `${JSON.stringify(obj.client_ip)},${JSON.stringify(
obj.user_id,
)}`;
ipDictionary[key] = (ipDictionary[key] || 0) + 1;
counter += 1;
});

Object.keys(ipDictionary).forEach(key => {
updatedList.push({
'IP Address': key.replaceAll('"', ''),
'IP Address': key.split(',')[0].replaceAll('"', ''),
Count: ipDictionary[key],
'User Email': key.split(',')[1].replaceAll('"', ''),
});
});

Expand All @@ -90,7 +97,6 @@ const ipToInt = (ip: any) =>

// Main Component
function AtAGlanceUserIDCore(props: AtAGlanceUserIDProps) {
const [userIDString, setUserIDString] = useState('');
LicenseManager.setLicenseKey(props.agGridLicenseKey);

const [columnDefs] = useState([
Expand Down Expand Up @@ -123,6 +129,13 @@ function AtAGlanceUserIDCore(props: AtAGlanceUserIDProps) {
sortable: true,
sort: 'desc',
},
{
field: 'User Email',
flex: 1,
resizable: true,
sortable: true,
minWidth: 275,
},
]);

const [canadianIpsListData, setCanadianIpsListData] = useState([{}]);
Expand All @@ -145,23 +158,6 @@ function AtAGlanceUserIDCore(props: AtAGlanceUserIDProps) {
const OPERATION = 'operation';
const USER_LOGGED_IN = 'UserLoggedIn';

if (typeof props.formData?.extraFormData?.filters !== 'undefined') {
for (
let i = 0;
i < props.formData?.extraFormData?.filters?.length;
i += 1
) {
const filter = props.formData.extraFormData.filters[i];
if (filter.col === 'user_id') {
const localUserId: string = filter.val[0];
setUserIDString(localUserId);
break;
}
}
} else {
setUserIDString('');
}

// eslint-disable-next-line react-hooks/exhaustive-deps
canadianIpsList = props.data.filter(function (item: any) {
return (
Expand Down Expand Up @@ -210,24 +206,7 @@ function AtAGlanceUserIDCore(props: AtAGlanceUserIDProps) {
<div>
<table style={styles.Table}>
<tr>
<td>
**Please note that the results in this chart are only for the
first User Email**
</td>
</tr>
<tr>
<td>*This chart only contains the first 100 results*</td>
</tr>
<tr>
<td>User Email: {userIDString}</td>
</tr>
<tr>
<td>
User ID:{' '}
{userIDString !== ''
? getPayloadField('user_key', props.data[0])
: ''}
</td>
<td>*This chart only contains the first 1000 results*</td>
</tr>
</table>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const AtAGlance = {
};

const Table = {
width: '500px',
width: '100%',
};

const AtAGlanceLists = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ config.controlPanelSections.push({
},
},
],
[
{
name: 'enable_row_numbers',
config: {
type: 'CheckboxControl',
label: t('Row numbers'),
renderTrigger: true,
default: true,
description: t('Whether to enable row numbers'),
},
},
],
[
{
name: 'page_length',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default function transformProps(chartProps: CccsGridChartProps) {
include_search,
enable_grouping,
column_state,
enable_row_numbers,
}: CccsGridQueryFormData = { ...DEFAULT_FORM_DATA, ...formData };
const data = queriesData[0].data as TimeseriesDataRecord[];
const agGridLicenseKey = queriesData[0].agGridLicenseKey as String;
Expand Down Expand Up @@ -167,7 +168,7 @@ export default function transformProps(chartProps: CccsGridChartProps) {
COUNTRY: 'countryValueRenderer',
JSON: 'jsonValueRenderer',
};

const percentMetricValueFormatter = function (params: ValueFormatterParams) {
return getNumberFormatter(NumberFormats.PERCENT_3_POINT).format(
params.value,
Expand Down Expand Up @@ -271,6 +272,16 @@ export default function transformProps(chartProps: CccsGridChartProps) {
}
}

if (enable_row_numbers) {
columnDefs.splice(0, 0, {
headerName: '#',
colId: 'rowNum',
pinned: 'left',
valueGetter: (params: any) =>
params.node ? params.node.rowIndex + 1 : null,
} as any);
}

return {
formData,
setDataMask,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type CccsGridQueryFormData = QueryFormData & {
page_length: number;
enable_grouping: boolean;
column_state: ColumnState[];
enable_row_numbers: boolean;
};

export interface CccsGridStylesProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('CccsGrid buildQuery', () => {
enable_grouping: false,
viz_type: 'my_chart',
column_state: [],
enable_row_numbers: false,
};

it('should build groupby with series in form data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('CccsGrid tranformProps', () => {
enable_grouping: false,
viz_type: 'my_chart',
column_state: [],
enable_row_numbers: false,
};
const chartProps = new CccsGridChartProps({
formData,
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/components/Icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const IconFileNames = [
'copy',
'cursor_target',
'database',
'datahub',
'dataset_physical',
'dataset_virtual_greyscale',
'dataset_virtual',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,9 @@ test('should refresh the charts', async () => {
userEvent.click(screen.getByText('Refresh dashboard'));
expect(mockedProps.onRefresh).toHaveBeenCalledTimes(1);
});

test('should show datahub link', async () => {
const mockedProps = createProps();
setup(mockedProps);
expect(screen.getByTestId('datahub_link')).toBeInTheDocument();
});
24 changes: 17 additions & 7 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { options as PeriodicRefreshOptions } from 'src/dashboard/components/Refr
import findPermission from 'src/dashboard/util/findPermission';
import { FILTER_BOX_MIGRATION_STATES } from 'src/explore/constants';
import { PageHeaderWithActions } from 'src/components/PageHeaderWithActions';
import { datahubUrl } from 'src/preamble';
import { DashboardEmbedModal } from '../DashboardEmbedControls';

const propTypes = {
Expand Down Expand Up @@ -510,13 +511,22 @@ class Header extends React.PureComponent {
showTooltip: true,
}}
titlePanelAdditionalItems={
<PublishedStatus
dashboardId={dashboardInfo.id}
isPublished={isPublished}
savePublished={this.props.savePublished}
canEdit={userCanEdit}
canSave={userCanSaveAs}
/>
<>
<PublishedStatus
dashboardId={dashboardInfo.id}
isPublished={isPublished}
savePublished={this.props.savePublished}
canEdit={userCanEdit}
canSave={userCanSaveAs}
/>
<a
href={`${datahubUrl}dashboard/urn:li:dashboard:(superset,${dashboardInfo.id})`}
style={{ paddingLeft: '0.5em' }}
data-test="datahub_link"
>
<Icons.Datahub viewBox="0 0 180 180" />
</a>
</>
}
rightPanelAdditionalItems={
<div className="button-container">
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/preamble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ const getMe = makeApi<void, User>({
endpoint: '/api/v1/me/',
});

export const datahubUrl = bootstrapData?.common?.datahub_url;

/**
* When you re-open the window, we check if you are still logged in.
* If your session expired or you signed out, we'll redirect to login.
Expand Down
Loading

0 comments on commit ffff759

Please sign in to comment.