Skip to content
Snippets Groups Projects

feat: add graphics full tab business logic (MIN-165)

Merged Adrian Orłów requested to merge MIN-165-graphics-full-tab-business-logic into development
9 unresolved threads

Closes MIN-165

Objective:

Implement export graphics tab business logic

What has been done:

  • CheckboxFilter handle radio type
  • ImageFormat component
  • ImageSize component
  • graphics download handler
  • unit tests for all above
Edited by Adrian Orłów

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 import { ZERO } from '@/constants/common';
  • 1 import { ZERO } from '@/constants/common';
    2 import { useAppSelector } from '@/redux/hooks/useAppSelector';
    3 import { loadingModelsSelector, modelsDataSelector } from '@/redux/models/models.selectors';
    4 import { useContext } from 'react';
    5 import { CheckboxFilter } from '../../CheckboxFilter';
    6 import { CollapsibleSection } from '../../CollapsibleSection';
    7 import { ExportContext } from '../ExportCompound.context';
    8
    9 export const Submap = (): React.ReactNode => {
    10 const { setModels, data } = useContext(ExportContext);
    11 const currentModels = data.models;
  • 1 /* eslint-disable react/no-multi-comp */
    • I understand your intention of unit testing hooks (because of pair programming) - thats why this helper exist. I'm still not huge fan of writing big utilities to allow us to test single function cuz it all could be covered in component tests. Approach to testing like this could be part of team discussion in the future - I see it as opportunity to learn.

    • I agree - that's a good point for discussion

    • Please register or sign in to reply
  • 10 export const getGraphicsDownloadUrl = ({
    11 backgroundId,
    12 modelId,
    13 handler,
    14 zoom,
    15 }: GetGraphicsDownloadUrlProps): string | undefined => {
    16 const isAllElementsTruthy = [backgroundId, modelId, handler, zoom].reduce(
    17 (a, b) => Boolean(a) && Boolean(b),
    18 true,
    19 );
    20
    21 if (!isAllElementsTruthy) {
    22 return undefined;
    23 }
    24
    25 return `${BASE_API_URL}/projects/${PROJECT_ID}/models/${modelId}:downloadImage?backgroundOverlayId=${backgroundId}&handlerClass=${handler}&zoomLevel=${zoom}`;
  • 1 import { ZERO } from '@/constants/common';
    2 import { MapModel } from '@/types/models';
    3
    4 const ZOOM_BASE = 6;
    5
    6 export const getModelExportZoom = (exportWidth: number, model?: MapModel): number => {
  • 1 import { Export } from '../ExportCompound';
    • How do you know all components work together to trigger download graphics correctly? If I remove image size component - will functionality still work?

    • Every element is needed, so if any is lacking, data fetch will simply not start

      export const getGraphicsDownloadUrl = ({
        backgroundId,
        modelId,
        handler,
        zoom,
      }: GetGraphicsDownloadUrlProps): string | undefined => {
        const isAllElementsTruthy = [backgroundId, modelId, handler, zoom].reduce(
          (a, b) => Boolean(a) && Boolean(b),
          true,
        );
    • Please register or sign in to reply
  • 89 92 },
    90 93 );
    91 94
    95 export const imageFormatsSelector = createSelector(
    96 configurationMainSelector,
    97 state => state?.imageFormats,
    98 );
    99
    100 export const imageFormatsEntriesSelector = createSelector(
    101 imageFormatsSelector,
    102 (modelFormats): Record<string, ConfigurationFormatSchema> => {
    103 return Object.fromEntries(
    104 (modelFormats || [])
    105 .flat()
    106 .filter((format: ConfigurationFormatSchema): format is ConfigurationFormatSchema =>
  • 91 94
    95 export const imageFormatsSelector = createSelector(
    96 configurationMainSelector,
    97 state => state?.imageFormats,
    98 );
    99
    100 export const imageFormatsEntriesSelector = createSelector(
    101 imageFormatsSelector,
    102 (modelFormats): Record<string, ConfigurationFormatSchema> => {
    103 return Object.fromEntries(
    104 (modelFormats || [])
    105 .flat()
    106 .filter((format: ConfigurationFormatSchema): format is ConfigurationFormatSchema =>
    107 Boolean(format),
    108 )
    109 .map((format: ConfigurationFormatSchema) => [format.name, format]),
  • 1 import { ZERO } from '@/constants/common';
    2
    3 export const numberToInt = (num: number): number => {
  • LGTM. Pair programming session definitely helped me understand code faster. It's clear to see that choosing compound patter didn't work well since submap and image size component are tight together logically.

  • Tadeusz Miesiąc approved this merge request

    approved this merge request

  • I noticed one more thing. I would add margin at the bottom to add some space just bellow download button. It could look a bit better to the user

    image

    Edited by Tadeusz Miesiąc
  • Adrian Orłów added 1 commit

    added 1 commit

    Compare with previous version

  • merged

  • Adrian Orłów mentioned in commit 29618c1f

    mentioned in commit 29618c1f

  • Please register or sign in to reply
    Loading