Skip to content

Commit

Permalink
Merge pull request #563 from psarando/CORE-1967-local-contexts-label-…
Browse files Browse the repository at this point in the history
…display

CORE-1967 Initial Local Contexts label display
  • Loading branch information
psarando authored Mar 5, 2024
2 parents a1c492e + d9b1b70 commit 7d0ce9f
Show file tree
Hide file tree
Showing 15 changed files with 662 additions and 64 deletions.
2 changes: 2 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ services:
base: https://www.ebi.ac.uk/ols/api/select
unified_astronomy_thesaurus:
base: https://vocabs.ands.org.au/repository/api/lda/aas/the-unified-astronomy-thesaurus/current/concept.json
local_contexts:
base: https://sandbox.localcontextshub.org/api/v1

grouper:
allUsers: GrouperAll
Expand Down
7 changes: 7 additions & 0 deletions public/static/locales/en/localcontexts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dataHasLocalContextsLabelsNotices": "This data has associated <ExternalLink href=\"https://localcontexts.org\">Local Contexts</ExternalLink> labels or notices.",
"localContextsAttrDefaultValue": "The \"{{projectTitle}}\" project has Labels and/or Notices applied through the Local Contexts Hub. For more information, refer to the project page: {{projectPage}}",
"localContextsHubError": "Error fetching Local Contexts Hub project information.",
"localContextsHubProjectURI": "Local Contexts Hub Project URI",
"projectMoreInfoWithLink": "For more information on the <ExternalLink href=\"https://localcontexts.org\">Local Contexts</ExternalLink> project for this data, please visit the project's page: <ProjectLink>{{projectTitle}}</ProjectLink>"
}
74 changes: 72 additions & 2 deletions src/components/data/listing/Listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ import {
DEFAULTS_MAPPING_QUERY_KEY,
} from "serviceFacades/instantlaunches";

import {
getFilesystemMetadata,
FILESYSTEM_METADATA_QUERY_KEY,
LOCAL_CONTEXTS_QUERY_KEY,
getLocalContextsProject,
} from "serviceFacades/metadata";

import { announce } from "components/announcer/CyVerseAnnouncer";
import { ERROR, INFO } from "components/announcer/AnnouncerConstants";
import buildID from "components/utils/DebugIDUtil";
Expand All @@ -64,7 +71,7 @@ import { useBagAddItems } from "serviceFacades/bags";

import { useQueryClient, useMutation, useQuery } from "react-query";

import { Button, Typography, useTheme } from "@mui/material";
import { Button, Stack, Typography, useTheme } from "@mui/material";
import DEDialog from "components/utils/DEDialog";
import PublicLinks from "../PublicLinks";
import constants from "../../../constants";
Expand All @@ -82,6 +89,12 @@ import {
} from "serviceFacades/dashboard";
import { getUserQuota } from "common/resourceUsage";

import LocalContextsLabelDisplay from "components/metadata/LocalContextsLabelDisplay";
import {
LocalContextsAttrs,
parseProjectID,
} from "components/models/metadata/LocalContexts";

function Listing(props) {
const {
baseId,
Expand All @@ -102,7 +115,7 @@ function Listing(props) {
} = props;
const [config] = useConfig();

const { t } = useTranslation(["data", "common"]);
const { t } = useTranslation(["data", "common", "localcontexts"]);

const [userProfile] = useUserProfile();
const uploadTracker = useUploadTrackingState();
Expand All @@ -112,6 +125,7 @@ function Listing(props) {
const [selected, setSelected] = useState([]);
const [lastSelectIndex, setLastSelectIndex] = useState(-1);
const [data, setData] = useState({ total: 0, listing: [] });
const [localContextsProjectURI, setLocalContextsProjectURI] = useState();
const [detailsEnabled, setDetailsEnabled] = useState(false);
const [detailsOpen, setDetailsOpen] = useState(false);
const [advancedSearchOpen, setAdvancedSearchOpen] = useState(false);
Expand Down Expand Up @@ -204,6 +218,8 @@ function Listing(props) {
path,
});
setData({
id: respData?.id,
label: respData?.label,
total: respData?.total,
permission: respData?.permission,
listing: [
Expand All @@ -217,6 +233,8 @@ function Listing(props) {
})),
].map((i) => camelcaseit(i)), // camelcase the fields for each object, for consistency.
});

setLocalContextsProjectURI(null);
},
});

Expand All @@ -234,6 +252,42 @@ function Listing(props) {
{ exact: true }
);

useQuery({
queryKey: [FILESYSTEM_METADATA_QUERY_KEY, { dataId: data?.id }],
queryFn: () => getFilesystemMetadata({ dataId: data?.id }),
enabled: !!data?.id,
onSuccess: (metadata) => {
const { avus } = metadata;

const rightsURI = avus
?.find((avu) => avu.attr === LocalContextsAttrs.LOCAL_CONTEXTS)
?.avus?.find(
(childAVU) =>
childAVU.attr === LocalContextsAttrs.RIGHTS_URI
)?.value;

setLocalContextsProjectURI(rightsURI);
},
onError: (error) =>
console.log(
"Unable to fetch metadata for folder " + data?.label,
error
), // fail silently.
});

const projectID = parseProjectID(localContextsProjectURI);

const { data: localContextsProject } = useQuery({
queryKey: [LOCAL_CONTEXTS_QUERY_KEY, projectID],
queryFn: () => getLocalContextsProject({ projectID }),
enabled: !!localContextsProjectURI,
onError: (error) =>
console.log("Error fetching Local Contexts project.", {
localContextsProjectURI,
error,
}), // fail silently.
});

const { isFetching: isFetchingDefaultsMapping } = useQuery({
queryKey: [DEFAULTS_MAPPING_QUERY_KEY],
queryFn: getDefaultsMapping,
Expand Down Expand Up @@ -324,6 +378,7 @@ function Listing(props) {

useEffect(() => {
setSelected([]);
setLocalContextsProjectURI(null);
}, [path, rowsPerPage, orderBy, order, page, uploadsCompleted]);

const viewUploadQueue = useCallback(() => {
Expand Down Expand Up @@ -677,6 +732,21 @@ function Listing(props) {
onMoveSelected={onMoveSelected}
uploadsEnabled={uploadsEnabled}
/>
{localContextsProjectURI && localContextsProject && (
<Stack>
<Typography>
<Trans
t={t}
i18nKey="localcontexts:dataHasLocalContextsLabelsNotices"
components={{ ExternalLink: <ExternalLink /> }}
/>
</Typography>
<LocalContextsLabelDisplay
size="large"
project={localContextsProject}
/>
</Stack>
)}
{!isGridView && (
<TableView
loading={isLoading}
Expand Down
Loading

0 comments on commit 7d0ce9f

Please sign in to comment.