Skip to content

Commit

Permalink
pkp/pkp-lib#10692 Structured Citations
Browse files Browse the repository at this point in the history
  • Loading branch information
GaziYucel committed Jan 31, 2025
1 parent 47e3d71 commit af51c8a
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
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: [],
};

0 comments on commit af51c8a

Please sign in to comment.