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

Structured Citations #464

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
17 changes: 17 additions & 0 deletions src/components/Form/fields/FieldCitations.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Primary, Controls, Stories, Meta, ArgTypes} from '@storybook/blocks';

import * as FieldCitationsStories from './FieldCitations.stories.js';

<Meta of={FieldCitationsStories} />

# FieldCitations

## Usage

A special component to maintain structured citations of publications.

The `value` are an array of Citation objects.

<Primary />
<Controls />
<Stories />
28 changes: 28 additions & 0 deletions src/components/Form/fields/FieldCitations.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import FieldCitations from './FieldCitations.vue';
import FieldCitationsMock from '@/components/Form/mocks/field-citations.js';

const args = {...FieldCitationsMock};

export default {
title: 'Forms/FieldCitations',
component: FieldCitations,
args: {},
parameters: {},
render: (args) => ({
components: {FieldCitations},
setup() {
return {args};
},
template: `
<FieldCitations v-bind="args"/>`,
}),
decorators: [
() => ({
template: '<div style="height: 600px"><story/></div>',
}),
],
};

export const Base = {
args: {...FieldCitationsMock},
};
99 changes: 99 additions & 0 deletions src/components/Form/fields/FieldCitations.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<div class="pkpFormField pkpFormField--citations">
<div class="pkpFormField__heading">
<label class="pkpFormFieldLabel">
user.citations
</label>
</div>
<div class="pkpFormField__description">
user.citations.description
</div>
<div class="pkpFormField__control pkpFormField--affiliations__control">
Structured Citations
</div>
</div>
</template>

<script setup>
import {ref, computed, onMounted, watch, onBeforeUnmount} from 'vue';

/** Define component props */
const props = defineProps({
/** Field key used for form submission */
name: {
type: String,
default: null,
},
/** Current value of the field */
value: {
type: Array,
default: () => [],
},
/** Default locale of the form */
primaryLocale: {
type: String,
default: 'en',
},
/** Locale key for multilingual support */
localeKey: {
type: String,
default: '',
},
/** List of supported locales */
locales: {
type: Array,
default: () => [],
},
/** Object containing all form errors */
allErrors: {
type: Object,
default() {
return {};
},
},
/** Indicates if the field supports multiple languages */
isMultilingual: {
type: Boolean,
default: true,
},
});

/** Emits component events */
const emit = defineEmits(['change', 'set-errors']);

/** Stores the primary locale of the form */
const primaryLocale = props.primaryLocale;

/** Stores the list of supported locales */
const locales = props.locales;

/** Current value of the field, with a setter to emit changes */
const currentValue = computed({
get: () => props.value,
set: (newVal) => emit('change', props.name, 'value', newVal),
});

/** Keys of supported locales */
const supportedFormLocaleKeys = props.locales.map((language) => language.key);

/** Default locale for the application */
const defaultLocale = 'en';

/** Computed property to determine error messages for the field */
computed(() => {
if (!Object.keys(props.allErrors).includes(props.name)) {
return [];
}
let errors = props.allErrors[props.name];
if (props.isMultilingual && Object.keys(errors).includes(props.localeKey)) {
return errors[props.localeKey];
} else if (!props.isMultilingual) {
return errors;
}
return [];
});
</script>

<style lang="less">
@import '../../../styles/_import';
</style>
11 changes: 11 additions & 0 deletions src/components/Form/mocks/field-citations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
name: 'author-citations',
component: 'author-citations',
primaryLocale: 'en',
locales: [
{key: 'en', label: 'English'},
{key: 'fr_CA', label: 'French (Canada)'},
{key: 'de', label: 'German'},
],
value: [],
};