-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rsd host filter when at least one remote defined and add re…
…mote_rsd_name env variable
- Loading branch information
1 parent
8d3025f
commit a7f69a8
Showing
15 changed files
with
406 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- SPDX-FileCopyrightText: 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
-- SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
-- | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
|
||
-- RSD info table | ||
-- used to obtain RSD name to use for remotes | ||
-- it should provide basic info about rsd instance (eg. endpoints) | ||
CREATE TABLE rsd_info ( | ||
key VARCHAR(100) PRIMARY KEY, | ||
value VARCHAR(250), | ||
created_at TIMESTAMPTZ NOT NULL, | ||
updated_at TIMESTAMPTZ NOT NULL | ||
); | ||
|
||
CREATE FUNCTION sanitise_insert_rsd_info() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
$$ | ||
BEGIN | ||
NEW.created_at = LOCALTIMESTAMP; | ||
NEW.updated_at = NEW.created_at; | ||
return NEW; | ||
END | ||
$$; | ||
|
||
CREATE TRIGGER sanitise_insert_rsd_info BEFORE INSERT ON | ||
rsd_info FOR EACH ROW EXECUTE PROCEDURE sanitise_insert_rsd_info(); | ||
|
||
CREATE FUNCTION sanitise_update_rsd_info() RETURNS TRIGGER LANGUAGE plpgsql AS | ||
$$ | ||
BEGIN | ||
NEW.created_at = OLD.created_at; | ||
NEW.updated_at = LOCALTIMESTAMP; | ||
return NEW; | ||
END | ||
$$; | ||
|
||
CREATE TRIGGER sanitise_update_rsd_info BEFORE UPDATE ON | ||
rsd_info FOR EACH ROW EXECUTE PROCEDURE sanitise_update_rsd_info(); | ||
|
||
-- Insert remote_name key extracted from env variable RSD_REMOTE_NAME | ||
-- add basic endpoints info | ||
INSERT INTO rsd_info VALUES | ||
('remote_name',current_setting('rsd.remote_name')), | ||
('postgrest_api','/api/v1'), | ||
('images_api','/images'), | ||
('swagger','/swagger'), | ||
('codemeta','/metadata/codemeta') | ||
; | ||
|
||
-- RLS | ||
-- rsd info table | ||
ALTER TABLE rsd_info ENABLE ROW LEVEL SECURITY; | ||
-- anyone can read (SELECT) | ||
CREATE POLICY anyone_can_read ON rsd_info FOR SELECT TO rsd_web_anon, rsd_user | ||
USING (TRUE); | ||
-- rsd_admin has all rights | ||
CREATE POLICY admin_all_rights ON rsd_info TO rsd_admin | ||
USING (TRUE) | ||
WITH CHECK (TRUE); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-FileCopyrightText: 2023 - 2024 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (dv4all) | ||
// SPDX-FileCopyrightText: 2023 dv4all | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {useEffect, useState} from 'react' | ||
|
||
import Autocomplete from '@mui/material/Autocomplete' | ||
import TextField from '@mui/material/TextField' | ||
import FilterTitle from './FilterTitle' | ||
import FilterOption from './FilterOption' | ||
|
||
export type SourcesFilterOption = { | ||
source: string | ||
source_cnt: number | ||
} | ||
|
||
type RsdSourceFilterProps = { | ||
sources: string[], | ||
sourcesList: SourcesFilterOption[], | ||
handleQueryChange: (key: string, value: string | string[]) => void | ||
title?: string | ||
} | ||
|
||
export default function RsdSourceFilter({sources, sourcesList,handleQueryChange,title='Host RSD'}: RsdSourceFilterProps) { | ||
const [selected, setSelected] = useState<SourcesFilterOption[]>([]) | ||
const [options, setOptions] = useState<SourcesFilterOption[]>(sourcesList) | ||
|
||
useEffect(() => { | ||
if (sources.length > 0 && sourcesList.length > 0) { | ||
const selected = sourcesList.filter(option => { | ||
return sources.includes(option.source) | ||
}) | ||
setSelected(selected) | ||
} else { | ||
setSelected([]) | ||
} | ||
setOptions(sourcesList) | ||
},[sources,sourcesList]) | ||
|
||
return ( | ||
<div> | ||
<FilterTitle | ||
title={title} | ||
count={sourcesList.length ?? ''} | ||
/> | ||
<Autocomplete | ||
className="mt-4" | ||
value={selected} | ||
size="small" | ||
multiple | ||
clearOnEscape | ||
options={options} | ||
getOptionLabel={(option) => option.source} | ||
isOptionEqualToValue={(option, value) => { | ||
return option.source === value.source | ||
}} | ||
defaultValue={[]} | ||
filterSelectedOptions | ||
renderOption={(props, option) => ( | ||
<FilterOption | ||
key={option.source} | ||
props={props} | ||
label={option.source} | ||
count={option.source_cnt} | ||
/> | ||
)} | ||
renderInput={(params) => ( | ||
<TextField {...params} placeholder={title} /> | ||
)} | ||
onChange={(_, newValue) => { | ||
// extract values into string[] for url query | ||
const queryFilter = newValue.map(item => item.source) | ||
// update query url | ||
handleQueryChange('sources', queryFilter) | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.