Skip to content

Commit 7a9316b

Browse files
author
GitLab Bot
committed
Add latest changes from gitlab-org/gitlab@master
1 parent 5ba562e commit 7a9316b

File tree

53 files changed

+1601
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1601
-149
lines changed

app/assets/javascripts/observability/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ export const DATE_RANGE_END_QUERY_KEY = 'date_end';
5252
export const TIMESTAMP_QUERY_KEY = 'timestamp';
5353

5454
export const FILTERED_SEARCH_TERM_QUERY_KEY = 'search';
55+
56+
export const UTC_FULL_DATE_TIME_FORMAT = `UTC:mmm dd yyyy HH:MM:ss.l Z`;
57+
export const UTC_SHORT_DATE_TIME_FORMAT = `UTC:mmm dd yyyy HH:MM:ss Z`;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
query getBlobSearchQuery(
2+
$search: String!
3+
$groupId: GroupID
4+
$projectId: ProjectID
5+
$page: Int
6+
$chunkCount: Int
7+
$regex: Boolean
8+
) {
9+
blobSearch(
10+
search: $search
11+
groupId: $groupId
12+
projectId: $projectId
13+
page: $page
14+
chunkCount: $chunkCount
15+
regex: $regex
16+
) {
17+
fileCount
18+
files {
19+
blameUrl
20+
chunks {
21+
lines {
22+
lineNumber
23+
richText
24+
text
25+
}
26+
matchCountInChunk
27+
}
28+
fileUrl
29+
matchCount
30+
matchCountTotal
31+
path
32+
projectPath
33+
}
34+
matchCount
35+
perPage
36+
searchLevel
37+
searchType
38+
}
39+
}

app/assets/javascripts/search/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { initSearchSort } from './sort';
66
import createStore from './store';
77
import { initTopbar } from './topbar';
88
import { initBlobRefSwitcher } from './under_topbar';
9+
import { SEARCH_TYPE_ZOEKT, SCOPE_BLOB } from './sidebar/constants/index';
10+
import { initZoektBlobResult } from './results/index';
911

