Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-14275] Support custom icons #3473

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cypress/e2e/MainPage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ Feature: User interacts with Main page
Then you see the opt out component for Child Programme
When you opt out to use the new enrollment Dashboard for Child Programme
Then you see the opt in component for Child Programme

@v<41
Scenario: The icon is rendered as an svg
Given you are in the main page with no selections made
When you select Child Programme
Then the icon is rendered as an svg

@v>=41
Scenario: The icon is rendered as a custom icon
Given you are in the main page with no selections made
When you select Child Programme
Then the icon is rendered as a custom icon
12 changes: 12 additions & 0 deletions cypress/e2e/MainPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ And('you can load the view with the name Events assigned to me', () => {
});
});

Then('the icon is rendered as a custom icon', () => {
cy.get('[alt="child_program_positive"]')
.invoke('attr', 'src')
.should('match', /\/icons\/child_program_positive\/icon$/);
});

Then('the icon is rendered as an svg', () => {
cy.get('[alt="child_program_positive"]')
.invoke('attr', 'src')
.should('match', /\/icons\/child_program_positive\/icon.svg$/);
});

Then('the TEI working list is displayed', () => {
cy.get('[data-test="tei-working-lists"]').within(() => {
cy.contains('Rows per page').should('exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
export const FEATURES = Object.freeze({
programStageWorkingList: 'programStageWorkingList',
storeProgramStageWorkingList: 'storeProgramStageWorkingList',
customIcons: 'customIcons',
});

// The first minor version that supports the feature
const MINOR_VERSION_SUPPORT = Object.freeze({
[FEATURES.programStageWorkingList]: 39,
[FEATURES.storeProgramStageWorkingList]: 40,
[FEATURES.customIcons]: 41,
});

export const hasAPISupportForFeature = (minorVersion: string, featureName: string) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// @flow
import React from 'react';
import { useConfig } from '@dhis2/app-runtime';
import { buildUrl } from 'capture-core-utils';
import { buildUrl, FEATURES, useFeature } from 'capture-core-utils';
import { NonBundledIcon } from 'capture-ui';
import type { Props } from './nonBundledDhis2Icon.types';

export const NonBundledDhis2Icon = ({ name, alternativeText = name, ...passOnProps }: Props) => {
const supportCustomIcons = useFeature(FEATURES.customIcons);
const { baseUrl, apiVersion } = useConfig();
const source = name && buildUrl(baseUrl, `api/${apiVersion}/icons/${name}/icon.svg`);
let source;

if (name) {
source = buildUrl(baseUrl, `api/${apiVersion}/icons/${name}/icon`);
// Append .svg to source if supportCustomIcons is false (feature flag v41)
source = supportCustomIcons ? source : `${source}.svg`;
}

return (
<NonBundledIcon
Expand Down
Loading