Skip to content

Commit

Permalink
Merge pull request #998 from jetstreamapp/feat/display-table-ids-as-l…
Browse files Browse the repository at this point in the history
…inks

Display ids in query results tables as links
  • Loading branch information
paustint authored Aug 10, 2024
2 parents a0c1b8a + 2b54ab4 commit 78a4f53
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 305 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { formatNumber } from '@jetstream/shared/ui-utils';
import { REGEX, groupByFlat } from '@jetstream/shared/utils';
import { DescribeGlobalSObjectResult, InsertUpdateUpsertDelete, Maybe, SalesforceOrgUi } from '@jetstream/types';
import { Alert, AutoFullHeightContainer, DataTable, Grid, GridCol, RowWithKey, Spinner, getColumnsForGenericTable } from '@jetstream/ui';
import { ErrorBoundaryFallback, fromLoadRecordsState } from '@jetstream/ui-core';
import { ErrorBoundaryFallback, applicationCookieState, fromLoadRecordsState, selectSkipFrontdoorAuth } from '@jetstream/ui-core';
import isNil from 'lodash/isNil';
import { FunctionComponent, useEffect, useRef, useState } from 'react';
import { Column } from 'react-data-grid';
import { ErrorBoundary } from 'react-error-boundary';
import { useRecoilState } from 'recoil';
import { useRecoilState, useRecoilValue } from 'recoil';

