-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: more robust publicAccess filter
- Loading branch information
Showing
5 changed files
with
49 additions
and
3 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
20 changes: 20 additions & 0 deletions
20
src/components/sectionList/filters/filterSelectors/PublicAccessFilter.tsx
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 |
---|---|---|
@@ -1,19 +1,39 @@ | ||
import i18n from '@dhis2/d2-i18n' | ||
import React from 'react' | ||
import { formatPublicAccess, parsePublicAccessString } from '../../../../lib' | ||
import { ConstantSelectionFilter } from './ConstantSelectionFilter' | ||
|
||
// currently we only care about metadata access | ||
// we may want to revist this and potentially rename to "publicMetadataAccess" | ||
// and have another component for data access | ||
const constants = { | ||
'rw------': 'Public can edit', | ||
'r-------': 'Public can view', | ||
'--------': 'Public cannot access', | ||
} | ||
|
||
export const PublicAccessFilter = () => { | ||
const formatFilter = (filter: string | undefined) => { | ||
if (!filter) { | ||
return undefined | ||
} | ||
const parsedPublicAccessString = parsePublicAccessString(filter) | ||
if (!parsedPublicAccessString) { | ||
return undefined | ||
} | ||
const withoutDataAccess = formatPublicAccess({ | ||
metadata: parsedPublicAccessString.metadata, | ||
data: { read: false, write: false }, | ||
}) | ||
return withoutDataAccess | ||
} | ||
|
||
return ( | ||
<ConstantSelectionFilter | ||
label={i18n.t('Public access')} | ||
filterKey="publicAccess" | ||
constants={constants} | ||
formatFilter={formatFilter} | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export { isValidUid } from './uid' | ||
export { parsePublicAccessString } from './parsePublicAccess' | ||
export { | ||
parsePublicAccessString, | ||
formatPublicAccess, | ||
} from './parsePublicAccess' | ||
export { getIn, stringToPathArray, getFieldFilterFromPath } from './path' |
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