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

refactor: create text util library #2356

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default {
'<rootDir>/packages/i18n',
'<rootDir>/packages/oembed',
'<rootDir>/packages/portal',
'<rootDir>/packages/utils',
'<rootDir>/packages/vue-router-query',
'<rootDir>/packages/vue-session',
'<rootDir>/packages/vue-visible-on-scroll'
Expand Down
14 changes: 8 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@europeana/oembed": "link:./packages/oembed",
"@europeana/portal": "link:./packages/portal",
"@europeana/style": "link:./packages/style",
"@europeana/utils": "link:./packages/utils",
"@europeana/vue-router-query": "link:./packages/vue-router-query",
"@europeana/vue-session": "link:./packages/vue-session",
"@europeana/vue-visible-on-scroll": "link:./packages/vue-visible-on-scroll"
Expand Down
1 change: 1 addition & 0 deletions packages/portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@elastic/apm-rum-vue": "^1.3.1",
"@europeana/i18n": "^1.150.0",
"@europeana/oembed": "^1.150.0",
"@europeana/utils": "^1.151.2",
"@europeana/vue-router-query": "^1.150.0",
"@europeana/vue-session": "^1.150.0",
"@europeana/vue-visible-on-scroll": "^1.150.0",
Expand Down
9 changes: 5 additions & 4 deletions packages/portal/src/components/content/ContentCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
import SmartLink from '../generic/SmartLink';
import langAttributeMixin from '@/mixins/langAttribute';
import stripMarkdownMixin from '@/mixins/stripMarkdown';
import truncateMixin from '@/mixins/truncate';
import { truncate } from '@europeana/utils';
import { langMapValueForLocale } from '@europeana/i18n';

const HIT_TEXT_AFFIX_MAX_WORDS = 15;
Expand All @@ -139,8 +139,7 @@

mixins: [
langAttributeMixin,
stripMarkdownMixin,
truncateMixin
stripMarkdownMixin
],

props: {
Expand Down Expand Up @@ -420,14 +419,16 @@
},

methods: {
truncate,

cardText(values) {
const limited = (this.limitValuesWithinEachText > -1) ? values.slice(0, this.limitValuesWithinEachText) : [].concat(values);
if (values.length > limited.length) {
limited.push('…');
}
const joined = limited.join('; ');
const stripped = this.stripMarkdown(joined);
return this.truncate(stripped, 255);
return truncate(stripped, 255);
},

redrawMasonry() {
Expand Down
12 changes: 4 additions & 8 deletions packages/portal/src/components/download/DownloadSuccessModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,11 @@
</template>

<script>
import stringify from '@/mixins/stringify';
import { stringify } from '@europeana/utils';

export default {
name: 'DownloadSuccessModal',

mixins: [
stringify
],

props: {
title: {
type: String,
Expand Down Expand Up @@ -90,9 +86,9 @@
data() {
return {
snippetCopied: false,
providerString: this.stringify(this.provider),
creatorString: this.stringify(this.creator),
yearString: this.stringify(this.year)
providerString: stringify(this.provider),
creatorString: stringify(this.creator),
yearString: stringify(this.year)
};
},

Expand Down
7 changes: 3 additions & 4 deletions packages/portal/src/components/entity/EntityHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<script>
import ClientOnly from 'vue-client-only';
import langAttributeMixin from '@/mixins/langAttribute';
import truncateMixin from '@/mixins/truncate';
import { truncate } from '@europeana/utils';
import { getWikimediaThumbnailUrl } from '@/plugins/europeana/entity';
import ShareButton from '@/components/share/ShareButton';
import ShareSocialModal from '@/components/share/ShareSocialModal';
Expand All @@ -112,8 +112,7 @@
},

mixins: [
langAttributeMixin,
truncateMixin
langAttributeMixin
],

props: {
Expand Down Expand Up @@ -197,7 +196,7 @@

computed: {
truncatedDescription() {
return this.truncate(this.fullDescription, this.limitCharacters);
return truncate(this.fullDescription, this.limitCharacters);
},
hasDescription() {
return (this.description?.values?.length || 0) >= 1;
Expand Down
7 changes: 3 additions & 4 deletions packages/portal/src/components/item/ItemSummaryInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<script>
import MetadataOriginLabel from '../metadata/MetadataOriginLabel';
import langAttributeMixin from '@/mixins/langAttribute';
import truncateMixin from '@/mixins/truncate';
import { truncate } from '@europeana/utils';

export default {
name: 'ItemSummaryInfo',
Expand All @@ -87,8 +87,7 @@
},

mixins: [
langAttributeMixin,
truncateMixin
langAttributeMixin
],

props: {
Expand All @@ -114,7 +113,7 @@
},
truncatedDescription() {
if (this.description?.values) {
return this.truncate(this.description.values[0], this.limitCharacters);
return truncate(this.description.values[0], this.limitCharacters);
}
return false;
},
Expand Down
13 changes: 0 additions & 13 deletions packages/portal/src/mixins/stringify.js

This file was deleted.

7 changes: 3 additions & 4 deletions packages/portal/src/pages/item/_.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
} from '@europeana/i18n';
import Item from '@/plugins/europeana/edm/Item.js';
import WebResource from '@/plugins/europeana/edm/WebResource.js';
import stringify from '@/mixins/stringify';
import { stringify } from '@europeana/utils';
import logEventMixin from '@/mixins/logEvent';
import canonicalUrlMixin from '@/mixins/canonicalUrl';
import pageMetaMixin from '@/mixins/pageMeta';
Expand All @@ -175,7 +175,6 @@
},

mixins: [
stringify,
canonicalUrlMixin,
pageMetaMixin,
redirectToMixin,
Expand Down Expand Up @@ -307,8 +306,8 @@
matomoOptions() {
return {
dimension1: langMapValueForLocale(this.metadata.edmCountry, 'en').values[0],
dimension2: this.stringify(langMapValueForLocale(this.metadata.edmDataProvider, 'en').values[0]),
dimension3: this.stringify(langMapValueForLocale(this.metadata.edmProvider, 'en').values[0]),
dimension2: stringify(langMapValueForLocale(this.metadata.edmDataProvider, 'en').values[0]),
dimension3: stringify(langMapValueForLocale(this.metadata.edmProvider, 'en').values[0]),
dimension4: langMapValueForLocale(this.metadata.edmRights, 'en').values[0]
};
},
Expand Down
2 changes: 1 addition & 1 deletion packages/portal/src/plugins/europeana/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pick from 'lodash/pick.js';

import { isLangMap, reduceLangMapsForLocale } from '@europeana/i18n';
import { escapeLuceneSpecials } from './utils.js';
import { truncate } from '../../mixins/truncate.js';
import { truncate } from '@europeana/utils';

// Some facets do not support enquoting of their field values.
export const unquotableFacets = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';
import createHttpError from 'http-errors';

import { errorHandler } from '../utils.js';
import { truncate } from '../../../mixins/truncate.js';
import { truncate } from '@europeana/utils';

const JIRA_SERVICE_DESK_API_PATH = '/rest/servicedeskapi/request';
const JSON_CONTENT_TYPE = 'application/json';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

import { errorHandler } from '../utils.js';
import { truncate } from '../../../mixins/truncate.js';
import { truncate } from '@europeana/utils';

const JIRA_SERVICE_DESK_API_PATH = '/rest/servicedeskapi/request';
const JSON_CONTENT_TYPE = 'application/json';
Expand Down
33 changes: 0 additions & 33 deletions packages/portal/tests/unit/mixins/stringify.spec.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/portal/tests/unit/mixins/truncate.spec.js

This file was deleted.

9 changes: 9 additions & 0 deletions packages/utils/babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Babel config used by Jest, e.g. for unit tests
module.exports = {
presets: [
[
'@babel/preset-env',
{ targets: { node: 'current' } }
]
]
};
18 changes: 18 additions & 0 deletions packages/utils/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
displayName: '@europeana/utils',
moduleFileExtensions: [
'js',
'json',
'mjs'
],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
},
testEnvironment: 'jsdom',
testPathIgnorePatterns: [
'/node_modules/'
],
transform: {
'^.+\\.(js|mjs)$': 'babel-jest'
}
};
12 changes: 12 additions & 0 deletions packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@europeana/utils",
"version": "1.151.2",
"description": "Europeana utility functions",
"license": "EUPL-1.2",
"type": "module",
"sideEffects": false,
"main": "./src/index.js",
"exports": {
".": "./src/index.js"
}
}
7 changes: 7 additions & 0 deletions packages/utils/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import stringify from './text/stringify.js';
import truncate from './text/truncate.js';

export {
stringify,
truncate
};
9 changes: 9 additions & 0 deletions packages/utils/src/text/stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default (field) => {
let stringified = field;

if (field && !Array.isArray(field) && (typeof field === 'object') && field.values) {
stringified = field.values[0];
}

return stringified;
};
Loading
Loading