const MAX_RECORD_FOR_PREVIEW = 100_000;
const MAX_COLUMNS_TO_KEEP_SET_FILTER = 2000;
Expand Down Expand Up @@ -81,6 +81,8 @@ export const LoadRecordsDataPreview: FunctionComponent<LoadRecordsDataPreviewPro
loadType,
}) => {
const isMounted = useRef(true);
const { serverUrl } = useRecoilValue(applicationCookieState);
const skipFrontdoorLogin = useRecoilValue(selectSkipFrontdoorAuth);
const [totalRecordCount, setTotalRecordCount] = useRecoilState(fromLoadRecordsState.loadExistingRecordCount);
const [omitTotalRecordCount, setOmitTotalRecordCount] = useState(true);
const [columns, setColumns] = useState<Maybe<Column<RowWithKey>[]>>(null);
Expand Down Expand Up @@ -191,7 +193,14 @@ export const LoadRecordsDataPreview: FunctionComponent<LoadRecordsDataPreviewPro
<p className="slds-text-heading_small">File Preview</p>
<ErrorBoundary FallbackComponent={ErrorBoundaryFallback}>
<AutoFullHeightContainer fillHeight setHeightAttr bottomBuffer={25}>
<DataTable columns={columns} data={rows} getRowKey={getRowId} />
<DataTable
org={selectedOrg}
serverUrl={serverUrl}
skipFrontdoorLogin={skipFrontdoorLogin}
columns={columns}
data={rows}
getRowKey={getRowId}
/>
</AutoFullHeightContainer>
</ErrorBoundary>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export const LoadRecordsBatchApiResults: FunctionComponent<LoadRecordsBatchApiRe
)}
{resultsModalData.open && (
<LoadRecordsResultsModal
org={selectedOrg}
type={resultsModalData.type}
header={resultsModalData.header}
rows={resultsModalData.data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export const LoadRecordsBulkApiResults: FunctionComponent<LoadRecordsBulkApiResu
)}
{resultsModalData.open && (
<LoadRecordsResultsModal
org={selectedOrg}
type={resultsModalData.type}
header={resultsModalData.header}
rows={resultsModalData.data}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const PerformLoadCustomMetadata: FunctionComponent<PerformLoadCustomMetad
)}
{resultsModalData.open && (
<LoadRecordsResultsModal
org={selectedOrg}
type={resultsModalData.type}
header={resultsModalData.header}
rows={resultsModalData.data}
Expand Down
14 changes: 12 additions & 2 deletions libs/shared/ui-core/src/load/LoadRecordsResultsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { css } from '@emotion/react';
import { useNonInitialEffect } from '@jetstream/shared/ui-utils';
import { SalesforceOrgUi } from '@jetstream/types';
import {
AutoFullHeightContainer,
ColumnWithFilter,
Expand All @@ -12,6 +13,8 @@ import {
Spinner,
} from '@jetstream/ui';
import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react';
import { useRecoilValue } from 'recoil';
import { applicationCookieState, selectSkipFrontdoorAuth } from '../state-management/app-state';

const COL_WIDTH_MAP = {
_id: 195,
Expand All @@ -22,6 +25,7 @@ const COL_WIDTH_MAP = {
const getRowHeight = (row: any) => (row?._errors ? 75 : 25);

export interface LoadRecordsResultsModalProps {
org: SalesforceOrgUi;
type: 'results' | 'failures';
loading?: boolean;
header: string[];
Expand All @@ -35,9 +39,12 @@ export const LoadRecordsResultsModal: FunctionComponent<LoadRecordsResultsModalP
loading = false,
header,
rows,
org,
onDownload,
onClose,
}) => {
const { serverUrl, defaultApiVersion } = useRecoilValue(applicationCookieState);
const skipFrontdoorLogin = useRecoilValue(selectSkipFrontdoorAuth);
const modalRef = useRef();
const [columns, setColumns] = useState<ColumnWithFilter<any>[] | null>(null);
// Store each row as key and the index as a value to use as a unique id for the row
Expand All @@ -47,7 +54,7 @@ export const LoadRecordsResultsModal: FunctionComponent<LoadRecordsResultsModalP
if (header) {
setColumns(
header.map((item) => {
const baseColumn = setColumnFromType(item, getRowTypeFromValue(rows?.[0]?.[item], false));
const baseColumn = setColumnFromType(item, item === '_id' ? 'salesforceId' : getRowTypeFromValue(rows?.[0]?.[item], false));
return {
...baseColumn,
name: item,
Expand Down Expand Up @@ -118,11 +125,14 @@ export const LoadRecordsResultsModal: FunctionComponent<LoadRecordsResultsModalP
{loading && <Spinner />}
{Array.isArray(rows) && Array.isArray(columns) && (
<DataTable
org={org}
serverUrl={serverUrl}
skipFrontdoorLogin={skipFrontdoorLogin}
columns={columns}
data={rows}
getRowKey={getRowKey}
rowHeight={getRowHeight}
context={{ portalRefForFilters: modalRef }}
context={{ defaultApiVersion, portalRefForFilters: modalRef }}
/>
)}
</AutoFullHeightContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ export const MassUpdateRecordsDeploymentRow: FunctionComponent<MassUpdateRecords
)}
{resultsModalData.open && (
<LoadRecordsResultsModal
org={selectedOrg}
type={resultsModalData.type}
header={resultsModalData.header}
rows={resultsModalData.data}
Expand Down
10 changes: 7 additions & 3 deletions libs/shared/ui-utils/src/lib/shared-ui-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1462,15 +1462,19 @@ export function useReducerFetchFn<T>() {
return reducer;
}

const is15or18Digits = /[a-z0-9]{15}|[a-z0-9]{18}/i;
const is18Digits = /[a-z0-9]{18}/i;

/**
* Validate if a string is a valid salesforce id
* https://gist.github.com/step307/3d265b7c7cb4eccdf0cf55a68c9cfefa
*/
export function isValidSalesforceRecordId(recordId?: string) {
if (!recordId || !/[a-z0-9]{15}|[a-z0-9]{18}/i.test(recordId)) {
export function isValidSalesforceRecordId(recordId?: string, allow15Char = true): boolean {
const regex = allow15Char ? is15or18Digits : is18Digits;
if (!recordId || !regex.test(recordId)) {
return false;
}
if (recordId.length === 15) {
if (recordId.length === 15 && allow15Char) {
// no way to completely validate this
return true;
}
Expand Down
1 change: 0 additions & 1 deletion libs/shared/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './lib/convert-quill-delta';
export * from './lib/regex';
export * from './lib/utils';
Loading

0 comments on commit 78a4f53

Please sign in to comment.