Skip to content

Commit

Permalink
Merge branch '3.1.0' into CRDCDH-1760
Browse files Browse the repository at this point in the history
  • Loading branch information
amattu2 committed Oct 15, 2024
2 parents 22309c5 + 1d6c5d1 commit 3fae1a5
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ REACT_APP_UPLOADER_CLI_WINDOWS=""
REACT_APP_UPLOADER_CLI_MAC_X64=""
REACT_APP_UPLOADER_CLI_MAC_ARM=""

# Data Common Config
REACT_APP_HIDDEN_MODELS=""

# Optional - Frontend Build/Version
REACT_APP_FE_VERSION=""

Expand Down
1 change: 1 addition & 0 deletions conf/inject.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ window.injectedEnv = {
REACT_APP_UPLOADER_CLI_WINDOWS: "${REACT_APP_UPLOADER_CLI_WINDOWS}",
REACT_APP_UPLOADER_CLI_MAC_X64: "${REACT_APP_UPLOADER_CLI_MAC_X64}",
REACT_APP_UPLOADER_CLI_MAC_ARM: "${REACT_APP_UPLOADER_CLI_MAC_ARM}",
REACT_APP_HIDDEN_MODELS: "${HIDDEN_MODELS}",
};
1 change: 1 addition & 0 deletions public/js/injectEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ window.injectedEnv = {
REACT_APP_GA_TRACKING_ID: "",
REACT_APP_FE_VERSION: "",
REACT_APP_BACKEND_API: "",
REACT_APP_HIDDEN_MODELS: "",
};
9 changes: 8 additions & 1 deletion src/config/DataCommons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logo from "../assets/header/Logo.jpg";
import { getFilteredDataCommons } from "../utils/envUtils";

