Skip to content

Commit dea3247

Browse files
authored
refactoring: consolidate componentspec yaml parse load utils (#1466)
## Description Moved YAML-related utility functions from `componentStore.ts` to `yaml.ts` to better organize code by functionality. Specifically, relocated `componentSpecToYaml` and `componentSpecToText` functions to the appropriate YAML utilities file and updated all imports across the codebase. ## Type of Change - [x] Cleanup/Refactor ## Checklist - [x] I have tested this does not break current pipelines / runs functionality - [ ] I have tested the changes on staging ## Test Instructions 1. No functional changes to the app 2. No regression should be found across the app
1 parent 40c05c1 commit dea3247

File tree

12 files changed

+29
-26
lines changed

12 files changed

+29
-26
lines changed

src/components/shared/ComponentEditor/utils/preserveComponentName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import yaml from "js-yaml";
22

33
import type { ComponentSpec } from "@/utils/componentSpec";
44
import { isValidComponentSpec } from "@/utils/componentSpec";
5-
import { componentSpecToYaml } from "@/utils/componentStore";
5+
import { componentSpecToYaml } from "@/utils/yaml";
66

77
export const preserveComponentName = (
88
yamlText: string,

src/components/shared/ReactFlow/FlowSidebar/sections/FileActions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { useAutoSaveStatus } from "@/providers/AutoSaveProvider";
2121
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
2222
import { EDITOR_PATH } from "@/routes/router";
2323
import { getPipelineFile, useSavePipeline } from "@/services/pipelineService";
24-
import { componentSpecToYaml } from "@/utils/componentStore";
2524
import { formatRelativeTime } from "@/utils/date";
25+
import { componentSpecToYaml } from "@/utils/yaml";
2626

2727
const FileActions = ({ isOpen }: { isOpen: boolean }) => {
2828
const { componentSpec } = useComponentSpec();

src/components/shared/TaskDetails/Implementation.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useMemo } from "react";
22

33
import { CodeViewer } from "@/components/shared/CodeViewer";
44
import type { ComponentSpec } from "@/utils/componentSpec";
5-
import { componentSpecToText } from "@/utils/componentStore";
5+
import { componentSpecToText } from "@/utils/yaml";
66

77
interface TaskImplementationProps {
88
displayName: string;

src/providers/ComponentLibraryProvider/componentLibrary.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from "@/utils/componentSpec";
1414
import * as componentStore from "@/utils/componentStore";
1515
import * as localforage from "@/utils/localforage";
16+
import * as yamlUtils from "@/utils/yaml";
1617

1718
import {
1819
fetchFavoriteComponents,
@@ -35,6 +36,7 @@ const mockLocalforage = vi.mocked(localforage);
3536
describe("componentLibrary", () => {
3637
beforeEach(() => {
3738
vi.clearAllMocks();
39+
vi.spyOn(yamlUtils, "componentSpecToYaml").mockReturnValue("spec-as-yaml");
3840
});
3941

4042
afterEach(() => {
@@ -373,7 +375,9 @@ describe("componentLibrary", () => {
373375
};
374376

375377
// Mock componentSpecToYaml to return predictable text
376-
mockComponentStore.componentSpecToYaml.mockReturnValue("spec-as-yaml");
378+
vi.spyOn(yamlUtils, "componentSpecToYaml").mockReturnValue(
379+
"spec-as-yaml",
380+
);
377381

378382
// Act
379383
const result = await populateComponentRefs(folder);
@@ -388,7 +392,7 @@ describe("componentLibrary", () => {
388392
},
389393
text: "spec-as-yaml",
390394
});
391-
expect(mockComponentStore.componentSpecToYaml).toHaveBeenCalledWith(
395+
expect(yamlUtils.componentSpecToYaml).toHaveBeenCalledWith(
392396
componentRef.spec,
393397
);
394398
expect(mockComponentStore.generateDigest).toHaveBeenCalledWith(

src/providers/ComponentLibraryProvider/componentLibrary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import type {
99
TaskSpec,
1010
} from "@/utils/componentSpec";
1111
import {
12-
componentSpecToYaml,
1312
generateDigest,
1413
getAllComponentFilesFromList,
1514
} from "@/utils/componentStore";
1615
import { USER_COMPONENTS_LIST_NAME } from "@/utils/constants";
1716
import { getComponentByUrl } from "@/utils/localforage";
17+
import { componentSpecToYaml } from "@/utils/yaml";
1818

1919
export const fetchUserComponents = async (): Promise<ComponentFolder> => {
2020
try {

src/providers/ComponentSpecProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
type ComponentValidationIssue,
2323
type ValidationError,
2424
} from "@/utils/validations";
25+
import { componentSpecToYaml } from "@/utils/yaml";
2526

2627
import {
2728
createRequiredContext,
@@ -34,7 +35,6 @@ import {
3435
} from "../utils/componentSpec";
3536
import {
3637
type ComponentReferenceWithSpec,
37-
componentSpecToYaml,
3838
generateDigest,
3939
writeComponentToFileListFromText,
4040
} from "../utils/componentStore";

src/services/componentService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
type TaskSpec,
2626
type UnknownComponentReference,
2727
} from "@/utils/componentSpec";
28-
import { componentSpecToYaml, generateDigest } from "@/utils/componentStore";
28+
import { generateDigest } from "@/utils/componentStore";
2929
import {
3030
componentExistsByUrl,
3131
getAllUserComponents,
@@ -34,6 +34,7 @@ import {
3434
saveComponent,
3535
type UserComponent,
3636
} from "@/utils/localforage";
37+
import { componentSpecToYaml } from "@/utils/yaml";
3738
import { componentSpecFromYaml } from "@/utils/yaml";
3839

3940
export interface ExistingAndNewComponent {

src/services/pipelineRunService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
isGraphImplementation,
1010
} from "@/utils/componentSpec";
1111
import {
12-
componentSpecToYaml,
1312
getComponentFileFromList,
1413
writeComponentToFileListFromText,
1514
} from "@/utils/componentStore";
@@ -19,6 +18,7 @@ import {
1918
USER_PIPELINES_LIST_NAME,
2019
} from "@/utils/constants";
2120
import { fetchWithErrorHandling } from "@/utils/fetchWithErrorHandling";
21+
import { componentSpecToYaml } from "@/utils/yaml";
2222

2323
export const createPipelineRun = async (
2424
payload: BodyCreateApiPipelineRunsPost,

src/services/pipelineService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import {
99
} from "@/utils/componentSpec";
1010
import {
1111
type ComponentFileEntry,
12-
componentSpecToYaml,
1312
deleteComponentFileFromList,
1413
fullyLoadComponentRefFromUrl,
1514
getAllComponentFilesFromList,
1615
getComponentFileFromList,
1716
writeComponentToFileListFromText,
1817
} from "@/utils/componentStore";
1918
import { USER_PIPELINES_LIST_NAME } from "@/utils/constants";
19+
import { componentSpecToYaml } from "@/utils/yaml";
2020
import { componentSpecFromYaml } from "@/utils/yaml";
2121

2222
export const deletePipeline = async (name: string, onDelete?: () => void) => {

src/utils/URL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { RUNS_BASE_PATH } from "@/routes/router";
22

33
import type { ComponentSpec } from "./componentSpec";
4-
import { componentSpecToText } from "./componentStore";
4+
import { componentSpecToText } from "./yaml";
55

66
const convertGcsUrlToBrowserUrl = (
77
url: string,

0 commit comments

Comments
 (0)