Skip to content

Refactor Frontend to Centralize Downloads Using DownloadService - #2920

Merged
kunwp1 merged 6 commits into
masterfrom
chris-download-service
Oct 11, 2024
Merged

kunwp1 merged 6 commits into
masterfrom
chris-download-service

Conversation

@kunwp1

@kunwp1 kunwp1 commented Oct 11, 2024

Copy link
Copy Markdown
Contributor

This PR refactors the frontend codebase to replace the use of FileSaverService with DownloadService for all download operations. The main objective of this refactor is to centralize and streamline the downloading process across the platform, ensuring consistency and maintainability.

Key changes include:

  • Replacing local download logic with the unified DownloadService.
  • Refactoring both the workflow result download and the multi-select workflow downloads to utilize the new service.

This update simplifies future enhancements and bug fixes by consolidating all download-related functionality into one service.

@kunwp1 kunwp1 added refactor Refactor the code frontend Changes related to the frontend GUI labels Oct 11, 2024
@kunwp1
kunwp1 requested a review from bobbai00 October 11, 2024 03:46
@kunwp1 kunwp1 self-assigned this Oct 11, 2024

@bobbai00 bobbai00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left two minors. Looks good!

@kunwp1
kunwp1 merged commit 5798437 into master Oct 11, 2024
@kunwp1
kunwp1 deleted the chris-download-service branch October 11, 2024 16:45
PurelyBlank pushed a commit that referenced this pull request Dec 4, 2024
This PR refactors the frontend codebase to replace the use of
`FileSaverService` with `DownloadService` for all download operations.
The main objective of this refactor is to centralize and streamline the
downloading process across the platform, ensuring consistency and
maintainability.

Key changes include:
- Replacing local download logic with the unified `DownloadService`.
- Refactoring both the workflow result download and the multi-select
workflow downloads to utilize the new service.

This update simplifies future enhancements and bug fixes by
consolidating all download-related functionality into one service.

---------

Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
SarahAsad23 pushed a commit to madisonmlin/texera that referenced this pull request May 20, 2026
…he#2920)

This PR refactors the frontend codebase to replace the use of
`FileSaverService` with `DownloadService` for all download operations.
The main objective of this refactor is to centralize and streamline the
downloading process across the platform, ensuring consistency and
maintainability.

Key changes include:
- Replacing local download logic with the unified `DownloadService`.
- Refactoring both the workflow result download and the multi-select
workflow downloads to utilize the new service.

This update simplifies future enhancements and bug fixes by
consolidating all download-related functionality into one service.

---------

Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
…he#2920)

This PR refactors the frontend codebase to replace the use of
`FileSaverService` with `DownloadService` for all download operations.
The main objective of this refactor is to centralize and streamline the
downloading process across the platform, ensuring consistency and
maintainability.

Key changes include:
- Replacing local download logic with the unified `DownloadService`.
- Refactoring both the workflow result download and the multi-select
workflow downloads to utilize the new service.

This update simplifies future enhancements and bug fixes by
consolidating all download-related functionality into one service.

