Skip to content

Commit

Permalink
Merge branch 'main' into 263-polygon-coordinates-to-bounding-box-coor…
Browse files Browse the repository at this point in the history
…dinates
  • Loading branch information
fostermh committed Dec 6, 2023
2 parents 9615890 + 2f92363 commit 39985e7
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "cioos-metadata-form"
}
}
23 changes: 23 additions & 0 deletions .github/workflows/firebase-hosting-delete-channel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Close PR delete firebase channel
on:
pull_request:
types: [closed]
jobs:
delete_firebase_channel:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- id: get-short-name
run: |
id=$(echo ${{github.event.pull_request.head.ref}} | cut -c 1-20)
echo "id=$id" >> $GITHUB_OUTPUT
- name: Delete Preview Channel on Firebase
uses: w9jds/firebase-action@master
with:
args: hosting:channel:delete pr${{github.event.number}}-${{steps.get-short-name.outputs.id}} --force
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
PROJECT_ID: cioos-metadata-form
GITHUB_AUTH: ${{ secrets.ISSUE_CREATOR_PAT }}
39 changes: 39 additions & 0 deletions .github/workflows/firebase-hosting-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This file was auto-generated by the Firebase CLI
# https://github.com/firebase/firebase-tools

name: Deploy to Firebase Hosting on PR
'on':
pull_request:
workflow_dispatch:
jobs:
build_and_preview:
if: '${{ github.event.pull_request.head.repo.full_name == github.repository }}'
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Install and Build 🔧
env:
NODE_OPTIONS: --openssl-legacy-provider
REACT_APP_DEV_DEPLOYMENT: true
PUBLIC_URL: /
run: npm ci && npm run build
- uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: '${{ secrets.GITHUB_TOKEN }}'
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_CIOOS_METADATA_FORM }}'
expires: 30d
entryPoint: '.'
projectId: cioos-metadata-form
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
GMAIL_USER: ${{ secrets.GMAIL_USER }}
GMAIL_PASS: ${{ secrets.GMAIL_PASS }}
DATACITE_USER: ${{ secrets.DATACITE_USER }}
DATACITE_PASS: ${{ secrets.DATACITE_PASS }}
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESSKEYID: ${{ secrets.AWS_ACCESSKEYID }}
AWS_SECRETACCESSKEY: ${{ secrets.AWS_SECRETACCESSKEY }}
GITHUB_AUTH: ${{ secrets.ISSUE_CREATOR_PAT }}
PROJECT_PATH: ./firebase-functions
REACT_APP_DEV_DEPLOYMENT: true
62 changes: 62 additions & 0 deletions .github/workflows/netlify_deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Netlify Deploy a Preview URL In PR Comment

env:
DEPLOY_DIRECTORY: ./build

on:
pull_request:
paths:
- "src/**"

jobs:
build-deploy-preview:
timeout-minutes: 15
concurrency:
group: ci-${{ github.ref }}
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Install and Build 🔧
env:
NODE_OPTIONS: --openssl-legacy-provider
run: |
npm ci
npm run build
- name: install netlify cli and deploy to preview mode
id: deploy-preview
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
SENTRY_ENVIRONMENT: "netlify"
run: |
npm install netlify-cli@13 -g
COMMAND="netlify deploy --prod --dir=$DEPLOY_DIRECTORY"
OUTPUT=$(sh -c "$COMMAND")
NETLIFY_OUTPUT=$(echo "$OUTPUT")
NETLIFY_PREVIEW_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://[a-zA-Z0-9./?=_-]*(--)[a-zA-Z0-9./?=_-]*')
NETLIFY_LOGS_URL=$(echo "$OUTPUT" | grep -Eo '(http|https)://app.netlify.com/[a-zA-Z0-9./?=_-]*')
echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> $GITHUB_OUTPUT
echo "NETLIFY_LOGS_URL=$NETLIFY_LOGS_URL" >> $GITHUB_OUTPUT
shell: bash

- name: find the netlify information comment
uses: peter-evans/[email protected]
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Netlify Preview Deployment Information

