Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add functionnalities to ConsoleFooter #525

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Display buttons for each OIDC provider and perform user authentication if the global configuration file is declared.
* Draw page:
* Add variables panel in left drawer.
* Add panel to display all errors.
* Select component in error and open its details from the error's console.
* Select file in error and open text editor and selected file open.
* Rename component id.
* Text editor page:
* Add panel to display all errors.
Expand Down
145 changes: 102 additions & 43 deletions src/components/table/ErrorsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,34 @@
:columns="columns"
row-key="message"
data-cy="errors-table"
/>
>
<template #body-cell-component="data">
<q-td :props="data">
<span
class="body-link"
@click="selectComponent(data.row.componentId)"
>
{{ data.value }}
</span>
</q-td>
</template>
<template #body-cell-file="data">
<q-td :props="data">
<span
class="body-link"
@click="selectFile(data.row.path)"
>
{{ data.value }}
</span>
</q-td>
</template>
</q-table>
</template>

<script setup>
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import PluginEvent from 'src/composables/events/PluginEvent';

const { t } = useI18n();

Expand All @@ -27,62 +49,99 @@ const props = defineProps({
});

const columns = computed(() => {
const severityColumn = {
const array = [{
name: 'severity',
align: 'left',
label: t('footer.consoleFooter.errorsTable.severity'),
field: (row) => t(`parser.severity.${row.severity}`),
style: 'width: 2rem',
};
const messageColumn = {
name: 'message',
align: 'left',
label: t('footer.consoleFooter.errorsTable.message'),
field: (row) => t(row.message, {
initialErrorMessage: row.initialErrorMessage,
extraData: row.extraData,
attribute: row.attribute,
}),
};
}];

if (props.editorType === 'text') {
return [
severityColumn,
{
name: 'line',
align: 'center',
label: t('footer.consoleFooter.errorsTable.line'),
field: (row) => `${row.startLineNumber}-${row.endLineNumber}`,
style: 'width: 2rem',
},
{
name: 'column',
align: 'center',
label: t('footer.consoleFooter.errorsTable.column'),
field: (row) => `${row.startColumn}-${row.endColumn}`,
style: 'width: 2rem',
},
messageColumn,
];
}

return [
severityColumn,
{
if (props.editorType === 'diagram') {
array.push({
name: 'component',
align: 'center',
label: t('footer.consoleFooter.errorsTable.component'),
field: (row) => row.componentId,
field: (row) => row.componentName,
style: 'width: 2rem',
},
{
});
array.push({
name: 'attribute',
align: 'center',
label: t('footer.consoleFooter.errorsTable.attribute'),
field: (row) => row.attribute,
style: 'width: 2rem',
},
messageColumn,
];
});
array.push({
name: 'file',
align: 'center',
label: t('footer.consoleFooter.errorsTable.file'),
field: (row) => row.path,
style: 'width: 2rem',
});
}

array.push({
name: 'line',
align: 'center',
label: t('footer.consoleFooter.errorsTable.line'),
field: (row) => `${row.startLineNumber}-${row.endLineNumber}`,
style: 'width: 2rem',
});

array.push({
name: 'column',
align: 'center',
label: t('footer.consoleFooter.errorsTable.column'),
field: (row) => `${row.startColumn}-${row.endColumn}`,
style: 'width: 2rem',
});

array.push({
name: 'message',
align: 'left',
label: t('footer.consoleFooter.errorsTable.message'),
field: (row) => t(row.message, {
initialErrorMessage: row.initialErrorMessage,
extraData: row.extraData,
attribute: row.attribute,
}),
});

return array;
});

/**
* Send event to select component and open its detail panel.
* @param {string} id - Component id.
*/
function selectComponent(id) {
PluginEvent.RequestEvent.next({
type: 'select',
ids: [id],
});
PluginEvent.RequestEvent.next({
type: 'edit',
id,
});
}

/**
* Send event to select file and open it in text editor.
* @param {string} path - File path.
*/
function selectFile(path) {
PluginEvent.RequestEvent.next({
type: 'openFile',
path,
});
}
</script>