/**
* The URL of the Data Commons Model Repo
Expand All @@ -14,7 +15,7 @@ export const MODEL_FILE_REPO = "https://raw.githubusercontent.com/CBIIT/crdc-dat
/**
* A collection of site-wide supported Data Commons.
*/
export const DataCommons: DataCommon[] = [
const DataCommons: DataCommon[] = [
{
name: "CCDI",
assets: null,
Expand Down Expand Up @@ -436,3 +437,9 @@ export const DataCommons: DataCommon[] = [
},
},
];

// TODO: This is a TEMPORARY implementation to hide Data Commons from the UI
// for 3.1.0 only. This will be refactored in 3.2.0
const HiddenModels = getFilteredDataCommons();
const FilteredDataCommons = DataCommons.filter((dc) => !HiddenModels.includes(dc.name));
export { FilteredDataCommons as DataCommons };
17 changes: 4 additions & 13 deletions src/config/SubmitButtonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ export const SUBMIT_BUTTON_CONDITIONS: SubmitButtonCondition[] = [
preConditionCheck: (s) => s.intention === "Delete",
check: (s) => !!s.metadataValidationStatus,
tooltip: TOOLTIP_TEXT.SUBMISSION_ACTIONS.SUBMIT.DISABLED.NEW_DATA_OR_VALIDATION_ERRORS,
required: false,
required: true,
},
{
_identifier: "Metadata validation should be initialized for 'Metadata Only' submissions",
preConditionCheck: (s) => s.dataType === "Metadata Only",
check: (s) => !!s.metadataValidationStatus,
tooltip: TOOLTIP_TEXT.SUBMISSION_ACTIONS.SUBMIT.DISABLED.NEW_DATA_OR_VALIDATION_ERRORS,
required: false,
required: true,
},
{
_identifier:
"Data file validation should be initialized for 'Metadata and Data Files' submissions",
preConditionCheck: (s) => s.dataType === "Metadata and Data Files",
check: (s) => !!s.fileValidationStatus,
tooltip: TOOLTIP_TEXT.SUBMISSION_ACTIONS.SUBMIT.DISABLED.MISSING_DATA_FILE,
required: false,
required: true,
},
{
_identifier:
"Metadata validation should be initialized for 'Metadata and Data Files' submissions",
preConditionCheck: (s) => s.dataType === "Metadata and Data Files",
check: (s) => !!s.metadataValidationStatus,
tooltip: TOOLTIP_TEXT.SUBMISSION_ACTIONS.SUBMIT.DISABLED.NEW_DATA_OR_VALIDATION_ERRORS,
required: false,
required: true,
},
{
_identifier: "There should be no validation errors for metadata or data files",
Expand All @@ -104,13 +104,4 @@ export const ADMIN_OVERRIDE_CONDITIONS: AdminOverrideCondition[] = [
check: (s) => s.metadataValidationStatus === "Error" || s.fileValidationStatus === "Error",
tooltip: undefined,
},
{
_identifier:
"Admin Override - Submission is missing either metadata or data files for 'Metadata and Data Files' submissions",
check: (s) =>
(!!s.metadataValidationStatus && !s.fileValidationStatus) ||
(!s.metadataValidationStatus && !!s.fileValidationStatus),
preConditionCheck: (s) => s.dataType === "Metadata and Data Files",
tooltip: undefined,
},
];
7 changes: 7 additions & 0 deletions src/types/AppEnv.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ type AppEnv = {
* @example "mvp-2.213"
*/
REACT_APP_FE_VERSION: string;
/**
* A CSV string of Data Commons to hide from the UI
*
* @note Can be a string of 0 or more Data Commons
* @since 3.1.0
*/
REACT_APP_HIDDEN_MODELS: string;
/**
* The deployment environment the app is running in
*/
Expand Down
16 changes: 8 additions & 8 deletions src/utils/dataSubmissionUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,15 @@ describe("Admin Submit", () => {
expect(result.isAdminOverride).toBe(false);
});

it("should allow admin override when metadata is passed but file validation is null", () => {
it("should not allow admin override when metadata is passed but file validation is null", () => {
const submission: Submission = {
...baseSubmission,
metadataValidationStatus: "Passed",
fileValidationStatus: null,
};
const result = utils.shouldEnableSubmit(submission, "Admin");
expect(result.enabled).toBe(true);
expect(result.isAdminOverride).toBe(true);
expect(result.enabled).toBe(false);
expect(result.isAdminOverride).toBe(false);
});

it("should not enable submit when both validations are null", () => {
Expand All @@ -373,6 +373,7 @@ describe("Admin Submit", () => {
it("should allow admin override when file validation is null and intention is 'Delete'", () => {
const submission: Submission = {
...baseSubmission,
dataType: "Metadata Only",
metadataValidationStatus: "Error",
fileValidationStatus: null,
intention: "Delete",
Expand Down Expand Up @@ -437,6 +438,7 @@ describe("Admin Submit", () => {
it("should allow submit with isAdminOverride when metadata validation is 'Error', file validation is null, and intention is 'Delete'", () => {
const submission: Submission = {
...baseSubmission,
dataType: "Metadata Only",
metadataValidationStatus: "Error",
fileValidationStatus: null,
intention: "Delete",
Expand Down Expand Up @@ -514,14 +516,12 @@ describe("shouldAllowAdminOverride", () => {
it("should check condition if preConditionCheck is met", () => {
const submission: Submission = {
...baseSubmission,
dataType: "Metadata and Data Files",
metadataValidationStatus: "Passed",
dataType: "Metadata Only",
metadataValidationStatus: "Error",
fileValidationStatus: null,
};
const result = utils.shouldAllowAdminOverride(submission);
expect(result._identifier).toBe(
"Admin Override - Submission is missing either metadata or data files for 'Metadata and Data Files' submissions"
);
expect(result._identifier).toBe("Admin Override - Submission has validation errors");
expect(result.enabled).toBe(true);
expect(result.isAdminOverride).toBe(true);
});
Expand Down
64 changes: 64 additions & 0 deletions src/utils/envUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,67 @@ describe("buildReleaseNotesUrl cases", () => {
);
});
});

describe("getFilteredDataCommons cases", () => {
const originalEnv = process.env;

beforeEach(() => {
jest.resetModules();

// Reset the environment variables back to their original values
process.env = { ...originalEnv };
});

afterAll(() => {
jest.restoreAllMocks();
});

it("should return an empty array when REACT_APP_HIDDEN_MODELS is not set", async () => {
delete process.env.REACT_APP_HIDDEN_MODELS;

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual([]);
});

it("should return an empty array when REACT_APP_HIDDEN_MODELS is not a string", async () => {
process.env.REACT_APP_HIDDEN_MODELS = 0 as unknown as string; // NOTE: Officially only be strings

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual([]);
});

it("should return an empty array when REACT_APP_HIDDEN_MODELS is an empty string", async () => {
process.env.REACT_APP_HIDDEN_MODELS = "";

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual([]);
});

it("should return an empty array when REACT_APP_HIDDEN_MODELS is an CSV of nothing", async () => {
process.env.REACT_APP_HIDDEN_MODELS = ",,,";

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual([]);
});

it("should return an array of hidden Data Commons when REACT_APP_HIDDEN_MODELS is set", async () => {
process.env.REACT_APP_HIDDEN_MODELS = "dc1,dc2,dc3";

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual(["dc1", "dc2", "dc3"]);
});

it("should return an array of 1 when REACT_APP_HIDDEN_MODELS is set to a single Data Commons", async () => {
process.env.REACT_APP_HIDDEN_MODELS = "dc1";

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual(["dc1"]);
});

it("should filter out empty Data Commons from the list", async () => {
process.env.REACT_APP_HIDDEN_MODELS = "dc1,,dc3";

const { getFilteredDataCommons } = await import("./envUtils");
expect(getFilteredDataCommons()).toEqual(["dc1", "dc3"]);
});
});
25 changes: 25 additions & 0 deletions src/utils/envUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ export const buildReleaseNotesUrl = (): string => {

return "https://raw.githubusercontent.com/CBIIT/crdc-datahub-ui/refs/heads/main/CHANGELOG.md";
};

/**
* A utility to safely get the hidden Data Commons from the environment variable.
* If it is not set, return an empty array.
*
* @returns An array of hidden Data Commons or an empty array if not set.
*/
export const getFilteredDataCommons = (): string[] => {
const { REACT_APP_HIDDEN_MODELS } = env || {};

if (!REACT_APP_HIDDEN_MODELS || typeof REACT_APP_HIDDEN_MODELS !== "string") {
Logger.error("getFilteredDataCommons: REACT_APP_HIDDEN_MODELS is not set or is not a string");
return [];
}

const mapped = REACT_APP_HIDDEN_MODELS.split(",")
.map((dc) => dc?.trim())
.filter((dc) => dc?.length);

if (!mapped?.length) {
return [];
}

return mapped;
};

0 comments on commit 3fae1a5

Please sign in to comment.