Skip to content

Commit

Permalink
fix: improve organisation filtering and remove unused code.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmijatovic committed Oct 7, 2022
1 parent bd1696e commit 2989b38
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 138 deletions.
2 changes: 1 addition & 1 deletion frontend/components/projects/edit/organisations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export default function ProjectOrganisations({slug}: { slug: string }) {
const resp = await deleteOrganisationFromProject({
project: project.id,
organisation: organisation.id,
role: 'participating',
role: organisation.role ?? 'participating',
token: session.token
})
if (resp.status === 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function useParticipatingOrganisations({project, token, account}: UsePart
project,
token,
frontend: true,
role:'participating'
roles:['participating','hosting']
})
// collect isMaintainerRequests
const promises:Promise<boolean>[] = []
Expand Down
1 change: 1 addition & 0 deletions frontend/types/Organisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type FundingOrganisation = SearchOrganisation

// extending with other props for software edit page
export type EditOrganisation = SearchOrganisation & {
role?: OrganisationRole,
position?: number
// new image to upload
logo_b64: string | null
Expand Down
24 changes: 17 additions & 7 deletions frontend/utils/editOrganisation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import {AutocompleteOption} from '../types/AutocompleteOptions'
import {
EditOrganisation, Organisation,
OrganisationRole,
OrganisationsForSoftware,
SearchOrganisation, SoftwareForOrganisation
} from '../types/Organisation'
Expand Down Expand Up @@ -574,22 +575,31 @@ export function updateDataObjectAfterSave({data, id}:
return data
}

export function newOrganisationProps({name, position, primary_maintainer, is_tenant = false, parent=null}:
{ name: string, position: number, primary_maintainer: string | null, is_tenant?: boolean, parent?:string|null}) {
type NewOrganisation = {
name: string
position: number
primary_maintainer: string | null
role?: OrganisationRole
is_tenant?: boolean
parent?: string | null
}

export function newOrganisationProps(props: NewOrganisation) {
const initOrg = {
id: null,
parent,
name,
is_tenant,
parent: props?.parent ?? null,
name: props.name,
is_tenant: props?.is_tenant ?? false,
slug: null,
ror_id: null,
position,
position: props.position,
logo_b64: null,
logo_mime_type: null,
logo_id: null,
website: null,
source: 'MANUAL' as 'MANUAL',
primary_maintainer,
primary_maintainer: props.primary_maintainer,
role: props?.role ?? 'participating',
canEdit: false
}
return initOrg
Expand Down
133 changes: 4 additions & 129 deletions frontend/utils/getProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import {RelatedSoftwareOfProject} from '~/types/SoftwareTypes'
import {getUrlFromLogoId} from './editOrganisation'
import {extractCountFromHeader} from './extractCountFromHeader'
import {createJsonHeaders} from './fetchHelpers'
import {getPropsFromObject} from './getPropsFromObject'
import logger from './logger'
import {paginationUrlParams} from './postgrestUrl'
import {sortOnStrProp} from './sortFn'

export async function getProjectList({url, token}: { url: string, token?: string }) {
try {
Expand Down Expand Up @@ -53,74 +50,6 @@ export async function getProjectList({url, token}: { url: string, token?: string
}
}
}

// export async function getProjectList({rows=12,page=0,baseUrl='/api/v1',searchFor,token}:
// {rows: number, page: number, baseUrl?: string, searchFor?: string,token?:string}
// ){
// try {
// const columns = 'id,slug,title,subtitle,date_start,date_end,updated_at,is_published,image_for_project(project)'
// let url = `${baseUrl}/project?select=${columns}`
// // search
// if (searchFor) {
// url += `&or=(title.ilike.*${searchFor}*,subtitle.ilike.*${searchFor}*))`
// }
// // order, by default on updated_at descending
// // use also id to prevent repeating records
// // see https://stackoverflow.com/questions/13580826/postgresql-repeating-rows-from-limit-offset
// url +='&order=updated_at.desc,title,id'
// // pagination
// url += paginationUrlParams({rows, page})

// const resp = await fetch(url, {
// method: 'GET',
// headers: {
// ...createJsonHeaders(token),
// // request record count to be returned
// // note: it's returned in the header
// 'Prefer': 'count=exact'
// }
// })

// if ([200,206].includes(resp.status)){
// const json: RawProject[] = await resp.json()
// const data = prepareData(json)
// return {
// count: extractCountFromHeader(resp.headers),
// data
// }
// } else{
// logger(`getProjectList failed: ${resp.status} ${resp.statusText}`, 'warn')
// return {
// count:0,
// data:[]
// }
// }
// }catch(e:any){
// logger(`getProjectList: ${e?.message}`,'error')
// return {
// count:0,
// data:[]
// }
// }
// }

// export function prepareData(json:RawProject[]) {
// const data:Project[] = json.map(item => {
// const project = getPropsFromObject(item, [
// 'id', 'slug',
// 'title',
// 'subtitle',
// 'date_start',
// 'date_end',
// 'updated_at',
// 'is_published'
// ])
// project['image_id'] = extractImageInfo(item)
// return project
// })
// return data
// }

export function extractImageInfo(item: RawProject) {
if (item.image_for_project && item.image_for_project.length > 0) {
return item.image_for_project[0].project
Expand Down Expand Up @@ -178,11 +107,11 @@ export function getImageUrl(image_id:string|null) {
}


export async function getOrganisationsOfProject({project, token, frontend = true, role}:
{ project: string, token: string, frontend?: boolean, role?: OrganisationRole }) {
export async function getOrganisationsOfProject({project, token, frontend = true, roles}:
{ project: string, token: string, frontend?: boolean, roles?: OrganisationRole[] }) {
try {
let query = `rpc/organisations_of_project?project_id=${project}&order=name.asc`
if (role) query += `&role=eq.${role}`
if (roles) query += `&role=in.(${roles.toString()})`
// SSR request within docker network
let url = `${process.env.POSTGREST_URL}/${query}`
if (frontend) {
Expand All @@ -208,7 +137,7 @@ export async function getOrganisationsOfProject({project, token, frontend = true
}

export async function getOrganisations({project, token, frontend = true}:
{project: string, token: string, frontend?: boolean }) {
{ project: string, token: string, frontend?: boolean}) {
const resp = await getOrganisationsOfProject({project, token, frontend})
// filter only approved organisations
// extract only properties used
Expand Down Expand Up @@ -249,60 +178,6 @@ export function getProjectStatus({date_start, date_end}:
}
}

// PHAISED OUT - WE USE RESEARCH DOMAINS AND KEYWORDS
// export async function getTagsForProject({project, token, frontend=false}:
// {project: string, token: string, frontend?: boolean }
// ) {
// try {
// // this request is always perfomed from backend
// // the content is order by tag ascending
// let url = `${process.env.POSTGREST_URL}/tag_for_project?project=eq.${project}&order=tag.asc`
// if (frontend === true) {
// url = `/api/v1/tag_for_project?project=eq.${project}&order=tag.asc`
// }
// const resp = await fetch(url, {
// method: 'GET',
// headers: createJsonHeaders(token)
// })
// if (resp.status === 200) {
// const data: ProjectTag[] = await resp.json()
// return data.map(item=>item.tag)
// }
// logger(`getTopicForProject: [${resp.status}] ${resp.statusText}`, 'warn')
// return []
// } catch (e: any) {
// logger(`getTagsForProject: ${e?.message}`, 'error')
// return []
// }
// }

// PHAISED OUT - WE USE RESEARCH DOMAINS AND KEYWORDS
// export async function getTopicsForProject({project, token, frontend = false}:
// { project: string, token: string, frontend?: boolean }
// ) {
// try {
// // this request is always perfomed from backend
// // the content is order by tag ascending
// let url = `${process.env.POSTGREST_URL}/topic_for_project?project=eq.${project}&order=topic.asc`
// if (frontend === true) {
// url = `/api/v1/topic_for_project?project=eq.${project}&order=topic.asc`
// }
// const resp = await fetch(url, {
// method: 'GET',
// headers: createJsonHeaders(token)
// })
// if (resp.status === 200) {
// const data: ProjectTopic[] = await resp.json()
// return data.map(item => item.topic)
// }
// logger(`getTopicsForProject: [${resp.status}] ${resp.statusText}`, 'warn')
// return []
// } catch (e: any) {
// logger(`getTopicsForProject: ${e?.message}`, 'error')
// return []
// }
// }

export async function getResearchDomainsForProject({project, token, frontend = false}:
{ project: string, token: string, frontend?: boolean }
) {
Expand Down

0 comments on commit 2989b38

Please sign in to comment.