Skip to content

Commit b45bb93

Browse files
committed
PATCH: fix(visa): properly handle visa on document with history
1 parent 260c300 commit b45bb93

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/components/specific/files/visas-table/VisasTable.vue

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,18 @@ import { computed, watch, ref } from "vue";
9494
import { useI18n } from "vue-i18n";
9595
import { useStandardBreakpoints } from "../../../../composables/responsive.js";
9696
import { VISA_STATUS, VALIDATION_STATUS } from "../../../../config/visa.js";
97-
import { enhanceVisa } from "../../../../utils/visas.js";
9897
import { useFiles } from "../../../../state/files.js";
99-
98+
import { useProjects } from "../../../../state/projects.js";
10099
import { useUser } from "../../../../state/user.js";
101100
import { fullName } from "../../../../utils/users.js";
101+
import { enhanceVisa } from "../../../../utils/visas.js";
102102
import columnsDef, { columnsLG, columnsXL, columnsXXL } from "./columns.js";
103103
104104
import UserAvatarList from "../../users/user-avatar-list/UserAvatarList.vue";
105105
import VisaActionsCell from "./visa-actions-cell/VisaActionsCell.vue";
106106
import FilePathCell from "../files-table/file-path-cell/FilePathCell.vue";
107107
import VisaValidatorCell from "./visa-validator-cell/VisaValidatorCell.vue";
108+
108109
export default {
109110
components: {
110111
UserAvatarList,
@@ -118,7 +119,6 @@ export default {
118119
},
119120
visas: {
120121
type: Array,
121-
default: () => [],
122122
required: true,
123123
},
124124
selection: {
@@ -128,13 +128,23 @@ export default {
128128
emits: ["delete", "file-clicked", "go-folders-view", "reach-visa", "selection-changed"],
129129
setup(props) {
130130
const { t } = useI18n();
131-
const { user } = useUser();
132131
const { isLG, isXL, isXXL } = useStandardBreakpoints();
133132
133+
const { user } = useUser();
134+
const { currentProject } = useProjects();
134135
const { fileStructureHandler: handler } = useFiles();
135136
136-
const enhancedVisas = computed(() =>
137-
props.visas.map((visa) => enhanceVisa(visa, user.value, t, handler)),
137+
const enhancedVisas = ref([]);
138+
watch(
139+
() => props.visas,
140+
async () => {
141+
enhancedVisas.value = await Promise.all(
142+
props.visas.map((visa) => enhanceVisa(visa, user.value, currentProject.value, t, handler))
143+
).then(
144+
visas => visas.filter(visa => !!visa)
145+
);
146+
},
147+
{ immediate: true }
138148
);
139149
140150
const columns = computed(() => {
@@ -202,9 +212,9 @@ export default {
202212
203213
return {
204214
columns,
215+
enhancedVisas,
205216
user,
206217
fullName,
207-
enhancedVisas,
208218
isCreator,
209219
isDelay,
210220
statusClasses,

src/components/specific/visa/visa-summary/VisaSummary.vue

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<BIMDataTextbox
157157
class="visa-summary__shell__file__content__name"
158158
:text="formatedVisa.document.name"
159-
@click="$emit('preview-visa', formatedVisa.document.file)"
159+
@click="$emit('preview-visa', formatedVisa.document)"
160160
width="calc(100% - 20px - 12px * 3)"
161161
/>
162162
</div>
@@ -169,8 +169,8 @@
169169
height="40px"
170170
@click="
171171
$emit('reach-file', {
172-
...formatedVisa.document,
173-
nature: formatedVisa.document.model_id ? 'Model' : 'Document',
172+
id: formatedVisa.document.head_id ?? formatedVisa.document.id,
173+
nature: 'Document',
174174
})
175175
"
176176
>
@@ -296,10 +296,6 @@ export default {
296296
...visa.creator,
297297
fullName: visa.creator ? fullName(visa.creator) : t("Visa.summary.deletedUser"),
298298
},
299-
document: {
300-
...visa.document,
301-
file: handler.get({ id: visa.document.id, nature: "Document" }),
302-
},
303299
validations: visa.validations
304300
.map((validation) => ({
305301
...validation,

src/utils/visas.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { fullName } from "./users.js";
21
import { VISA_STATUS, VALIDATION_STATUS } from "../config/visa.js";
2+
import FileService from "../services/FileService.js";
3+
import { fullName } from "./users.js";
34

45
const safeFullName = (user) => (user ? fullName(user) : "");
56

6-
export const enhanceVisa = (visa, user, t, handler) => {
7+
export const enhanceVisa = async (visa, user, project, t, handler) => {
78
const validationType = () => {
89
if (visa.status === VISA_STATUS.CLOSE) {
910
return t("Visa.view.visaClosed");
@@ -39,10 +40,19 @@ export const enhanceVisa = (visa, user, t, handler) => {
3940
return emailValidators;
4041
};
4142

42-
const document = handler.get({
43-
id: visa.document.head_id ?? visa.document.id,
44-
nature: "Document",
45-
});
43+
let document
44+
try {
45+
document = handler.get({
46+
id: visa.document.id,
47+
nature: "Document",
48+
});
49+
if (!document) {
50+
document = await FileService.getDocument(project, { id: visa.document_id });
51+
}
52+
} catch (error) {
53+
console.error("[Visa Utils]", error);
54+
}
55+
if (!document) return;
4656

4757
return {
4858
...visa,

0 commit comments

Comments
 (0)