1012
const sidebarInitState = () => {
1113
const el = document.getElementById('js-search-sidebar');
@@ -67,4 +69,12 @@ export const initSearchApp = () => {
6769

6870
setHighlightClass(query.search); // Code Highlighting
6971
initBlobRefSwitcher(); // Code Search Branch Picker
72+
73+
if (
74+
searchType === SEARCH_TYPE_ZOEKT &&
75+
store.getters.currentScope === SCOPE_BLOB &&
76+
gon.features.zoektMultimatchFrontend
77+
) {
78+
initZoektBlobResult(store);
79+
}
7080
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<script>
2+
// eslint-disable-next-line no-restricted-imports
3+
import { mapState, mapGetters } from 'vuex';
4+
import { __ } from '~/locale';
5+
import { SCOPE_BLOB, SEARCH_TYPE_ZOEKT } from '~/search/sidebar/constants/index';
6+
import ZoektBlobResults from '~/search/results/components/zoekt_blob_results.vue';
7+
8+
export default {
9+
name: 'GlobalSearchResultsApp',
10+
i18n: {
11+
headerText: __('Search results'),
12+
},
13+
components: {
14+
ZoektBlobResults,
15+
},
16+
computed: {
17+
...mapState(['searchType']),
18+
...mapGetters(['currentScope']),
19+
isBlobScope() {
20+
return this.currentScope === SCOPE_BLOB;
21+
},
22+
isZoektSearch() {
23+
return this.searchType === SEARCH_TYPE_ZOEKT;
24+
},
25+
},
26+
};
27+
</script>
28+
29+
<template>
30+
<section>
31+
<zoekt-blob-results v-if="isBlobScope && isZoektSearch" />
32+
</section>
33+
</template>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<script>
2+
import { GlLoadingIcon } from '@gitlab/ui';
3+
// eslint-disable-next-line no-restricted-imports
4+
import { mapState } from 'vuex';
5+
import { createAlert } from '~/alert';
6+
import { __, s__ } from '~/locale';
7+
import getBlobSearchQuery from '~/search/graphql/blob_search_zoekt.query.graphql';
8+
import { convertToGraphQLId } from '~/graphql_shared/utils';
9+
10+
import {
11+
DEFAULT_FETCH_CHUNKS,
12+
PROJECT_GRAPHQL_ID_TYPE,
13+
GROUP_GRAPHQL_ID_TYPE,
14+
SEARCH_RESULTS_DEBOUNCE,
15+
} from '~/search/results/constants';
16+
17+
export default {
18+
name: 'ZoektBlobResults',
19+
components: {
20+
GlLoadingIcon,
21+
},
22+
i18n: {
23+
headerText: __('Search results'),
24+
blobDataFetchError: s__(
25+
'GlobalSearch|Could not load search results. Please refresh the page to try again.',
26+
),
27+
},
28+
data() {
29+
return {
30+
hasError: false,
31+
blobSearch: [],
32+
};
33+
},
34+
apollo: {
35+
blobSearch: {
36+
query() {
37+
return getBlobSearchQuery;
38+
},
39+
variables() {
40+
return {
41+
search: this.query.search,
42+
groupId:
43+
this.query.group_id && convertToGraphQLId(GROUP_GRAPHQL_ID_TYPE, this.query.group_id),
44+
projectId:
45+
this.query.project_id &&
46+
convertToGraphQLId(PROJECT_GRAPHQL_ID_TYPE, this.query.project_id),
47+
page: this.query.page,
48+
chunkCount: DEFAULT_FETCH_CHUNKS,
49+
regex: this.query.regex ? JSON.parse(this.query.regex) : false,
50+
};
51+
},
52+
result({ data }) {
53+
this.blobSearch = data?.blobSearch;
54+
this.hasError = false;
55+
},
56+
debounce: SEARCH_RESULTS_DEBOUNCE,
57+
error(error) {
58+
this.hasError = true;
59+
createAlert({
60+
message: this.$options.i18n.blobDataFetchError,
61+
captureError: true,
62+
error,
63+
});
64+
},
65+
},
66+
},
67+
computed: {
68+
...mapState(['query']),
69+
isLoading() {
70+
return this.$apollo.queries.blobSearch.loading;
71+
},
72+
},
73+
};
74+
</script>
75+
76+
<template>
77+
<div class="gl-flex gl-justify-center gl-flex-col">
78+
<gl-loading-icon v-if="isLoading" size="sm" />
79+
</div>
80+
</template>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const DEFAULT_FETCH_CHUNKS = 50;
2+
export const PROJECT_GRAPHQL_ID_TYPE = 'Project';
3+
export const GROUP_GRAPHQL_ID_TYPE = 'Group';
4+
export const SEARCH_RESULTS_DEBOUNCE = 500;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Vue from 'vue';
2+
import VueApollo from 'vue-apollo';
3+
import { defaultClient } from '~/graphql_shared/issuable_client';
4+
import GlobalSearchResults from './components/app.vue';
5+
6+
Vue.use(VueApollo);
7+
8+
const apolloProvider = new VueApollo({
9+
defaultClient,
10+
});
11+
12+
export const initZoektBlobResult = (store) => {
13+
const el = document.getElementById('js-search-zoekt-blob-results');
14+
if (!el) return false;
15+
16+
return new Vue({
17+
el,
18+
name: 'GlobalSearchResults',
19+
store,
20+
apolloProvider,
21+
render(createElement) {
22+
return createElement(GlobalSearchResults);
23+
},
24+
});
25+
};

app/assets/javascripts/search/store/actions.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import Api from '~/api';
22
import { createAlert } from '~/alert';
33
import axios from '~/lib/utils/axios_utils';
4-
import { visitUrl, setUrlParams, getNormalizedURL } from '~/lib/utils/url_utility';
4+
import { visitUrl, setUrlParams, getNormalizedURL, updateHistory } from '~/lib/utils/url_utility';
55
import { logError } from '~/lib/logger';
66
import { __ } from '~/locale';
77
import { LABEL_FILTER_PARAM } from '~/search/sidebar/components/label_filter/data';
8-
import { SCOPE_BLOB } from '~/search/sidebar/constants';
8+
import { SCOPE_BLOB, SEARCH_TYPE_ZOEKT } from '~/search/sidebar/constants';
99
import {
1010
GROUPS_LOCAL_STORAGE_KEY,
1111
PROJECTS_LOCAL_STORAGE_KEY,
@@ -102,7 +102,7 @@ export const setFrequentProject = ({ state, commit }, item) => {
102102
commit(types.LOAD_FREQUENT_ITEMS, { key: PROJECTS_LOCAL_STORAGE_KEY, data: frequentItems });
103103
};
104104

105-
export const setQuery = ({ state, commit }, { key, value }) => {
105+
export const setQuery = ({ state, commit, getters }, { key, value }) => {
106106
commit(types.SET_QUERY, { key, value });
107107
if (SIDEBAR_PARAMS.includes(key)) {
108108
commit(types.SET_SIDEBAR_DIRTY, isSidebarDirty(state.query, state.urlQuery));
@@ -111,6 +111,15 @@ export const setQuery = ({ state, commit }, { key, value }) => {
111111
if (key === REGEX_PARAM) {
112112
setDataToLS(LS_REGEX_HANDLE, value);
113113
}
114+
115+
if (
116+
state.searchType === SEARCH_TYPE_ZOEKT &&
117+
getters.currentScope === SCOPE_BLOB &&
118+
gon.features.zoektMultimatchFrontend
119+
) {
120+
const newUrl = setUrlParams({ ...state.query, page: null }, window.location.href, false, true);
121+
updateHistory({ state: state.query, url: newUrl, replace: true });
122+
}
114123
};
115124

116125
export const applyQuery = ({ state }) => {

0 commit comments

Comments
 (0)