Skip to content

Commit

Permalink
Merge pull request konfuzio-ai#235 from konfuzio-ai/10879-details-link
Browse files Browse the repository at this point in the history
Add customizable document details link
  • Loading branch information
PedroDinis authored Dec 19, 2023
2 parents eefc404 + 1cc7ad2 commit ce67004
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ VUE_APP_DOCUMENT_IMAGES_URL=
# Document id to fetch and show on the app
VUE_APP_DOCUMENT_ID=

# Link to the document details page; if empty there will be no details link
VUE_APP_DOCUMENT_DETAILS_URL=

# User token to access API endpoints that require authentication
VUE_APP_GUEST_USER_TOKEN=

# SENTRY_DSN and ENVIRONMENT e.g. "https://[email protected]/1234567"; can be left empty
VUE_APP_SENTRY_DSN=
VUE_APP_SENTRY_ENVIRONMENT=
VUE_APP_SENTRY_ENVIRONMENT=

# translations default lang
VUE_APP_I18N_LOCALE=
VUE_APP_I18N_FALLBACK_LOCALE=

# Path to app's list of documents if it exists
VUE_APP_DOCUMENTS_LIST_PATH=
VUE_APP_DOCUMENTS_LIST_PATH=
16 changes: 16 additions & 0 deletions src/components/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export default {
required: false,
default: "",
},
// eslint-disable-next-line vue/prop-name-casing
details_url: {
type: String,
required: false,
default: "",
},
},
computed: {
documentId() {
Expand Down Expand Up @@ -115,6 +121,15 @@ export default {
return null;
}
},
detailsUrl() {
if (process.env.VUE_APP_DOCUMENT_DETAILS_URL) {
return process.env.VUE_APP_DOCUMENT_DETAILS_URL;
} else if (this.details_url) {
return this.details_url;
} else {
return null;
}
},
},
created() {
// Sentry config
Expand Down Expand Up @@ -156,6 +171,7 @@ export default {
// document and project config
Promise.all([
this.$store.dispatch("display/setDetailsUrl", this.detailsUrl),
this.$store.dispatch("document/setDocId", this.documentId),
this.$store.dispatch("document/setPublicView", this.isPublicView),
this.$store.dispatch(
Expand Down
16 changes: 3 additions & 13 deletions src/components/DocumentTopBar/DocumentName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@
<span>{{ saved ? $t("saved") : $t("not_saved") }}</span>
</div>

<div
v-if="showDetailsButton"
class="details-btn btn"
@click="openDocumentDetails"
>
<div v-if="detailsUrl" class="details-btn btn" @click="openDocumentDetails">
{{ $t("document_details") }}
</div>
</div>
Expand All @@ -71,7 +67,6 @@
import ServerImage from "../../assets/images/ServerImage";
import FileNameSaved from "../../assets/images/FileNameSavedImage";
import FileNameNotSaved from "../../assets/images/FileNameNotSavedImage";
import { isKonfuzioDomain, getDocumentDetailsLink } from "../../utils/utils";
import { mapGetters, mapState } from "vuex";
export default {
Expand Down Expand Up @@ -101,19 +96,14 @@ export default {
saved: false,
};
},
computed: {
showDetailsButton() {
return isKonfuzioDomain();
},
},
computed: {
...mapState("document", [
"selectedDocument",
"publicView",
"recalculatingAnnotations",
"documentId",
]),
...mapState("display", ["optimalResolution"]),
...mapState("display", ["optimalResolution", "detailsUrl"]),
...mapState("edit", ["editMode"]),
...mapGetters("document", ["isDocumentReviewed"]),
textContent() {
Expand Down Expand Up @@ -245,7 +235,7 @@ export default {
}
},
openDocumentDetails() {
window.location.href = getDocumentDetailsLink(this.documentId);
window.location.href = this.detailsUrl;
},
},
};
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"edit": "Edit",
"rename": "Rename",
"save": "Save",
"details": "Details",
"autosaving": "Auto saving...",
"saved": "Saved",
"not_saved": "Could not save. Try again",
Expand Down
8 changes: 8 additions & 0 deletions src/store/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const state = {
searchResults: [],
searchLoading: false,
currentSearchResult: null,
detailsUrl: null,
};

const getters = {
Expand Down Expand Up @@ -291,6 +292,10 @@ const actions = {
commit("SET_PAGE_CHANGED_FROM_THUMBNAIL", value);
},

setDetailsUrl: ({ commit }, value) => {
commit("SET_DETAILS_URL", value);
},

debounceSearch: debounce(({ commit, dispatch }, query) => {
dispatch("search", query);
}, 300),
Expand Down Expand Up @@ -409,6 +414,9 @@ const mutations = {
SET_CURRENT_SEARCH_RESULT: (state, n) => {
state.currentSearchResult = n;
},
SET_DETAILS_URL: (state, value) => {
state.detailsUrl = value;
},
};

export default {
Expand Down
9 changes: 0 additions & 9 deletions src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ export function navigateToDocumentsList(path, projectId, userId) {
return true;
}

export function isKonfuzioDomain() {
return window.location.hostname.includes("konfuzio.com");
}

export function getDocumentDetailsLink(docId) {
const domain = window.location.hostname;
return `https://${domain}/admin/server/document/${docId}/change`;
}

export function isElementArray(element) {
return Array.isArray(element);
}

0 comments on commit ce67004

Please sign in to comment.