<style lang="scss">
.body-link {
color: $info;
text-decoration: underline;
cursor: pointer;
}
</style>
1 change: 1 addition & 0 deletions src/i18n/en-US/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export default {
errorsTable: {
message: 'Message',
line: 'Start/End Line',
file: 'File',
column: 'Start/End Column',
severity: 'Severity',
component: 'Component',
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/ModelizerDrawLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async function initView() {
).then((logs) => {
LogEvent.FileLogEvent.next(logs.map((log) => ({
...log,
componentId: log.componentId ? data.plugin.data.getComponentById(log.componentId).externalId : '',
componentName: log.componentId ? data.plugin.data.getComponentById(log.componentId).externalId : '',
})));
data.plugin.draw();
}),
Expand Down
1 change: 0 additions & 1 deletion src/layouts/ModelizerTextLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
v-model="splitter"
:limits="[50, 100]"
separator-class="separator-class"
:class="isVisible ? '' : 'splitter-invisible'"
:style="{ height: `calc(100vh - ${reservedHeight + 70}px)` }"
>
<template #before>
Expand Down
18 changes: 17 additions & 1 deletion src/pages/ModelizerDrawPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@ import {
reactive,
ref,
} from 'vue';
import { useRoute } from 'vue-router';
import { useRoute, useRouter } from 'vue-router';
import { Notify } from 'quasar';
import { useI18n } from 'vue-i18n';
import PluginEvent from 'src/composables/events/PluginEvent';
import { getTemplatesByType } from 'src/composables/TemplateManager';
import DialogEvent from 'src/composables/events/DialogEvent';
import { ComponentLink } from '@ditrit/leto-modelizer-plugin-core';
import DrawerEvent from 'src/composables/events/DrawerEvent';
import FileEvent from 'src/composables/events/FileEvent';

const { t } = useI18n();
const route = useRoute();
const router = useRouter();

const HAS_BACKEND = computed(() => process.env.HAS_BACKEND);
const projectName = computed(() => route.params.projectName);
Expand Down Expand Up @@ -193,6 +195,20 @@ async function onRequestEvent(event) {
key: 'ComponentDetailPanel',
id: event.id,
});
} else if (event.type === 'select') {
const parent = data.plugin.data.getComponentById(event.ids[0]);
data.plugin.data.scene.selection = event.ids;
data.plugin.data.scene.selectionRef = parent.id;
data.plugin.draw();
} else if (event.type === 'openFile') {
await router.push({
name: 'Text',
params: {
projectName: projectName.value,
},
query: query.value,
});
FileEvent.SelectFileTabEvent.next(event.path);
}

if (needRender) {
Expand Down
41 changes: 39 additions & 2 deletions tests/unit/components/table/ErrorsTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { installQuasarPlugin } from '@quasar/quasar-app-extension-testing-unit-j
import { shallowMount } from '@vue/test-utils';
import i18nConfiguration from 'src/i18n';
import ErrorsTable from 'src/components/table/ErrorsTable.vue';
import PluginEvent from 'src/composables/events/PluginEvent';

installQuasarPlugin();

Expand All @@ -11,6 +12,12 @@ jest.mock('vue-i18n', () => ({
}),
}));

jest.mock('src/composables/events/PluginEvent', () => ({
RequestEvent: {
next: jest.fn(),
},
}));

describe('Test component: ErrorsTable', () => {
let wrapper;
const { createI18n } = jest.requireActual('vue-i18n');
Expand Down Expand Up @@ -44,11 +51,14 @@ describe('Test component: ErrorsTable', () => {
editorType: 'diagram',
});

expect(wrapper.vm.columns.length).toEqual(4);
expect(wrapper.vm.columns.length).toEqual(7);
expect(wrapper.vm.columns[0].name).toEqual('severity');
expect(wrapper.vm.columns[1].name).toEqual('component');
expect(wrapper.vm.columns[2].name).toEqual('attribute');
expect(wrapper.vm.columns[3].name).toEqual('message');
expect(wrapper.vm.columns[3].name).toEqual('file');
expect(wrapper.vm.columns[4].name).toEqual('line');
expect(wrapper.vm.columns[5].name).toEqual('column');
expect(wrapper.vm.columns[6].name).toEqual('message');
});

it('should have valid columns for text page', async () => {
Expand All @@ -63,4 +73,31 @@ describe('Test component: ErrorsTable', () => {
expect(wrapper.vm.columns[3].name).toEqual('message');
});
});

describe('Test function: selectComponent', () => {
it('should emit events', () => {
PluginEvent.RequestEvent.next.mockClear();

wrapper.vm.selectComponent('id_1');

expect(PluginEvent.RequestEvent.next).toHaveBeenCalledTimes(2);
expect(PluginEvent.RequestEvent.next.mock.calls).toEqual([
[{ type: 'select', ids: ['id_1'] }],
[{ type: 'edit', id: 'id_1' }],
]);
});
});

describe('Test function: selectFile', () => {
it('should emit event', () => {
PluginEvent.RequestEvent.next.mockClear();

wrapper.vm.selectFile('path');

expect(PluginEvent.RequestEvent.next).toHaveBeenCalledTimes(1);
expect(PluginEvent.RequestEvent.next.mock.calls).toEqual([
[{ type: 'openFile', path: 'path' }],
]);
});
});
});
Loading
Loading