2020-04-22 19:07:51 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-03-13 15:44:24 +05:30
|
|
|
import * as types from './mutation_types';
|
|
|
|
import { getCurrentHoverElement, setCurrentHoverElement, addInteractionClass } from '../utils';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
setInitialData({ commit }, data) {
|
|
|
|
commit(types.SET_INITIAL_DATA, data);
|
|
|
|
},
|
|
|
|
requestDataError({ commit }) {
|
|
|
|
commit(types.REQUEST_DATA_ERROR);
|
|
|
|
},
|
|
|
|
fetchData({ commit, dispatch, state }) {
|
|
|
|
commit(types.REQUEST_DATA);
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
state.blobs.forEach(({ path, codeNavigationPath }) => {
|
|
|
|
axios
|
|
|
|
.get(codeNavigationPath)
|
|
|
|
.then(({ data }) => {
|
|
|
|
const normalizedData = data.reduce((acc, d) => {
|
|
|
|
if (d.hover) {
|
2020-07-28 23:09:34 +05:30
|
|
|
acc[`${d.start_line}:${d.start_char}`] = {
|
|
|
|
...d,
|
|
|
|
definitionLineNumber: parseInt(d.definition_path?.split('#L').pop() || 0, 10),
|
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
addInteractionClass(path, d);
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
commit(types.REQUEST_DATA_SUCCESS, { path, normalizedData });
|
|
|
|
})
|
|
|
|
.catch(() => dispatch('requestDataError'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showBlobInteractionZones({ state }, path) {
|
2020-05-24 23:13:21 +05:30
|
|
|
if (state.data && state.data[path]) {
|
|
|
|
Object.values(state.data[path]).forEach(d => addInteractionClass(path, d));
|
|
|
|
}
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
showDefinition({ commit, state }, { target: el }) {
|
|
|
|
let definition;
|
|
|
|
let position;
|
|
|
|
|
|
|
|
if (!state.data) return;
|
|
|
|
|
|
|
|
const isCurrentElementPopoverOpen = el.classList.contains('hll');
|
|
|
|
|
|
|
|
if (getCurrentHoverElement()) {
|
|
|
|
getCurrentHoverElement().classList.remove('hll');
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
const blobEl = el.closest('[data-path]');
|
|
|
|
|
|
|
|
if (!blobEl) {
|
|
|
|
commit(types.SET_CURRENT_DEFINITION, { definition, position });
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const blobPath = blobEl.dataset.path;
|
|
|
|
const data = state.data[blobPath];
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
if (el.closest('.js-code-navigation') && !isCurrentElementPopoverOpen) {
|
2020-03-13 15:44:24 +05:30
|
|
|
const { lineIndex, charIndex } = el.dataset;
|
2020-04-22 19:07:51 +05:30
|
|
|
const { x, y } = el.getBoundingClientRect();
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
position = {
|
2020-04-22 19:07:51 +05:30
|
|
|
x: x || 0,
|
|
|
|
y: y + window.scrollY || 0,
|
2020-03-13 15:44:24 +05:30
|
|
|
height: el.offsetHeight,
|
2020-07-28 23:09:34 +05:30
|
|
|
lineIndex: parseInt(lineIndex, 10),
|
2020-03-13 15:44:24 +05:30
|
|
|
};
|
2020-04-22 19:07:51 +05:30
|
|
|
definition = data[`${lineIndex}:${charIndex}`];
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
el.classList.add('hll');
|
|
|
|
|
|
|
|
setCurrentHoverElement(el);
|
|
|
|
}
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
commit(types.SET_CURRENT_DEFINITION, { definition, position, blobPath });
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
};
|