@drodil/backstage-plugin-qeta-react 3.28.0 → 3.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils/utils.esm.js
CHANGED
|
@@ -103,10 +103,14 @@ const useConfirmNavigationIfEdited = (edited) => {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
window.addEventListener("beforeunload", handleBeforeUnload);
|
|
106
|
-
|
|
106
|
+
if ("navigation" in window && window.navigation) {
|
|
107
|
+
window.navigation.addEventListener("navigate", handleLocationChange);
|
|
108
|
+
}
|
|
107
109
|
return () => {
|
|
108
110
|
window.removeEventListener("beforeunload", handleBeforeUnload);
|
|
109
|
-
|
|
111
|
+
if ("navigation" in window && window.navigation) {
|
|
112
|
+
window.navigation.removeEventListener("navigate", handleLocationChange);
|
|
113
|
+
}
|
|
110
114
|
};
|
|
111
115
|
}, [edited, msg]);
|
|
112
116
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils/utils.ts"],"sourcesContent":["import { Entity, stringifyEntityRef } from '@backstage/catalog-model';\nimport { Filters } from '../components/FilterPanel/FilterPanel';\nimport FileType from 'file-type';\nimport { ErrorApi } from '@backstage/core-plugin-api';\nimport { QetaApi } from '@drodil/backstage-plugin-qeta-common';\nimport { useEffect } from 'react';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { qetaTranslationRef } from '../translation.ts';\n\nexport const imageUpload = (opts: {\n qetaApi: QetaApi;\n errorApi: ErrorApi;\n onImageUpload?: (id: number) => void;\n postId?: number;\n answerId?: number;\n collectionId?: number;\n}) => {\n const { qetaApi, errorApi, onImageUpload, postId, answerId, collectionId } =\n opts;\n // eslint-disable-next-line func-names\n return async function* (data: ArrayBuffer) {\n const fileType = await FileType.fromBuffer(data);\n\n const mimeType = fileType ? fileType.mime : 'text/plain';\n const attachment = await qetaApi.postAttachment(\n new Blob([data], { type: mimeType }),\n { postId, answerId, collectionId },\n );\n if ('errors' in attachment) {\n errorApi.post({\n name: 'Upload failed',\n message: attachment.errors?.map(e => e.message).join(', ') ?? '',\n });\n return false;\n }\n onImageUpload?.(attachment.id);\n yield attachment.locationUri;\n return true;\n };\n};\n\nexport const formatEntityName = (username?: string) => {\n if (!username) {\n return '';\n }\n const plainName = username.split(/[/:]+/).pop();\n return plainName\n ?.split(/[_.-]+/)\n .map(a => a.charAt(0).toUpperCase() + a.slice(1))\n .join(' ');\n};\n\nexport const getEntityTitle = (\n entity: Entity,\n opts?: { withType: boolean },\n): string => {\n const { withType } = opts || { withType: true };\n const stringified = stringifyEntityRef(entity);\n return `${\n entity.metadata.title ?? formatEntityName(stringified) ?? stringified\n }${withType && entity.spec?.type ? ` (${entity.spec.type})` : ''}`;\n};\n\nexport const formatDate = (localDate: Date) => {\n let date: any = localDate.getDate();\n let month: any = localDate.getMonth() + 1;\n if (date < 10) {\n date = `0${date}`;\n }\n\n if (month < 10) {\n month = `0${month}`;\n }\n return `${localDate.getFullYear()}-${month}-${date}`;\n};\n\nexport type FiltersWithDateRange = Filters & {\n fromDate: string;\n toDate: string;\n};\n\nexport const getFiltersWithDateRange = (filters: Filters) => {\n let filtersWithDateRange: FiltersWithDateRange;\n const to = new Date();\n const from = new Date(to);\n if (filters.dateRange) {\n let fromDate = '';\n let toDate = '';\n\n switch (filters.dateRange) {\n case '7-days':\n toDate = formatDate(to);\n from.setDate(to.getDate() - 6);\n fromDate = formatDate(from);\n break;\n\n case '30-days':\n toDate = formatDate(to);\n from.setDate(to.getDate() - 29);\n fromDate = formatDate(from);\n break;\n default:\n if (filters.dateRange.indexOf('--') > 0) {\n fromDate = filters.dateRange.split('--')[0];\n toDate = filters.dateRange.split('--')[1];\n }\n break;\n }\n if (fromDate && toDate) {\n filtersWithDateRange = { ...filters, fromDate, toDate };\n delete filtersWithDateRange.dateRange;\n return filtersWithDateRange;\n }\n }\n\n if ('dateRange' in filters) {\n delete filters.dateRange;\n }\n\n return filters;\n};\n\nexport const useConfirmNavigationIfEdited = (edited: boolean) => {\n const { t } = useTranslationRef(qetaTranslationRef);\n const msg = t('common.unsaved_changes');\n useEffect(() => {\n const handleBeforeUnload = (event: BeforeUnloadEvent) => {\n if (edited) {\n event.preventDefault();\n event.returnValue = msg; // Included for legacy support, e.g. Chrome/Edge < 119\n }\n };\n\n const handleLocationChange = (event: any) => {\n if (edited) {\n // eslint-disable-next-line no-alert\n const response = window.confirm(msg);\n if (!response) {\n event.preventDefault();\n }\n }\n };\n\n window.addEventListener('beforeunload', handleBeforeUnload);\n // @ts-ignore\n
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../src/utils/utils.ts"],"sourcesContent":["import { Entity, stringifyEntityRef } from '@backstage/catalog-model';\nimport { Filters } from '../components/FilterPanel/FilterPanel';\nimport FileType from 'file-type';\nimport { ErrorApi } from '@backstage/core-plugin-api';\nimport { QetaApi } from '@drodil/backstage-plugin-qeta-common';\nimport { useEffect } from 'react';\nimport { useTranslationRef } from '@backstage/core-plugin-api/alpha';\nimport { qetaTranslationRef } from '../translation.ts';\n\nexport const imageUpload = (opts: {\n qetaApi: QetaApi;\n errorApi: ErrorApi;\n onImageUpload?: (id: number) => void;\n postId?: number;\n answerId?: number;\n collectionId?: number;\n}) => {\n const { qetaApi, errorApi, onImageUpload, postId, answerId, collectionId } =\n opts;\n // eslint-disable-next-line func-names\n return async function* (data: ArrayBuffer) {\n const fileType = await FileType.fromBuffer(data);\n\n const mimeType = fileType ? fileType.mime : 'text/plain';\n const attachment = await qetaApi.postAttachment(\n new Blob([data], { type: mimeType }),\n { postId, answerId, collectionId },\n );\n if ('errors' in attachment) {\n errorApi.post({\n name: 'Upload failed',\n message: attachment.errors?.map(e => e.message).join(', ') ?? '',\n });\n return false;\n }\n onImageUpload?.(attachment.id);\n yield attachment.locationUri;\n return true;\n };\n};\n\nexport const formatEntityName = (username?: string) => {\n if (!username) {\n return '';\n }\n const plainName = username.split(/[/:]+/).pop();\n return plainName\n ?.split(/[_.-]+/)\n .map(a => a.charAt(0).toUpperCase() + a.slice(1))\n .join(' ');\n};\n\nexport const getEntityTitle = (\n entity: Entity,\n opts?: { withType: boolean },\n): string => {\n const { withType } = opts || { withType: true };\n const stringified = stringifyEntityRef(entity);\n return `${\n entity.metadata.title ?? formatEntityName(stringified) ?? stringified\n }${withType && entity.spec?.type ? ` (${entity.spec.type})` : ''}`;\n};\n\nexport const formatDate = (localDate: Date) => {\n let date: any = localDate.getDate();\n let month: any = localDate.getMonth() + 1;\n if (date < 10) {\n date = `0${date}`;\n }\n\n if (month < 10) {\n month = `0${month}`;\n }\n return `${localDate.getFullYear()}-${month}-${date}`;\n};\n\nexport type FiltersWithDateRange = Filters & {\n fromDate: string;\n toDate: string;\n};\n\nexport const getFiltersWithDateRange = (filters: Filters) => {\n let filtersWithDateRange: FiltersWithDateRange;\n const to = new Date();\n const from = new Date(to);\n if (filters.dateRange) {\n let fromDate = '';\n let toDate = '';\n\n switch (filters.dateRange) {\n case '7-days':\n toDate = formatDate(to);\n from.setDate(to.getDate() - 6);\n fromDate = formatDate(from);\n break;\n\n case '30-days':\n toDate = formatDate(to);\n from.setDate(to.getDate() - 29);\n fromDate = formatDate(from);\n break;\n default:\n if (filters.dateRange.indexOf('--') > 0) {\n fromDate = filters.dateRange.split('--')[0];\n toDate = filters.dateRange.split('--')[1];\n }\n break;\n }\n if (fromDate && toDate) {\n filtersWithDateRange = { ...filters, fromDate, toDate };\n delete filtersWithDateRange.dateRange;\n return filtersWithDateRange;\n }\n }\n\n if ('dateRange' in filters) {\n delete filters.dateRange;\n }\n\n return filters;\n};\n\nexport const useConfirmNavigationIfEdited = (edited: boolean) => {\n const { t } = useTranslationRef(qetaTranslationRef);\n const msg = t('common.unsaved_changes');\n useEffect(() => {\n const handleBeforeUnload = (event: BeforeUnloadEvent) => {\n if (edited) {\n event.preventDefault();\n event.returnValue = msg; // Included for legacy support, e.g. Chrome/Edge < 119\n }\n };\n\n const handleLocationChange = (event: any) => {\n if (edited) {\n // eslint-disable-next-line no-alert\n const response = window.confirm(msg);\n if (!response) {\n event.preventDefault();\n }\n }\n };\n\n window.addEventListener('beforeunload', handleBeforeUnload);\n if ('navigation' in window && window.navigation) {\n // @ts-ignore\n window.navigation.addEventListener('navigate', handleLocationChange);\n }\n\n return () => {\n window.removeEventListener('beforeunload', handleBeforeUnload);\n if ('navigation' in window && window.navigation) {\n // @ts-ignore\n window.navigation.removeEventListener('navigate', handleLocationChange);\n }\n };\n }, [edited, msg]);\n};\n"],"names":[],"mappings":";;;;;;AASa,MAAA,WAAA,GAAc,CAAC,IAOtB,KAAA;AACJ,EAAA,MAAM,EAAE,OAAS,EAAA,QAAA,EAAU,eAAe,MAAQ,EAAA,QAAA,EAAU,cAC1D,GAAA,IAAA;AAEF,EAAA,OAAO,iBAAiB,IAAmB,EAAA;AACzC,IAAA,MAAM,QAAW,GAAA,MAAM,QAAS,CAAA,UAAA,CAAW,IAAI,CAAA;AAE/C,IAAM,MAAA,QAAA,GAAW,QAAW,GAAA,QAAA,CAAS,IAAO,GAAA,YAAA;AAC5C,IAAM,MAAA,UAAA,GAAa,MAAM,OAAQ,CAAA,cAAA;AAAA,MAC/B,IAAI,KAAK,CAAC,IAAI,GAAG,EAAE,IAAA,EAAM,UAAU,CAAA;AAAA,MACnC,EAAE,MAAQ,EAAA,QAAA,EAAU,YAAa;AAAA,KACnC;AACA,IAAA,IAAI,YAAY,UAAY,EAAA;AAC1B,MAAA,QAAA,CAAS,IAAK,CAAA;AAAA,QACZ,IAAM,EAAA,eAAA;AAAA,QACN,OAAA,EAAS,UAAW,CAAA,MAAA,EAAQ,GAAI,CAAA,CAAA,CAAA,KAAK,EAAE,OAAO,CAAA,CAAE,IAAK,CAAA,IAAI,CAAK,IAAA;AAAA,OAC/D,CAAA;AACD,MAAO,OAAA,KAAA;AAAA;AAET,IAAA,aAAA,GAAgB,WAAW,EAAE,CAAA;AAC7B,IAAA,MAAM,UAAW,CAAA,WAAA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GAAG,CAAC,CAAA;AAClB;;;;"}
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"frontend",
|
|
8
8
|
"backstage.io"
|
|
9
9
|
],
|
|
10
|
-
"version": "3.28.
|
|
10
|
+
"version": "3.28.1",
|
|
11
11
|
"main": "dist/index.esm.js",
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"prepublishOnly": "yarn tsc && yarn build",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@backstage/plugin-permission-common": "^0.9.0",
|
|
58
58
|
"@backstage/plugin-permission-react": "^0.4.34",
|
|
59
59
|
"@backstage/plugin-signals-react": "^0.0.13",
|
|
60
|
-
"@drodil/backstage-plugin-qeta-common": "^3.28.
|
|
60
|
+
"@drodil/backstage-plugin-qeta-common": "^3.28.1",
|
|
61
61
|
"@jsdevtools/rehype-toc": "^3.0.2",
|
|
62
62
|
"@material-ui/core": "^4.12.2",
|
|
63
63
|
"@material-ui/icons": "^4.11.3",
|