2020-03-24 14:07:55 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-02-06 07:10:29 -05:00
|
|
|
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-09 02:09:30 -04:00
|
|
|
state.blobs.forEach(({ path, codeNavigationPath }) => {
|
|
|
|
axios
|
|
|
|
.get(codeNavigationPath)
|
|
|
|
.then(({ data }) => {
|
|
|
|
const normalizedData = data.reduce((acc, d) => {
|
|
|
|
if (d.hover) {
|
|
|
|
acc[`${d.start_line}:${d.start_char}`] = d;
|
|
|
|
addInteractionClass(path, d);
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
commit(types.REQUEST_DATA_SUCCESS, { path, normalizedData });
|
|
|
|
})
|
|
|
|
.catch(() => dispatch('requestDataError'));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showBlobInteractionZones({ state }, path) {
|
|
|
|
Object.values(state.data[path]).forEach(d => addInteractionClass(path, d));
|
2020-02-06 07:10:29 -05:00
|
|
|
},
|
|
|
|
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-09 02:09:30 -04:00
|
|
|
const blobEl = el.closest('[data-path]');
|
|
|
|
|
|
|
|
if (!blobEl) {
|
|
|
|
commit(types.SET_CURRENT_DEFINITION, { definition, position });
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-24 14:09:46 -04:00
|
|
|
const blobPath = blobEl.dataset.path;
|
|
|
|
const data = state.data[blobPath];
|
2020-04-09 02:09:30 -04:00
|
|
|
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
if (el.closest('.js-code-navigation') && !isCurrentElementPopoverOpen) {
|
2020-02-06 07:10:29 -05:00
|
|
|
const { lineIndex, charIndex } = el.dataset;
|
2020-04-09 02:09:30 -04:00
|
|
|
const { x, y } = el.getBoundingClientRect();
|
2020-02-06 07:10:29 -05:00
|
|
|
|
|
|
|
position = {
|
2020-04-09 02:09:30 -04:00
|
|
|
x: x || 0,
|
|
|
|
y: y + window.scrollY || 0,
|
2020-02-06 07:10:29 -05:00
|
|
|
height: el.offsetHeight,
|
|
|
|
};
|
2020-04-09 02:09:30 -04:00
|
|
|
definition = data[`${lineIndex}:${charIndex}`];
|
2020-02-06 07:10:29 -05:00
|
|
|
|
|
|
|
el.classList.add('hll');
|
|
|
|
|
|
|
|
setCurrentHoverElement(el);
|
|
|
|
}
|
|
|
|
|
2020-04-24 14:09:46 -04:00
|
|
|
commit(types.SET_CURRENT_DEFINITION, { definition, position, blobPath });
|
2020-02-06 07:10:29 -05:00
|
|
|
},
|
|
|
|
};
|