---------

Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
Co-authored-by: Kunwoo Park <[email protected]>
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Aug 13, 2026
…one individually (apache#7611)

### What changes were proposed in this PR?

Selecting several workflows and using the toolbar's "Download added
workflow as a ZIP file" action saved one loose `.json` file per selected
workflow **in addition to** the archive, so N selected workflows
produced N+1 downloads.

Root cause is in
`frontend/src/app/dashboard/service/user/download/download.service.ts`.
`downloadWorkflow(id, name)` both retrieves a workflow and saves it to
disk — the save is the `tap(this.saveFile.bind(this))` at the end of the
pipe — which is exactly what the per-row download action needs.
`createWorkflowsZip` reused that same method purely to obtain each blob,
so the save fired for every entry before the blob was added to the
archive.

This is a regression rather than intended behaviour: before apache#2920
(`57984370c`, "Refactor Frontend to Centralize Downloads Using
DownloadService") the bulk path assembled the zip inline and called
`saveAs` exactly once. That refactor moved the logic into
`DownloadService` and reused `downloadWorkflow` for retrieval,
inheriting its save side effect.

The fix splits retrieval from saving:

- new private `retrieveWorkflowItem(id, name)` returns the
`DownloadableItem` (blob + file name) **without** saving — it is the
former body of `downloadWorkflow` minus the `tap`;
- `downloadWorkflow` is now
`retrieveWorkflowItem(...).pipe(tap(this.saveFile.bind(this)))`, i.e.
behaviour is unchanged for the three per-row callers
(`user-workflow-list-item.component.ts`, `list-item.component.ts`,
`card-item.component.ts`), which subscribe without a value handler and
rely solely on that side effect;
- `createWorkflowsZip` calls `retrieveWorkflowItem` directly.

`A.pipe(map, tap)` and `A.pipe(map).pipe(tap)` compose the same chain,
so the emitted value, timing, subscription semantics and error
propagation of `downloadWorkflow` are unchanged. The public API is
untouched and no call site needed updating.

**Before** — three workflows selected, then "Download as ZIP": the
archive plus `test1.json`, `test2.json`, `test3.json`, four files in
total.

<img width="1493" height="755" alt="Screenshot 2026-08-12 at 3 48 45 PM"
src="https://github.com/user-attachments/assets/7a7b8cb0-330a-452f-b853-b7aabfc04acd"
/>

**After** — same three workflows, same action: only
`workflowExports-*.zip`.

<img width="1482" height="750" alt="Screenshot 2026-08-12 at 4 43 38 PM"
src="https://github.com/user-attachments/assets/bdc64245-91bc-4fa0-a06d-2b80e2871706"
/>

### Any related issues, documentation, discussions?

Closes apache#7608

### How was this PR tested?

Seven cases were added to
`frontend/src/app/dashboard/service/user/download/download.service.spec.ts`
(23 → 30). Three of them fail on `main` and pass with this change.

Pinning the fix:

- `saves only the zip, not one JSON per workflow, when several workflows
are zipped` — three workflows, asserts `saveAs` is called exactly once
with the archive, and that no `Alpha.json` / `Beta.json` / `Gamma.json`
was saved
- `saves only the zip for a single-workflow selection` — the N=1
boundary, which a plain "one extra file" check would miss

Guarding the other direction, so the bug cannot be "fixed" by deleting
the save:

- `still saves the file when a single workflow is downloaded on its own`
— passes before and after; it fails if `downloadWorkflow` stops saving,
which would break the per-row download action

Edge cases:

- `saves nothing when one of the workflows fails to retrieve` — the
archive aborts as a whole, so the workflows that did come back must not
be left behind as loose files (previously they were already saved by the
time `forkJoin` errored)
- `writes the workflow content into the zip entries` — reads an entry
back out of the produced archive and parses it, since the pre-existing
tests only asserted entry *names*
- `does not save anything when the standalone workflow download fails` —
error propagates, nothing is written; mirrors the existing dataset /
single-file error cases
- `saves nothing for an empty selection` — `forkJoin([])` completes
without emitting, so nothing is retrieved and no empty archive is
written (the toolbar already guards this case)

```
cd frontend
node --max-old-space-size=8192 ./node_modules/@angular/cli/bin/ng test --watch=false \
  --include="src/app/dashboard/service/user/download/download.service.spec.ts"
```

`Test Files 1 passed (1)` / `Tests 30 passed (30)`. Reverting only the
source change makes exactly three of them fail.

The specs of the three components that depend on `downloadWorkflow`
still saving were also run and pass unchanged (`list-item`, `card-item`,
`user-workflow-list-item`).

Manually verified against a local stack, as shown in the screenshots
above: create three workflows, select them, click the ZIP download
action, and compare the browser's download list before and after the
change.

### Was this PR authored or co-authored using generative AI tooling?

Co-authored by: Claude Code (Claude Opus 5)
renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 26, 2026
### What changes were proposed in this PR?

Remove code that nothing uses from the workflow persistence service, the
dashboard's workflow list, the canvas graph wrapper, a context-menu spec
and the Parca deployment files (**+48/−274 lines**). There is no
behavior change.

- **Workflow search clients:** `WorkflowPersistService.searchWorkflows`
and `retrieveWorkflowsBySessionUser` have no caller. apache#1988 removed the
last call to the first, and apache#7463 removed the project feature that
called the second. Their private response formatter, the unused
`WORKFLOW_LIST_URL`, `WORKFLOW_SEARCH_URL` and `WORKFLOW_USER_ACCESS`
constants, and the test stub's `searchWorkflows` forwarder go with them,
along with their spec cases.
- **Dashboard workflow list:** `UserWorkflowComponent` loses five dead
pieces.
- A private `nameWorkflow` copy that nothing has called since apache#2920
moved ZIP downloads into `DownloadService`, which keeps its own.
  - An unused `ExecutionMode` import.
  - An empty `next` handler around a commented-out call.
  - An unread error argument.
- A class comment whose steps name functions the component no longer
has, such as `searchWorkflows()`, `synchronousSearch()` and
`asyncSearch()`.
- **Graph wrapper:** `JointGraphWrapper` loses four unused pieces.
- The event-tuple detail, unused since apache#2301 removed the drag stream
typed with it.
  - Exports nothing imports, which become file-local.
  - A static `_async` helper that only returned `context.async`.
- A coeditor argument that `removeCurrentEditing` and
`removePropertyChanged` never read; `CoeditorPresenceService` stops
passing it.
- **Context-menu spec:** `ReactiveFormsModule`, `NzDropDownModule` and
`NzModalModule` in its two test beds are not needed. `NzModalService`
stays.
- **Parca:** `parca-agent.env` sets `PARCA_AGENT_*` variables that the
pinned agent never reads; the Compose command already passes every value
as a flag. The env file and its `env_file` entry go. The Compose
comments, README, `ParcaConfigSpec` and the release-tarball test now
point at the command's values.

| Event | PR / Commit |
| --- | --- |
| Introduced by | Workflow search clients: apache#1885 (2023-04-20);
`nameWorkflow`: apache#1629 (2022-08-17); graph wrapper: the coeditor argument
apache#1676 (2022-10-06), the context helper apache#1433 (2022-02-07); context-menu
spec: apache#2901 (2024-10-06); Parca env file: apache#5377 (2026-10-28) |
| Usage removed by | `searchWorkflows`: apache#1988 (2023-06-12).
`retrieveWorkflowsBySessionUser`: apache#7463 (2026-08-29). `nameWorkflow`:
apache#2920 (2024-10-11). Graph event detail: apache#2301 (2024-01-28). Everything
else: unused since introduction. |

As of 2026-11-25:
- The coeditor argument has gone unread for over 4 years, and the search
client has had no caller for over 2 years.
- The event-tuple detail has been unread for almost 2 years, and
`nameWorkflow` uncalled for over a year.
- The session-user client has been unused for almost 3 months, and the
Parca variables unread for the month since they were added.

### Any related issues, documentation, discussions?

Closes apache#9713.

### How was this PR tested?

Ran on this branch and on `main` at `f4adf7f588` (Windows 11; Node 24
with Yarn 4.14.1; JDK 17):

```bash
cd frontend
npx ng test --watch=false --include='**/workflow-persist.service.spec.ts' --include='**/user-workflow.component.spec.ts' --include='**/context-menu.component.spec.ts' --include='**/coeditor-presence.service.spec.ts' --include='**/joint-graph-wrapper.spec.ts'
npx tsc --noEmit -p src/tsconfig.app.json
npx tsc --noEmit -p src/tsconfig.spec.json
npx ngc -p src/tsconfig.app.json --noEmit
yarn prettier-eslint --list-different $(git diff --name-only --relative origin/main -- src)
yarn eslint $(git diff --name-only --relative origin/main -- src | grep -E '\.(ts|html)$')
cd ..
sbt "Config/testOnly org.apache.texera.observability.ParcaConfigSpec" Config/scalafmtCheckAll "Config/scalafixAll --check"
bash .github/scripts/test_create_release_tarballs.sh
(cd bin/single-node && docker compose config -q)
```

- **Frontend:** the five specs run 301 tests on this branch and 304 on
`main`, all passing.
- The three extra on `main` are the deleted methods' own cases
(`searchWorkflows`, `retrieveWorkflowsBySessionUser` and
`nameWorkflow`). Every other test keeps its name and outcome.
  - Both typechecks, the AOT compile, prettier-eslint and ESLint pass.
- **Parca:** `ParcaConfigSpec` runs 9 tests, all passing on both sides;
four of them now read the Compose command instead of the env file.
scalafmt and scalafix pass. The release-tarball regression test passes,
and `docker compose config` accepts the single-node file.

To re-check, this returns no hits on this branch:

```bash
git grep -nwE "searchWorkflows|retrieveWorkflowsBySessionUser|makeRequestAndFormatWorkflowResponse|WORKFLOW_SEARCH_URL|_async|parca-agent\.env" -- frontend/src bin common/config
```

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend Changes related to the frontend GUI refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants