Skip to content

Commit

Permalink
Merge pull request #34 from bcgov/migration/filepath-name
Browse files Browse the repository at this point in the history
Update all uses of 'goRulesJSONFilename' to 'filepath'
  • Loading branch information
timwekkenbc committed Oct 7, 2024
2 parents 644a78b + d784065 commit 842b93c
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 62 deletions.
8 changes: 4 additions & 4 deletions app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function Admin() {
} else if (
initialRule._id !== rule._id ||
initialRule.title !== rule.title ||
initialRule.goRulesJSONFilename !== rule.goRulesJSONFilename
initialRule.filepath !== rule.filepath
) {
return { rule, action: ACTION_STATUS.UPDATE };
}
Expand Down Expand Up @@ -112,9 +112,9 @@ export default function Admin() {
width: "220px",
},
{
title: "GoRules JSON Filename",
dataIndex: "goRulesJSONFilename",
render: renderInputField("goRulesJSONFilename"),
title: "Filepath",
dataIndex: "filepath",
render: renderInputField("filepath"),
},
{
dataIndex: "delete",
Expand Down
2 changes: 1 addition & 1 deletion app/components/RuleHeader/RuleHeader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jest.mock("next/navigation", () => ({
}));

describe("RuleHeader - doneEditingTitle", () => {
const ruleInfoMock = { _id: "1", title: "Original Title", goRulesJSONFilename: "filename.json" };
const ruleInfoMock = { _id: "1", title: "Original Title", filepath: "filename.json" };

it("updates title on success", async () => {
api.updateRuleData.mockResolvedValue({}); // Mock success
Expand Down
8 changes: 4 additions & 4 deletions app/components/RuleHeader/RuleHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default function RuleHeader({
const inputRef = useRef<HTMLInputElement>(null);

useEffect(() => {
const { title, goRulesJSONFilename } = ruleInfo;
setSavedTitle(title || goRulesJSONFilename);
setCurrTitle(title || goRulesJSONFilename);
const { title, filepath } = ruleInfo;
setSavedTitle(title || filepath);
setCurrTitle(title || filepath);
}, [ruleInfo]);

useEffect(() => {
Expand Down Expand Up @@ -100,7 +100,7 @@ export default function RuleHeader({
currTitle
)}
</h1>
<p className={styles.titleFilePath}>{ruleInfo.goRulesJSONFilename}</p>
<p className={styles.titleFilePath}>{ruleInfo.filepath}</p>
</Flex>
{isEditingTitle && (
<button className={styles.editButton} onClick={isEditingTitle ? doneEditingTitle : startEditingTitle}>
Expand Down
2 changes: 1 addition & 1 deletion app/components/RuleManager/RuleManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function RuleManager({
editing = false,
showAllScenarioTabs = true,
}: RuleManagerProps) {
const { _id: ruleId, goRulesJSONFilename: jsonFile } = ruleInfo;
const { _id: ruleId, filepath: jsonFile } = ruleInfo;
const createRuleMap = (array: any[] = [], preExistingContext?: Record<string, any>) => {
return array.reduce(
(acc, obj) => {
Expand Down
22 changes: 11 additions & 11 deletions app/components/RuleViewerEditor/subcomponents/LinkRuleComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface LinkRuleComponent extends GraphNodeProps {
export default function LinkRuleComponent({ specification, id, isSelected, name, isEditable }: LinkRuleComponent) {
const { updateNode } = useDecisionGraphActions();
const node = useDecisionGraphState((state) => (state.decisionGraph?.nodes || []).find((n) => n.id === id));
const goRulesJSONFilename = node?.content?.key;
const filepath = node?.content?.key;

const [openRuleDrawer, setOpenRuleDrawer] = useState(false);
const [ruleOptions, setRuleOptions] = useState<DefaultOptionType[]>([]);
Expand All @@ -30,9 +30,9 @@ export default function LinkRuleComponent({ specification, id, isSelected, name,
const getRuleOptions = async () => {
const ruleData = await getAllRuleData();
setRuleOptions(
ruleData.map(({ title, goRulesJSONFilename }) => ({
label: title || goRulesJSONFilename,
value: goRulesJSONFilename,
ruleData.map(({ title, filepath }) => ({
label: title || filepath,
value: filepath,
}))
);
};
Expand All @@ -42,10 +42,10 @@ export default function LinkRuleComponent({ specification, id, isSelected, name,
}, [openRuleDrawer]);

useEffect(() => {
if (goRulesJSONFilename) {
updateRuleContent(goRulesJSONFilename);
if (filepath) {
updateRuleContent(filepath);
}
}, [goRulesJSONFilename]);
}, [filepath]);

const showRuleDrawer = () => {
setOpenRuleDrawer(true);
Expand All @@ -67,7 +67,7 @@ export default function LinkRuleComponent({ specification, id, isSelected, name,
return (
<GraphNode id={id} specification={specification} name={name} isSelected={isSelected}>
<Button onClick={showRuleDrawer}>
{goRulesJSONFilename ? getShortFilenameOnly(goRulesJSONFilename) : "Add rule"}
{filepath ? getShortFilenameOnly(filepath) : "Add rule"}
<EditOutlined />
</Button>
<Drawer title={name} onClose={closeRuleDrawer} open={openRuleDrawer} width="80%">
Expand All @@ -83,14 +83,14 @@ export default function LinkRuleComponent({ specification, id, isSelected, name,
}
options={ruleOptions}
onChange={onChangeSelection}
value={goRulesJSONFilename}
value={filepath}
className={styles.ruleSelect}
/>
<Button onClick={closeRuleDrawer}>Done</Button>
</Flex>
{goRulesJSONFilename && (
{filepath && (
<RuleManager
ruleInfo={{ _id: id, goRulesJSONFilename }}
ruleInfo={{ _id: id, filepath }}
initialRuleContent={selectedRuleContent}
editing={false}
showAllScenarioTabs={false}
Expand Down
2 changes: 1 addition & 1 deletion app/components/SavePublish/SavePublish.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface SavePublishProps {
}

export default function SavePublish({ ruleInfo, ruleContent, setHasSaved }: SavePublishProps) {
const { _id: ruleId, goRulesJSONFilename: filePath, reviewBranch } = ruleInfo;
const { _id: ruleId, filepath: filePath, reviewBranch } = ruleInfo;

const { message } = App.useApp();
const [openNewReviewModal, setOpenNewReviewModal] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function ScenarioGenerator({
const newScenario: Scenario = {
title: scenarioName,
ruleID: ruleId,
goRulesJSONFilename: jsonFile,
filepath: jsonFile,
variables,
expectedResults,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ export default function ScenarioResults({ scenarios, jsonFile, ruleContent }: Sc
return resultStatus;
};

const updateScenarioResults = async (goRulesJSONFilename: string) => {
const updateScenarioResults = async (filepath: string) => {
try {
const results = await runDecisionsForScenarios(goRulesJSONFilename, ruleContent);
const results = await runDecisionsForScenarios(filepath, ruleContent);
// Loop through object and check if data.result is an array
for (const key in results) {
if (Array.isArray(results[key].result)) {
Expand Down
8 changes: 4 additions & 4 deletions app/hooks/getRuleDataForVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export default async function getRuleDataForVersion(ruleId: string, version?: st
if (!ruleInfo.reviewBranch) {
throw new Error("No branch in review");
}
ruleContent = await getFileAsJsonIfAlreadyExists(ruleInfo.reviewBranch, ruleInfo.goRulesJSONFilename);
ruleContent = await getFileAsJsonIfAlreadyExists(ruleInfo.reviewBranch, ruleInfo.filepath);
break;
default:
ruleContent = await getDocument(ruleInfo.goRulesJSONFilename);
ruleContent = await getDocument(ruleInfo.filepath);
}
} catch (error) {
console.error("Error fetching rule content:", error);
Expand All @@ -37,8 +37,8 @@ export default async function getRuleDataForVersion(ruleId: string, version?: st
}

async function getPublishedRuleContentOrDefault(ruleInfo: RuleInfo) {
if (ruleInfo.goRulesJSONFilename) {
return await getDocument(ruleInfo.goRulesJSONFilename);
if (ruleInfo.filepath) {
return await getDocument(ruleInfo.filepath);
}
return DEFAULT_RULE_CONTENT;
}
4 changes: 2 additions & 2 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default function Home() {
getRules();
}, []);

const mappedRules = rules.map(({ _id, title, goRulesJSONFilename, reviewBranch, isPublished }) => {
const mappedRules = rules.map(({ _id, title, filepath, reviewBranch, isPublished }) => {
const ruleLink = `/rule/${_id}`;
const draftLink = `${ruleLink}?version=draft`;
return {
key: _id,
titleLink: (
<b>
<a href={isPublished ? ruleLink : draftLink} className={styles.mainLink}>
{title || goRulesJSONFilename}
{title || filepath}
</a>
</b>
),
Expand Down
2 changes: 1 addition & 1 deletion app/rule/[ruleId]/embedded/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function Rule({ params: { ruleId } }: { params: { ruleId: s
return <h1>Rule not found</h1>;
}
// Get scenario information
const scenarios: Scenario[] = await getScenariosByFilename(ruleInfo.goRulesJSONFilename);
const scenarios: Scenario[] = await getScenariosByFilename(ruleInfo.filepath);

return (
<RuleManager
Expand Down
4 changes: 2 additions & 2 deletions app/rule/[ruleId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import RuleManager from "@/app/components/RuleManager";
import { Scenario } from "@/app/types/scenario";
import getRuleDataForVersion from "@/app/hooks/getRuleDataForVersion";
import { RULE_VERSION } from "@/app/constants/ruleVersion";
import { GithubAuthProvider, GithubAuthContextType } from "@/app/components/GithubAuthProvider";
import { GithubAuthProvider } from "@/app/components/GithubAuthProvider";
import useGithubAuth from "@/app/hooks/useGithubAuth";

export let metadata: Metadata;
Expand Down Expand Up @@ -36,7 +36,7 @@ export default async function Rule({
metadata = { title: ruleInfo.title };

// Get scenario information
const scenarios: Scenario[] = await getScenariosByFilename(ruleInfo.goRulesJSONFilename);
const scenarios: Scenario[] = await getScenariosByFilename(ruleInfo.filepath);

return (
<GithubAuthProvider authInfo={githubAuthInfo}>
Expand Down
10 changes: 4 additions & 6 deletions app/rule/new/NewRule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default function NewRule() {
const [ruleInfo, setRuleInfo] = useState<RuleInfo>({
_id: "",
title: "New rule",
goRulesJSONFilename: "",
filepath: "",
});

useEffect(() => {
setOpenNewRuleModal(!ruleInfo.goRulesJSONFilename);
setOpenNewRuleModal(!ruleInfo.filepath);
}, [ruleInfo]);

const createNewRule = async (newRuleInfo: Partial<RuleInfo>) => {
Expand All @@ -43,7 +43,7 @@ export default function NewRule() {
</Form.Item>
<Form.Item
label="File path/name"
name="goRulesJSONFilename"
name="filepath"
tooltip="example: my-rule.json or my-path/my-rule.json"
rules={[
{
Expand Down Expand Up @@ -72,9 +72,7 @@ export default function NewRule() {
</Form>
</Modal>
<RuleHeader ruleInfo={ruleInfo} version={RULE_VERSION.draft} />
{ruleInfo.goRulesJSONFilename && (
<RuleManager ruleInfo={ruleInfo} initialRuleContent={DEFAULT_RULE_CONTENT} editing />
)}
{ruleInfo.filepath && <RuleManager ruleInfo={ruleInfo} initialRuleContent={DEFAULT_RULE_CONTENT} editing />}
</>
);
}
3 changes: 2 additions & 1 deletion app/types/ruleInfo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export interface RuleDraft {

export interface RuleInfoBasic {
_id: string;
name: string;
title?: string;
goRulesJSONFilename: string;
filepath: string;
}

export interface RuleInfo extends RuleInfoBasic {
Expand Down
2 changes: 1 addition & 1 deletion app/types/scenario.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface Scenario {
_id?: string; //optional for create scenario as generated id
title: string;
ruleID: string;
goRulesJSONFilename: string;
filepath: string;
variables: Variable[];
expectedResults: any[];
}
Expand Down
Loading

0 comments on commit 842b93c

Please sign in to comment.