Skip to content

Commit

Permalink
feat: switch diff fields to only show the latest committed, and what …
Browse files Browse the repository at this point in the history
…will change (no states in between)
  • Loading branch information
mikevespi committed May 10, 2024
1 parent 39ad9bb commit ae52688
Showing 1 changed file with 7 additions and 59 deletions.
66 changes: 7 additions & 59 deletions app/lib/theme/CustomDiffFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ const renderArrow = () => {
};

const renderDiffData = ({
oldData,
newData,
latestCommittedData,
id,
Expand All @@ -72,31 +71,10 @@ const renderDiffData = ({
contentSuffix,
}) => {
let components = [];
if (oldData !== null && oldData !== undefined) {
components.push(
<NumberFormatWrapper
value={oldData}
className={diffOldClsName}
id={`${id}-${diffOldClsName}`}
isMoney={isMoney}
isPercentage={isPercentage}
decimalScale={decimalScale}
/>
);
if (contentSuffix) {
components.push(
contentSuffixElement(`${id}-${diffOldClsName}`, contentSuffix)
);
}
if (newData !== null && newData !== undefined) {
components.push(renderArrow());
}
}

if (
latestCommittedData !== null &&
latestCommittedData !== undefined &&
latestCommittedData !== oldData &&
latestCommittedData !== newData
) {
components.push(
Expand All @@ -120,8 +98,8 @@ const renderDiffData = ({
if (
newData !== null &&
newData !== undefined &&
oldData !== null &&
oldData !== undefined
latestCommittedData !== null &&
latestCommittedData !== undefined
) {
components.push(
<NumberFormatWrapper
Expand Down Expand Up @@ -162,7 +140,6 @@ const renderDiffData = ({
};

const renderDiffString = ({
oldData,
newData,
latestCommittedData,
id,
Expand All @@ -172,31 +149,10 @@ const renderDiffString = ({
diffNewClsName,
}) => {
let components = [];
if (oldData !== null && oldData !== undefined) {
components.push(
<StringFormatWrapper
value={isDate ? getLocaleFormattedDate(oldData) : oldData}
className={diffOldClsName}
id={`${id}-${diffOldClsName}`}
/>
);
if (contentSuffix) {
components.push(
contentSuffixElement(`${id}-${diffOldClsName}`, contentSuffix)
);
}
if (
(newData !== null && newData !== undefined) ||
(latestCommittedData !== null && latestCommittedData !== undefined)
) {
components.push(renderArrow());
}
}

if (
latestCommittedData !== null &&
latestCommittedData !== undefined &&
latestCommittedData !== oldData &&
latestCommittedData !== newData
) {
components.push(
Expand All @@ -223,8 +179,8 @@ const renderDiffString = ({
if (
newData !== null &&
newData !== undefined &&
oldData !== null &&
oldData !== undefined
latestCommittedData !== null &&
latestCommittedData !== undefined
) {
components.push(
<StringFormatWrapper
Expand All @@ -238,7 +194,8 @@ const renderDiffString = ({
contentSuffixElement(`${id}-${diffOldClsName}`, contentSuffix)
);
}
} else if (newData !== null && newData !== undefined) {
}
else if (newData !== null && newData !== undefined) {
components.push(<span className={diffOldClsName}>Not Entered</span>);
components.push(renderArrow());
components.push(
Expand All @@ -261,13 +218,10 @@ const CUSTOM_DIFF_FIELDS = {
StringField: (props) => {
const { idSchema, formData, formContext, uiSchema } = props;
const id = idSchema?.$id;
const oldData = formContext?.oldData?.[props.name];
const latestCommittedData = formContext?.latestCommittedData?.[props.name];
const isDate = uiSchema["ui:widget"] === "DateWidget";
const contentSuffix = uiSchema?.["ui:options"]?.contentSuffix;

return renderDiffString({
oldData,
newData: formData,
latestCommittedData,
id,
Expand All @@ -280,7 +234,6 @@ const CUSTOM_DIFF_FIELDS = {
NumberField: (props) => {
const { idSchema, formData, formContext, uiSchema } = props;
const id = idSchema?.$id;
const oldData = formContext?.oldData?.[props.name];
const latestCommittedData = formContext?.latestCommittedData?.[props.name];
const isMoney = uiSchema?.isMoney;
const isPercentage = uiSchema?.isPercentage;
Expand All @@ -289,16 +242,13 @@ const CUSTOM_DIFF_FIELDS = {

// Handle text data mapping for certain number values
let textData = uiSchema?.["ui:options"]?.text as string;
let oldTextData =
formContext?.oldUiSchema?.[props.name]?.["ui:options"]?.text;
let latestCommittedTextData =
formContext?.latestCommittedUiSchema?.[props.name]?.["ui:options"]?.text;

if (formContext?.operation === "ARCHIVE") {
// Switch to string rendering for archive
textData = undefined;
return renderDiffString({
oldData: oldTextData,
newData: textData,
latestCommittedData: latestCommittedTextData,
id,
Expand All @@ -309,9 +259,8 @@ const CUSTOM_DIFF_FIELDS = {
});
}

if (oldTextData || textData || latestCommittedTextData) {
if (textData || latestCommittedTextData) {
return renderDiffString({
oldData: oldTextData,
newData: textData,
latestCommittedData: latestCommittedTextData,
id,
Expand All @@ -322,7 +271,6 @@ const CUSTOM_DIFF_FIELDS = {
});
} else {
return renderDiffData({
oldData,
newData: formData,
latestCommittedData,
id,
Expand Down

0 comments on commit ae52688

Please sign in to comment.