-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: file section for configurable products #1619
Open
ivan-kalachikov
wants to merge
24
commits into
dev
Choose a base branch
from
feat/VCST-2796-file-section-configurable-products
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
94feb70
feat: update types
ivan-kalachikov 0bb0c80
feat: update types
ivan-kalachikov 8c0d208
feat: file section for configurable products
ivan-kalachikov ae1d5eb
feat: update jsdoc
ivan-kalachikov 2980223
feat: refactor
ivan-kalachikov 68b7496
feat: add file section validation test cases
ivan-kalachikov 0ea4624
feat: add file section common test cases
ivan-kalachikov 103adb7
feat: add file section common test cases
ivan-kalachikov 94028c6
fix: remove file handling
ivan-kalachikov 7ed5f51
feat: add locales
ivan-kalachikov 8bfc84d
fix: refactor and improve UI
ivan-kalachikov 8f451d8
fix: tests
ivan-kalachikov f90686c
feat: improve file section
ivan-kalachikov cba2ddc
fix: resolve comments
ivan-kalachikov 3a398ad
fix: memoize once fetched options to avoid multi requests
ivan-kalachikov 5e29e6e
fix: move fetching file options inside a lifecycle hook
ivan-kalachikov ca1017f
Merge branch 'dev' into feat/VCST-2796-file-section-configurable-prod…
ivan-kalachikov 47d84a7
Merge branch 'dev' into feat/VCST-2796-file-section-configurable-prod…
ivan-kalachikov c00503d
Merge branch 'dev' into feat/VCST-2796-file-section-configurable-prod…
ivan-kalachikov d4fa0e9
fix: import path
ivan-kalachikov 7e81957
fix: import path
ivan-kalachikov 6b1cc38
fix: import path
ivan-kalachikov 32a4692
fix: locales and minor refactor
ivan-kalachikov a78e469
fix: change files scope
ivan-kalachikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,9 @@ fragment fullLineItem on LineItemType { | |
name | ||
customText | ||
type | ||
files { | ||
name | ||
url | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,12 @@ query GetConfigurationItems( | |
productId | ||
sectionId | ||
type | ||
files { | ||
contentType | ||
name | ||
size | ||
url | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,5 +59,9 @@ fragment orderLineItemFields on OrderLineItemType { | |
name | ||
customText | ||
type | ||
files { | ||
name | ||
url | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
client-app/shared/catalog/components/configuration/option-file.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<template> | ||
<div class="option-file"> | ||
<VcFileUploader | ||
:files="files" | ||
v-bind="fileOptions" | ||
removable | ||
@add-files="onAddFiles" | ||
@remove-files="onRemoveFiles" | ||
@download="onFileDownload" | ||
/> | ||
<div class="option-file__errors"> | ||
<VcAlert | ||
v-for="(file, index) in filesWithErrors" | ||
:key="index" | ||
color="danger" | ||
variant="solid-light" | ||
size="sm" | ||
icon | ||
> | ||
{{ file.errorMessage }} | ||
</VcAlert> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, toRefs, watchEffect } from "vue"; | ||
import { downloadFile, useFiles } from "@/shared/files"; | ||
import { toAttachedFile } from "@/ui-kit/utilities"; | ||
import type { CartConfigurationItemFileType } from "@/core/api/graphql/types"; | ||
import type { DeepReadonly } from "vue"; | ||
|
||
const emit = defineEmits<IEmits>(); | ||
const props = defineProps<IProps>(); | ||
|
||
const { value } = toRefs(props); | ||
|
||
const DEFAULT_FILES_SCOPE = "configuration-files"; | ||
|
||
interface IProps { | ||
value?: DeepReadonly<CartConfigurationItemFileType[]>; | ||
} | ||
|
||
interface IEmits { | ||
(e: "input", value: CartConfigurationItemFileType[]): void; | ||
} | ||
|
||
const initialFiles = computed( | ||
() => value.value?.map((file) => toAttachedFile(file.name, file.size, file.contentType, file.url)) ?? [], | ||
); | ||
|
||
const { | ||
files, | ||
attachedAndUploadedFiles, | ||
addFiles, | ||
validateFiles, | ||
removeFiles, | ||
uploadFiles, | ||
fetchOptions: fetchFileOptions, | ||
options: fileOptions, | ||
} = useFiles(DEFAULT_FILES_SCOPE, initialFiles); | ||
|
||
async function onAddFiles(items: INewFile[]) { | ||
addFiles(items); | ||
validateFiles(); | ||
await uploadFiles(); | ||
emit("input", attachedAndUploadedFiles.value); | ||
} | ||
|
||
const filesWithErrors = computed(() => files.value.filter((file) => file.errorMessage)); | ||
|
||
async function onRemoveFiles(filesToRemove: FileType[]) { | ||
await removeFiles(filesToRemove); | ||
validateFiles(); | ||
emit("input", attachedAndUploadedFiles.value); | ||
} | ||
|
||
function onFileDownload(file: FileType) { | ||
if (file && file.url) { | ||
void downloadFile(file.url, file.name); | ||
} | ||
} | ||
|
||
watchEffect(async () => { | ||
await fetchFileOptions(); | ||
}); | ||
</script> | ||
|
||
<style lang="scss"> | ||
.option-file { | ||
&__errors { | ||
@apply mt-2 flex flex-col gap-2; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why async?
have you tried watchEffect(fetchFileOptions)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just copy-pasted it from similar places. But you are right async is not needed here as well as a watchEffect, removed that. Simple
void fetchFileOptions();
works fine here.