- name: create or update comment
uses: peter-evans/[email protected]
id: update-comment
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Netlify Preview Deployment Information
- Log URL: ${{ steps.deploy-preview.outputs.NETLIFY_LOGS_URL }}
- Preview URL: ${{ steps.deploy-preview.outputs.NETLIFY_PREVIEW_URL }}
edit-mode: replace
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
2 changes: 1 addition & 1 deletion src/components/FormComponents/MetadataRecordListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const MetadataRecordListItem = ({
} else if (fileType === "erddap") {
data = [recordToERDDAP(record)];
} else if (fileType === "json") {
data = [JSON.stringify(recordToDataCite(record), null, 2)];
data = [JSON.stringify(recordToDataCite(record, language, region), null, 2)];
} else {
const res = await downloadRecord({ record, fileType });
data = Object.values(res.data.message);
Expand Down
27 changes: 16 additions & 11 deletions src/components/Tabs/IdentificationTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import RequiredMark from "../FormComponents/RequiredMark";
import SelectInput from "../FormComponents/SelectInput";
import licenses from "../../utils/licenses";
import recordToDataCite from "../../utils/recordToDataCite";
import { validateField, doiRegexp } from "../../utils/validate";
import { validateField, validateDOI } from "../../utils/validate";

import {
QuestionText,
Expand All @@ -44,9 +44,8 @@ const IdentificationTab = ({
const { createDraftDoi, updateDraftDoi, deleteDraftDoi } = useContext(UserContext);
const { language, region, userID } = useParams();
const regionInfo = regions[region];
const doiIsValid = Boolean(
!record.datasetIdentifier || doiRegexp.test(record.datasetIdentifier)
);
const doiIsValid =validateDOI(record.datasetIdentifier)

const languageUpperCase = language.toUpperCase();
const [doiGenerated, setDoiGenerated] = useState(false);
const [doiErrorFlag, setDoiErrorFlag] = useState(false);
Expand Down Expand Up @@ -89,13 +88,13 @@ const IdentificationTab = ({
})
.then(async (attributes) => {
// Update the record object with datasetIdentifier and doiCreationStatus
updateRecord("datasetIdentifier")(attributes.doi);
updateRecord("datasetIdentifier")(`https://doi.org/${attributes.doi}`);
updateRecord("doiCreationStatus")("draft");

// Create a new object with updated properties
const updatedRecord = {
...record,
datasetIdentifier: attributes.doi,
datasetIdentifier: `https://doi.org/${attributes.doi}`,
doiCreationStatus: "draft",
};

Expand Down Expand Up @@ -134,8 +133,11 @@ const IdentificationTab = ({
delete mappedDataCiteObject.data.type;
delete mappedDataCiteObject.data.attributes.prefix;

// Extract DOI from the full URL
const doi = record.datasetIdentifier.replace('https://doi.org/', '');

const dataObject = {
doi: record.datasetIdentifier,
doi,
data: mappedDataCiteObject,
}

Expand All @@ -161,7 +163,10 @@ const IdentificationTab = ({
setLoadingDoiDelete(true);

try {
deleteDraftDoi(record.datasetIdentifier)
// Extract DOI from the full URL
const doi = record.datasetIdentifier.replace('https://doi.org/', '');

deleteDraftDoi(doi)
.then((response) => response.data)
.then(async (statusCode) => {
if (statusCode === 204) {
Expand Down Expand Up @@ -732,7 +737,7 @@ const IdentificationTab = ({
Loading...
</>
) : (
"Generate Draft DOI"
"Generate DOI"
)}
</div>
</Button>
Expand All @@ -749,7 +754,7 @@ const IdentificationTab = ({
Loading...
</>
) : (
"Update Draft DOI"
"Update DOI"
)}
</div>
</Button>
Expand All @@ -766,7 +771,7 @@ const IdentificationTab = ({
Loading...
</>
) : (
"Delete Draft DOI"
"Delete DOI"
)}
</div>
</Button>
Expand Down
6 changes: 4 additions & 2 deletions src/utils/emlTemplate.j2
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@
<!-- TODO GCMD and another? -->
<keywordThesaurus>GCMD</keywordThesaurus>
</keywordSet>
{% if record.license != "None" %}
<intellectualRights>
<para>
This work is licensed under
<ulink url="{{ licenses[record.license]?.url }}">
<citetitle>{{ licenses[record.license]?.title }}</citetitle>
<ulink url="{{ licenses[record.license].url }}">
<citetitle>{{ licenses[record.license].title }}</citetitle>
</ulink>
.
</para>
</intellectualRights>
{% endif %}
<distribution scope="document">
<online>
<url function="information">{{ record.datasetIdentifier }}</url>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function isValidHttpUrl(string) {

return url.protocol === "http:" || url.protocol === "https:";
}

export const validateDOI = (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val));
const validateLatitude = (num) => num >= -90 && num <= 90;

const deepCompare = (obj1, obj2) =>
Expand Down Expand Up @@ -81,7 +81,7 @@ const validators = {
},
},
datasetIdentifier: {
validation: (val) => !val || (doiRegexp.test(val) && isValidHttpUrl(val)),
validation: validateDOI,
optional: true,
tab: "dataID",
error: {
Expand Down

0 comments on commit 39985e7

Please sign in to comment.