Skip to content

Commit

Permalink
fix: show correct org name
Browse files Browse the repository at this point in the history
  • Loading branch information
pooriamehregan committed Jan 26, 2024
1 parent c32edf7 commit 07f8d57
Show file tree
Hide file tree
Showing 8 changed files with 6,792 additions and 11,212 deletions.
17,941 changes: 6,750 additions & 11,191 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
"devDependencies": {
"@babel/core": "^7.20.12",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@storybook/addon-actions": "^6.5.16",
"@storybook/addon-essentials": "^6.5.16",
"@storybook/addon-interactions": "^6.5.16",
"@storybook/addon-links": "^6.5.16",
"@storybook/builder-webpack5": "^6.5.16",
"@storybook/addon-actions": "^7.6.10",
"@storybook/addon-essentials": "^7.6.10",
"@storybook/addon-interactions": "^7.6.10",
"@storybook/addon-links": "^7.6.10",
"@storybook/builder-webpack5": "^7.6.10",
"@storybook/manager-webpack5": "^6.5.16",
"@storybook/react": "^6.5.16",
"@storybook/testing-library": "^0.0.13",
"@storybook/react": "^7.6.10",
"@storybook/testing-library": "^0.2.2",
"@svgr/webpack": "^6.5.1",
"@types/lodash": "^4.14.185",
"@types/node": "^18.11.18",
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@types/styled-components": "^5.1.26",
"axios": "^1.3.1",
"axios": "^1.6.5",
"babel-loader": "^9.1.2",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^11.0.0",
Expand Down Expand Up @@ -79,6 +79,7 @@
"glob-parent": "^5.1.2",
"trim": "^0.0.3",
"trim-newlines": "^3.0.1",
"json5": "^2.2.2"
"json5": "^2.2.2",
"axios": "^1.6.5"
}
}
4 changes: 3 additions & 1 deletion src/context/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum ACTION_TYPE {
ADD_TABLE_HEADER,
SEARCH_IN_DATASETS,
UPDATE_TABLE,
SET_ORGANIZATION_NAME
}

type ACTION =
Expand All @@ -52,6 +53,7 @@ type ACTION =
| { type: ACTION_TYPE.INIT_TABLE; payload: { datasets: Dataset[] } }
| { type: ACTION_TYPE.UPDATE_TABLE; payload: { datasets: Dataset[] } }
| { type: ACTION_TYPE.ADD_TABLE_HEADER; payload: { headerColumns: CellType[] } }
| { type: ACTION_TYPE.ADD_TABLE_ROWS; payload: { rows: RowProps<ColumnProps>[] } };
| { type: ACTION_TYPE.ADD_TABLE_ROWS; payload: { rows: RowProps<ColumnProps>[] } }
| { type: ACTION_TYPE.SET_ORGANIZATION_NAME; payload: string };

export { ACTION, ACTION_TYPE, STATUS };
14 changes: 12 additions & 2 deletions src/context/datasets-context/api-front-back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import env from '../../utils/constants/env';
import AuthService from '../../utils/authentication/auth-service';

const { FDK_REGISTRATION_BASE_URI } = env;
const { FDK_REGISTRATION_BASE_URI, ORGANIZATION_API_HOST } = env;

const getDatasets = async (catalogId: string) => {
try {
Expand Down Expand Up @@ -69,4 +69,14 @@ const createDatasetSeries = async (catalogId: string) => {
}
};

export { createDataset, getDatasets, createDatasetSeries };
const getOrganizationName = async (catalogId: string) => {
try {
return await axios
.get(`${ORGANIZATION_API_HOST}/organizations/${catalogId}`)
.then(response => response?.data?.name);
} catch (error) {
console.error('getOrganizationName() failed!', error);
}
};

export { createDataset, getDatasets, createDatasetSeries, getOrganizationName };
12 changes: 10 additions & 2 deletions src/context/datasets-context/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { FC, PropsWithChildren, useContext, useEffect, useReducer } from 'react';

import { getDatasets } from './api-front-back';
import { getDatasets, getOrganizationName } from './api-front-back';
import { reducer, STATE } from './reducer';
import { ACTION, ACTION_TYPE, STATUS } from '../actions';

const initialState: STATE = { status: STATUS.IDLE, catalogId: '', datasets: [] };
const initialState: STATE = { status: STATUS.IDLE, catalogId: '', organizationName: '', datasets: [] };

// Context
const Context = React.createContext(initialState);
Expand Down Expand Up @@ -33,6 +33,14 @@ const DatasetsContext: FC<PropsWithChildren> = ({ children }) => {
dispatch({ type: ACTION_TYPE.ERROR });
console.error('DatasetsContext failed on getDatasets()!', error);
});
getOrganizationName(state.catalogId)
.then(organizationName => {
dispatch({ type: ACTION_TYPE.SET_ORGANIZATION_NAME, payload: organizationName ?? '' });
})
.catch(error => {
dispatch({ type: ACTION_TYPE.ERROR });
console.error('DatasetsContext failed on getOrganizationName()!', error);
});
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/context/datasets-context/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ACTION, ACTION_TYPE, STATUS } from '../actions';
import { produce } from 'immer';
import { createDataset, createDatasetSeries } from './api-front-back';

type STATE = { status: STATUS; catalogId: string; datasets: Dataset[]; newlyCreatedDatasetPromise?: Promise<Dataset> };
type STATE = { status: STATUS; catalogId: string; organizationName: string; datasets: Dataset[]; newlyCreatedDatasetPromise?: Promise<Dataset> };

const reducer = produce((state: STATE, action: ACTION) => {
switch (action.type) {
Expand All @@ -21,6 +21,9 @@ const reducer = produce((state: STATE, action: ACTION) => {
case ACTION_TYPE.ADD_CATALOG_ID:
state.catalogId = action.payload;
return state;
case ACTION_TYPE.SET_ORGANIZATION_NAME:
state.organizationName = action.payload;
return state;
case ACTION_TYPE.ADD_DATASET:
state.datasets.push(action.payload.dataset);
state.newlyCreatedDatasetPromise = undefined;
Expand Down
8 changes: 2 additions & 6 deletions src/pages/datasets-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@ const delayTableLoad = async (promise: Promise<typeof import('./populated-table'
};

const DatasetsPage: FC = () => {
let pageSubtitle = 'Mangler tittel';
const datasetsContext = useDatasetsContext();

if (datasetsContext.datasets?.length && datasetsContext.datasets?.length > 0)
pageSubtitle = datasetsContext.datasets[0]?.publisher.name;

const { catalogId } = useParams();
const datasetsContext = useDatasetsContext();
const pageSubtitle = datasetsContext.organizationName ?? localization.missingName;
const datasetsDispatch = useDatasetsDispatch();

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/language/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const nb = {
catalogType: 'Datasettkatalog',
dataVillage: ['Datalandsbyen', 'Lenke til Datalandsbyen'],
harvestData: ['Høste data', 'Lenke til å høste data'],
missingName: 'Mangler navn',
registerData: ['Registrere data', 'Lenke til å registrere data'],
searchForDataset: 'Søk etter datasettbeskrivelse',
searchInCatalogs: ['Søk i Felles datakatalog', 'Lenke til søk i felles datakatalog'],
Expand Down

0 comments on commit 07f8d57

Please sign in to comment.